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

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

Fixed a bug with ah0h/reset of a serial drive that was found during COM detect.

File size: 6.7 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 successful, 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" emulated 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 ; Resetting our hard disks will modify dl and bl to be idevars offset based instead of drive number based,
54 ; such that this call must be the last in the list of reset routines called.
55 ;
56 ; This needs to happen after ResetForeignHardDisks, as that call may have set the error code for 80h,
57 ; and we need to override that value if we are xlate'd into 80h with one of our drives.
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 DPT pointer is not available, or error result in BH won't be used anyway,
142; enter through .ErrorCodeNotUsed.
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 xor bl, bl ; Assume Null IdevarsOffset for now, assuming foreign drive
151 test di, di
152 jz .ErrorCodeNotUsed
153 mov bl, [di+DPT.bIdevarsOffset] ; replace drive number with Idevars pointer for cmp with dl
154
155.ErrorCodeNotUsed: ; BH will be garbage on exit if this entry point is used,
156 ; but reset of all drives will still happen
157
158 mov dl, ROMVARS.ideVars0 ; starting Idevars offset
159
160 ; Get count of ALL Idevars structures, not just the ones that are configured. This may seem odd,
161 ; but it catches the .ideVarsSerialAuto structure, which would not be scanned if the count from
162 ; RamVars_GetIdeControllerCountToCX was used. Unused controllers won't make a difference, since no DPT
163 ; will point to them. Performance isn't an issue, as this is a reset operation.
164 ;
165 mov cx, (ROMVARS.ideVarsEnd - ROMVARS.ideVarsBegin) / IDEVARS_size
166
167.loop:
168 call FindDPT_ForIdevarsOffsetInDL ; look for the first drive on this controller, if any
169 jc .notFound
170
171 call AHDh_ResetDrive ; reset master and slave on that controller
172 call BackupErrorCodeFromTheRequestedDriveToBH ; save error code if same controller as drive from entry
173
174.notFound:
175 add dl, IDEVARS_size ; move Idevars pointer forward
176 loop .loop
177
178.done:
179 ret
Note: See TracBrowser for help on using the repository browser.