source: xtideuniversalbios/trunk/XTIDE_Universal_BIOS/Src/Initialization/Interrupts.asm@ 121

Last change on this file since 121 was 120, checked in by Tomi Tilli, 14 years ago

Changes to XTIDE Universal BIOS:

  • Display library now gets initialized.
  • Small optimizations.
  • Something is still broken.
File size: 7.1 KB
RevLine 
[90]1; Project name : XTIDE Universal BIOS
[33]2; Description : Functions for initializing the BIOS.
3
4; Section containing code
5SECTION .text
6
7;--------------------------------------------------------------------
8; Interrupts_InitializeInterruptVectors
9; Parameters:
10; DS: RAMVARS segment
11; ES: BDA and Interrupt Vector segment (zero)
12; Returns:
13; Nothing
14; Corrupts registers:
15; All except segments
[86]16;--------------------------------------------------------------------
[33]17Interrupts_InitializeInterruptVectors:
[97]18 ; Fall to .InitializeInt13hAnd40h
[33]19
20;--------------------------------------------------------------------
[97]21; .InitializeInt13hAnd40h
[33]22; Parameters:
23; DS: RAMVARS segment
24; ES: BDA and Interrupt Vector segment (zero)
25; Returns:
26; Nothing
27; Corrupts registers:
28; AX, BX, CX, DX, SI, DI
[86]29;--------------------------------------------------------------------
[97]30.InitializeInt13hAnd40h:
[33]31 mov ax, [es:INTV_DISK_FUNC*4] ; Load old INT 13h offset
32 mov dx, [es:INTV_DISK_FUNC*4+2] ; Load old INT 13h segment
33 mov [RAMVARS.fpOldI13h], ax ; Store old INT 13h offset
34 mov [RAMVARS.fpOldI13h+2], dx ; Store old INT 13h segment
35 mov bx, INTV_DISK_FUNC ; INT 13h interrupt vector offset
36 mov si, Int13h_DiskFunctions ; Interrupt handler offset
37 call Interrupts_InstallHandlerToVectorInBXFromCSSI
38
39 ; Only store INT 13h handler to 40h if 40h is not already installed.
40 ; At least AMI BIOS for 286 stores 40h handler by itself and calls
41 ; 40h from 13h. That system locks to infinite loop if we copy 13h to 40h.
42 call FloppyDrive_IsInt40hInstalled
[97]43 jc SHORT .InitializeInt19h
44 mov [es:INTV_FLOPPY_FUNC*4], ax ; Store old INT 13h offset
45 mov [es:INTV_FLOPPY_FUNC*4+2], dx ; Store old INT 13h segment
46 ; Fall to .InitializeInt19h
[33]47
48;--------------------------------------------------------------------
[97]49; .InitializeInt19h
[33]50; Parameters:
51; DS: RAMVARS segment
52; ES: BDA and Interrupt Vector segment (zero)
53; Returns:
54; Nothing
55; Corrupts registers:
56; BX, SI
[86]57;--------------------------------------------------------------------
[97]58.InitializeInt19h:
[90]59 mov bx, INTV_BOOTSTRAP
[33]60 mov si, Int19hMenu_BootLoader
[97]61 call Interrupts_InstallHandlerToVectorInBXFromCSSI
62 ; Fall to .InitializeHardwareIrqHandlers
[33]63
64;--------------------------------------------------------------------
[97]65; .InitializeHardwareIrqHandlers
[33]66; Parameters:
67; ES: BDA and Interrupt Vector segment (zero)
68; Returns:
69; Nothing
70; Corrupts registers:
71; BX, CX, DX, SI, DI
[86]72;--------------------------------------------------------------------
[97]73.InitializeHardwareIrqHandlers:
[33]74 call RamVars_GetIdeControllerCountToCX
75 mov di, ROMVARS.ideVars0 ; CS:SI points to first IDEVARS
76.IdeControllerLoop:
77 eMOVZX bx, BYTE [cs:di+IDEVARS.bIRQ]
78 add di, BYTE IDEVARS_size ; Increment to next controller
79 call .InstallLowOrHighIrqHandler
80 loop .IdeControllerLoop
[86]81.Return:
82 ret ; This ret is shared with .InstallLowOrHighIrqHandler
[33]83
84;--------------------------------------------------------------------
85; .InstallLowOrHighIrqHandler
86; Parameters:
87; BX: IRQ number, 0 if IRQ disabled
88; ES: BDA and Interrupt Vector segment (zero)
89; Returns:
90; Nothing
91; Corrupts registers:
92; BX, SI
[86]93;--------------------------------------------------------------------
[33]94.InstallLowOrHighIrqHandler:
[86]95 test bl, bl
96 jz SHORT .Return ; IRQ not used
[33]97 cmp bl, 8
[86]98 jb SHORT .InstallLowIrqHandler
99 ; Fall through to .InstallHighIrqHandler
[33]100
101;--------------------------------------------------------------------
102; .InstallHighIrqHandler
103; Parameters:
104; BX: IRQ number (8...15)
105; ES: BDA and Interrupt Vector segment (zero)
106; Returns:
107; Nothing
108; Corrupts registers:
109; BX, SI
[86]110;--------------------------------------------------------------------
[97]111.InstallHighIrqHandler:
[33]112 add bx, BYTE INTV_IRQ8 - 8 ; Interrupt vector number
113 mov si, HIRQ_InterruptServiceRoutineForIrqs8to15
114 jmp SHORT Interrupts_InstallHandlerToVectorInBXFromCSSI
115
116;--------------------------------------------------------------------
117; .InstallLowIrqHandler
118; Parameters:
119; BX: IRQ number (0...7)
120; ES: BDA and Interrupt Vector segment (zero)
121; Returns:
122; Nothing
123; Corrupts registers:
124; BX, SI
[86]125;--------------------------------------------------------------------
[33]126.InstallLowIrqHandler:
127 add bx, BYTE INTV_IRQ0 ; Interrupt vector number
128 mov si, HIRQ_InterruptServiceRoutineForIrqs2to7
129 ; Fall to Interrupts_InstallHandlerToVectorInBXFromCSSI
130
131
132;--------------------------------------------------------------------
133; Interrupts_InstallHandlerToVectorInBXFromCSSI
134; Parameters:
135; BX: Interrupt vector number (for example 13h)
136; ES: BDA and Interrupt Vector segment (zero)
137; CS:SI: Ptr to interrupt handler
138; Returns:
139; Nothing
140; Corrupts registers:
141; BX
[86]142;--------------------------------------------------------------------
[33]143Interrupts_InstallHandlerToVectorInBXFromCSSI:
[120]144 shl bx, 1
145 shl bx, 1 ; Shift for DWORD offset
[33]146 mov [es:bx], si ; Store offset
147 mov [es:bx+2], cs ; Store segment
148 ret
149
150
151;--------------------------------------------------------------------
152; Interrupts_UnmaskInterruptControllerForDriveInDSDI
153; Parameters:
154; DS:DI: Ptr to DPT
155; Returns:
156; Nothing
157; Corrupts registers:
158; AX, BX, DX
159;--------------------------------------------------------------------
160Interrupts_UnmaskInterruptControllerForDriveInDSDI:
161 eMOVZX bx, BYTE [di+DPT.bIdeOff]
162 mov al, [cs:bx+IDEVARS.bIRQ]
[86]163 test al, al
164 jz SHORT .Return ; Interrupts disabled
[33]165 cmp al, 8
[86]166 jb SHORT .UnmaskLowIrqController
167 ; Fall through to .UnmaskHighIrqController
[33]168
169;--------------------------------------------------------------------
170; .UnmaskHighIrqController
171; Parameters:
172; AL: IRQ number (8...15)
173; Returns:
174; Nothing
175; Corrupts registers:
176; AX, DX
177;--------------------------------------------------------------------
[97]178.UnmaskHighIrqController:
[33]179 sub al, 8 ; Slave interrupt number
180 mov dx, PORT_8259SL_IMR ; Load Slave Mask Register address
181 call .ClearBitFrom8259MaskRegister
182 mov al, 2 ; Master IRQ 2 to allow slave IRQs
183 ; Fall to .UnmaskLowIrqController
184
185;--------------------------------------------------------------------
186; .UnmaskLowIrqController
187; Parameters:
188; AL: IRQ number (0...7)
189; Returns:
190; Nothing
191; Corrupts registers:
192; AX, DX
193;--------------------------------------------------------------------
194.UnmaskLowIrqController:
195 mov dx, PORT_8259MA_IMR ; Load Mask Register address
196 ; Fall to .ClearBitFrom8259MaskRegister
197
198;--------------------------------------------------------------------
199; .ClearBitFrom8259MaskRegister
200; Parameters:
201; AL: 8259 interrupt index (0...7)
202; DX: Port address to Interrupt Mask Register
203; Returns:
204; Nothing
205; Corrupts registers:
206; AX
207;--------------------------------------------------------------------
208.ClearBitFrom8259MaskRegister:
209 push cx
210 xchg ax, cx ; IRQ index to CL
211 mov ch, 1 ; Load 1 to be shifted
212 shl ch, cl ; Shift bit to correct position
213 not ch ; Invert to create bit mask for clearing
214 in al, dx ; Read Interrupt Mask Register
215 and al, ch ; Clear wanted bit
216 out dx, al ; Write modified Interrupt Mask Register
217 pop cx
[86]218.Return:
[33]219 ret
Note: See TracBrowser for help on using the repository browser.