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

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

Changes to XTIDE Universal BIOS:

  • IRQ related stuff is now optional MODULE_IRQ.
  • XT builds no longer include support for IDE IRQ.
File size: 7.9 KB
RevLine 
[90]1; Project name : XTIDE Universal BIOS
[33]2; Description : Functions for initializing the BIOS.
3
[376]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
[33]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
[86]32;--------------------------------------------------------------------
[33]33Interrupts_InitializeInterruptVectors:
[97]34 ; Fall to .InitializeInt13hAnd40h
[33]35
36;--------------------------------------------------------------------
[97]37; .InitializeInt13hAnd40h
[33]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
[86]45;--------------------------------------------------------------------
[97]46.InitializeInt13hAnd40h:
[181]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
[152]50 mov ax, [es:BIOS_DISK_INTERRUPT_13h*4] ; Load old INT 13h offset
[33]51 mov [RAMVARS.fpOldI13h], ax ; Store old INT 13h offset
[181]52
[33]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
[243]57 jc SHORT .Int40hAlreadyInstalled
[152]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
[243]60.Int40hAlreadyInstalled:
[258]61
62 mov al, BIOS_DISK_INTERRUPT_13h ; INT 13h interrupt vector offset
63 mov si, Int13h_DiskFunctionsHandler ; Interrupt handler offset
64 call Interrupts_InstallHandlerToVectorInALFromCSSI
[392]65
66 ; Install INT 19h handler to properly reset the system
67 mov al, BIOS_BOOT_LOADER_INTERRUPT_19h ; INT 19h interrupt vector offset
68 mov si, Int19hReset_Handler ; INT 19h handler to reboot the system
[398]69%ifndef MODULE_IRQ
70 ; Fall to Interrupts_InstallHandlerToVectorInALFromCSSI
71%else
[392]72 call Interrupts_InstallHandlerToVectorInALFromCSSI
[97]73 ; Fall to .InitializeHardwareIrqHandlers
[33]74
75;--------------------------------------------------------------------
[97]76; .InitializeHardwareIrqHandlers
[33]77; Parameters:
78; ES: BDA and Interrupt Vector segment (zero)
79; Returns:
80; Nothing
81; Corrupts registers:
[258]82; BX, CX, DX, SI, DI, AX
[86]83;--------------------------------------------------------------------
[97]84.InitializeHardwareIrqHandlers:
[33]85 call RamVars_GetIdeControllerCountToCX
86 mov di, ROMVARS.ideVars0 ; CS:SI points to first IDEVARS
87.IdeControllerLoop:
[294]88 mov al, [cs:di+IDEVARS.bIRQ]
[33]89 add di, BYTE IDEVARS_size ; Increment to next controller
90 call .InstallLowOrHighIrqHandler
91 loop .IdeControllerLoop
[86]92.Return:
93 ret ; This ret is shared with .InstallLowOrHighIrqHandler
[33]94
95;--------------------------------------------------------------------
96; .InstallLowOrHighIrqHandler
97; Parameters:
[258]98; AL: IRQ number, 0 if IRQ disabled
[33]99; ES: BDA and Interrupt Vector segment (zero)
100; Returns:
101; Nothing
102; Corrupts registers:
103; BX, SI
[86]104;--------------------------------------------------------------------
[33]105.InstallLowOrHighIrqHandler:
[258]106 test al, al
[86]107 jz SHORT .Return ; IRQ not used
[258]108 cmp al, 8
[86]109 jb SHORT .InstallLowIrqHandler
[162]110 ; Fall to .InstallHighIrqHandler
[33]111
112;--------------------------------------------------------------------
113; .InstallHighIrqHandler
114; Parameters:
115; BX: IRQ number (8...15)
116; ES: BDA and Interrupt Vector segment (zero)
117; Returns:
118; Nothing
119; Corrupts registers:
[258]120; AL, BX, SI
[86]121;--------------------------------------------------------------------
[97]122.InstallHighIrqHandler:
[258]123 add al, BYTE HARDWARE_IRQ_8_INTERRUPT_70h - 8 ; Interrupt vector number
[150]124 mov si, IdeIrq_InterruptServiceRoutineForIrqs8to15
[258]125 jmp SHORT Interrupts_InstallHandlerToVectorInALFromCSSI
[33]126
127;--------------------------------------------------------------------
128; .InstallLowIrqHandler
129; Parameters:
[258]130; AL: IRQ number (0...7)
[33]131; ES: BDA and Interrupt Vector segment (zero)
132; Returns:
133; Nothing
134; Corrupts registers:
[258]135; AL, BX, SI
[86]136;--------------------------------------------------------------------
[33]137.InstallLowIrqHandler:
[258]138 add al, BYTE HARDWARE_IRQ_0_INTERRUPT_08h ; Interrupt vector number
[150]139 mov si, IdeIrq_InterruptServiceRoutineForIrqs2to7
[258]140 ; Fall to Interrupts_InstallHandlerToVectorInALFromCSSI
[398]141%endif ; MODULE_IRQ
[33]142
143
144;--------------------------------------------------------------------
[258]145; Interrupts_InstallHandlerToVectorInALFromCSSI
[33]146; Parameters:
[258]147; AL: Interrupt vector number (for example 13h)
[33]148; ES: BDA and Interrupt Vector segment (zero)
149; CS:SI: Ptr to interrupt handler
150; Returns:
151; Nothing
152; Corrupts registers:
[258]153; AX, BX
[86]154;--------------------------------------------------------------------
[258]155Interrupts_InstallHandlerToVectorInALFromCSSI:
156 mov bl, 4 ; Shift for DWORD offset, MUL smaller than other alternatives
157 mul bl
158 xchg ax, bx
[33]159 mov [es:bx], si ; Store offset
160 mov [es:bx+2], cs ; Store segment
161 ret
162
163
[398]164%ifdef MODULE_IRQ
[33]165;--------------------------------------------------------------------
166; Interrupts_UnmaskInterruptControllerForDriveInDSDI
167; Parameters:
168; DS:DI: Ptr to DPT
169; Returns:
170; Nothing
171; Corrupts registers:
172; AX, BX, DX
173;--------------------------------------------------------------------
174Interrupts_UnmaskInterruptControllerForDriveInDSDI:
[294]175 eMOVZX bx, [di+DPT.bIdevarsOffset]
[33]176 mov al, [cs:bx+IDEVARS.bIRQ]
[86]177 test al, al
178 jz SHORT .Return ; Interrupts disabled
[33]179 cmp al, 8
[86]180 jb SHORT .UnmaskLowIrqController
[162]181 ; Fall to .UnmaskHighIrqController
[33]182
183;--------------------------------------------------------------------
184; .UnmaskHighIrqController
185; Parameters:
186; AL: IRQ number (8...15)
187; Returns:
188; Nothing
189; Corrupts registers:
190; AX, DX
191;--------------------------------------------------------------------
[97]192.UnmaskHighIrqController:
[33]193 sub al, 8 ; Slave interrupt number
[152]194 mov dx, SLAVE_8259_IMR
[33]195 call .ClearBitFrom8259MaskRegister
196 mov al, 2 ; Master IRQ 2 to allow slave IRQs
197 ; Fall to .UnmaskLowIrqController
198
199;--------------------------------------------------------------------
200; .UnmaskLowIrqController
201; Parameters:
202; AL: IRQ number (0...7)
203; Returns:
204; Nothing
205; Corrupts registers:
206; AX, DX
207;--------------------------------------------------------------------
208.UnmaskLowIrqController:
[152]209 mov dx, MASTER_8259_IMR
[33]210 ; Fall to .ClearBitFrom8259MaskRegister
211
212;--------------------------------------------------------------------
213; .ClearBitFrom8259MaskRegister
214; Parameters:
215; AL: 8259 interrupt index (0...7)
216; DX: Port address to Interrupt Mask Register
217; Returns:
218; Nothing
219; Corrupts registers:
220; AX
221;--------------------------------------------------------------------
222.ClearBitFrom8259MaskRegister:
223 push cx
224 xchg ax, cx ; IRQ index to CL
225 mov ch, 1 ; Load 1 to be shifted
226 shl ch, cl ; Shift bit to correct position
227 not ch ; Invert to create bit mask for clearing
228 in al, dx ; Read Interrupt Mask Register
229 and al, ch ; Clear wanted bit
230 out dx, al ; Write modified Interrupt Mask Register
231 pop cx
[86]232.Return:
[33]233 ret
[398]234
235%endif ; MODULE_IRQ
Note: See TracBrowser for help on using the repository browser.