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

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

Changes to XTIDE Universal BIOS:

  • IRQ related stuff is now optional MODULE_IRQ.
  • XT builds no longer include support for IDE IRQ.
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
[398]57 %ifdef MODULE_IRQ
58 call IdeIrq_WaitForIRQ
59 %endif
[238]60%endif
[150]61 ; Always fall to IdeWait_PollStatusFlagInBLwithTimeoutInBH for error processing
62
63
64;--------------------------------------------------------------------
65; IdeWait_PollStatusFlagInBLwithTimeoutInBH
66; Parameters:
67; BH: Timeout ticks
68; BL: IDE Status Register bit to poll
69; DS:DI: Ptr to DPT (in RAMVARS segment)
70; Returns:
71; AH: INT 13h Error Code
72; CF: Cleared if success, Set if error
73; Corrupts registers:
74; AL, BX, CX, DX
75;--------------------------------------------------------------------
[238]76IDEDEVICE%+Wait_PollStatusFlagInBLwithTimeoutInBH:
[150]77 mov ah, bl
[155]78 mov cl, bh
79 call Timer_InitializeTimeoutWithTicksInCL
[150]80 and ah, ~FLG_STATUS_BSY
[238]81 jz SHORT IDEDEVICE%+PollBsyOnly
[150]82 ; Fall to PollBsyAndFlgInAH
83
84;--------------------------------------------------------------------
85; PollBsyAndFlgInAH
86; Parameters:
87; AH: Status Register Flag to poll (until set) when device not busy
88; DS:DI: Ptr to DPT (in RAMVARS segment)
89; Returns:
90; AH: BIOS Error code
91; CF: Clear if wait completed successfully (no errors)
92; Set if any error
93; Corrupts registers:
94; AL, BX, CX, DX
95;--------------------------------------------------------------------
[266]96IDEDEVICE%+PollBsyAndFlgInAH:
97 INPUT_TO_AL_FROM_IDE_REGISTER STATUS_REGISTER_in ; Discard contents for first read
[150]98ALIGN JUMP_ALIGN
99.PollLoop:
[266]100 INPUT_TO_AL_FROM_IDE_REGISTER STATUS_REGISTER_in
[150]101 test al, FLG_STATUS_BSY ; Controller busy?
102 jnz SHORT .UpdateTimeout ; If so, jump to timeout update
103 test al, ah ; Test secondary flag
[238]104 jnz SHORT IDEDEVICE%+Error_GetBiosErrorCodeToAHfromPolledStatusRegisterInAL
[150]105.UpdateTimeout:
[155]106 call Timer_SetCFifTimeout
[150]107 jnc SHORT .PollLoop ; Loop if time left
[238]108 call IDEDEVICE%+Error_GetBiosErrorCodeToAHfromPolledStatusRegisterInAL
[150]109 jc SHORT .ReturnErrorCodeInAH
110 mov ah, RET_HD_TIMEOUT ; Expected bit never got set
111 stc
112.ReturnErrorCodeInAH:
113 ret
114
115
116;--------------------------------------------------------------------
117; PollBsyOnly
118; Parameters:
119; DS:DI: Ptr to DPT (in RAMVARS segment)
120; Returns:
121; AH: BIOS Error code
122; CF: Clear if wait completed successfully (no errors)
123; Set if any error
124; Corrupts registers:
125; AL, BX, CX, DX
126;--------------------------------------------------------------------
[238]127IDEDEVICE%+PollBsyOnly:
[266]128 INPUT_TO_AL_FROM_IDE_REGISTER STATUS_REGISTER_in ; Discard contents for first read
[150]129ALIGN JUMP_ALIGN
130.PollLoop:
[266]131 INPUT_TO_AL_FROM_IDE_REGISTER STATUS_REGISTER_in
[150]132 test al, FLG_STATUS_BSY ; Controller busy?
[238]133 jz SHORT IDEDEVICE%+Error_GetBiosErrorCodeToAHfromPolledStatusRegisterInAL
[155]134 call Timer_SetCFifTimeout ; Update timeout counter
[150]135 jnc SHORT .PollLoop ; Loop if time left (sets CF on timeout)
[238]136 jmp SHORT IDEDEVICE%+Error_GetBiosErrorCodeToAHfromPolledStatusRegisterInAL
Note: See TracBrowser for help on using the repository browser.