source: xtideuniversalbios/trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/Common/HIRQ.asm@ 31

Last change on this file since 31 was 28, checked in by Tomi Tilli, 14 years ago
  • v1.1.1 broke booting from foreign drives, it is now fixed.
  • Improved error handling a bit.
  • Longer DRQ and IRQ timeouts to minimize write timouts with some (bad) CF cards.
  • Default boot menu drive should now be properly selected.
File size: 5.4 KB
RevLine 
[3]1; File name : HIRQ.asm
2; Project name : IDE BIOS
3; Created date : 11.12.2009
[28]4; Last update : 1.8.2010
[3]5; Author : Tomi Tilli
6; Description : Interrupt handling related functions.
7
8; Section containing code
9SECTION .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:
[28]22; AL
[3]23;--------------------------------------------------------------------
24ALIGN JUMP_ALIGN
25HIRQ_WaitIRQ:
26 push es
27
[28]28 LOAD_BDA_SEGMENT_TO es, ax
29%ifdef USE_AT ; OS hook only available on AT+ machines
30 call .NotifyOperatingSystemAboutWaitingForIRQ
31 cmc
32 jnc SHORT .TaskFlagPollingComplete
33%endif
34 call .WaitUntilTaskFlagIsSet ; Process errors
35
36ALIGN JUMP_ALIGN
37.TaskFlagPollingComplete:
38 call HError_ProcessErrorsAfterPollingTaskFlag
39 pop es
40 ret
41
42;--------------------------------------------------------------------
43; .NotifyOperatingSystemAboutWaitingForIRQ
44; Parameters:
45; ES: BDA segment (zero)
46; Returns:
47; CF: Set if wait done by operating system
48; Cleared if BIOS must perform task flag polling
49; Corrupts registers:
50; AX
51;--------------------------------------------------------------------
52%ifdef USE_AT
53ALIGN JUMP_ALIGN
54.NotifyOperatingSystemAboutWaitingForIRQ:
[3]55 cli ; Disable interrupts
[28]56 xor ax, ax
57 cmp al, [es:BDA.bHDTaskFlg] ; Task flag already set?
58 jc SHORT .ReturnFromWaitNotify ; If so, skip OS notification
[3]59
60 mov ah, 90h ; Hard disk busy (AX=9000h)
61 int INTV_SYSTEM_SERVICES ; OS hook, device busy
[28]62 jnc SHORT .ReturnFromWaitNotify ; CF cleared, BIOS handles waiting
[3]63
[28]64 ; Make sure that OS hooks are supported, otherwise the CF means unsupported function
65 test ah, ah ; OS hook supported? (clears CF)
66 jnz SHORT .ReturnFromWaitNotify ; AH has error, BIOS must do the wait
67 stc ; Set CF since wait done by OS
68.ReturnFromWaitNotify:
[3]69 sti ; Enable interrupts
70 ret
[28]71%endif
[3]72
73;--------------------------------------------------------------------
74; Polls IRQ Task Flag until it has been set or timeout.
75;
[28]76; .WaitUntilTaskFlagIsSet
[3]77; Parameters:
78; DS: RAMVARS segment
79; ES: BDA segment
80; Returns:
[28]81; CF: Set if timeout
82; Cleared if Task Flag set
[3]83; Corrupts registers:
[28]84; AX
[3]85;--------------------------------------------------------------------
86ALIGN JUMP_ALIGN
[28]87.WaitUntilTaskFlagIsSet:
88 push cx
89
[3]90 mov cl, B_TIMEOUT_DRQ ; Load timeout ticks
91 call SoftDelay_InitTimeout ; Initialize timeout counter
92 xor ax, ax ; Zero AX
93ALIGN JUMP_ALIGN
94.PollIrqFlag:
[28]95 cli ; Disable interrupt until next HLT
96 cmp [es:BDA.bHDTaskFlg], al ; Task flag set? (clears CF)
97 jne SHORT .Return
[3]98 call SoftDelay_UpdTimeout ; Update timeout
[28]99 jc SHORT .Return ; Return if timeout
100 sti ; Enable interrupts (STI has delay so HLT will catch all interrupts)
[3]101 hlt ; Sleep until any interrupt
102 jmp SHORT .PollIrqFlag ; Jump to check if IDE interrupt
103ALIGN JUMP_ALIGN
[28]104.Return:
105 pop cx
106 sti
[3]107 ret
108
109
110;--------------------------------------------------------------------
111; Clears task (interrupt) flag from BIOS Data Area.
112;
113; HIRQ_ClearTaskFlag
114; Parameters:
115; Nothing
116; Returns:
117; Nothing
118; Corrupts registers:
119; AX
120;--------------------------------------------------------------------
121ALIGN JUMP_ALIGN
122HIRQ_ClearTaskFlag:
123 push ds
124 LOAD_BDA_SEGMENT_TO ds, ax ; Also zero AX
125 mov [BDA.bHDTaskFlg], al
126 pop ds
127 ret
128
129
130;--------------------------------------------------------------------
131; IDE Interrupt Service Routines.
132;
133; HIRQ_InterruptServiceRoutineForIrqs2to7
134; HIRQ_InterruptServiceRoutineForIrqs8to15
135; Parameters:
136; Nothing
137; Returns:
138; Nothing
139; Corrupts registers:
140; Nothing
141;--------------------------------------------------------------------
142ALIGN JUMP_ALIGN
143HIRQ_InterruptServiceRoutineForIrqs2to7:
144 push ax
[28]145 call AcknowledgeIdeInterruptAndStoreStatusAndErrorRegistersToBDA
146
[3]147 mov al, CMD_END_OF_INTERRUPT
[28]148 jmp SHORT AcknowledgeMasterInterruptController
[3]149
150ALIGN JUMP_ALIGN
151HIRQ_InterruptServiceRoutineForIrqs8to15:
152 push ax
[28]153 call AcknowledgeIdeInterruptAndStoreStatusAndErrorRegistersToBDA
[3]154
155 mov al, CMD_END_OF_INTERRUPT ; Load EOI command to AL
156 out WPORT_8259SL_COMMAND, al ; Acknowledge Slave 8259
[28]157AcknowledgeMasterInterruptController:
[3]158 out WPORT_8259MA_COMMAND, al ; Acknowledge Master 8259
159
160%ifdef USE_AT ; OS hook only available on AT+ machines
161 ; Issue Int 15h, function AX=9100h (Interrupt ready)
162 mov ax, 9100h ; Interrupt ready, device 0 (HD)
163 int INTV_SYSTEM_SERVICES
164%endif
165
166 pop ax ; Restore AX
167 iret
168
169;--------------------------------------------------------------------
170; Acknowledges IDE interrupt by reading status register and
171; stores Status and Error Registers to BDA. Task flag in BDA will
172; also be set.
173;
[28]174; AcknowledgeIdeInterruptAndStoreStatusAndErrorRegistersToBDA
[3]175; Parameters:
176; Nothing
177; Returns:
178; Nothing
179; Corrupts registers:
180; AX
181;--------------------------------------------------------------------
182ALIGN JUMP_ALIGN
[28]183AcknowledgeIdeInterruptAndStoreStatusAndErrorRegistersToBDA:
[3]184 push ds
185 push di
186 push dx
187
188 ; Reading Status Register acknowledges IDE interrupt
189 call RamVars_GetSegmentToDS
[28]190 call HError_GetStatusAndErrorRegistersToAXandStoreThemToBDA
191 mov BYTE [BDA.bHDTaskFlg], 0FFh ; Set task flag
[3]192
193 pop dx
194 pop di
195 pop ds
196 ret
Note: See TracBrowser for help on using the repository browser.