source: xtideuniversalbios/trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdeWait.asm@ 318

Last change on this file since 318 was 267, checked in by aitotat@…, 13 years ago

Changes to XTIDE Universal BIOS:

  • More JR-IDE/ISA fixes.
File size: 4.2 KB
RevLine 
[150]1; Project name : XTIDE Universal BIOS
2; Description : IDE Device wait functions.
3
4; Section containing code
5SECTION .text
6
7;--------------------------------------------------------------------
8; IdeWait_IRQorDRQ
9; Parameters:
10; DS:DI: Ptr to DPT (in RAMVARS segment)
[267]11; SS:BP: Ptr to IDEPACK, PIOVARS or MEMPIOVARS
[150]12; Returns:
13; AH: INT 13h Error Code
14; CF: Cleared if success, Set if error
15; Corrupts registers:
16; AL, BX, CX, DX
17;--------------------------------------------------------------------
[238]18IDEDEVICE%+Wait_IRQorDRQ:
[150]19 mov bx, TIMEOUT_AND_STATUS_TO_WAIT(TIMEOUT_DRQ, FLG_STATUS_DRQ)
[238]20%ifdef ASSEMBLE_SHARED_IDE_DEVICE_FUNCTIONS ; JR-IDE/ISA does not support IRQ
[150]21 test BYTE [bp+IDEPACK.bDeviceControl], FLG_DEVCONTROL_nIEN
[238]22 jnz SHORT IDEDEVICE%+Wait_PollStatusFlagInBLwithTimeoutInBH ; Interrupt disabled
23%endif
[150]24 ; Fall to IdeWait_IRQorStatusFlagInBLwithTimeoutInBH
25
26
27;--------------------------------------------------------------------
28; IdeWait_IRQorStatusFlagInBLwithTimeoutInBH
29; Parameters:
30; BH: Timeout ticks
31; BL: IDE Status Register bit to wait
32; DS:DI: Ptr to DPT (in RAMVARS segment)
33; Returns:
34; AH: INT 13h Error Code
35; CF: Cleared if success, Set if error
36; Corrupts registers:
37; AL, BX, CX, DX
38;--------------------------------------------------------------------
[238]39IDEDEVICE%+Wait_IRQorStatusFlagInBLwithTimeoutInBH:
40%ifdef ASSEMBLE_SHARED_IDE_DEVICE_FUNCTIONS ; JR-IDE/ISA does not support IRQ
[150]41 call IdeIrq_WaitForIRQ
[238]42%endif
[150]43 ; Always fall to IdeWait_PollStatusFlagInBLwithTimeoutInBH for error processing
44
45
46;--------------------------------------------------------------------
47; IdeWait_PollStatusFlagInBLwithTimeoutInBH
48; Parameters:
49; BH: Timeout ticks
50; BL: IDE Status Register bit to poll
51; DS:DI: Ptr to DPT (in RAMVARS segment)
52; Returns:
53; AH: INT 13h Error Code
54; CF: Cleared if success, Set if error
55; Corrupts registers:
56; AL, BX, CX, DX
57;--------------------------------------------------------------------
[238]58IDEDEVICE%+Wait_PollStatusFlagInBLwithTimeoutInBH:
[150]59 mov ah, bl
[155]60 mov cl, bh
61 call Timer_InitializeTimeoutWithTicksInCL
[150]62 and ah, ~FLG_STATUS_BSY
[238]63 jz SHORT IDEDEVICE%+PollBsyOnly
[150]64 ; Fall to PollBsyAndFlgInAH
65
66;--------------------------------------------------------------------
67; PollBsyAndFlgInAH
68; Parameters:
69; AH: Status Register Flag to poll (until set) when device not busy
70; DS:DI: Ptr to DPT (in RAMVARS segment)
71; Returns:
72; AH: BIOS Error code
73; CF: Clear if wait completed successfully (no errors)
74; Set if any error
75; Corrupts registers:
76; AL, BX, CX, DX
77;--------------------------------------------------------------------
[266]78IDEDEVICE%+PollBsyAndFlgInAH:
79 INPUT_TO_AL_FROM_IDE_REGISTER STATUS_REGISTER_in ; Discard contents for first read
[150]80ALIGN JUMP_ALIGN
81.PollLoop:
[266]82 INPUT_TO_AL_FROM_IDE_REGISTER STATUS_REGISTER_in
[150]83 test al, FLG_STATUS_BSY ; Controller busy?
84 jnz SHORT .UpdateTimeout ; If so, jump to timeout update
85 test al, ah ; Test secondary flag
[238]86 jnz SHORT IDEDEVICE%+Error_GetBiosErrorCodeToAHfromPolledStatusRegisterInAL
[150]87.UpdateTimeout:
[155]88 call Timer_SetCFifTimeout
[150]89 jnc SHORT .PollLoop ; Loop if time left
[238]90 call IDEDEVICE%+Error_GetBiosErrorCodeToAHfromPolledStatusRegisterInAL
[150]91 jc SHORT .ReturnErrorCodeInAH
92 mov ah, RET_HD_TIMEOUT ; Expected bit never got set
93 stc
94.ReturnErrorCodeInAH:
95 ret
96
97
98;--------------------------------------------------------------------
99; PollBsyOnly
100; Parameters:
101; DS:DI: Ptr to DPT (in RAMVARS segment)
102; Returns:
103; AH: BIOS Error code
104; CF: Clear if wait completed successfully (no errors)
105; Set if any error
106; Corrupts registers:
107; AL, BX, CX, DX
108;--------------------------------------------------------------------
[238]109IDEDEVICE%+PollBsyOnly:
[266]110 INPUT_TO_AL_FROM_IDE_REGISTER STATUS_REGISTER_in ; Discard contents for first read
[150]111ALIGN JUMP_ALIGN
112.PollLoop:
[266]113 INPUT_TO_AL_FROM_IDE_REGISTER STATUS_REGISTER_in
[150]114 test al, FLG_STATUS_BSY ; Controller busy?
[238]115 jz SHORT IDEDEVICE%+Error_GetBiosErrorCodeToAHfromPolledStatusRegisterInAL
[155]116 call Timer_SetCFifTimeout ; Update timeout counter
[150]117 jnc SHORT .PollLoop ; Loop if time left (sets CF on timeout)
[238]118 jmp SHORT IDEDEVICE%+Error_GetBiosErrorCodeToAHfromPolledStatusRegisterInAL
Note: See TracBrowser for help on using the repository browser.