[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
|
---|
| 21 | SECTION .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] | 33 | Interrupts_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
|
---|
[417] | 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
|
---|
[258] | 68 | call Interrupts_InstallHandlerToVectorInALFromCSSI
|
---|
[392] | 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
|
---|
[398] | 73 | %ifndef MODULE_IRQ
|
---|
| 74 | ; Fall to Interrupts_InstallHandlerToVectorInALFromCSSI
|
---|
| 75 | %else
|
---|
[392] | 76 | call Interrupts_InstallHandlerToVectorInALFromCSSI
|
---|
[97] | 77 | ; Fall to .InitializeHardwareIrqHandlers
|
---|
[33] | 78 |
|
---|
| 79 | ;--------------------------------------------------------------------
|
---|
[97] | 80 | ; .InitializeHardwareIrqHandlers
|
---|
[33] | 81 | ; Parameters:
|
---|
| 82 | ; ES: BDA and Interrupt Vector segment (zero)
|
---|
| 83 | ; Returns:
|
---|
| 84 | ; Nothing
|
---|
| 85 | ; Corrupts registers:
|
---|
[258] | 86 | ; BX, CX, DX, SI, DI, AX
|
---|
[86] | 87 | ;--------------------------------------------------------------------
|
---|
[97] | 88 | .InitializeHardwareIrqHandlers:
|
---|
[33] | 89 | call RamVars_GetIdeControllerCountToCX
|
---|
| 90 | mov di, ROMVARS.ideVars0 ; CS:SI points to first IDEVARS
|
---|
| 91 | .IdeControllerLoop:
|
---|
[294] | 92 | mov al, [cs:di+IDEVARS.bIRQ]
|
---|
[33] | 93 | add di, BYTE IDEVARS_size ; Increment to next controller
|
---|
| 94 | call .InstallLowOrHighIrqHandler
|
---|
| 95 | loop .IdeControllerLoop
|
---|
[86] | 96 | .Return:
|
---|
| 97 | ret ; This ret is shared with .InstallLowOrHighIrqHandler
|
---|
[33] | 98 |
|
---|
| 99 | ;--------------------------------------------------------------------
|
---|
| 100 | ; .InstallLowOrHighIrqHandler
|
---|
| 101 | ; Parameters:
|
---|
[258] | 102 | ; AL: IRQ number, 0 if IRQ disabled
|
---|
[33] | 103 | ; ES: BDA and Interrupt Vector segment (zero)
|
---|
| 104 | ; Returns:
|
---|
| 105 | ; Nothing
|
---|
| 106 | ; Corrupts registers:
|
---|
| 107 | ; BX, SI
|
---|
[86] | 108 | ;--------------------------------------------------------------------
|
---|
[33] | 109 | .InstallLowOrHighIrqHandler:
|
---|
[258] | 110 | test al, al
|
---|
[86] | 111 | jz SHORT .Return ; IRQ not used
|
---|
[258] | 112 | cmp al, 8
|
---|
[86] | 113 | jb SHORT .InstallLowIrqHandler
|
---|
[162] | 114 | ; Fall to .InstallHighIrqHandler
|
---|
[33] | 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:
|
---|
[258] | 124 | ; AL, BX, SI
|
---|
[86] | 125 | ;--------------------------------------------------------------------
|
---|
[97] | 126 | .InstallHighIrqHandler:
|
---|
[258] | 127 | add al, BYTE HARDWARE_IRQ_8_INTERRUPT_70h - 8 ; Interrupt vector number
|
---|
[150] | 128 | mov si, IdeIrq_InterruptServiceRoutineForIrqs8to15
|
---|
[258] | 129 | jmp SHORT Interrupts_InstallHandlerToVectorInALFromCSSI
|
---|
[33] | 130 |
|
---|
| 131 | ;--------------------------------------------------------------------
|
---|
| 132 | ; .InstallLowIrqHandler
|
---|
| 133 | ; Parameters:
|
---|
[258] | 134 | ; AL: IRQ number (0...7)
|
---|
[33] | 135 | ; ES: BDA and Interrupt Vector segment (zero)
|
---|
| 136 | ; Returns:
|
---|
| 137 | ; Nothing
|
---|
| 138 | ; Corrupts registers:
|
---|
[258] | 139 | ; AL, BX, SI
|
---|
[86] | 140 | ;--------------------------------------------------------------------
|
---|
[33] | 141 | .InstallLowIrqHandler:
|
---|
[258] | 142 | add al, BYTE HARDWARE_IRQ_0_INTERRUPT_08h ; Interrupt vector number
|
---|
[150] | 143 | mov si, IdeIrq_InterruptServiceRoutineForIrqs2to7
|
---|
[258] | 144 | ; Fall to Interrupts_InstallHandlerToVectorInALFromCSSI
|
---|
[398] | 145 | %endif ; MODULE_IRQ
|
---|
[33] | 146 |
|
---|
| 147 |
|
---|
| 148 | ;--------------------------------------------------------------------
|
---|
[258] | 149 | ; Interrupts_InstallHandlerToVectorInALFromCSSI
|
---|
[33] | 150 | ; Parameters:
|
---|
[258] | 151 | ; AL: Interrupt vector number (for example 13h)
|
---|
[33] | 152 | ; ES: BDA and Interrupt Vector segment (zero)
|
---|
| 153 | ; CS:SI: Ptr to interrupt handler
|
---|
| 154 | ; Returns:
|
---|
| 155 | ; Nothing
|
---|
| 156 | ; Corrupts registers:
|
---|
[258] | 157 | ; AX, BX
|
---|
[86] | 158 | ;--------------------------------------------------------------------
|
---|
[258] | 159 | Interrupts_InstallHandlerToVectorInALFromCSSI:
|
---|
| 160 | mov bl, 4 ; Shift for DWORD offset, MUL smaller than other alternatives
|
---|
| 161 | mul bl
|
---|
| 162 | xchg ax, bx
|
---|
[33] | 163 | mov [es:bx], si ; Store offset
|
---|
| 164 | mov [es:bx+2], cs ; Store segment
|
---|
| 165 | ret
|
---|
| 166 |
|
---|
| 167 |
|
---|
[398] | 168 | %ifdef MODULE_IRQ
|
---|
[33] | 169 | ;--------------------------------------------------------------------
|
---|
| 170 | ; Interrupts_UnmaskInterruptControllerForDriveInDSDI
|
---|
| 171 | ; Parameters:
|
---|
| 172 | ; DS:DI: Ptr to DPT
|
---|
| 173 | ; Returns:
|
---|
| 174 | ; Nothing
|
---|
| 175 | ; Corrupts registers:
|
---|
| 176 | ; AX, BX, DX
|
---|
| 177 | ;--------------------------------------------------------------------
|
---|
| 178 | Interrupts_UnmaskInterruptControllerForDriveInDSDI:
|
---|
[294] | 179 | eMOVZX bx, [di+DPT.bIdevarsOffset]
|
---|
[33] | 180 | mov al, [cs:bx+IDEVARS.bIRQ]
|
---|
[86] | 181 | test al, al
|
---|
| 182 | jz SHORT .Return ; Interrupts disabled
|
---|
[33] | 183 | cmp al, 8
|
---|
[86] | 184 | jb SHORT .UnmaskLowIrqController
|
---|
[162] | 185 | ; Fall to .UnmaskHighIrqController
|
---|
[33] | 186 |
|
---|
| 187 | ;--------------------------------------------------------------------
|
---|
| 188 | ; .UnmaskHighIrqController
|
---|
| 189 | ; Parameters:
|
---|
| 190 | ; AL: IRQ number (8...15)
|
---|
| 191 | ; Returns:
|
---|
| 192 | ; Nothing
|
---|
| 193 | ; Corrupts registers:
|
---|
| 194 | ; AX, DX
|
---|
| 195 | ;--------------------------------------------------------------------
|
---|
[97] | 196 | .UnmaskHighIrqController:
|
---|
[33] | 197 | sub al, 8 ; Slave interrupt number
|
---|
[152] | 198 | mov dx, SLAVE_8259_IMR
|
---|
[33] | 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:
|
---|
[152] | 213 | mov dx, MASTER_8259_IMR
|
---|
[33] | 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
|
---|
[86] | 236 | .Return:
|
---|
[33] | 237 | ret
|
---|
[398] | 238 |
|
---|
| 239 | %endif ; MODULE_IRQ
|
---|