1 | ; Project name : XTIDE Universal BIOS
|
---|
2 | ; Description : IDE Device wait functions.
|
---|
3 |
|
---|
4 | ; Section containing code
|
---|
5 | SECTION .text
|
---|
6 |
|
---|
7 | ;--------------------------------------------------------------------
|
---|
8 | ; IdeWait_IRQorDRQ
|
---|
9 | ; Parameters:
|
---|
10 | ; DS:DI: Ptr to DPT (in RAMVARS segment)
|
---|
11 | ; SS:BP: Ptr to IDEPACK, PIOVARS or MEMPIOVARS
|
---|
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 | ;--------------------------------------------------------------------
|
---|
18 | IDEDEVICE%+Wait_IRQorDRQ:
|
---|
19 | mov bx, TIMEOUT_AND_STATUS_TO_WAIT(TIMEOUT_DRQ, FLG_STATUS_DRQ)
|
---|
20 | %ifdef ASSEMBLE_SHARED_IDE_DEVICE_FUNCTIONS ; JR-IDE/ISA does not support IRQ
|
---|
21 | test BYTE [bp+IDEPACK.bDeviceControl], FLG_DEVCONTROL_nIEN
|
---|
22 | jnz SHORT IDEDEVICE%+Wait_PollStatusFlagInBLwithTimeoutInBH ; Interrupt disabled
|
---|
23 | %endif
|
---|
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 | ;--------------------------------------------------------------------
|
---|
39 | IDEDEVICE%+Wait_IRQorStatusFlagInBLwithTimeoutInBH:
|
---|
40 | %ifdef ASSEMBLE_SHARED_IDE_DEVICE_FUNCTIONS ; JR-IDE/ISA does not support IRQ
|
---|
41 | call IdeIrq_WaitForIRQ
|
---|
42 | %endif
|
---|
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 | ;--------------------------------------------------------------------
|
---|
58 | IDEDEVICE%+Wait_PollStatusFlagInBLwithTimeoutInBH:
|
---|
59 | mov ah, bl
|
---|
60 | mov cl, bh
|
---|
61 | call Timer_InitializeTimeoutWithTicksInCL
|
---|
62 | and ah, ~FLG_STATUS_BSY
|
---|
63 | jz SHORT IDEDEVICE%+PollBsyOnly
|
---|
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 | ;--------------------------------------------------------------------
|
---|
78 | IDEDEVICE%+PollBsyAndFlgInAH:
|
---|
79 | INPUT_TO_AL_FROM_IDE_REGISTER STATUS_REGISTER_in ; Discard contents for first read
|
---|
80 | ALIGN JUMP_ALIGN
|
---|
81 | .PollLoop:
|
---|
82 | INPUT_TO_AL_FROM_IDE_REGISTER STATUS_REGISTER_in
|
---|
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
|
---|
86 | jnz SHORT IDEDEVICE%+Error_GetBiosErrorCodeToAHfromPolledStatusRegisterInAL
|
---|
87 | .UpdateTimeout:
|
---|
88 | call Timer_SetCFifTimeout
|
---|
89 | jnc SHORT .PollLoop ; Loop if time left
|
---|
90 | call IDEDEVICE%+Error_GetBiosErrorCodeToAHfromPolledStatusRegisterInAL
|
---|
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 | ;--------------------------------------------------------------------
|
---|
109 | IDEDEVICE%+PollBsyOnly:
|
---|
110 | INPUT_TO_AL_FROM_IDE_REGISTER STATUS_REGISTER_in ; Discard contents for first read
|
---|
111 | ALIGN JUMP_ALIGN
|
---|
112 | .PollLoop:
|
---|
113 | INPUT_TO_AL_FROM_IDE_REGISTER STATUS_REGISTER_in
|
---|
114 | test al, FLG_STATUS_BSY ; Controller busy?
|
---|
115 | jz SHORT IDEDEVICE%+Error_GetBiosErrorCodeToAHfromPolledStatusRegisterInAL
|
---|
116 | call Timer_SetCFifTimeout ; Update timeout counter
|
---|
117 | jnc SHORT .PollLoop ; Loop if time left (sets CF on timeout)
|
---|
118 | jmp SHORT IDEDEVICE%+Error_GetBiosErrorCodeToAHfromPolledStatusRegisterInAL
|
---|