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