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

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

Changes to all parts of the project:

  • Size optimizations.
  • Added a define (EXCLUDE_FROM_XTIDECFG) to exclude unused library code from XTIDECFG.
  • Tried to minimize time spent with interrupts disabled.
  • Some minor attempts to improve speed (reordering instructions etc).
  • Tried to improve readability, did some cleanup and fixed some errors in comments.
File size: 7.2 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 .InitializeInt19h
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 ; Fall to .InitializeInt19h
49
50;--------------------------------------------------------------------
51; .InitializeInt19h
52; Parameters:
53; DS: RAMVARS segment
54; ES: BDA and Interrupt Vector segment (zero)
55; Returns:
56; Nothing
57; Corrupts registers:
58; BX, SI
59;--------------------------------------------------------------------
60.InitializeInt19h:
61 mov bx, BIOS_BOOT_LOADER_INTERRUPT_19h
62 mov si, Int19hMenu_BootLoader
63 call Interrupts_InstallHandlerToVectorInBXFromCSSI
64 ; Fall to .InitializeHardwareIrqHandlers
65
66;--------------------------------------------------------------------
67; .InitializeHardwareIrqHandlers
68; Parameters:
69; ES: BDA and Interrupt Vector segment (zero)
70; Returns:
71; Nothing
72; Corrupts registers:
73; BX, CX, DX, SI, DI
74;--------------------------------------------------------------------
75.InitializeHardwareIrqHandlers:
76 call RamVars_GetIdeControllerCountToCX
77 mov di, ROMVARS.ideVars0 ; CS:SI points to first IDEVARS
78.IdeControllerLoop:
79 eMOVZX bx, BYTE [cs:di+IDEVARS.bIRQ]
80 add di, BYTE IDEVARS_size ; Increment to next controller
81 call .InstallLowOrHighIrqHandler
82 loop .IdeControllerLoop
83.Return:
84 ret ; This ret is shared with .InstallLowOrHighIrqHandler
85
86;--------------------------------------------------------------------
87; .InstallLowOrHighIrqHandler
88; Parameters:
89; BX: IRQ number, 0 if IRQ disabled
90; ES: BDA and Interrupt Vector segment (zero)
91; Returns:
92; Nothing
93; Corrupts registers:
94; BX, SI
95;--------------------------------------------------------------------
96.InstallLowOrHighIrqHandler:
97 test bl, bl
98 jz SHORT .Return ; IRQ not used
99 cmp bl, 8
100 jb SHORT .InstallLowIrqHandler
101 ; Fall to .InstallHighIrqHandler
102
103;--------------------------------------------------------------------
104; .InstallHighIrqHandler
105; Parameters:
106; BX: IRQ number (8...15)
107; ES: BDA and Interrupt Vector segment (zero)
108; Returns:
109; Nothing
110; Corrupts registers:
111; BX, SI
112;--------------------------------------------------------------------
113.InstallHighIrqHandler:
114 add bx, BYTE HARDWARE_IRQ_8_INTERRUPT_70h - 8 ; Interrupt vector number
115 mov si, IdeIrq_InterruptServiceRoutineForIrqs8to15
116 jmp SHORT Interrupts_InstallHandlerToVectorInBXFromCSSI
117
118;--------------------------------------------------------------------
119; .InstallLowIrqHandler
120; Parameters:
121; BX: IRQ number (0...7)
122; ES: BDA and Interrupt Vector segment (zero)
123; Returns:
124; Nothing
125; Corrupts registers:
126; BX, SI
127;--------------------------------------------------------------------
128.InstallLowIrqHandler:
129 add bx, BYTE HARDWARE_IRQ_0_INTERRUPT_08h ; Interrupt vector number
130 mov si, IdeIrq_InterruptServiceRoutineForIrqs2to7
131 ; Fall to Interrupts_InstallHandlerToVectorInBXFromCSSI
132
133
134;--------------------------------------------------------------------
135; Interrupts_InstallHandlerToVectorInBXFromCSSI
136; Parameters:
137; BX: Interrupt vector number (for example 13h)
138; ES: BDA and Interrupt Vector segment (zero)
139; CS:SI: Ptr to interrupt handler
140; Returns:
141; Nothing
142; Corrupts registers:
143; BX
144;--------------------------------------------------------------------
145Interrupts_InstallHandlerToVectorInBXFromCSSI:
146 eSHL_IM bx, 2 ; Shift for DWORD offset
147 mov [es:bx], si ; Store offset
148 mov [es:bx+2], cs ; Store segment
149 ret
150
151
152;--------------------------------------------------------------------
153; Interrupts_UnmaskInterruptControllerForDriveInDSDI
154; Parameters:
155; DS:DI: Ptr to DPT
156; Returns:
157; Nothing
158; Corrupts registers:
159; AX, BX, DX
160;--------------------------------------------------------------------
161Interrupts_UnmaskInterruptControllerForDriveInDSDI:
162 eMOVZX bx, BYTE [di+DPT.bIdevarsOffset]
163 mov al, [cs:bx+IDEVARS.bIRQ]
164 test al, al
165 jz SHORT .Return ; Interrupts disabled
166 cmp al, 8
167 jb SHORT .UnmaskLowIrqController
168 ; Fall to .UnmaskHighIrqController
169
170;--------------------------------------------------------------------
171; .UnmaskHighIrqController
172; Parameters:
173; AL: IRQ number (8...15)
174; Returns:
175; Nothing
176; Corrupts registers:
177; AX, DX
178;--------------------------------------------------------------------
179.UnmaskHighIrqController:
180 sub al, 8 ; Slave interrupt number
181 mov dx, SLAVE_8259_IMR
182 call .ClearBitFrom8259MaskRegister
183 mov al, 2 ; Master IRQ 2 to allow slave IRQs
184 ; Fall to .UnmaskLowIrqController
185
186;--------------------------------------------------------------------
187; .UnmaskLowIrqController
188; Parameters:
189; AL: IRQ number (0...7)
190; Returns:
191; Nothing
192; Corrupts registers:
193; AX, DX
194;--------------------------------------------------------------------
195.UnmaskLowIrqController:
196 mov dx, MASTER_8259_IMR
197 ; Fall to .ClearBitFrom8259MaskRegister
198
199;--------------------------------------------------------------------
200; .ClearBitFrom8259MaskRegister
201; Parameters:
202; AL: 8259 interrupt index (0...7)
203; DX: Port address to Interrupt Mask Register
204; Returns:
205; Nothing
206; Corrupts registers:
207; AX
208;--------------------------------------------------------------------
209.ClearBitFrom8259MaskRegister:
210 push cx
211 xchg ax, cx ; IRQ index to CL
212 mov ch, 1 ; Load 1 to be shifted
213 shl ch, cl ; Shift bit to correct position
214 not ch ; Invert to create bit mask for clearing
215 in al, dx ; Read Interrupt Mask Register
216 and al, ch ; Clear wanted bit
217 out dx, al ; Write modified Interrupt Mask Register
218 pop cx
219.Return:
220 ret
Note: See TracBrowser for help on using the repository browser.