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

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

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

File size: 6.7 KB
RevLine 
[128]1; Project name : XTIDE Universal BIOS
[3]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;
[271]10; Note: We handle all AH=0h calls, even for drives handled by other
11; BIOSes!
12;
[3]13; AH0h_HandlerForDiskControllerReset
14; Parameters:
[148]15; DL: Translated Drive number (ignored so all drives are reset)
[3]16; If bit 7 is set all hard disks and floppy disks reset.
[275]17; DS:DI: Ptr to DPT (or Null if foreign drive)
[150]18; SS:BP: Ptr to IDEPACK
19; Returns with INTPACK:
[23]20; AH: Int 13h return status (from drive requested in DL)
[294]21; CF: 0 if successful, 1 if error
[3]22;--------------------------------------------------------------------
23ALIGN JUMP_ALIGN
24AH0h_HandlerForDiskControllerReset:
[23]25 eMOVZX bx, dl ; Copy requested drive to BL, zero BH to assume no errors
[26]26 call ResetFloppyDrivesWithInt40h
[259]27
28%ifdef MODULE_SERIAL_FLOPPY
29;
[294]30; "Reset" emulated serial floppy drives, if any. There is nothing to actually do for this reset,
[259]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
[294]41 ; If no drive is present, this will result in ffh which
[259]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.
[294]50
[26]51 call ResetForeignHardDisks
[264]52
[294]53 ; Resetting our hard disks will modify dl and bl to be idevars offset based instead of drive number based,
[275]54 ; such that this call must be the last in the list of reset routines called.
55 ;
[282]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 ;
[294]59 call ResetHardDisksHandledByOurBIOS
[264]60
[26]61.SkipHardDiskReset:
[148]62 mov ah, bh
63 jmp Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH
[3]64
65
66;--------------------------------------------------------------------
[26]67; ResetFloppyDrivesWithInt40h
[3]68; Parameters:
[23]69; BL: Requested drive (DL when entering AH=00h)
70; Returns:
71; BH: Error code from requested drive (if available)
72; Corrupts registers:
[27]73; AX, DL, DI
[128]74;--------------------------------------------------------------------
[26]75ResetFloppyDrivesWithInt40h:
[271]76 call GetDriveNumberForForeignHardDiskHandlerToDL
[27]77 and dl, 7Fh ; Clear hard disk bit
[26]78 xor ah, ah ; Disk Controller Reset
[148]79 int BIOS_DISKETTE_INTERRUPT_40h
[26]80 jmp SHORT BackupErrorCodeFromTheRequestedDriveToBH
[23]81
82
83;--------------------------------------------------------------------
[26]84; ResetForeignHardDisks
[23]85; Parameters:
86; BL: Requested drive (DL when entering AH=00h)
[3]87; DS: RAMVARS segment
88; Returns:
[23]89; BH: Error code from requested drive (if available)
[3]90; Corrupts registers:
[27]91; AX, DL, DI
[128]92;--------------------------------------------------------------------
[26]93ResetForeignHardDisks:
[271]94 call GetDriveNumberForForeignHardDiskHandlerToDL
[27]95 xor ah, ah ; Disk Controller Reset
[32]96 call Int13h_CallPreviousInt13hHandler
[258]97;;; fall-through to BackupErrorCodeFromTheRequestedDriveToBH
[23]98
[26]99
[3]100;--------------------------------------------------------------------
[258]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
[271]116
[258]117;--------------------------------------------------------------------
[271]118; GetDriveNumberForForeignHardDiskHandlerToDL
[27]119; Parameters:
120; BL: Requested drive (DL when entering AH=00h)
121; DS: RAMVARS segment
122; Returns:
[275]123; DS:DI: Ptr to DPT if our drive (or Null if foreign drive)
[27]124; DL: BL if foreign drive
125; 80h if our drive
[128]126;--------------------------------------------------------------------
[271]127GetDriveNumberForForeignHardDiskHandlerToDL:
[27]128 mov dl, bl
[275]129 test di, di
130 jz SHORT .Return
[271]131 mov dl, 80h ; First possible Hard Disk should be safe value
[275]132.Return:
[27]133 ret
134
[275]135AH0h_ResetAllOurHardDisksAtTheEndOfDriveInitialization equ ResetHardDisksHandledByOurBIOS.ErrorCodeNotUsed
[27]136
137;--------------------------------------------------------------------
[271]138; ResetHardDisksHandledByOurBIOS
139; Parameters:
140; DS:DI: Ptr to DPT for requested drive
[294]141; If DPT pointer is not available, or error result in BH won't be used anyway,
[282]142; enter through .ErrorCodeNotUsed.
[271]143; SS:BP: Ptr to IDEPACK
144; Returns:
[23]145; BH: Error code from requested drive (if available)
146; Corrupts registers:
[275]147; AX, BX, CX, DX, SI, DI
[23]148;--------------------------------------------------------------------
[271]149ResetHardDisksHandledByOurBIOS:
[294]150 xor bl, bl ; Assume Null IdevarsOffset for now, assuming foreign drive
[282]151 test di, di
152 jz .ErrorCodeNotUsed
[264]153 mov bl, [di+DPT.bIdevarsOffset] ; replace drive number with Idevars pointer for cmp with dl
[294]154
155.ErrorCodeNotUsed: ; BH will be garbage on exit if this entry point is used,
[275]156 ; but reset of all drives will still happen
157
[264]158 mov dl, ROMVARS.ideVars0 ; starting Idevars offset
159
[316]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
[262]167.loop:
[271]168 call FindDPT_ForIdevarsOffsetInDL ; look for the first drive on this controller, if any
[262]169 jc .notFound
[264]170
[262]171 call AHDh_ResetDrive ; reset master and slave on that controller
[264]172 call BackupErrorCodeFromTheRequestedDriveToBH ; save error code if same controller as drive from entry
173
[262]174.notFound:
[264]175 add dl, IDEVARS_size ; move Idevars pointer forward
176 loop .loop
177
178.done:
[259]179 ret
Note: See TracBrowser for help on using the repository browser.