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

Last change on this file since 168 was 162, checked in by krille_n_@…, 13 years ago

Changes to all parts of the project:

  • Size optimizations, mostly by excluding code from the BIOS.
  • Cleaned the source a bit, fixed spelling and grammar mistakes.
File size: 7.1 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] ; Load old INT 13h offset
32 mov dx, [es:BIOS_DISK_INTERRUPT_13h*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, BIOS_DISK_INTERRUPT_13h ; INT 13h interrupt vector offset
36 mov si, Int13h_DiskFunctionsHandler ; 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
43 jc SHORT .InitializeInt19h
44 mov [es:BIOS_DISKETTE_INTERRUPT_40h*4], ax ; Store old INT 13h offset
45 mov [es:BIOS_DISKETTE_INTERRUPT_40h*4+2], dx ; Store old INT 13h segment
46 ; Fall to .InitializeInt19h
47
48;--------------------------------------------------------------------
49; .InitializeInt19h
50; Parameters:
51; DS: RAMVARS segment
52; ES: BDA and Interrupt Vector segment (zero)
53; Returns:
54; Nothing
55; Corrupts registers:
56; BX, SI
57;--------------------------------------------------------------------
58.InitializeInt19h:
59 mov bx, BIOS_BOOT_LOADER_INTERRUPT_19h
60 mov si, Int19hMenu_BootLoader
61 call Interrupts_InstallHandlerToVectorInBXFromCSSI
62 ; Fall to .InitializeHardwareIrqHandlers
63
64;--------------------------------------------------------------------
65; .InitializeHardwareIrqHandlers
66; Parameters:
67; ES: BDA and Interrupt Vector segment (zero)
68; Returns:
69; Nothing
70; Corrupts registers:
71; BX, CX, DX, SI, DI
72;--------------------------------------------------------------------
73.InitializeHardwareIrqHandlers:
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
81.Return:
82 ret ; This ret is shared with .InstallLowOrHighIrqHandler
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
93;--------------------------------------------------------------------
94.InstallLowOrHighIrqHandler:
95 test bl, bl
96 jz SHORT .Return ; IRQ not used
97 cmp bl, 8
98 jb SHORT .InstallLowIrqHandler
99 ; Fall to .InstallHighIrqHandler
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
110;--------------------------------------------------------------------
111.InstallHighIrqHandler:
112 add bx, BYTE HARDWARE_IRQ_8_INTERRUPT_70h - 8 ; Interrupt vector number
113 mov si, IdeIrq_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
125;--------------------------------------------------------------------
126.InstallLowIrqHandler:
127 add bx, BYTE HARDWARE_IRQ_0_INTERRUPT_08h ; Interrupt vector number
128 mov si, IdeIrq_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
142;--------------------------------------------------------------------
143Interrupts_InstallHandlerToVectorInBXFromCSSI:
144 eSHL_IM bx, 2 ; Shift for DWORD offset
145 mov [es:bx], si ; Store offset
146 mov [es:bx+2], cs ; Store segment
147 ret
148
149
150;--------------------------------------------------------------------
151; Interrupts_UnmaskInterruptControllerForDriveInDSDI
152; Parameters:
153; DS:DI: Ptr to DPT
154; Returns:
155; Nothing
156; Corrupts registers:
157; AX, BX, DX
158;--------------------------------------------------------------------
159Interrupts_UnmaskInterruptControllerForDriveInDSDI:
160 eMOVZX bx, BYTE [di+DPT.bIdevarsOffset]
161 mov al, [cs:bx+IDEVARS.bIRQ]
162 test al, al
163 jz SHORT .Return ; Interrupts disabled
164 cmp al, 8
165 jb SHORT .UnmaskLowIrqController
166 ; Fall to .UnmaskHighIrqController
167
168;--------------------------------------------------------------------
169; .UnmaskHighIrqController
170; Parameters:
171; AL: IRQ number (8...15)
172; Returns:
173; Nothing
174; Corrupts registers:
175; AX, DX
176;--------------------------------------------------------------------
177.UnmaskHighIrqController:
178 sub al, 8 ; Slave interrupt number
179 mov dx, SLAVE_8259_IMR
180 call .ClearBitFrom8259MaskRegister
181 mov al, 2 ; Master IRQ 2 to allow slave IRQs
182 ; Fall to .UnmaskLowIrqController
183
184;--------------------------------------------------------------------
185; .UnmaskLowIrqController
186; Parameters:
187; AL: IRQ number (0...7)
188; Returns:
189; Nothing
190; Corrupts registers:
191; AX, DX
192;--------------------------------------------------------------------
193.UnmaskLowIrqController:
194 mov dx, MASTER_8259_IMR
195 ; Fall to .ClearBitFrom8259MaskRegister
196
197;--------------------------------------------------------------------
198; .ClearBitFrom8259MaskRegister
199; Parameters:
200; AL: 8259 interrupt index (0...7)
201; DX: Port address to Interrupt Mask Register
202; Returns:
203; Nothing
204; Corrupts registers:
205; AX
206;--------------------------------------------------------------------
207.ClearBitFrom8259MaskRegister:
208 push cx
209 xchg ax, cx ; IRQ index to CL
210 mov ch, 1 ; Load 1 to be shifted
211 shl ch, cl ; Shift bit to correct position
212 not ch ; Invert to create bit mask for clearing
213 in al, dx ; Read Interrupt Mask Register
214 and al, ch ; Clear wanted bit
215 out dx, al ; Write modified Interrupt Mask Register
216 pop cx
217.Return:
218 ret
Note: See TracBrowser for help on using the repository browser.