[3] | 1 | ; File name : HIRQ.asm |
---|
| 2 | ; Project name : IDE BIOS |
---|
| 3 | ; Created date : 11.12.2009 |
---|
[33] | 4 | ; Last update : 23.8.2010 |
---|
[3] | 5 | ; Author : Tomi Tilli |
---|
| 6 | ; Description : Interrupt handling related functions. |
---|
| 7 | |
---|
| 8 | ; Section containing code |
---|
| 9 | SECTION .text |
---|
| 10 | |
---|
| 11 | ;-------------------------------------------------------------------- |
---|
[34] | 12 | ; HIRQ_WaitForIRQ |
---|
[3] | 13 | ; Parameters: |
---|
| 14 | ; DS: RAMVARS segment |
---|
| 15 | ; Returns: |
---|
[34] | 16 | ; CF: Set if wait done by operating system |
---|
| 17 | ; Cleared if BIOS must perform task flag polling |
---|
[3] | 18 | ; Corrupts registers: |
---|
[34] | 19 | ; AX |
---|
[3] | 20 | ;-------------------------------------------------------------------- |
---|
| 21 | ALIGN JUMP_ALIGN |
---|
[34] | 22 | HIRQ_WaitForIRQ: |
---|
| 23 | test BYTE [bx+DPT.bDrvCtrl], FLG_IDE_CTRL_nIEN ; Clears CF |
---|
| 24 | jz SHORT .NotifyOperatingSystemAboutWaitingForIRQ |
---|
| 25 | ret ; Go to poll status register |
---|
[3] | 26 | |
---|
[28] | 27 | ;-------------------------------------------------------------------- |
---|
| 28 | ; .NotifyOperatingSystemAboutWaitingForIRQ |
---|
| 29 | ; Parameters: |
---|
[34] | 30 | ; Nothing |
---|
[28] | 31 | ; Returns: |
---|
| 32 | ; CF: Set if wait done by operating system |
---|
| 33 | ; Cleared if BIOS must perform task flag polling |
---|
| 34 | ; Corrupts registers: |
---|
| 35 | ; AX |
---|
| 36 | ;-------------------------------------------------------------------- |
---|
| 37 | ALIGN JUMP_ALIGN |
---|
| 38 | .NotifyOperatingSystemAboutWaitingForIRQ: |
---|
[34] | 39 | push ds |
---|
| 40 | |
---|
| 41 | LOAD_BDA_SEGMENT_TO ds, ax ; Zero AX |
---|
[3] | 42 | cli ; Disable interrupts |
---|
[34] | 43 | cmp al, [ds:BDA.bHDTaskFlg] ; Task flag already set? |
---|
[28] | 44 | jc SHORT .ReturnFromWaitNotify ; If so, skip OS notification |
---|
[3] | 45 | |
---|
| 46 | mov ah, 90h ; Hard disk busy (AX=9000h) |
---|
| 47 | int INTV_SYSTEM_SERVICES ; OS hook, device busy |
---|
[28] | 48 | jnc SHORT .ReturnFromWaitNotify ; CF cleared, BIOS handles waiting |
---|
[3] | 49 | |
---|
[28] | 50 | ; Make sure that OS hooks are supported, otherwise the CF means unsupported function |
---|
| 51 | test ah, ah ; OS hook supported? (clears CF) |
---|
| 52 | jnz SHORT .ReturnFromWaitNotify ; AH has error, BIOS must do the wait |
---|
| 53 | stc ; Set CF since wait done by OS |
---|
| 54 | .ReturnFromWaitNotify: |
---|
[34] | 55 | pop ds |
---|
[3] | 56 | sti ; Enable interrupts |
---|
| 57 | ret |
---|
| 58 | |
---|
[28] | 59 | |
---|
[3] | 60 | ;-------------------------------------------------------------------- |
---|
| 61 | ; Clears task (interrupt) flag from BIOS Data Area. |
---|
| 62 | ; |
---|
| 63 | ; HIRQ_ClearTaskFlag |
---|
| 64 | ; Parameters: |
---|
| 65 | ; Nothing |
---|
| 66 | ; Returns: |
---|
| 67 | ; Nothing |
---|
| 68 | ; Corrupts registers: |
---|
| 69 | ; AX |
---|
| 70 | ;-------------------------------------------------------------------- |
---|
| 71 | ALIGN JUMP_ALIGN |
---|
| 72 | HIRQ_ClearTaskFlag: |
---|
| 73 | push ds |
---|
| 74 | LOAD_BDA_SEGMENT_TO ds, ax ; Also zero AX |
---|
| 75 | mov [BDA.bHDTaskFlg], al |
---|
| 76 | pop ds |
---|
| 77 | ret |
---|
| 78 | |
---|
| 79 | |
---|
| 80 | ;-------------------------------------------------------------------- |
---|
| 81 | ; IDE Interrupt Service Routines. |
---|
| 82 | ; |
---|
| 83 | ; HIRQ_InterruptServiceRoutineForIrqs2to7 |
---|
| 84 | ; HIRQ_InterruptServiceRoutineForIrqs8to15 |
---|
| 85 | ; Parameters: |
---|
| 86 | ; Nothing |
---|
| 87 | ; Returns: |
---|
| 88 | ; Nothing |
---|
| 89 | ; Corrupts registers: |
---|
| 90 | ; Nothing |
---|
| 91 | ;-------------------------------------------------------------------- |
---|
| 92 | ALIGN JUMP_ALIGN |
---|
| 93 | HIRQ_InterruptServiceRoutineForIrqs2to7: |
---|
| 94 | push ax |
---|
[28] | 95 | call AcknowledgeIdeInterruptAndStoreStatusAndErrorRegistersToBDA |
---|
| 96 | |
---|
[3] | 97 | mov al, CMD_END_OF_INTERRUPT |
---|
[28] | 98 | jmp SHORT AcknowledgeMasterInterruptController |
---|
[3] | 99 | |
---|
| 100 | ALIGN JUMP_ALIGN |
---|
| 101 | HIRQ_InterruptServiceRoutineForIrqs8to15: |
---|
| 102 | push ax |
---|
[28] | 103 | call AcknowledgeIdeInterruptAndStoreStatusAndErrorRegistersToBDA |
---|
[3] | 104 | |
---|
| 105 | mov al, CMD_END_OF_INTERRUPT ; Load EOI command to AL |
---|
| 106 | out WPORT_8259SL_COMMAND, al ; Acknowledge Slave 8259 |
---|
[28] | 107 | AcknowledgeMasterInterruptController: |
---|
[3] | 108 | out WPORT_8259MA_COMMAND, al ; Acknowledge Master 8259 |
---|
| 109 | |
---|
| 110 | ; Issue Int 15h, function AX=9100h (Interrupt ready) |
---|
| 111 | mov ax, 9100h ; Interrupt ready, device 0 (HD) |
---|
| 112 | int INTV_SYSTEM_SERVICES |
---|
| 113 | |
---|
| 114 | pop ax ; Restore AX |
---|
| 115 | iret |
---|
| 116 | |
---|
| 117 | ;-------------------------------------------------------------------- |
---|
| 118 | ; Acknowledges IDE interrupt by reading status register and |
---|
| 119 | ; stores Status and Error Registers to BDA. Task flag in BDA will |
---|
| 120 | ; also be set. |
---|
| 121 | ; |
---|
[28] | 122 | ; AcknowledgeIdeInterruptAndStoreStatusAndErrorRegistersToBDA |
---|
[3] | 123 | ; Parameters: |
---|
| 124 | ; Nothing |
---|
| 125 | ; Returns: |
---|
| 126 | ; Nothing |
---|
| 127 | ; Corrupts registers: |
---|
| 128 | ; AX |
---|
| 129 | ;-------------------------------------------------------------------- |
---|
| 130 | ALIGN JUMP_ALIGN |
---|
[28] | 131 | AcknowledgeIdeInterruptAndStoreStatusAndErrorRegistersToBDA: |
---|
[3] | 132 | push ds |
---|
| 133 | push di |
---|
| 134 | push dx |
---|
| 135 | |
---|
| 136 | ; Reading Status Register acknowledges IDE interrupt |
---|
[34] | 137 | call RamVars_GetSegmentToDS |
---|
| 138 | call HError_GetStatusAndErrorRegistersToAXandStoreThemToBDA |
---|
[28] | 139 | mov BYTE [BDA.bHDTaskFlg], 0FFh ; Set task flag |
---|
[3] | 140 | |
---|
| 141 | pop dx |
---|
| 142 | pop di |
---|
| 143 | pop ds |
---|
| 144 | ret |
---|