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