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

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

Cleaned recent changes a bit to save few bytes.

File size: 5.5 KB
Line 
1; File name : AH0h_HReset.asm
2; Project name : IDE BIOS
3; Created date : 27.9.2007
4; Last update : 24.8.2010
5; Author : Tomi Tilli
6; Description : Int 13h function AH=0h, Disk Controller Reset.
7
8; Section containing code
9SECTION .text
10
11;--------------------------------------------------------------------
12; Int 13h function AH=0h, Disk Controller Reset.
13;
14; AH0h_HandlerForDiskControllerReset
15; Parameters:
16; AH: Bios function 0h
17; DL: Drive number (ignored so all drives are reset)
18; If bit 7 is set all hard disks and floppy disks reset.
19; Parameters loaded by Int13h_Jump:
20; DS: RAMVARS segment
21; Returns:
22; AH: Int 13h return status (from drive requested in DL)
23; CF: 0 if succesfull, 1 if error
24; IF: 1
25; Corrupts registers:
26; Flags
27;--------------------------------------------------------------------
28ALIGN JUMP_ALIGN
29AH0h_HandlerForDiskControllerReset:
30 push dx
31 push cx
32 push bx
33 push ax
34
35 eMOVZX bx, dl ; Copy requested drive to BL, zero BH to assume no errors
36 call ResetFloppyDrivesWithInt40h
37 test bl, 80h
38 jz SHORT .SkipHardDiskReset
39 call ResetForeignHardDisks
40 call AH0h_ResetHardDisksHandledByOurBIOS
41ALIGN JUMP_ALIGN
42.SkipHardDiskReset:
43 mov ah, bh ; Copy error code to AH
44 xor al, al ; Zero AL...
45 cmp al, bh ; ...and set CF if error
46 jmp Int13h_PopXRegsAndReturn
47
48
49;--------------------------------------------------------------------
50; ResetFloppyDrivesWithInt40h
51; Parameters:
52; BL: Requested drive (DL when entering AH=00h)
53; Returns:
54; BH: Error code from requested drive (if available)
55; Corrupts registers:
56; AX, DL, DI
57;--------------------------------------------------------------------
58ALIGN JUMP_ALIGN
59ResetFloppyDrivesWithInt40h:
60 call GetDriveNumberForForeignBiosesToDL
61 and dl, 7Fh ; Clear hard disk bit
62 xor ah, ah ; Disk Controller Reset
63 int INTV_FLOPPY_FUNC
64 jmp SHORT BackupErrorCodeFromTheRequestedDriveToBH
65
66
67;--------------------------------------------------------------------
68; ResetForeignHardDisks
69; Parameters:
70; BL: Requested drive (DL when entering AH=00h)
71; DS: RAMVARS segment
72; Returns:
73; BH: Error code from requested drive (if available)
74; Corrupts registers:
75; AX, DL, DI
76;--------------------------------------------------------------------
77ALIGN JUMP_ALIGN
78ResetForeignHardDisks:
79 call GetDriveNumberForForeignBiosesToDL
80 xor ah, ah ; Disk Controller Reset
81 call Int13h_CallPreviousInt13hHandler
82 jmp SHORT BackupErrorCodeFromTheRequestedDriveToBH
83
84
85;--------------------------------------------------------------------
86; GetDriveNumberForForeignBiosesToDL
87; Parameters:
88; BL: Requested drive (DL when entering AH=00h)
89; DS: RAMVARS segment
90; Returns:
91; DL: BL if foreign drive
92; 80h if our drive
93; Corrupts registers:
94; DI
95;--------------------------------------------------------------------
96ALIGN JUMP_ALIGN
97GetDriveNumberForForeignBiosesToDL:
98 mov dl, bl
99 call RamVars_IsDriveHandledByThisBIOS
100 jc SHORT .GetFirstDriveForForeignBios
101 ret ; Return what was in BL unmodified
102ALIGN JUMP_ALIGN
103.GetFirstDriveForForeignBios:
104 mov dl, 80h
105 ret
106
107
108;--------------------------------------------------------------------
109; ResetHardDisksHandledByOurBIOS
110; Parameters:
111; BL: Requested drive (DL when entering AH=00h)
112; DS: RAMVARS segment
113; Returns:
114; BH: Error code from requested drive (if available)
115; Corrupts registers:
116; AX, CX, DX, DI
117;--------------------------------------------------------------------
118ALIGN JUMP_ALIGN
119AH0h_ResetHardDisksHandledByOurBIOS:
120 mov dh, [RAMVARS.bDrvCnt] ; Load drive count to DH
121 test dh, dh
122 jz SHORT .AllDrivesReset ; Return if no drives
123 mov dl, [RAMVARS.bFirstDrv] ; Load number of first our drive
124 add dh, dl ; DH = one past last drive to reset
125ALIGN JUMP_ALIGN
126.DriveResetLoop:
127 call AHDh_ResetDrive
128 call .BackupErrorCodeFromMasterOrSlaveToBH
129 inc dx
130 cmp dl, dh ; All done?
131 jb SHORT .DriveResetLoop ; If not, reset next drive
132.AllDrivesReset:
133 ret
134
135;--------------------------------------------------------------------
136; .BackupErrorCodeFromMasterOrSlaveToBH
137; Parameters:
138; AH: Error code for drive DL reset
139; BL: Requested drive (DL when entering AH=00h)
140; DL: Drive just resetted
141; DS: RAMVARS segment
142; Returns:
143; BH: Backuped error code
144; DL: Incremented if next drive is slave drive
145; (=already resetted)
146; Corrupts registers:
147; CX, DI
148;--------------------------------------------------------------------
149ALIGN JUMP_ALIGN
150.BackupErrorCodeFromMasterOrSlaveToBH:
151 call BackupErrorCodeFromTheRequestedDriveToBH
152 mov cx, [RAMVARS.wIdeBase] ; Load base port for resetted drive
153
154 inc dx ; DL to next drive
155 call FindDPT_ForDriveNumber ; Get DPT to DS:DI, store port to RAMVARS
156 jnc SHORT .NoMoreDrivesOrNoSlaveDrive
157 cmp cx, [RAMVARS.wIdeBase] ; Next drive is from same controller?
158 je SHORT BackupErrorCodeFromTheRequestedDriveToBH
159.NoMoreDrivesOrNoSlaveDrive:
160 dec dx
161 ret
162
163
164;--------------------------------------------------------------------
165; BackupErrorCodeFromTheRequestedDriveToBH
166; Parameters:
167; AH: Error code from the last resetted drive
168; DL: Drive last resetted
169; BL: Requested drive (DL when entering AH=00h)
170; Returns:
171; BH: Backuped error code
172; Corrupts registers:
173; Nothing
174;--------------------------------------------------------------------
175ALIGN JUMP_ALIGN
176BackupErrorCodeFromTheRequestedDriveToBH:
177 cmp dl, bl ; Requested drive?
178 jne SHORT .Return
179 mov bh, ah
180ALIGN JUMP_ALIGN
181.Return:
182 ret
Note: See TracBrowser for help on using the repository browser.