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

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

Changes to XTIDE Universal BIOS:

  • Makefile now builds small (8k) and large versions.
  • Completely untested support for JR-IDE/ISA.
File size: 4.6 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)
11; SS:BP: Ptr to IDEPACK or PIOVARS
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;--------------------------------------------------------------------
[238]78%ifdef ASSEMBLE_SHARED_IDE_DEVICE_FUNCTIONS
[150]79PollBsyAndFlgInAH:
[238]80 call IDEDEVICE%+ReadIdeStatusRegisterToAL; Discard contents for first read
[150]81ALIGN JUMP_ALIGN
82.PollLoop:
[238]83 call IDEDEVICE%+ReadIdeStatusRegisterToAL
[150]84 test al, FLG_STATUS_BSY ; Controller busy?
85 jnz SHORT .UpdateTimeout ; If so, jump to timeout update
86 test al, ah ; Test secondary flag
[238]87 jnz SHORT IDEDEVICE%+Error_GetBiosErrorCodeToAHfromPolledStatusRegisterInAL
[150]88.UpdateTimeout:
[155]89 call Timer_SetCFifTimeout
[150]90 jnc SHORT .PollLoop ; Loop if time left
[238]91 call IDEDEVICE%+Error_GetBiosErrorCodeToAHfromPolledStatusRegisterInAL
[150]92 jc SHORT .ReturnErrorCodeInAH
93 mov ah, RET_HD_TIMEOUT ; Expected bit never got set
94 stc
95.ReturnErrorCodeInAH:
96 ret
[238]97%endif
[150]98
99
100;--------------------------------------------------------------------
101; PollBsyOnly
102; Parameters:
103; DS:DI: Ptr to DPT (in RAMVARS segment)
104; Returns:
105; AH: BIOS Error code
106; CF: Clear if wait completed successfully (no errors)
107; Set if any error
108; Corrupts registers:
109; AL, BX, CX, DX
110;--------------------------------------------------------------------
[238]111IDEDEVICE%+PollBsyOnly:
112 call IDEDEVICE%+ReadIdeStatusRegisterToAL; Discard contents for first read
[150]113ALIGN JUMP_ALIGN
114.PollLoop:
[238]115 call IDEDEVICE%+ReadIdeStatusRegisterToAL
[150]116 test al, FLG_STATUS_BSY ; Controller busy?
[238]117 jz SHORT IDEDEVICE%+Error_GetBiosErrorCodeToAHfromPolledStatusRegisterInAL
[155]118 call Timer_SetCFifTimeout ; Update timeout counter
[150]119 jnc SHORT .PollLoop ; Loop if time left (sets CF on timeout)
[238]120 jmp SHORT IDEDEVICE%+Error_GetBiosErrorCodeToAHfromPolledStatusRegisterInAL
[150]121
122
123;--------------------------------------------------------------------
124; ReadIdeStatusRegisterToAL
125; Parameters:
126; DS:DI: Ptr to DPT (in RAMVARS segment)
127; Returns:
128; AL: IDE Status Register contents
129; Corrupts registers:
130; BX, DX
131;--------------------------------------------------------------------
132ALIGN JUMP_ALIGN
[238]133IDEDEVICE%+ReadIdeStatusRegisterToAL:
134 JUMP_TO_INPUT_TO_AL_FROM_IDE_REGISTER STATUS_REGISTER_in
Note: See TracBrowser for help on using the repository browser.