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

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

Changes to XTIDE Universal BIOS:

  • AT builds now relocate INT 13h stack to top of stolen conventional memory.
  • Some small fixes here and there.
File size: 8.0 KB
Line 
1; Project name : XTIDE Universal BIOS
2; Description : Functions for initializing the BIOS.
3
4;
5; XTIDE Universal BIOS and Associated Tools
6; Copyright (C) 2009-2010 by Tomi Tilli, 2011-2012 by XTIDE Universal BIOS Team.
7;
8; This program is free software; you can redistribute it and/or modify
9; it under the terms of the GNU General Public License as published by
10; the Free Software Foundation; either version 2 of the License, or
11; (at your option) any later version.
12;
13; This program is distributed in the hope that it will be useful,
14; but WITHOUT ANY WARRANTY; without even the implied warranty of
15; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16; GNU General Public License for more details.
17; Visit http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
18;
19
20; Section containing code
21SECTION .text
22
23;--------------------------------------------------------------------
24; Interrupts_InitializeInterruptVectors
25; Parameters:
26; DS: RAMVARS segment
27; ES: BDA and Interrupt Vector segment (zero)
28; Returns:
29; Nothing
30; Corrupts registers:
31; All except segments
32;--------------------------------------------------------------------
33Interrupts_InitializeInterruptVectors:
34 ; Fall to .InitializeInt13hAnd40h
35
36;--------------------------------------------------------------------
37; .InitializeInt13hAnd40h
38; Parameters:
39; DS: RAMVARS segment
40; ES: BDA and Interrupt Vector segment (zero)
41; Returns:
42; Nothing
43; Corrupts registers:
44; AX, BX, CX, DX, SI, DI
45;--------------------------------------------------------------------
46.InitializeInt13hAnd40h:
47 mov ax, [es:BIOS_DISK_INTERRUPT_13h*4+2]; Load old INT 13h segment
48 mov [RAMVARS.fpOldI13h+2], ax ; Store old INT 13h segment
49 xchg dx, ax
50 mov ax, [es:BIOS_DISK_INTERRUPT_13h*4] ; Load old INT 13h offset
51 mov [RAMVARS.fpOldI13h], ax ; Store old INT 13h offset
52
53 ; Only store INT 13h handler to 40h if 40h is not already installed.
54 ; At least AMI BIOS for 286 stores 40h handler by itself and calls
55 ; 40h from 13h. That system locks to infinite loop if we copy 13h to 40h.
56 call FloppyDrive_IsInt40hInstalled
57 jc SHORT .Int40hAlreadyInstalled
58 mov [es:BIOS_DISKETTE_INTERRUPT_40h*4], ax ; Store old INT 13h offset
59 mov [es:BIOS_DISKETTE_INTERRUPT_40h*4+2], dx ; Store old INT 13h segment
60.Int40hAlreadyInstalled:
61
62 mov al, BIOS_DISK_INTERRUPT_13h ; INT 13h interrupt vector offset
63 mov si, Int13h_DiskFunctionsHandler
64%ifdef RELOCATE_INT13H_STACK
65 test BYTE [cs:ROMVARS.wFlags], FLG_ROMVARS_FULLMODE
66 eCMOVNZ si, Int13h_DiskFunctionsHandlerWithStackChange
67%endif
68 call Interrupts_InstallHandlerToVectorInALFromCSSI
69
70 ; Install INT 19h handler to properly reset the system
71 mov al, BIOS_BOOT_LOADER_INTERRUPT_19h ; INT 19h interrupt vector offset
72 mov si, Int19hReset_Handler ; INT 19h handler to reboot the system
73%ifndef MODULE_IRQ
74 ; Fall to Interrupts_InstallHandlerToVectorInALFromCSSI
75%else
76 call Interrupts_InstallHandlerToVectorInALFromCSSI
77 ; Fall to .InitializeHardwareIrqHandlers
78
79;--------------------------------------------------------------------
80; .InitializeHardwareIrqHandlers
81; Parameters:
82; ES: BDA and Interrupt Vector segment (zero)
83; Returns:
84; Nothing
85; Corrupts registers:
86; BX, CX, DX, SI, DI, AX
87;--------------------------------------------------------------------
88.InitializeHardwareIrqHandlers:
89 call RamVars_GetIdeControllerCountToCX
90 mov di, ROMVARS.ideVars0 ; CS:SI points to first IDEVARS
91.IdeControllerLoop:
92 mov al, [cs:di+IDEVARS.bIRQ]
93 add di, BYTE IDEVARS_size ; Increment to next controller
94 call .InstallLowOrHighIrqHandler
95 loop .IdeControllerLoop
96.Return:
97 ret ; This ret is shared with .InstallLowOrHighIrqHandler
98
99;--------------------------------------------------------------------
100; .InstallLowOrHighIrqHandler
101; Parameters:
102; AL: IRQ number, 0 if IRQ disabled
103; ES: BDA and Interrupt Vector segment (zero)
104; Returns:
105; Nothing
106; Corrupts registers:
107; BX, SI
108;--------------------------------------------------------------------
109.InstallLowOrHighIrqHandler:
110 test al, al
111 jz SHORT .Return ; IRQ not used
112 cmp al, 8
113 jb SHORT .InstallLowIrqHandler
114 ; Fall to .InstallHighIrqHandler
115
116;--------------------------------------------------------------------
117; .InstallHighIrqHandler
118; Parameters:
119; BX: IRQ number (8...15)
120; ES: BDA and Interrupt Vector segment (zero)
121; Returns:
122; Nothing
123; Corrupts registers:
124; AL, BX, SI
125;--------------------------------------------------------------------
126.InstallHighIrqHandler:
127 add al, BYTE HARDWARE_IRQ_8_INTERRUPT_70h - 8 ; Interrupt vector number
128 mov si, IdeIrq_InterruptServiceRoutineForIrqs8to15
129 jmp SHORT Interrupts_InstallHandlerToVectorInALFromCSSI
130
131;--------------------------------------------------------------------
132; .InstallLowIrqHandler
133; Parameters:
134; AL: IRQ number (0...7)
135; ES: BDA and Interrupt Vector segment (zero)
136; Returns:
137; Nothing
138; Corrupts registers:
139; AL, BX, SI
140;--------------------------------------------------------------------
141.InstallLowIrqHandler:
142 add al, BYTE HARDWARE_IRQ_0_INTERRUPT_08h ; Interrupt vector number
143 mov si, IdeIrq_InterruptServiceRoutineForIrqs2to7
144 ; Fall to Interrupts_InstallHandlerToVectorInALFromCSSI
145%endif ; MODULE_IRQ
146
147
148;--------------------------------------------------------------------
149; Interrupts_InstallHandlerToVectorInALFromCSSI
150; Parameters:
151; AL: Interrupt vector number (for example 13h)
152; ES: BDA and Interrupt Vector segment (zero)
153; CS:SI: Ptr to interrupt handler
154; Returns:
155; Nothing
156; Corrupts registers:
157; AX, BX
158;--------------------------------------------------------------------
159Interrupts_InstallHandlerToVectorInALFromCSSI:
160 mov bl, 4 ; Shift for DWORD offset, MUL smaller than other alternatives
161 mul bl
162 xchg ax, bx
163 mov [es:bx], si ; Store offset
164 mov [es:bx+2], cs ; Store segment
165 ret
166
167
168%ifdef MODULE_IRQ
169;--------------------------------------------------------------------
170; Interrupts_UnmaskInterruptControllerForDriveInDSDI
171; Parameters:
172; DS:DI: Ptr to DPT
173; Returns:
174; Nothing
175; Corrupts registers:
176; AX, BX, DX
177;--------------------------------------------------------------------
178Interrupts_UnmaskInterruptControllerForDriveInDSDI:
179 eMOVZX bx, [di+DPT.bIdevarsOffset]
180 mov al, [cs:bx+IDEVARS.bIRQ]
181 test al, al
182 jz SHORT .Return ; Interrupts disabled
183 cmp al, 8
184 jb SHORT .UnmaskLowIrqController
185 ; Fall to .UnmaskHighIrqController
186
187;--------------------------------------------------------------------
188; .UnmaskHighIrqController
189; Parameters:
190; AL: IRQ number (8...15)
191; Returns:
192; Nothing
193; Corrupts registers:
194; AX, DX
195;--------------------------------------------------------------------
196.UnmaskHighIrqController:
197 sub al, 8 ; Slave interrupt number
198 mov dx, SLAVE_8259_IMR
199 call .ClearBitFrom8259MaskRegister
200 mov al, 2 ; Master IRQ 2 to allow slave IRQs
201 ; Fall to .UnmaskLowIrqController
202
203;--------------------------------------------------------------------
204; .UnmaskLowIrqController
205; Parameters:
206; AL: IRQ number (0...7)
207; Returns:
208; Nothing
209; Corrupts registers:
210; AX, DX
211;--------------------------------------------------------------------
212.UnmaskLowIrqController:
213 mov dx, MASTER_8259_IMR
214 ; Fall to .ClearBitFrom8259MaskRegister
215
216;--------------------------------------------------------------------
217; .ClearBitFrom8259MaskRegister
218; Parameters:
219; AL: 8259 interrupt index (0...7)
220; DX: Port address to Interrupt Mask Register
221; Returns:
222; Nothing
223; Corrupts registers:
224; AX
225;--------------------------------------------------------------------
226.ClearBitFrom8259MaskRegister:
227 push cx
228 xchg ax, cx ; IRQ index to CL
229 mov ch, 1 ; Load 1 to be shifted
230 shl ch, cl ; Shift bit to correct position
231 not ch ; Invert to create bit mask for clearing
232 in al, dx ; Read Interrupt Mask Register
233 and al, ch ; Clear wanted bit
234 out dx, al ; Write modified Interrupt Mask Register
235 pop cx
236.Return:
237 ret
238
239%endif ; MODULE_IRQ
Note: See TracBrowser for help on using the repository browser.