[3] | 1 | ; File name : HIRQ.asm |
---|
| 2 | ; Project name : IDE BIOS |
---|
| 3 | ; Created date : 11.12.2009 |
---|
| 4 | ; Last update : 28.3.2010 |
---|
| 5 | ; Author : Tomi Tilli |
---|
| 6 | ; Description : Interrupt handling related functions. |
---|
| 7 | |
---|
| 8 | ; Section containing code |
---|
| 9 | SECTION .text |
---|
| 10 | |
---|
| 11 | ;-------------------------------------------------------------------- |
---|
| 12 | ; Wait for IRQ. |
---|
| 13 | ; |
---|
| 14 | ; HIRQ_WaitIRQ |
---|
| 15 | ; Parameters: |
---|
| 16 | ; DS: RAMVARS segment |
---|
| 17 | ; Returns: |
---|
| 18 | ; AH: BIOS Error code |
---|
| 19 | ; CF: Cleared if wait succesfull |
---|
| 20 | ; Set if any error |
---|
| 21 | ; Corrupts registers: |
---|
| 22 | ; AL, CX |
---|
| 23 | ;-------------------------------------------------------------------- |
---|
| 24 | ALIGN JUMP_ALIGN |
---|
| 25 | HIRQ_WaitIRQ: |
---|
| 26 | ; Load BDA segment to ES |
---|
| 27 | push es |
---|
| 28 | xor ax, ax ; Zero AX and clear CF |
---|
| 29 | mov es, ax ; Copy BDA segment (zero) to ES |
---|
| 30 | |
---|
| 31 | ; Check if interrupt has already occurred |
---|
| 32 | cli ; Disable interrupts |
---|
| 33 | cmp [es:BDA.bHDTaskFlg], al ; Interrupt ready? |
---|
| 34 | jne SHORT .CheckIdeErrors ; If so, return |
---|
| 35 | |
---|
| 36 | %ifdef USE_AT ; OS hook only available on AT+ machines |
---|
| 37 | ; OS device busy notification |
---|
| 38 | mov ah, 90h ; Hard disk busy (AX=9000h) |
---|
| 39 | int INTV_SYSTEM_SERVICES ; OS hook, device busy |
---|
| 40 | jnc SHORT .WaitUntilTaskFlagSet ; CF cleared, BIOS handles waiting |
---|
| 41 | test ah, ah ; OS hook supported? (clear CF) |
---|
| 42 | jz SHORT .CheckIdeErrors ; If so, waiting completed |
---|
| 43 | ALIGN JUMP_ALIGN |
---|
| 44 | .WaitUntilTaskFlagSet: |
---|
| 45 | %endif |
---|
| 46 | |
---|
| 47 | ; Poll task flag until it has been set by interrupt service routine |
---|
| 48 | call HIRQ_WaitUntilTaskFlagIsSet |
---|
| 49 | jc SHORT .ReturnTimeout ; Return if timeout |
---|
| 50 | |
---|
| 51 | ALIGN JUMP_ALIGN |
---|
| 52 | .CheckIdeErrors: |
---|
| 53 | mov ax, [es:HDBDA.wHDStAndErr] ; Load Status and Error regs stored by ISR |
---|
| 54 | call HError_ConvertIdeErrorToBiosRet |
---|
| 55 | .ReturnTimeout: |
---|
| 56 | mov BYTE [es:BDA.bHDTaskFlg], 0 ; Clear Task Flag |
---|
| 57 | pop es |
---|
| 58 | sti ; Enable interrupts |
---|
| 59 | ret |
---|
| 60 | |
---|
| 61 | |
---|
| 62 | ;-------------------------------------------------------------------- |
---|
| 63 | ; Polls IRQ Task Flag until it has been set or timeout. |
---|
| 64 | ; |
---|
| 65 | ; HIRQ_WaitUntilTaskFlagIsSet |
---|
| 66 | ; Parameters: |
---|
| 67 | ; DS: RAMVARS segment |
---|
| 68 | ; ES: BDA segment |
---|
| 69 | ; Returns: |
---|
| 70 | ; AH: BIOS Error code |
---|
| 71 | ; CF: Cleared if wait succesfull |
---|
| 72 | ; Set if timeout |
---|
| 73 | ; Corrupts registers: |
---|
| 74 | ; AL, CX |
---|
| 75 | ;-------------------------------------------------------------------- |
---|
| 76 | ALIGN JUMP_ALIGN |
---|
| 77 | HIRQ_WaitUntilTaskFlagIsSet: |
---|
| 78 | sti ; Enable interrupts |
---|
| 79 | mov cl, B_TIMEOUT_DRQ ; Load timeout ticks |
---|
| 80 | call SoftDelay_InitTimeout ; Initialize timeout counter |
---|
| 81 | xor ax, ax ; Zero AX |
---|
| 82 | ALIGN JUMP_ALIGN |
---|
| 83 | .PollIrqFlag: |
---|
| 84 | cli ; Disable interrupts |
---|
| 85 | cmp [es:BDA.bHDTaskFlg], al ; Task flag set? |
---|
| 86 | jne SHORT .TaskFlagIsSet ; If so, return |
---|
| 87 | call SoftDelay_UpdTimeout ; Update timeout |
---|
| 88 | jc SHORT .Timeout ; Return if timeout |
---|
| 89 | sti ; Enable interrupts (one instruction delay) |
---|
| 90 | hlt ; Sleep until any interrupt |
---|
| 91 | jmp SHORT .PollIrqFlag ; Jump to check if IDE interrupt |
---|
| 92 | |
---|
| 93 | ALIGN JUMP_ALIGN |
---|
| 94 | .TaskFlagIsSet: |
---|
| 95 | xor ah, ah ; Zero AH, clear CF |
---|
| 96 | ret |
---|
| 97 | .Timeout: |
---|
| 98 | mov ah, RET_HD_TIMEOUT ; Load error code for timeout |
---|
| 99 | ret |
---|
| 100 | |
---|
| 101 | |
---|
| 102 | ;-------------------------------------------------------------------- |
---|
| 103 | ; Clears task (interrupt) flag from BIOS Data Area. |
---|
| 104 | ; |
---|
| 105 | ; HIRQ_ClearTaskFlag |
---|
| 106 | ; Parameters: |
---|
| 107 | ; Nothing |
---|
| 108 | ; Returns: |
---|
| 109 | ; Nothing |
---|
| 110 | ; Corrupts registers: |
---|
| 111 | ; AX |
---|
| 112 | ;-------------------------------------------------------------------- |
---|
| 113 | ALIGN JUMP_ALIGN |
---|
| 114 | HIRQ_ClearTaskFlag: |
---|
| 115 | push ds |
---|
| 116 | LOAD_BDA_SEGMENT_TO ds, ax ; Also zero AX |
---|
| 117 | mov [BDA.bHDTaskFlg], al |
---|
| 118 | pop ds |
---|
| 119 | ret |
---|
| 120 | |
---|
| 121 | |
---|
| 122 | ;-------------------------------------------------------------------- |
---|
| 123 | ; IDE Interrupt Service Routines. |
---|
| 124 | ; |
---|
| 125 | ; HIRQ_InterruptServiceRoutineForIrqs2to7 |
---|
| 126 | ; HIRQ_InterruptServiceRoutineForIrqs8to15 |
---|
| 127 | ; Parameters: |
---|
| 128 | ; Nothing |
---|
| 129 | ; Returns: |
---|
| 130 | ; Nothing |
---|
| 131 | ; Corrupts registers: |
---|
| 132 | ; Nothing |
---|
| 133 | ;-------------------------------------------------------------------- |
---|
| 134 | ALIGN JUMP_ALIGN |
---|
| 135 | HIRQ_InterruptServiceRoutineForIrqs2to7: |
---|
| 136 | ; Acknowledge IDE interrupt by reading status register |
---|
| 137 | push ax |
---|
| 138 | call ISR_IDE_AcknowledgeIdeAndStoreStatusToBDA |
---|
| 139 | mov al, CMD_END_OF_INTERRUPT |
---|
| 140 | jmp SHORT HIRQ_AcknowledgeMasterController |
---|
| 141 | |
---|
| 142 | ALIGN JUMP_ALIGN |
---|
| 143 | HIRQ_InterruptServiceRoutineForIrqs8to15: |
---|
| 144 | push ax |
---|
| 145 | call ISR_IDE_AcknowledgeIdeAndStoreStatusToBDA |
---|
| 146 | |
---|
| 147 | mov al, CMD_END_OF_INTERRUPT ; Load EOI command to AL |
---|
| 148 | out WPORT_8259SL_COMMAND, al ; Acknowledge Slave 8259 |
---|
| 149 | HIRQ_AcknowledgeMasterController: |
---|
| 150 | out WPORT_8259MA_COMMAND, al ; Acknowledge Master 8259 |
---|
| 151 | |
---|
| 152 | %ifdef USE_AT ; OS hook only available on AT+ machines |
---|
| 153 | ; Issue Int 15h, function AX=9100h (Interrupt ready) |
---|
| 154 | mov ax, 9100h ; Interrupt ready, device 0 (HD) |
---|
| 155 | int INTV_SYSTEM_SERVICES |
---|
| 156 | %endif |
---|
| 157 | |
---|
| 158 | ; Restore registers and return from interrupt |
---|
| 159 | pop ax ; Restore AX |
---|
| 160 | iret |
---|
| 161 | |
---|
| 162 | |
---|
| 163 | ;-------------------------------------------------------------------- |
---|
| 164 | ; Acknowledges IDE interrupt by reading status register and |
---|
| 165 | ; stores Status and Error Registers to BDA. Task flag in BDA will |
---|
| 166 | ; also be set. |
---|
| 167 | ; |
---|
| 168 | ; ISR_IDE_AcknowledgeIdeAndStoreStatusToBDA |
---|
| 169 | ; Parameters: |
---|
| 170 | ; Nothing |
---|
| 171 | ; Returns: |
---|
| 172 | ; Nothing |
---|
| 173 | ; Corrupts registers: |
---|
| 174 | ; AX |
---|
| 175 | ;-------------------------------------------------------------------- |
---|
| 176 | ALIGN JUMP_ALIGN |
---|
| 177 | ISR_IDE_AcknowledgeIdeAndStoreStatusToBDA: |
---|
| 178 | push ds |
---|
| 179 | push di |
---|
| 180 | push dx |
---|
| 181 | |
---|
| 182 | ; Read Status and Error registers. |
---|
| 183 | ; Reading Status Register acknowledges IDE interrupt |
---|
| 184 | call RamVars_GetSegmentToDS |
---|
| 185 | mov dx, [RAMVARS.wIdeBase] ; Load IDE base port address |
---|
| 186 | inc dx ; Increment to Error Register |
---|
| 187 | in al, dx ; Read Error Register... |
---|
| 188 | mov ah, al ; ...and copy it to AH |
---|
| 189 | add dx, REGR_IDE_ST-REGR_IDE_ERROR |
---|
| 190 | in al, dx ; Read Status Register to AL |
---|
| 191 | |
---|
| 192 | ; Store Status and Error register to BDA and set task flag |
---|
| 193 | LOAD_BDA_SEGMENT_TO ds, dx |
---|
| 194 | mov [HDBDA.wHDStAndErr], ax ; Store Status and Error Registers |
---|
| 195 | mov BYTE [BDA.bHDTaskFlg], 0FFh ; Set task flag |
---|
| 196 | |
---|
| 197 | pop dx |
---|
| 198 | pop di |
---|
| 199 | pop ds |
---|
| 200 | ret |
---|