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

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

Made some tweaks to ah0h, saving some space by taking advantage of DPT=null indicating foreign drive.

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