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

Last change on this file since 252 was 243, checked in by aitotat@…, 13 years ago

Changes to XTIDE Universal BIOS:

  • Brought back optional "A then C" boot loader.
  • Now there is only one INT 19h handler that remains unchanged.
File size: 6.7 KB
Line 
1; Project name : XTIDE Universal BIOS
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
16;--------------------------------------------------------------------
17Interrupts_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 mov bx, BIOS_DISK_INTERRUPT_13h ; INT 13h interrupt vector offset
38 mov si, Int13h_DiskFunctionsHandler ; Interrupt handler offset
39 call Interrupts_InstallHandlerToVectorInBXFromCSSI
40
41 ; Only store INT 13h handler to 40h if 40h is not already installed.
42 ; At least AMI BIOS for 286 stores 40h handler by itself and calls
43 ; 40h from 13h. That system locks to infinite loop if we copy 13h to 40h.
44 call FloppyDrive_IsInt40hInstalled
45 jc SHORT .Int40hAlreadyInstalled
46 mov [es:BIOS_DISKETTE_INTERRUPT_40h*4], ax ; Store old INT 13h offset
47 mov [es:BIOS_DISKETTE_INTERRUPT_40h*4+2], dx ; Store old INT 13h segment
48.Int40hAlreadyInstalled:
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
59;--------------------------------------------------------------------
60.InitializeHardwareIrqHandlers:
61 call RamVars_GetIdeControllerCountToCX
62 mov di, ROMVARS.ideVars0 ; CS:SI points to first IDEVARS
63.IdeControllerLoop:
64 eMOVZX bx, 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; BX: 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 bl, bl
83 jz SHORT .Return ; IRQ not used
84 cmp bl, 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; BX, SI
97;--------------------------------------------------------------------
98.InstallHighIrqHandler:
99 add bx, BYTE HARDWARE_IRQ_8_INTERRUPT_70h - 8 ; Interrupt vector number
100 mov si, IdeIrq_InterruptServiceRoutineForIrqs8to15
101 jmp SHORT Interrupts_InstallHandlerToVectorInBXFromCSSI
102
103;--------------------------------------------------------------------
104; .InstallLowIrqHandler
105; Parameters:
106; BX: IRQ number (0...7)
107; ES: BDA and Interrupt Vector segment (zero)
108; Returns:
109; Nothing
110; Corrupts registers:
111; BX, SI
112;--------------------------------------------------------------------
113.InstallLowIrqHandler:
114 add bx, BYTE HARDWARE_IRQ_0_INTERRUPT_08h ; Interrupt vector number
115 mov si, IdeIrq_InterruptServiceRoutineForIrqs2to7
116 ; Fall to Interrupts_InstallHandlerToVectorInBXFromCSSI
117
118
119;--------------------------------------------------------------------
120; Interrupts_InstallHandlerToVectorInBXFromCSSI
121; Parameters:
122; BX: 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; BX
129;--------------------------------------------------------------------
130Interrupts_InstallHandlerToVectorInBXFromCSSI:
131 eSHL_IM bx, 2 ; Shift for DWORD offset
132 mov [es:bx], si ; Store offset
133 mov [es:bx+2], cs ; Store segment
134 ret
135
136
137;--------------------------------------------------------------------
138; Interrupts_UnmaskInterruptControllerForDriveInDSDI
139; Parameters:
140; DS:DI: Ptr to DPT
141; Returns:
142; Nothing
143; Corrupts registers:
144; AX, BX, DX
145;--------------------------------------------------------------------
146Interrupts_UnmaskInterruptControllerForDriveInDSDI:
147 eMOVZX bx, BYTE [di+DPT.bIdevarsOffset]
148 mov al, [cs:bx+IDEVARS.bIRQ]
149 test al, al
150 jz SHORT .Return ; Interrupts disabled
151 cmp al, 8
152 jb SHORT .UnmaskLowIrqController
153 ; Fall to .UnmaskHighIrqController
154
155;--------------------------------------------------------------------
156; .UnmaskHighIrqController
157; Parameters:
158; AL: IRQ number (8...15)
159; Returns:
160; Nothing
161; Corrupts registers:
162; AX, DX
163;--------------------------------------------------------------------
164.UnmaskHighIrqController:
165 sub al, 8 ; Slave interrupt number
166 mov dx, SLAVE_8259_IMR
167 call .ClearBitFrom8259MaskRegister
168 mov al, 2 ; Master IRQ 2 to allow slave IRQs
169 ; Fall to .UnmaskLowIrqController
170
171;--------------------------------------------------------------------
172; .UnmaskLowIrqController
173; Parameters:
174; AL: IRQ number (0...7)
175; Returns:
176; Nothing
177; Corrupts registers:
178; AX, DX
179;--------------------------------------------------------------------
180.UnmaskLowIrqController:
181 mov dx, MASTER_8259_IMR
182 ; Fall to .ClearBitFrom8259MaskRegister
183
184;--------------------------------------------------------------------
185; .ClearBitFrom8259MaskRegister
186; Parameters:
187; AL: 8259 interrupt index (0...7)
188; DX: Port address to Interrupt Mask Register
189; Returns:
190; Nothing
191; Corrupts registers:
192; AX
193;--------------------------------------------------------------------
194.ClearBitFrom8259MaskRegister:
195 push cx
196 xchg ax, cx ; IRQ index to CL
197 mov ch, 1 ; Load 1 to be shifted
198 shl ch, cl ; Shift bit to correct position
199 not ch ; Invert to create bit mask for clearing
200 in al, dx ; Read Interrupt Mask Register
201 and al, ch ; Clear wanted bit
202 out dx, al ; Write modified Interrupt Mask Register
203 pop cx
204.Return:
205 ret
Note: See TracBrowser for help on using the repository browser.