1 | ; Project name : XTIDE Universal 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 | Interrupts_InitializeInterruptVectors:
|
---|
18 | ; Fall to .InitializeInt13hAnd40h
|
---|
19 |
|
---|
20 | ;--------------------------------------------------------------------
|
---|
21 | ; .InitializeInt13hAnd40h
|
---|
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
|
---|
29 | ;--------------------------------------------------------------------
|
---|
30 | .InitializeInt13hAnd40h:
|
---|
31 | mov ax, [es:BIOS_DISK_INTERRUPT_13h*4+2]; Load old INT 13h segment
|
---|
32 | mov [RAMVARS.fpOldI13h+2], ax ; Store old INT 13h segment
|
---|
33 | xchg dx, ax
|
---|
34 | mov ax, [es:BIOS_DISK_INTERRUPT_13h*4] ; Load old INT 13h offset
|
---|
35 | mov [RAMVARS.fpOldI13h], ax ; Store old INT 13h offset
|
---|
36 |
|
---|
37 | ; Only store INT 13h handler to 40h if 40h is not already installed.
|
---|
38 | ; At least AMI BIOS for 286 stores 40h handler by itself and calls
|
---|
39 | ; 40h from 13h. That system locks to infinite loop if we copy 13h to 40h.
|
---|
40 | call FloppyDrive_IsInt40hInstalled
|
---|
41 | jc SHORT .Int40hAlreadyInstalled
|
---|
42 | mov [es:BIOS_DISKETTE_INTERRUPT_40h*4], ax ; Store old INT 13h offset
|
---|
43 | mov [es:BIOS_DISKETTE_INTERRUPT_40h*4+2], dx ; Store old INT 13h segment
|
---|
44 | .Int40hAlreadyInstalled:
|
---|
45 |
|
---|
46 | mov al, BIOS_DISK_INTERRUPT_13h ; INT 13h interrupt vector offset
|
---|
47 | mov si, Int13h_DiskFunctionsHandler ; Interrupt handler offset
|
---|
48 | call Interrupts_InstallHandlerToVectorInALFromCSSI
|
---|
49 | ; Fall to .InitializeHardwareIrqHandlers
|
---|
50 |
|
---|
51 | ;--------------------------------------------------------------------
|
---|
52 | ; .InitializeHardwareIrqHandlers
|
---|
53 | ; Parameters:
|
---|
54 | ; ES: BDA and Interrupt Vector segment (zero)
|
---|
55 | ; Returns:
|
---|
56 | ; Nothing
|
---|
57 | ; Corrupts registers:
|
---|
58 | ; BX, CX, DX, SI, DI, AX
|
---|
59 | ;--------------------------------------------------------------------
|
---|
60 | .InitializeHardwareIrqHandlers:
|
---|
61 | call RamVars_GetIdeControllerCountToCX
|
---|
62 | mov di, ROMVARS.ideVars0 ; CS:SI points to first IDEVARS
|
---|
63 | .IdeControllerLoop:
|
---|
64 | mov al, BYTE [cs:di+IDEVARS.bIRQ]
|
---|
65 | add di, BYTE IDEVARS_size ; Increment to next controller
|
---|
66 | call .InstallLowOrHighIrqHandler
|
---|
67 | loop .IdeControllerLoop
|
---|
68 | .Return:
|
---|
69 | ret ; This ret is shared with .InstallLowOrHighIrqHandler
|
---|
70 |
|
---|
71 | ;--------------------------------------------------------------------
|
---|
72 | ; .InstallLowOrHighIrqHandler
|
---|
73 | ; Parameters:
|
---|
74 | ; AL: IRQ number, 0 if IRQ disabled
|
---|
75 | ; ES: BDA and Interrupt Vector segment (zero)
|
---|
76 | ; Returns:
|
---|
77 | ; Nothing
|
---|
78 | ; Corrupts registers:
|
---|
79 | ; BX, SI
|
---|
80 | ;--------------------------------------------------------------------
|
---|
81 | .InstallLowOrHighIrqHandler:
|
---|
82 | test al, al
|
---|
83 | jz SHORT .Return ; IRQ not used
|
---|
84 | cmp al, 8
|
---|
85 | jb SHORT .InstallLowIrqHandler
|
---|
86 | ; Fall to .InstallHighIrqHandler
|
---|
87 |
|
---|
88 | ;--------------------------------------------------------------------
|
---|
89 | ; .InstallHighIrqHandler
|
---|
90 | ; Parameters:
|
---|
91 | ; BX: IRQ number (8...15)
|
---|
92 | ; ES: BDA and Interrupt Vector segment (zero)
|
---|
93 | ; Returns:
|
---|
94 | ; Nothing
|
---|
95 | ; Corrupts registers:
|
---|
96 | ; AL, BX, SI
|
---|
97 | ;--------------------------------------------------------------------
|
---|
98 | .InstallHighIrqHandler:
|
---|
99 | add al, BYTE HARDWARE_IRQ_8_INTERRUPT_70h - 8 ; Interrupt vector number
|
---|
100 | mov si, IdeIrq_InterruptServiceRoutineForIrqs8to15
|
---|
101 | jmp SHORT Interrupts_InstallHandlerToVectorInALFromCSSI
|
---|
102 |
|
---|
103 | ;--------------------------------------------------------------------
|
---|
104 | ; .InstallLowIrqHandler
|
---|
105 | ; Parameters:
|
---|
106 | ; AL: IRQ number (0...7)
|
---|
107 | ; ES: BDA and Interrupt Vector segment (zero)
|
---|
108 | ; Returns:
|
---|
109 | ; Nothing
|
---|
110 | ; Corrupts registers:
|
---|
111 | ; AL, BX, SI
|
---|
112 | ;--------------------------------------------------------------------
|
---|
113 | .InstallLowIrqHandler:
|
---|
114 | add al, BYTE HARDWARE_IRQ_0_INTERRUPT_08h ; Interrupt vector number
|
---|
115 | mov si, IdeIrq_InterruptServiceRoutineForIrqs2to7
|
---|
116 | ; Fall to Interrupts_InstallHandlerToVectorInALFromCSSI
|
---|
117 |
|
---|
118 |
|
---|
119 | ;--------------------------------------------------------------------
|
---|
120 | ; Interrupts_InstallHandlerToVectorInALFromCSSI
|
---|
121 | ; Parameters:
|
---|
122 | ; AL: Interrupt vector number (for example 13h)
|
---|
123 | ; ES: BDA and Interrupt Vector segment (zero)
|
---|
124 | ; CS:SI: Ptr to interrupt handler
|
---|
125 | ; Returns:
|
---|
126 | ; Nothing
|
---|
127 | ; Corrupts registers:
|
---|
128 | ; AX, BX
|
---|
129 | ;--------------------------------------------------------------------
|
---|
130 | Interrupts_InstallHandlerToVectorInALFromCSSI:
|
---|
131 | mov bl, 4 ; Shift for DWORD offset, MUL smaller than other alternatives
|
---|
132 | mul bl
|
---|
133 | xchg ax, bx
|
---|
134 | mov [es:bx], si ; Store offset
|
---|
135 | mov [es:bx+2], cs ; Store segment
|
---|
136 | ret
|
---|
137 |
|
---|
138 |
|
---|
139 | ;--------------------------------------------------------------------
|
---|
140 | ; Interrupts_UnmaskInterruptControllerForDriveInDSDI
|
---|
141 | ; Parameters:
|
---|
142 | ; DS:DI: Ptr to DPT
|
---|
143 | ; Returns:
|
---|
144 | ; Nothing
|
---|
145 | ; Corrupts registers:
|
---|
146 | ; AX, BX, DX
|
---|
147 | ;--------------------------------------------------------------------
|
---|
148 | Interrupts_UnmaskInterruptControllerForDriveInDSDI:
|
---|
149 | eMOVZX bx, BYTE [di+DPT.bIdevarsOffset]
|
---|
150 | mov al, [cs:bx+IDEVARS.bIRQ]
|
---|
151 | test al, al
|
---|
152 | jz SHORT .Return ; Interrupts disabled
|
---|
153 | cmp al, 8
|
---|
154 | jb SHORT .UnmaskLowIrqController
|
---|
155 | ; Fall to .UnmaskHighIrqController
|
---|
156 |
|
---|
157 | ;--------------------------------------------------------------------
|
---|
158 | ; .UnmaskHighIrqController
|
---|
159 | ; Parameters:
|
---|
160 | ; AL: IRQ number (8...15)
|
---|
161 | ; Returns:
|
---|
162 | ; Nothing
|
---|
163 | ; Corrupts registers:
|
---|
164 | ; AX, DX
|
---|
165 | ;--------------------------------------------------------------------
|
---|
166 | .UnmaskHighIrqController:
|
---|
167 | sub al, 8 ; Slave interrupt number
|
---|
168 | mov dx, SLAVE_8259_IMR
|
---|
169 | call .ClearBitFrom8259MaskRegister
|
---|
170 | mov al, 2 ; Master IRQ 2 to allow slave IRQs
|
---|
171 | ; Fall to .UnmaskLowIrqController
|
---|
172 |
|
---|
173 | ;--------------------------------------------------------------------
|
---|
174 | ; .UnmaskLowIrqController
|
---|
175 | ; Parameters:
|
---|
176 | ; AL: IRQ number (0...7)
|
---|
177 | ; Returns:
|
---|
178 | ; Nothing
|
---|
179 | ; Corrupts registers:
|
---|
180 | ; AX, DX
|
---|
181 | ;--------------------------------------------------------------------
|
---|
182 | .UnmaskLowIrqController:
|
---|
183 | mov dx, MASTER_8259_IMR
|
---|
184 | ; Fall to .ClearBitFrom8259MaskRegister
|
---|
185 |
|
---|
186 | ;--------------------------------------------------------------------
|
---|
187 | ; .ClearBitFrom8259MaskRegister
|
---|
188 | ; Parameters:
|
---|
189 | ; AL: 8259 interrupt index (0...7)
|
---|
190 | ; DX: Port address to Interrupt Mask Register
|
---|
191 | ; Returns:
|
---|
192 | ; Nothing
|
---|
193 | ; Corrupts registers:
|
---|
194 | ; AX
|
---|
195 | ;--------------------------------------------------------------------
|
---|
196 | .ClearBitFrom8259MaskRegister:
|
---|
197 | push cx
|
---|
198 | xchg ax, cx ; IRQ index to CL
|
---|
199 | mov ch, 1 ; Load 1 to be shifted
|
---|
200 | shl ch, cl ; Shift bit to correct position
|
---|
201 | not ch ; Invert to create bit mask for clearing
|
---|
202 | in al, dx ; Read Interrupt Mask Register
|
---|
203 | and al, ch ; Clear wanted bit
|
---|
204 | out dx, al ; Write modified Interrupt Mask Register
|
---|
205 | pop cx
|
---|
206 | .Return:
|
---|
207 | ret
|
---|