source: xtideuniversalbios/tags/XTIDE_Universal_BIOS_v1.1.1/Src/Handlers/Int13h/AH0h_HReset.asm

Last change on this file was 23, checked in by Tomi Tilli, 14 years ago

Booting is now possible from hard disks if floppy controller reset fails.
AH=00h, Disk Controller Reset now returns error code for the requested drive only.

File size: 5.9 KB
Line 
1; File name : AH0h_HReset.asm
2; Project name : IDE BIOS
3; Created date : 27.9.2007
4; Last update : 1.7.2010
5; Author : Tomi Tilli
6; Description : Int 13h function AH=0h, Disk Controller Reset.
7
8RETRIES_IF_RESET_FAILS EQU 3
9TIMEOUT_BEFORE_RESET_RETRY EQU 5 ; System timer ticks
10
11; Section containing code
12SECTION .text
13
14;--------------------------------------------------------------------
15; Int 13h function AH=0h, Disk Controller Reset.
16;
17; AH0h_HandlerForDiskControllerReset
18; Parameters:
19; AH: Bios function 0h
20; DL: Drive number (ignored so all drives are reset)
21; If bit 7 is set all hard disks and floppy disks reset.
22; Parameters loaded by Int13h_Jump:
23; DS: RAMVARS segment
24; Returns:
25; AH: Int 13h return status (from drive requested in DL)
26; CF: 0 if succesfull, 1 if error
27; IF: 1
28; Corrupts registers:
29; Flags
30;--------------------------------------------------------------------
31ALIGN JUMP_ALIGN
32AH0h_HandlerForDiskControllerReset:
33 push dx
34 push cx
35 push bx
36 push ax
37
38 eMOVZX bx, dl ; Copy requested drive to BL, zero BH to assume no errors
39 call AH0h_ResetFloppyDrivesWithInt40h
40 test bl, 80h ; Reset hard disks too?
41 jz SHORT .Return
42 call AH0h_ResetForeignHardDisks
43 call AH0h_ResetAllOurControllers
44ALIGN JUMP_ALIGN
45.Return:
46 mov ah, bh ; Copy error code to AH
47 xor al, al ; Zero AL...
48 sub al, ah ; ...and set CF if error
49 jmp Int13h_PopXRegsAndReturn
50
51
52;--------------------------------------------------------------------
53; AH0h_ResetFloppyDrivesWithInt40h
54; Parameters:
55; BL: Requested drive (DL when entering AH=00h)
56; DL: Drive number
57; Returns:
58; BH: Error code from requested drive (if available)
59; Corrupts registers:
60; AX, DL
61;--------------------------------------------------------------------
62ALIGN JUMP_ALIGN
63AH0h_ResetFloppyDrivesWithInt40h:
64 xor ax, ax ; Disk Controller Reset
65 and dl, 7Fh ; Clear bit 7
66 int INTV_FLOPPY_FUNC
67 jmp SHORT AH0h_BackupErrorCodeFromTheRequestedDriveToBH
68
69
70;--------------------------------------------------------------------
71; AH0h_ResetForeignHardDisks
72; Parameters:
73; BL: Requested drive (DL when entering AH=00h)
74; DS: RAMVARS segment
75; Returns:
76; BH: Error code from requested drive (if available)
77; Corrupts registers:
78; AX, DL
79;--------------------------------------------------------------------
80ALIGN JUMP_ALIGN
81AH0h_ResetForeignHardDisks:
82 mov cl, [RAMVARS.bFirstDrv] ; Load number of first our drive
83 and cx, BYTE 7Fh ; CX = number of drives to reset
84 jz SHORT .Return
85 mov dl, 80h ; Start resetting from drive 80h
86ALIGN JUMP_ALIGN
87.DriveResetLoop:
88 mov ah, 0Dh ; Reset Hard Disk (Alternate reset)
89 pushf ; Push flags to simulate INT
90 cli ; Disable interrupts since INT does that
91 call FAR [RAMVARS.fpOldI13h]
92 sti ; Make sure interrupts are enabled again (some BIOSes fails to enable it)
93 call AH0h_BackupErrorCodeFromTheRequestedDriveToBH
94 inc dx ; Next drive to reset
95 loop .DriveResetLoop
96ALIGN JUMP_ALIGN
97.Return:
98 ret
99
100
101;--------------------------------------------------------------------
102; AH0h_ResetAllOurControllers
103; Parameters:
104; BL: Requested drive (DL when entering AH=00h)
105; DS: RAMVARS segment
106; Returns:
107; BH: Error code from requested drive (if available)
108; Corrupts registers:
109; AX, CX, DX, DI
110;--------------------------------------------------------------------
111ALIGN JUMP_ALIGN
112AH0h_ResetAllOurControllers:
113 push si
114 mov si, ROMVARS.ideVars0 ; Load offset to first IDEVARS
115 call Initialize_GetIdeControllerCountToCX
116ALIGN JUMP_ALIGN
117.ResetLoop:
118 call AH0h_ResetIdevarsControllerMasterAndSlaveDrives
119 add si, BYTE IDEVARS_size
120 loop .ResetLoop
121.Return:
122 pop si
123 ret
124
125
126;--------------------------------------------------------------------
127; AH0h_ResetIdevarsControllerMasterAndSlaveDrives
128; Parameters:
129; BL: Requested drive (DL when entering AH=00h)
130; CS:SI: Ptr to IDEVARS
131; DS: RAMVARS segment
132; Returns:
133; BH: Error code from requested drive (if available)
134; Corrupts registers:
135; AX, DX, DI
136;--------------------------------------------------------------------
137ALIGN JUMP_ALIGN
138AH0h_ResetIdevarsControllerMasterAndSlaveDrives:
139 mov dx, [cs:si+IDEVARS.wPort]
140 call FindDPT_ForIdeMasterAtPort ; Find master drive to DL
141 jc SHORT AH0h_ResetMasterAndSlaveDriveWithRetries
142 call FindDPT_ForIdeSlaveAtPort ; Find slave if master not present
143 jc SHORT AH0h_ResetMasterAndSlaveDriveWithRetries
144 ret
145
146;--------------------------------------------------------------------
147; AH0h_ResetMasterAndSlaveDriveWithRetries
148; Parameters:
149; BL: Requested drive (DL when entering AH=00h)
150; DL: Drive number for master or slave drive
151; DS: RAMVARS segment
152; Returns:
153; BH: Error code from requested drive (if available)
154; Corrupts registers:
155; AX, DI
156;--------------------------------------------------------------------
157ALIGN JUMP_ALIGN
158AH0h_ResetMasterAndSlaveDriveWithRetries:
159 push dx
160 push cx
161 push bx
162 mov di, RETRIES_IF_RESET_FAILS
163ALIGN JUMP_ALIGN
164.RetryLoop:
165 call AHDh_ResetDrive
166 jnc SHORT .Return ; Jump if successful
167 mov cx, TIMEOUT_BEFORE_RESET_RETRY
168 call SoftDelay_TimerTicks
169 dec di
170 jnz SHORT .RetryLoop
171ALIGN JUMP_ALIGN
172.Return:
173 pop bx
174 pop cx
175 pop dx
176 ; Fall to AH0h_BackupErrorCodeFromTheRequestedDriveToBH
177
178;--------------------------------------------------------------------
179; AH0h_BackupErrorCodeFromTheRequestedDriveToBH
180; Parameters:
181; AH: Error code from the last resetted drive
182; DL: Drive last resetted
183; BL: Requested drive (DL when entering AH=00h)
184; Returns:
185; BH: Backuped error code
186; Corrupts registers:
187; Nothing
188;--------------------------------------------------------------------
189ALIGN JUMP_ALIGN
190AH0h_BackupErrorCodeFromTheRequestedDriveToBH:
191 cmp dl, bl ; Requested drive?
192 jne SHORT .Return
193 mov bh, ah
194ALIGN JUMP_ALIGN
195.Return:
196 ret
Note: See TracBrowser for help on using the repository browser.