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

Last change on this file since 394 was 376, checked in by gregli@…, 13 years ago

WIDE checkin... Added copyright and license information to sorce files, as per the GPL instructions for usage.

File size: 4.9 KB
RevLine 
[150]1; Project name : XTIDE Universal BIOS
2; Description : IDE Device wait functions.
3
[376]4;
5; XTIDE Universal BIOS and Associated Tools
6; Copyright (C) 2009-2010 by Tomi Tilli, 2011-2012 by XTIDE Universal BIOS Team.
7;
8; This program is free software; you can redistribute it and/or modify
9; it under the terms of the GNU General Public License as published by
10; the Free Software Foundation; either version 2 of the License, or
11; (at your option) any later version.
12;
13; This program is distributed in the hope that it will be useful,
14; but WITHOUT ANY WARRANTY; without even the implied warranty of
15; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16; GNU General Public License for more details.
17; Visit http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
18;
19
[150]20; Section containing code
21SECTION .text
22
23;--------------------------------------------------------------------
24; IdeWait_IRQorDRQ
25; Parameters:
26; DS:DI: Ptr to DPT (in RAMVARS segment)
[267]27; SS:BP: Ptr to IDEPACK, PIOVARS or MEMPIOVARS
[150]28; Returns:
29; AH: INT 13h Error Code
30; CF: Cleared if success, Set if error
31; Corrupts registers:
32; AL, BX, CX, DX
33;--------------------------------------------------------------------
[238]34IDEDEVICE%+Wait_IRQorDRQ:
[150]35 mov bx, TIMEOUT_AND_STATUS_TO_WAIT(TIMEOUT_DRQ, FLG_STATUS_DRQ)
[238]36%ifdef ASSEMBLE_SHARED_IDE_DEVICE_FUNCTIONS ; JR-IDE/ISA does not support IRQ
[150]37 test BYTE [bp+IDEPACK.bDeviceControl], FLG_DEVCONTROL_nIEN
[238]38 jnz SHORT IDEDEVICE%+Wait_PollStatusFlagInBLwithTimeoutInBH ; Interrupt disabled
39%endif
[150]40 ; Fall to IdeWait_IRQorStatusFlagInBLwithTimeoutInBH
41
42
43;--------------------------------------------------------------------
44; IdeWait_IRQorStatusFlagInBLwithTimeoutInBH
45; Parameters:
46; BH: Timeout ticks
47; BL: IDE Status Register bit to wait
48; DS:DI: Ptr to DPT (in RAMVARS segment)
49; Returns:
50; AH: INT 13h Error Code
51; CF: Cleared if success, Set if error
52; Corrupts registers:
53; AL, BX, CX, DX
54;--------------------------------------------------------------------
[238]55IDEDEVICE%+Wait_IRQorStatusFlagInBLwithTimeoutInBH:
56%ifdef ASSEMBLE_SHARED_IDE_DEVICE_FUNCTIONS ; JR-IDE/ISA does not support IRQ
[150]57 call IdeIrq_WaitForIRQ
[238]58%endif
[150]59 ; Always fall to IdeWait_PollStatusFlagInBLwithTimeoutInBH for error processing
60
61
62;--------------------------------------------------------------------
63; IdeWait_PollStatusFlagInBLwithTimeoutInBH
64; Parameters:
65; BH: Timeout ticks
66; BL: IDE Status Register bit to poll
67; DS:DI: Ptr to DPT (in RAMVARS segment)
68; Returns:
69; AH: INT 13h Error Code
70; CF: Cleared if success, Set if error
71; Corrupts registers:
72; AL, BX, CX, DX
73;--------------------------------------------------------------------
[238]74IDEDEVICE%+Wait_PollStatusFlagInBLwithTimeoutInBH:
[150]75 mov ah, bl
[155]76 mov cl, bh
77 call Timer_InitializeTimeoutWithTicksInCL
[150]78 and ah, ~FLG_STATUS_BSY
[238]79 jz SHORT IDEDEVICE%+PollBsyOnly
[150]80 ; Fall to PollBsyAndFlgInAH
81
82;--------------------------------------------------------------------
83; PollBsyAndFlgInAH
84; Parameters:
85; AH: Status Register Flag to poll (until set) when device not busy
86; DS:DI: Ptr to DPT (in RAMVARS segment)
87; Returns:
88; AH: BIOS Error code
89; CF: Clear if wait completed successfully (no errors)
90; Set if any error
91; Corrupts registers:
92; AL, BX, CX, DX
93;--------------------------------------------------------------------
[266]94IDEDEVICE%+PollBsyAndFlgInAH:
95 INPUT_TO_AL_FROM_IDE_REGISTER STATUS_REGISTER_in ; Discard contents for first read
[150]96ALIGN JUMP_ALIGN
97.PollLoop:
[266]98 INPUT_TO_AL_FROM_IDE_REGISTER STATUS_REGISTER_in
[150]99 test al, FLG_STATUS_BSY ; Controller busy?
100 jnz SHORT .UpdateTimeout ; If so, jump to timeout update
101 test al, ah ; Test secondary flag
[238]102 jnz SHORT IDEDEVICE%+Error_GetBiosErrorCodeToAHfromPolledStatusRegisterInAL
[150]103.UpdateTimeout:
[155]104 call Timer_SetCFifTimeout
[150]105 jnc SHORT .PollLoop ; Loop if time left
[238]106 call IDEDEVICE%+Error_GetBiosErrorCodeToAHfromPolledStatusRegisterInAL
[150]107 jc SHORT .ReturnErrorCodeInAH
108 mov ah, RET_HD_TIMEOUT ; Expected bit never got set
109 stc
110.ReturnErrorCodeInAH:
111 ret
112
113
114;--------------------------------------------------------------------
115; PollBsyOnly
116; Parameters:
117; DS:DI: Ptr to DPT (in RAMVARS segment)
118; Returns:
119; AH: BIOS Error code
120; CF: Clear if wait completed successfully (no errors)
121; Set if any error
122; Corrupts registers:
123; AL, BX, CX, DX
124;--------------------------------------------------------------------
[238]125IDEDEVICE%+PollBsyOnly:
[266]126 INPUT_TO_AL_FROM_IDE_REGISTER STATUS_REGISTER_in ; Discard contents for first read
[150]127ALIGN JUMP_ALIGN
128.PollLoop:
[266]129 INPUT_TO_AL_FROM_IDE_REGISTER STATUS_REGISTER_in
[150]130 test al, FLG_STATUS_BSY ; Controller busy?
[238]131 jz SHORT IDEDEVICE%+Error_GetBiosErrorCodeToAHfromPolledStatusRegisterInAL
[155]132 call Timer_SetCFifTimeout ; Update timeout counter
[150]133 jnc SHORT .PollLoop ; Loop if time left (sets CF on timeout)
[238]134 jmp SHORT IDEDEVICE%+Error_GetBiosErrorCodeToAHfromPolledStatusRegisterInAL
Note: See TracBrowser for help on using the repository browser.