source: xtideuniversalbios/trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH0h_HReset.asm@ 270

Last change on this file since 270 was 269, checked in by gregli@…, 12 years ago

Fixed a bug with reporting the number of hard disks when there were only foreign disks (none managed by this bios). Also a few small optimizations.

File size: 6.1 KB
Line 
1; Project name : XTIDE Universal BIOS
2; Description : Int 13h function AH=0h, Disk Controller Reset.
3
4; Section containing code
5SECTION .text
6
7;--------------------------------------------------------------------
8; Int 13h function AH=0h, Disk Controller Reset.
9;
10; AH0h_HandlerForDiskControllerReset
11; Parameters:
12; DL: Translated Drive number (ignored so all drives are reset)
13; If bit 7 is set all hard disks and floppy disks reset.
14; DS:DI: Ptr to DPT (in RAMVARS segment)
15; SS:BP: Ptr to IDEPACK
16; Returns with INTPACK:
17; AH: Int 13h return status (from drive requested in DL)
18; CF: 0 if succesfull, 1 if error
19;--------------------------------------------------------------------
20ALIGN JUMP_ALIGN
21AH0h_HandlerForDiskControllerReset:
22 eMOVZX bx, dl ; Copy requested drive to BL, zero BH to assume no errors
23 call ResetFloppyDrivesWithInt40h
24
25%ifdef MODULE_SERIAL_FLOPPY
26;
27; "Reset" emulatd serial floppy drives, if any. There is nothing to actually do for this reset,
28; but record the proper error return code if one of these floppy drives is the drive requested.
29;
30 call RamVars_UnpackFlopCntAndFirstToAL
31 cbw ; Clears AH (there are flop drives) or ffh (there are not)
32 ; Either AH has success code (flop drives are present)
33 ; or it doesn't matter because we won't match drive ffh
34
35 cwd ; clears DX (there are flop drives) or ffffh (there are not)
36
37 adc dl, al ; second drive (CF set) if present
38 ; If no drive is present, this will result in ffh which
39 ; won't match a drive
40 call BackupErrorCodeFromTheRequestedDriveToBH
41 mov dl, al ; We may end up doing the first drive twice (if there is
42 call BackupErrorCodeFromTheRequestedDriveToBH ; only one drive), but doing it again is not harmful.
43%endif
44
45 test bl, bl ; If we were called with a floppy disk, then we are done,
46 jns SHORT .SkipHardDiskReset ; don't do hard disks.
47
48 call ResetForeignHardDisks
49
50 ; Resetting our hard disks will modify dl and bl such that this call must be the last in the list
51 ;
52 call AH0h_ResetHardDisksHandledByOurBIOS
53
54.SkipHardDiskReset:
55 mov ah, bh
56 jmp Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH
57
58
59;--------------------------------------------------------------------
60; ResetFloppyDrivesWithInt40h
61; Parameters:
62; BL: Requested drive (DL when entering AH=00h)
63; Returns:
64; BH: Error code from requested drive (if available)
65; Corrupts registers:
66; AX, DL, DI
67;--------------------------------------------------------------------
68ALIGN JUMP_ALIGN
69ResetFloppyDrivesWithInt40h:
70 call GetDriveNumberForForeignBiosesToDL
71 and dl, 7Fh ; Clear hard disk bit
72 xor ah, ah ; Disk Controller Reset
73 int BIOS_DISKETTE_INTERRUPT_40h
74 jmp SHORT BackupErrorCodeFromTheRequestedDriveToBH
75
76
77;--------------------------------------------------------------------
78; ResetForeignHardDisks
79; Parameters:
80; BL: Requested drive (DL when entering AH=00h)
81; DS: RAMVARS segment
82; Returns:
83; BH: Error code from requested drive (if available)
84; Corrupts registers:
85; AX, DL, DI
86;--------------------------------------------------------------------
87ALIGN JUMP_ALIGN
88ResetForeignHardDisks:
89 call GetDriveNumberForForeignBiosesToDL
90 xor ah, ah ; Disk Controller Reset
91 call Int13h_CallPreviousInt13hHandler
92;;; fall-through to BackupErrorCodeFromTheRequestedDriveToBH
93
94
95;--------------------------------------------------------------------
96; BackupErrorCodeFromTheRequestedDriveToBH
97; Parameters:
98; AH: Error code from the last resetted drive
99; DL: Drive last resetted
100; BL: Requested drive (DL when entering AH=00h)
101; Returns:
102; BH: Backuped error code
103; Corrupts registers:
104; Nothing
105;--------------------------------------------------------------------
106ALIGN JUMP_ALIGN
107BackupErrorCodeFromTheRequestedDriveToBH:
108 cmp dl, bl ; Requested drive?
109 eCMOVE bh, ah
110 ret
111
112
113;--------------------------------------------------------------------
114; GetDriveNumberForForeignBiosesToDL
115; Parameters:
116; BL: Requested drive (DL when entering AH=00h)
117; DS: RAMVARS segment
118; Returns:
119; DL: BL if foreign drive
120; 80h if our drive
121; Corrupts registers:
122; DI
123;--------------------------------------------------------------------
124ALIGN JUMP_ALIGN
125GetDriveNumberForForeignBiosesToDL:
126 mov dl, bl
127 test di, di
128 jz SHORT .Return ; Return what was in BL unmodified
129 mov dl, 80h
130.Return:
131 ret
132
133
134;--------------------------------------------------------------------
135; AH0h_ResetHardDisksHandledByOurBIOS
136; Parameters:
137; BL: Requested drive (DL when entering AH=00h)
138; DS: RAMVARS segment
139; SS:BP: Ptr to IDEPACK
140; Returns:
141; BH: Error code from requested drive (if available)
142; Corrupts registers:
143; AX, CX, DX, SI, DI
144;--------------------------------------------------------------------
145ALIGN JUMP_ALIGN
146AH0h_ResetHardDisksHandledByOurBIOS:
147 mov bl, [di+DPT.bIdevarsOffset] ; replace drive number with Idevars pointer for cmp with dl
148 mov dl, ROMVARS.ideVars0 ; starting Idevars offset
149
150 call RamVars_GetIdeControllerCountToCX
151 jcxz .done ; just in case bIdeCnt is zero (shouldn't be)
152
153 mov si, IterateFindFirstDPTforIdevars ; iteration routine (see below)
154
155.loop:
156 call IterateAllDPTs ; look for the first drive on this controller, if any
157 jc .notFound
158
159 call AHDh_ResetDrive ; reset master and slave on that controller
160 call BackupErrorCodeFromTheRequestedDriveToBH ; save error code if same controller as drive from entry
161
162.notFound:
163 add dl, IDEVARS_size ; move Idevars pointer forward
164 loop .loop
165
166.done:
167 ret
168
169;--------------------------------------------------------------------
170; Iteration routine for AH0h_ResetHardDisksHandledByOurBIOS,
171; for use with IterateAllDPTs
172;
173; Returns when DPT is found on the controller with Idevars offset in DL
174;--------------------------------------------------------------------
175IterateFindFirstDPTforIdevars:
176 cmp dl, [di+DPT.bIdevarsOffset] ; Clears CF if matched
177 jz .done
178 stc ; Set CF for not found
179.done:
180 ret
Note: See TracBrowser for help on using the repository browser.