1 | ; Project name : IDE BIOS
|
---|
2 | ; Description : Functions for initializing the BIOS.
|
---|
3 |
|
---|
4 | ; Section containing code
|
---|
5 | SECTION .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
|
---|
16 | ;--------------------------------------------------------------------
|
---|
17 | ALIGN JUMP_ALIGN
|
---|
18 | Interrupts_InitializeInterruptVectors:
|
---|
19 | call Interrupts_InitializeInt13hAnd40h
|
---|
20 | call Interrupts_InitializeInt19h
|
---|
21 | jmp SHORT Interrupts_InitializeHardwareIrqHandlers
|
---|
22 | ; Maybe all this should be inlined?
|
---|
23 |
|
---|
24 |
|
---|
25 | ;--------------------------------------------------------------------
|
---|
26 | ; Interrupts_Int13hAnd40h
|
---|
27 | ; Parameters:
|
---|
28 | ; DS: RAMVARS segment
|
---|
29 | ; ES: BDA and Interrupt Vector segment (zero)
|
---|
30 | ; Returns:
|
---|
31 | ; Nothing
|
---|
32 | ; Corrupts registers:
|
---|
33 | ; AX, BX, CX, DX, SI, DI
|
---|
34 | ;--------------------------------------------------------------------
|
---|
35 | ALIGN JUMP_ALIGN
|
---|
36 | Interrupts_InitializeInt13hAnd40h:
|
---|
37 | mov ax, [es:INTV_DISK_FUNC*4] ; Load old INT 13h offset
|
---|
38 | mov dx, [es:INTV_DISK_FUNC*4+2] ; Load old INT 13h segment
|
---|
39 | mov [RAMVARS.fpOldI13h], ax ; Store old INT 13h offset
|
---|
40 | mov [RAMVARS.fpOldI13h+2], dx ; Store old INT 13h segment
|
---|
41 | mov bx, INTV_DISK_FUNC ; INT 13h interrupt vector offset
|
---|
42 | mov si, Int13h_DiskFunctions ; Interrupt handler offset
|
---|
43 | call Interrupts_InstallHandlerToVectorInBXFromCSSI
|
---|
44 |
|
---|
45 | ; Only store INT 13h handler to 40h if 40h is not already installed.
|
---|
46 | ; At least AMI BIOS for 286 stores 40h handler by itself and calls
|
---|
47 | ; 40h from 13h. That system locks to infinite loop if we copy 13h to 40h.
|
---|
48 | call FloppyDrive_IsInt40hInstalled
|
---|
49 | jc SHORT .Return
|
---|
50 | mov [es:INTV_FLOPPY_FUNC*4], ax ; Store offset
|
---|
51 | mov [es:INTV_FLOPPY_FUNC*4+2], dx ; Store segment
|
---|
52 | .Return:
|
---|
53 | ret
|
---|
54 |
|
---|
55 |
|
---|
56 | ;--------------------------------------------------------------------
|
---|
57 | ; Interrupts_InitializeInt19h
|
---|
58 | ; Parameters:
|
---|
59 | ; DS: RAMVARS segment
|
---|
60 | ; ES: BDA and Interrupt Vector segment (zero)
|
---|
61 | ; Returns:
|
---|
62 | ; Nothing
|
---|
63 | ; Corrupts registers:
|
---|
64 | ; BX, SI
|
---|
65 | ;--------------------------------------------------------------------
|
---|
66 | ALIGN JUMP_ALIGN
|
---|
67 | Interrupts_InitializeInt19h:
|
---|
68 | eMOVZX bx, [cs:ROMVARS.bBootLdrType] ; Load boot loader type
|
---|
69 | mov si, INTV_BOOTSTRAP ; 19h
|
---|
70 | xchg bx, si ; SI=Loader type, BX=19h
|
---|
71 | jmp [cs:si+.rgwSetupBootLoader] ; Jump to install selected loader
|
---|
72 | ALIGN WORD_ALIGN
|
---|
73 | .rgwSetupBootLoader:
|
---|
74 | dw .SetupBootMenuLoader ; BOOTLOADER_TYPE_MENU
|
---|
75 | dw .SetupSimpleLoader ; BOOTLOADER_TYPE_SIMPLE
|
---|
76 | dw .SetupBootMenuLoader ; reserved
|
---|
77 | dw .NoBootLoader ; BOOTLOADER_TYPE_NONE
|
---|
78 |
|
---|
79 | ALIGN JUMP_ALIGN
|
---|
80 | .NoBootLoader:
|
---|
81 | test BYTE [cs:ROMVARS.wFlags], FLG_ROMVARS_LATE
|
---|
82 | jnz SHORT .SetupSimpleLoader ; Boot loader required for late initialization
|
---|
83 | ret
|
---|
84 | ALIGN JUMP_ALIGN
|
---|
85 | .SetupSimpleLoader:
|
---|
86 | mov si, Int19h_SimpleBootLoader
|
---|
87 | jmp Interrupts_InstallHandlerToVectorInBXFromCSSI
|
---|
88 | ALIGN JUMP_ALIGN
|
---|
89 | .SetupBootMenuLoader:
|
---|
90 | mov si, Int19hMenu_BootLoader
|
---|
91 | jmp Interrupts_InstallHandlerToVectorInBXFromCSSI
|
---|
92 |
|
---|
93 |
|
---|
94 | ;--------------------------------------------------------------------
|
---|
95 | ; Interrupts_InitializeHardwareIrqHandlers
|
---|
96 | ; Parameters:
|
---|
97 | ; ES: BDA and Interrupt Vector segment (zero)
|
---|
98 | ; Returns:
|
---|
99 | ; Nothing
|
---|
100 | ; Corrupts registers:
|
---|
101 | ; BX, CX, DX, SI, DI
|
---|
102 | ;--------------------------------------------------------------------
|
---|
103 | ALIGN JUMP_ALIGN
|
---|
104 | Interrupts_InitializeHardwareIrqHandlers:
|
---|
105 | call RamVars_GetIdeControllerCountToCX
|
---|
106 | mov di, ROMVARS.ideVars0 ; CS:SI points to first IDEVARS
|
---|
107 | ALIGN JUMP_ALIGN
|
---|
108 | .IdeControllerLoop:
|
---|
109 | eMOVZX bx, BYTE [cs:di+IDEVARS.bIRQ]
|
---|
110 | add di, BYTE IDEVARS_size ; Increment to next controller
|
---|
111 | call .InstallLowOrHighIrqHandler
|
---|
112 | loop .IdeControllerLoop
|
---|
113 | .Return:
|
---|
114 | ret ; This ret is shared with .InstallLowOrHighIrqHandler
|
---|
115 |
|
---|
116 | ;--------------------------------------------------------------------
|
---|
117 | ; .InstallLowOrHighIrqHandler
|
---|
118 | ; Parameters:
|
---|
119 | ; BX: IRQ number, 0 if IRQ disabled
|
---|
120 | ; ES: BDA and Interrupt Vector segment (zero)
|
---|
121 | ; Returns:
|
---|
122 | ; Nothing
|
---|
123 | ; Corrupts registers:
|
---|
124 | ; BX, SI
|
---|
125 | ;--------------------------------------------------------------------
|
---|
126 | ALIGN JUMP_ALIGN
|
---|
127 | .InstallLowOrHighIrqHandler:
|
---|
128 | test bl, bl
|
---|
129 | jz SHORT .Return ; IRQ not used
|
---|
130 | cmp bl, 8
|
---|
131 | jb SHORT .InstallLowIrqHandler
|
---|
132 | ; Fall through to .InstallHighIrqHandler
|
---|
133 |
|
---|
134 | ;--------------------------------------------------------------------
|
---|
135 | ; .InstallHighIrqHandler
|
---|
136 | ; Parameters:
|
---|
137 | ; BX: IRQ number (8...15)
|
---|
138 | ; ES: BDA and Interrupt Vector segment (zero)
|
---|
139 | ; Returns:
|
---|
140 | ; Nothing
|
---|
141 | ; Corrupts registers:
|
---|
142 | ; BX, SI
|
---|
143 | ;--------------------------------------------------------------------
|
---|
144 | ;ALIGN JUMP_ALIGN
|
---|
145 | ;.InstallHighIrqHandler:
|
---|
146 | add bx, BYTE INTV_IRQ8 - 8 ; Interrupt vector number
|
---|
147 | mov si, HIRQ_InterruptServiceRoutineForIrqs8to15
|
---|
148 | jmp SHORT Interrupts_InstallHandlerToVectorInBXFromCSSI
|
---|
149 |
|
---|
150 | ;--------------------------------------------------------------------
|
---|
151 | ; .InstallLowIrqHandler
|
---|
152 | ; Parameters:
|
---|
153 | ; BX: IRQ number (0...7)
|
---|
154 | ; ES: BDA and Interrupt Vector segment (zero)
|
---|
155 | ; Returns:
|
---|
156 | ; Nothing
|
---|
157 | ; Corrupts registers:
|
---|
158 | ; BX, SI
|
---|
159 | ;--------------------------------------------------------------------
|
---|
160 | ALIGN JUMP_ALIGN
|
---|
161 | .InstallLowIrqHandler:
|
---|
162 | add bx, BYTE INTV_IRQ0 ; Interrupt vector number
|
---|
163 | mov si, HIRQ_InterruptServiceRoutineForIrqs2to7
|
---|
164 | ; Fall to Interrupts_InstallHandlerToVectorInBXFromCSSI
|
---|
165 |
|
---|
166 |
|
---|
167 | ;--------------------------------------------------------------------
|
---|
168 | ; Interrupts_InstallHandlerToVectorInBXFromCSSI
|
---|
169 | ; Parameters:
|
---|
170 | ; BX: Interrupt vector number (for example 13h)
|
---|
171 | ; ES: BDA and Interrupt Vector segment (zero)
|
---|
172 | ; CS:SI: Ptr to interrupt handler
|
---|
173 | ; Returns:
|
---|
174 | ; Nothing
|
---|
175 | ; Corrupts registers:
|
---|
176 | ; BX
|
---|
177 | ;--------------------------------------------------------------------
|
---|
178 | ALIGN JUMP_ALIGN
|
---|
179 | Interrupts_InstallHandlerToVectorInBXFromCSSI:
|
---|
180 | eSHL_IM bx, 2 ; Shift for DWORD offset
|
---|
181 | mov [es:bx], si ; Store offset
|
---|
182 | mov [es:bx+2], cs ; Store segment
|
---|
183 | ret
|
---|
184 |
|
---|
185 |
|
---|
186 | ;--------------------------------------------------------------------
|
---|
187 | ; Interrupts_UnmaskInterruptControllerForDriveInDSDI
|
---|
188 | ; Parameters:
|
---|
189 | ; DS:DI: Ptr to DPT
|
---|
190 | ; Returns:
|
---|
191 | ; Nothing
|
---|
192 | ; Corrupts registers:
|
---|
193 | ; AX, BX, DX
|
---|
194 | ;--------------------------------------------------------------------
|
---|
195 | ALIGN JUMP_ALIGN
|
---|
196 | Interrupts_UnmaskInterruptControllerForDriveInDSDI:
|
---|
197 | eMOVZX bx, BYTE [di+DPT.bIdeOff]
|
---|
198 | mov al, [cs:bx+IDEVARS.bIRQ]
|
---|
199 | test al, al
|
---|
200 | jz SHORT .Return ; Interrupts disabled
|
---|
201 | cmp al, 8
|
---|
202 | jb SHORT .UnmaskLowIrqController
|
---|
203 | ; Fall through to .UnmaskHighIrqController
|
---|
204 |
|
---|
205 | ;--------------------------------------------------------------------
|
---|
206 | ; .UnmaskHighIrqController
|
---|
207 | ; Parameters:
|
---|
208 | ; AL: IRQ number (8...15)
|
---|
209 | ; Returns:
|
---|
210 | ; Nothing
|
---|
211 | ; Corrupts registers:
|
---|
212 | ; AX, DX
|
---|
213 | ;--------------------------------------------------------------------
|
---|
214 | ;ALIGN JUMP_ALIGN
|
---|
215 | ;.UnmaskHighIrqController:
|
---|
216 | sub al, 8 ; Slave interrupt number
|
---|
217 | mov dx, PORT_8259SL_IMR ; Load Slave Mask Register address
|
---|
218 | call .ClearBitFrom8259MaskRegister
|
---|
219 | mov al, 2 ; Master IRQ 2 to allow slave IRQs
|
---|
220 | ; Fall to .UnmaskLowIrqController
|
---|
221 |
|
---|
222 | ;--------------------------------------------------------------------
|
---|
223 | ; .UnmaskLowIrqController
|
---|
224 | ; Parameters:
|
---|
225 | ; AL: IRQ number (0...7)
|
---|
226 | ; Returns:
|
---|
227 | ; Nothing
|
---|
228 | ; Corrupts registers:
|
---|
229 | ; AX, DX
|
---|
230 | ;--------------------------------------------------------------------
|
---|
231 | ALIGN JUMP_ALIGN
|
---|
232 | .UnmaskLowIrqController:
|
---|
233 | mov dx, PORT_8259MA_IMR ; Load Mask Register address
|
---|
234 | ; Fall to .ClearBitFrom8259MaskRegister
|
---|
235 |
|
---|
236 | ;--------------------------------------------------------------------
|
---|
237 | ; .ClearBitFrom8259MaskRegister
|
---|
238 | ; Parameters:
|
---|
239 | ; AL: 8259 interrupt index (0...7)
|
---|
240 | ; DX: Port address to Interrupt Mask Register
|
---|
241 | ; Returns:
|
---|
242 | ; Nothing
|
---|
243 | ; Corrupts registers:
|
---|
244 | ; AX
|
---|
245 | ;--------------------------------------------------------------------
|
---|
246 | ;ALIGN JUMP_ALIGN
|
---|
247 | .ClearBitFrom8259MaskRegister:
|
---|
248 | push cx
|
---|
249 | xchg ax, cx ; IRQ index to CL
|
---|
250 | mov ch, 1 ; Load 1 to be shifted
|
---|
251 | shl ch, cl ; Shift bit to correct position
|
---|
252 | not ch ; Invert to create bit mask for clearing
|
---|
253 | in al, dx ; Read Interrupt Mask Register
|
---|
254 | and al, ch ; Clear wanted bit
|
---|
255 | out dx, al ; Write modified Interrupt Mask Register
|
---|
256 | pop cx
|
---|
257 | .Return:
|
---|
258 | ret
|
---|