[90] | 1 | ; Project name : XTIDE Universal BIOS |
---|
[33] | 2 | ; Description : Functions for initializing the BIOS. |
---|
| 3 | |
---|
| 4 | ; Section containing code |
---|
| 5 | SECTION .text |
---|
| 6 | |
---|
| 7 | ;-------------------------------------------------------------------- |
---|
| 8 | ; Interrupts_InitializeInterruptVectors |
---|
| 9 | ; Parameters: |
---|
| 10 | ; DS: RAMVARS segment |
---|
| 11 | ; ES: BDA and Interrupt Vector segment (zero) |
---|
| 12 | ; Returns: |
---|
| 13 | ; Nothing |
---|
| 14 | ; Corrupts registers: |
---|
| 15 | ; All except segments |
---|
[86] | 16 | ;-------------------------------------------------------------------- |
---|
[33] | 17 | Interrupts_InitializeInterruptVectors: |
---|
[97] | 18 | ; Fall to .InitializeInt13hAnd40h |
---|
[33] | 19 | |
---|
| 20 | ;-------------------------------------------------------------------- |
---|
[97] | 21 | ; .InitializeInt13hAnd40h |
---|
[33] | 22 | ; Parameters: |
---|
| 23 | ; DS: RAMVARS segment |
---|
| 24 | ; ES: BDA and Interrupt Vector segment (zero) |
---|
| 25 | ; Returns: |
---|
| 26 | ; Nothing |
---|
| 27 | ; Corrupts registers: |
---|
| 28 | ; AX, BX, CX, DX, SI, DI |
---|
[86] | 29 | ;-------------------------------------------------------------------- |
---|
[97] | 30 | .InitializeInt13hAnd40h: |
---|
[181] | 31 | mov ax, [es:BIOS_DISK_INTERRUPT_13h*4+2]; Load old INT 13h segment |
---|
| 32 | mov [RAMVARS.fpOldI13h+2], ax ; Store old INT 13h segment |
---|
| 33 | xchg dx, ax |
---|
[152] | 34 | mov ax, [es:BIOS_DISK_INTERRUPT_13h*4] ; Load old INT 13h offset |
---|
[33] | 35 | mov [RAMVARS.fpOldI13h], ax ; Store old INT 13h offset |
---|
[181] | 36 | |
---|
[152] | 37 | mov bx, BIOS_DISK_INTERRUPT_13h ; INT 13h interrupt vector offset |
---|
[148] | 38 | mov si, Int13h_DiskFunctionsHandler ; Interrupt handler offset |
---|
[33] | 39 | call Interrupts_InstallHandlerToVectorInBXFromCSSI |
---|
| 40 | |
---|
| 41 | ; Only store INT 13h handler to 40h if 40h is not already installed. |
---|
| 42 | ; At least AMI BIOS for 286 stores 40h handler by itself and calls |
---|
| 43 | ; 40h from 13h. That system locks to infinite loop if we copy 13h to 40h. |
---|
| 44 | call FloppyDrive_IsInt40hInstalled |
---|
[97] | 45 | jc SHORT .InitializeInt19h |
---|
[152] | 46 | mov [es:BIOS_DISKETTE_INTERRUPT_40h*4], ax ; Store old INT 13h offset |
---|
| 47 | mov [es:BIOS_DISKETTE_INTERRUPT_40h*4+2], dx ; Store old INT 13h segment |
---|
[97] | 48 | ; Fall to .InitializeInt19h |
---|
[33] | 49 | |
---|
| 50 | ;-------------------------------------------------------------------- |
---|
[97] | 51 | ; .InitializeInt19h |
---|
[33] | 52 | ; Parameters: |
---|
| 53 | ; DS: RAMVARS segment |
---|
| 54 | ; ES: BDA and Interrupt Vector segment (zero) |
---|
| 55 | ; Returns: |
---|
| 56 | ; Nothing |
---|
| 57 | ; Corrupts registers: |
---|
| 58 | ; BX, SI |
---|
[86] | 59 | ;-------------------------------------------------------------------- |
---|
[97] | 60 | .InitializeInt19h: |
---|
[152] | 61 | mov bx, BIOS_BOOT_LOADER_INTERRUPT_19h |
---|
[33] | 62 | mov si, Int19hMenu_BootLoader |
---|
[97] | 63 | call Interrupts_InstallHandlerToVectorInBXFromCSSI |
---|
| 64 | ; Fall to .InitializeHardwareIrqHandlers |
---|
[33] | 65 | |
---|
| 66 | ;-------------------------------------------------------------------- |
---|
[97] | 67 | ; .InitializeHardwareIrqHandlers |
---|
[33] | 68 | ; Parameters: |
---|
| 69 | ; ES: BDA and Interrupt Vector segment (zero) |
---|
| 70 | ; Returns: |
---|
| 71 | ; Nothing |
---|
| 72 | ; Corrupts registers: |
---|
| 73 | ; BX, CX, DX, SI, DI |
---|
[86] | 74 | ;-------------------------------------------------------------------- |
---|
[97] | 75 | .InitializeHardwareIrqHandlers: |
---|
[33] | 76 | call RamVars_GetIdeControllerCountToCX |
---|
| 77 | mov di, ROMVARS.ideVars0 ; CS:SI points to first IDEVARS |
---|
| 78 | .IdeControllerLoop: |
---|
| 79 | eMOVZX bx, BYTE [cs:di+IDEVARS.bIRQ] |
---|
| 80 | add di, BYTE IDEVARS_size ; Increment to next controller |
---|
| 81 | call .InstallLowOrHighIrqHandler |
---|
| 82 | loop .IdeControllerLoop |
---|
[86] | 83 | .Return: |
---|
| 84 | ret ; This ret is shared with .InstallLowOrHighIrqHandler |
---|
[33] | 85 | |
---|
| 86 | ;-------------------------------------------------------------------- |
---|
| 87 | ; .InstallLowOrHighIrqHandler |
---|
| 88 | ; Parameters: |
---|
| 89 | ; BX: IRQ number, 0 if IRQ disabled |
---|
| 90 | ; ES: BDA and Interrupt Vector segment (zero) |
---|
| 91 | ; Returns: |
---|
| 92 | ; Nothing |
---|
| 93 | ; Corrupts registers: |
---|
| 94 | ; BX, SI |
---|
[86] | 95 | ;-------------------------------------------------------------------- |
---|
[33] | 96 | .InstallLowOrHighIrqHandler: |
---|
[86] | 97 | test bl, bl |
---|
| 98 | jz SHORT .Return ; IRQ not used |
---|
[33] | 99 | cmp bl, 8 |
---|
[86] | 100 | jb SHORT .InstallLowIrqHandler |
---|
[162] | 101 | ; Fall to .InstallHighIrqHandler |
---|
[33] | 102 | |
---|
| 103 | ;-------------------------------------------------------------------- |
---|
| 104 | ; .InstallHighIrqHandler |
---|
| 105 | ; Parameters: |
---|
| 106 | ; BX: IRQ number (8...15) |
---|
| 107 | ; ES: BDA and Interrupt Vector segment (zero) |
---|
| 108 | ; Returns: |
---|
| 109 | ; Nothing |
---|
| 110 | ; Corrupts registers: |
---|
| 111 | ; BX, SI |
---|
[86] | 112 | ;-------------------------------------------------------------------- |
---|
[97] | 113 | .InstallHighIrqHandler: |
---|
[152] | 114 | add bx, BYTE HARDWARE_IRQ_8_INTERRUPT_70h - 8 ; Interrupt vector number |
---|
[150] | 115 | mov si, IdeIrq_InterruptServiceRoutineForIrqs8to15 |
---|
[33] | 116 | jmp SHORT Interrupts_InstallHandlerToVectorInBXFromCSSI |
---|
| 117 | |
---|
| 118 | ;-------------------------------------------------------------------- |
---|
| 119 | ; .InstallLowIrqHandler |
---|
| 120 | ; Parameters: |
---|
| 121 | ; BX: IRQ number (0...7) |
---|
| 122 | ; ES: BDA and Interrupt Vector segment (zero) |
---|
| 123 | ; Returns: |
---|
| 124 | ; Nothing |
---|
| 125 | ; Corrupts registers: |
---|
| 126 | ; BX, SI |
---|
[86] | 127 | ;-------------------------------------------------------------------- |
---|
[33] | 128 | .InstallLowIrqHandler: |
---|
[152] | 129 | add bx, BYTE HARDWARE_IRQ_0_INTERRUPT_08h ; Interrupt vector number |
---|
[150] | 130 | mov si, IdeIrq_InterruptServiceRoutineForIrqs2to7 |
---|
[33] | 131 | ; Fall to Interrupts_InstallHandlerToVectorInBXFromCSSI |
---|
| 132 | |
---|
| 133 | |
---|
| 134 | ;-------------------------------------------------------------------- |
---|
| 135 | ; Interrupts_InstallHandlerToVectorInBXFromCSSI |
---|
| 136 | ; Parameters: |
---|
| 137 | ; BX: Interrupt vector number (for example 13h) |
---|
| 138 | ; ES: BDA and Interrupt Vector segment (zero) |
---|
| 139 | ; CS:SI: Ptr to interrupt handler |
---|
| 140 | ; Returns: |
---|
| 141 | ; Nothing |
---|
| 142 | ; Corrupts registers: |
---|
| 143 | ; BX |
---|
[86] | 144 | ;-------------------------------------------------------------------- |
---|
[33] | 145 | Interrupts_InstallHandlerToVectorInBXFromCSSI: |
---|
[123] | 146 | eSHL_IM bx, 2 ; Shift for DWORD offset |
---|
[33] | 147 | mov [es:bx], si ; Store offset |
---|
| 148 | mov [es:bx+2], cs ; Store segment |
---|
| 149 | ret |
---|
| 150 | |
---|
| 151 | |
---|
| 152 | ;-------------------------------------------------------------------- |
---|
| 153 | ; Interrupts_UnmaskInterruptControllerForDriveInDSDI |
---|
| 154 | ; Parameters: |
---|
| 155 | ; DS:DI: Ptr to DPT |
---|
| 156 | ; Returns: |
---|
| 157 | ; Nothing |
---|
| 158 | ; Corrupts registers: |
---|
| 159 | ; AX, BX, DX |
---|
| 160 | ;-------------------------------------------------------------------- |
---|
| 161 | Interrupts_UnmaskInterruptControllerForDriveInDSDI: |
---|
[150] | 162 | eMOVZX bx, BYTE [di+DPT.bIdevarsOffset] |
---|
[33] | 163 | mov al, [cs:bx+IDEVARS.bIRQ] |
---|
[86] | 164 | test al, al |
---|
| 165 | jz SHORT .Return ; Interrupts disabled |
---|
[33] | 166 | cmp al, 8 |
---|
[86] | 167 | jb SHORT .UnmaskLowIrqController |
---|
[162] | 168 | ; Fall to .UnmaskHighIrqController |
---|
[33] | 169 | |
---|
| 170 | ;-------------------------------------------------------------------- |
---|
| 171 | ; .UnmaskHighIrqController |
---|
| 172 | ; Parameters: |
---|
| 173 | ; AL: IRQ number (8...15) |
---|
| 174 | ; Returns: |
---|
| 175 | ; Nothing |
---|
| 176 | ; Corrupts registers: |
---|
| 177 | ; AX, DX |
---|
| 178 | ;-------------------------------------------------------------------- |
---|
[97] | 179 | .UnmaskHighIrqController: |
---|
[33] | 180 | sub al, 8 ; Slave interrupt number |
---|
[152] | 181 | mov dx, SLAVE_8259_IMR |
---|
[33] | 182 | call .ClearBitFrom8259MaskRegister |
---|
| 183 | mov al, 2 ; Master IRQ 2 to allow slave IRQs |
---|
| 184 | ; Fall to .UnmaskLowIrqController |
---|
| 185 | |
---|
| 186 | ;-------------------------------------------------------------------- |
---|
| 187 | ; .UnmaskLowIrqController |
---|
| 188 | ; Parameters: |
---|
| 189 | ; AL: IRQ number (0...7) |
---|
| 190 | ; Returns: |
---|
| 191 | ; Nothing |
---|
| 192 | ; Corrupts registers: |
---|
| 193 | ; AX, DX |
---|
| 194 | ;-------------------------------------------------------------------- |
---|
| 195 | .UnmaskLowIrqController: |
---|
[152] | 196 | mov dx, MASTER_8259_IMR |
---|
[33] | 197 | ; Fall to .ClearBitFrom8259MaskRegister |
---|
| 198 | |
---|
| 199 | ;-------------------------------------------------------------------- |
---|
| 200 | ; .ClearBitFrom8259MaskRegister |
---|
| 201 | ; Parameters: |
---|
| 202 | ; AL: 8259 interrupt index (0...7) |
---|
| 203 | ; DX: Port address to Interrupt Mask Register |
---|
| 204 | ; Returns: |
---|
| 205 | ; Nothing |
---|
| 206 | ; Corrupts registers: |
---|
| 207 | ; AX |
---|
| 208 | ;-------------------------------------------------------------------- |
---|
| 209 | .ClearBitFrom8259MaskRegister: |
---|
| 210 | push cx |
---|
| 211 | xchg ax, cx ; IRQ index to CL |
---|
| 212 | mov ch, 1 ; Load 1 to be shifted |
---|
| 213 | shl ch, cl ; Shift bit to correct position |
---|
| 214 | not ch ; Invert to create bit mask for clearing |
---|
| 215 | in al, dx ; Read Interrupt Mask Register |
---|
| 216 | and al, ch ; Clear wanted bit |
---|
| 217 | out dx, al ; Write modified Interrupt Mask Register |
---|
| 218 | pop cx |
---|
[86] | 219 | .Return: |
---|
[33] | 220 | ret |
---|