[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
|
---|
| 63 | mov si, Int13h_DiskFunctionsHandler ; Interrupt handler offset
|
---|
| 64 | call Interrupts_InstallHandlerToVectorInALFromCSSI
|
---|
[97] | 65 | ; Fall to .InitializeHardwareIrqHandlers
|
---|
[33] | 66 |
|
---|
| 67 | ;--------------------------------------------------------------------
|
---|
[97] | 68 | ; .InitializeHardwareIrqHandlers
|
---|
[33] | 69 | ; Parameters:
|
---|
| 70 | ; ES: BDA and Interrupt Vector segment (zero)
|
---|
| 71 | ; Returns:
|
---|
| 72 | ; Nothing
|
---|
| 73 | ; Corrupts registers:
|
---|
[258] | 74 | ; BX, CX, DX, SI, DI, AX
|
---|
[86] | 75 | ;--------------------------------------------------------------------
|
---|
[97] | 76 | .InitializeHardwareIrqHandlers:
|
---|
[33] | 77 | call RamVars_GetIdeControllerCountToCX
|
---|
| 78 | mov di, ROMVARS.ideVars0 ; CS:SI points to first IDEVARS
|
---|
| 79 | .IdeControllerLoop:
|
---|
[294] | 80 | mov al, [cs:di+IDEVARS.bIRQ]
|
---|
[33] | 81 | add di, BYTE IDEVARS_size ; Increment to next controller
|
---|
| 82 | call .InstallLowOrHighIrqHandler
|
---|
| 83 | loop .IdeControllerLoop
|
---|
[86] | 84 | .Return:
|
---|
| 85 | ret ; This ret is shared with .InstallLowOrHighIrqHandler
|
---|
[33] | 86 |
|
---|
| 87 | ;--------------------------------------------------------------------
|
---|
| 88 | ; .InstallLowOrHighIrqHandler
|
---|
| 89 | ; Parameters:
|
---|
[258] | 90 | ; AL: IRQ number, 0 if IRQ disabled
|
---|
[33] | 91 | ; ES: BDA and Interrupt Vector segment (zero)
|
---|
| 92 | ; Returns:
|
---|
| 93 | ; Nothing
|
---|
| 94 | ; Corrupts registers:
|
---|
| 95 | ; BX, SI
|
---|
[86] | 96 | ;--------------------------------------------------------------------
|
---|
[33] | 97 | .InstallLowOrHighIrqHandler:
|
---|
[258] | 98 | test al, al
|
---|
[86] | 99 | jz SHORT .Return ; IRQ not used
|
---|
[258] | 100 | cmp al, 8
|
---|
[86] | 101 | jb SHORT .InstallLowIrqHandler
|
---|
[162] | 102 | ; Fall to .InstallHighIrqHandler
|
---|
[33] | 103 |
|
---|
| 104 | ;--------------------------------------------------------------------
|
---|
| 105 | ; .InstallHighIrqHandler
|
---|
| 106 | ; Parameters:
|
---|
| 107 | ; BX: IRQ number (8...15)
|
---|
| 108 | ; ES: BDA and Interrupt Vector segment (zero)
|
---|
| 109 | ; Returns:
|
---|
| 110 | ; Nothing
|
---|
| 111 | ; Corrupts registers:
|
---|
[258] | 112 | ; AL, BX, SI
|
---|
[86] | 113 | ;--------------------------------------------------------------------
|
---|
[97] | 114 | .InstallHighIrqHandler:
|
---|
[258] | 115 | add al, BYTE HARDWARE_IRQ_8_INTERRUPT_70h - 8 ; Interrupt vector number
|
---|
[150] | 116 | mov si, IdeIrq_InterruptServiceRoutineForIrqs8to15
|
---|
[258] | 117 | jmp SHORT Interrupts_InstallHandlerToVectorInALFromCSSI
|
---|
[33] | 118 |
|
---|
| 119 | ;--------------------------------------------------------------------
|
---|
| 120 | ; .InstallLowIrqHandler
|
---|
| 121 | ; Parameters:
|
---|
[258] | 122 | ; AL: IRQ number (0...7)
|
---|
[33] | 123 | ; ES: BDA and Interrupt Vector segment (zero)
|
---|
| 124 | ; Returns:
|
---|
| 125 | ; Nothing
|
---|
| 126 | ; Corrupts registers:
|
---|
[258] | 127 | ; AL, BX, SI
|
---|
[86] | 128 | ;--------------------------------------------------------------------
|
---|
[33] | 129 | .InstallLowIrqHandler:
|
---|
[258] | 130 | add al, BYTE HARDWARE_IRQ_0_INTERRUPT_08h ; Interrupt vector number
|
---|
[150] | 131 | mov si, IdeIrq_InterruptServiceRoutineForIrqs2to7
|
---|
[258] | 132 | ; Fall to Interrupts_InstallHandlerToVectorInALFromCSSI
|
---|
[33] | 133 |
|
---|
| 134 |
|
---|
| 135 | ;--------------------------------------------------------------------
|
---|
[258] | 136 | ; Interrupts_InstallHandlerToVectorInALFromCSSI
|
---|
[33] | 137 | ; Parameters:
|
---|
[258] | 138 | ; AL: Interrupt vector number (for example 13h)
|
---|
[33] | 139 | ; ES: BDA and Interrupt Vector segment (zero)
|
---|
| 140 | ; CS:SI: Ptr to interrupt handler
|
---|
| 141 | ; Returns:
|
---|
| 142 | ; Nothing
|
---|
| 143 | ; Corrupts registers:
|
---|
[258] | 144 | ; AX, BX
|
---|
[86] | 145 | ;--------------------------------------------------------------------
|
---|
[258] | 146 | Interrupts_InstallHandlerToVectorInALFromCSSI:
|
---|
| 147 | mov bl, 4 ; Shift for DWORD offset, MUL smaller than other alternatives
|
---|
| 148 | mul bl
|
---|
| 149 | xchg ax, bx
|
---|
[33] | 150 | mov [es:bx], si ; Store offset
|
---|
| 151 | mov [es:bx+2], cs ; Store segment
|
---|
| 152 | ret
|
---|
| 153 |
|
---|
| 154 |
|
---|
| 155 | ;--------------------------------------------------------------------
|
---|
| 156 | ; Interrupts_UnmaskInterruptControllerForDriveInDSDI
|
---|
| 157 | ; Parameters:
|
---|
| 158 | ; DS:DI: Ptr to DPT
|
---|
| 159 | ; Returns:
|
---|
| 160 | ; Nothing
|
---|
| 161 | ; Corrupts registers:
|
---|
| 162 | ; AX, BX, DX
|
---|
| 163 | ;--------------------------------------------------------------------
|
---|
| 164 | Interrupts_UnmaskInterruptControllerForDriveInDSDI:
|
---|
[294] | 165 | eMOVZX bx, [di+DPT.bIdevarsOffset]
|
---|
[33] | 166 | mov al, [cs:bx+IDEVARS.bIRQ]
|
---|
[86] | 167 | test al, al
|
---|
| 168 | jz SHORT .Return ; Interrupts disabled
|
---|
[33] | 169 | cmp al, 8
|
---|
[86] | 170 | jb SHORT .UnmaskLowIrqController
|
---|
[162] | 171 | ; Fall to .UnmaskHighIrqController
|
---|
[33] | 172 |
|
---|
| 173 | ;--------------------------------------------------------------------
|
---|
| 174 | ; .UnmaskHighIrqController
|
---|
| 175 | ; Parameters:
|
---|
| 176 | ; AL: IRQ number (8...15)
|
---|
| 177 | ; Returns:
|
---|
| 178 | ; Nothing
|
---|
| 179 | ; Corrupts registers:
|
---|
| 180 | ; AX, DX
|
---|
| 181 | ;--------------------------------------------------------------------
|
---|
[97] | 182 | .UnmaskHighIrqController:
|
---|
[33] | 183 | sub al, 8 ; Slave interrupt number
|
---|
[152] | 184 | mov dx, SLAVE_8259_IMR
|
---|
[33] | 185 | call .ClearBitFrom8259MaskRegister
|
---|
| 186 | mov al, 2 ; Master IRQ 2 to allow slave IRQs
|
---|
| 187 | ; Fall to .UnmaskLowIrqController
|
---|
| 188 |
|
---|
| 189 | ;--------------------------------------------------------------------
|
---|
| 190 | ; .UnmaskLowIrqController
|
---|
| 191 | ; Parameters:
|
---|
| 192 | ; AL: IRQ number (0...7)
|
---|
| 193 | ; Returns:
|
---|
| 194 | ; Nothing
|
---|
| 195 | ; Corrupts registers:
|
---|
| 196 | ; AX, DX
|
---|
| 197 | ;--------------------------------------------------------------------
|
---|
| 198 | .UnmaskLowIrqController:
|
---|
[152] | 199 | mov dx, MASTER_8259_IMR
|
---|
[33] | 200 | ; Fall to .ClearBitFrom8259MaskRegister
|
---|
| 201 |
|
---|
| 202 | ;--------------------------------------------------------------------
|
---|
| 203 | ; .ClearBitFrom8259MaskRegister
|
---|
| 204 | ; Parameters:
|
---|
| 205 | ; AL: 8259 interrupt index (0...7)
|
---|
| 206 | ; DX: Port address to Interrupt Mask Register
|
---|
| 207 | ; Returns:
|
---|
| 208 | ; Nothing
|
---|
| 209 | ; Corrupts registers:
|
---|
| 210 | ; AX
|
---|
| 211 | ;--------------------------------------------------------------------
|
---|
| 212 | .ClearBitFrom8259MaskRegister:
|
---|
| 213 | push cx
|
---|
| 214 | xchg ax, cx ; IRQ index to CL
|
---|
| 215 | mov ch, 1 ; Load 1 to be shifted
|
---|
| 216 | shl ch, cl ; Shift bit to correct position
|
---|
| 217 | not ch ; Invert to create bit mask for clearing
|
---|
| 218 | in al, dx ; Read Interrupt Mask Register
|
---|
| 219 | and al, ch ; Clear wanted bit
|
---|
| 220 | out dx, al ; Write modified Interrupt Mask Register
|
---|
| 221 | pop cx
|
---|
[86] | 222 | .Return:
|
---|
[33] | 223 | ret
|
---|