[128] | 1 | ; Project name : XTIDE Universal BIOS
|
---|
[3] | 2 | ; Description : Int 13h function AH=0h, Disk Controller Reset.
|
---|
| 3 |
|
---|
[376] | 4 | ;
|
---|
| 5 | ; XTIDE Universal BIOS and Associated Tools
|
---|
| 6 | ; Copyright (C) 2009-2010 by Tomi Tilli, 2011-2012 by XTIDE Universal BIOS Team.
|
---|
| 7 | ;
|
---|
| 8 | ; This program is free software; you can redistribute it and/or modify
|
---|
| 9 | ; it under the terms of the GNU General Public License as published by
|
---|
| 10 | ; the Free Software Foundation; either version 2 of the License, or
|
---|
| 11 | ; (at your option) any later version.
|
---|
| 12 | ;
|
---|
| 13 | ; This program is distributed in the hope that it will be useful,
|
---|
| 14 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 15 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 16 | ; GNU General Public License for more details.
|
---|
| 17 | ; Visit http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
---|
| 18 | ;
|
---|
| 19 |
|
---|
[3] | 20 | ; Section containing code
|
---|
| 21 | SECTION .text
|
---|
| 22 |
|
---|
| 23 | ;--------------------------------------------------------------------
|
---|
| 24 | ; Int 13h function AH=0h, Disk Controller Reset.
|
---|
| 25 | ;
|
---|
[271] | 26 | ; Note: We handle all AH=0h calls, even for drives handled by other
|
---|
| 27 | ; BIOSes!
|
---|
| 28 | ;
|
---|
[3] | 29 | ; AH0h_HandlerForDiskControllerReset
|
---|
| 30 | ; Parameters:
|
---|
[148] | 31 | ; DL: Translated Drive number (ignored so all drives are reset)
|
---|
[3] | 32 | ; If bit 7 is set all hard disks and floppy disks reset.
|
---|
[275] | 33 | ; DS:DI: Ptr to DPT (or Null if foreign drive)
|
---|
[150] | 34 | ; SS:BP: Ptr to IDEPACK
|
---|
| 35 | ; Returns with INTPACK:
|
---|
[23] | 36 | ; AH: Int 13h return status (from drive requested in DL)
|
---|
[294] | 37 | ; CF: 0 if successful, 1 if error
|
---|
[3] | 38 | ;--------------------------------------------------------------------
|
---|
| 39 | AH0h_HandlerForDiskControllerReset:
|
---|
[23] | 40 | eMOVZX bx, dl ; Copy requested drive to BL, zero BH to assume no errors
|
---|
[26] | 41 | call ResetFloppyDrivesWithInt40h
|
---|
[259] | 42 |
|
---|
| 43 | %ifdef MODULE_SERIAL_FLOPPY
|
---|
| 44 | ;
|
---|
[294] | 45 | ; "Reset" emulated serial floppy drives, if any. There is nothing to actually do for this reset,
|
---|
[259] | 46 | ; but record the proper error return code if one of these floppy drives is the drive requested.
|
---|
| 47 | ;
|
---|
| 48 | call RamVars_UnpackFlopCntAndFirstToAL
|
---|
| 49 | cbw ; Clears AH (there are flop drives) or ffh (there are not)
|
---|
| 50 | ; Either AH has success code (flop drives are present)
|
---|
| 51 | ; or it doesn't matter because we won't match drive ffh
|
---|
| 52 |
|
---|
| 53 | cwd ; clears DX (there are flop drives) or ffffh (there are not)
|
---|
| 54 |
|
---|
| 55 | adc dl, al ; second drive (CF set) if present
|
---|
[294] | 56 | ; If no drive is present, this will result in ffh which
|
---|
[259] | 57 | ; won't match a drive
|
---|
| 58 | call BackupErrorCodeFromTheRequestedDriveToBH
|
---|
| 59 | mov dl, al ; We may end up doing the first drive twice (if there is
|
---|
| 60 | call BackupErrorCodeFromTheRequestedDriveToBH ; only one drive), but doing it again is not harmful.
|
---|
| 61 | %endif
|
---|
| 62 |
|
---|
| 63 | test bl, bl ; If we were called with a floppy disk, then we are done,
|
---|
| 64 | jns SHORT .SkipHardDiskReset ; don't do hard disks.
|
---|
[294] | 65 |
|
---|
[26] | 66 | call ResetForeignHardDisks
|
---|
[264] | 67 |
|
---|
[294] | 68 | ; Resetting our hard disks will modify dl and bl to be idevars offset based instead of drive number based,
|
---|
[275] | 69 | ; such that this call must be the last in the list of reset routines called.
|
---|
| 70 | ;
|
---|
[282] | 71 | ; This needs to happen after ResetForeignHardDisks, as that call may have set the error code for 80h,
|
---|
| 72 | ; and we need to override that value if we are xlate'd into 80h with one of our drives.
|
---|
| 73 | ;
|
---|
[294] | 74 | call ResetHardDisksHandledByOurBIOS
|
---|
[264] | 75 |
|
---|
[26] | 76 | .SkipHardDiskReset:
|
---|
[148] | 77 | mov ah, bh
|
---|
| 78 | jmp Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH
|
---|
[3] | 79 |
|
---|
| 80 |
|
---|
| 81 | ;--------------------------------------------------------------------
|
---|
[26] | 82 | ; ResetFloppyDrivesWithInt40h
|
---|
[3] | 83 | ; Parameters:
|
---|
[23] | 84 | ; BL: Requested drive (DL when entering AH=00h)
|
---|
| 85 | ; Returns:
|
---|
| 86 | ; BH: Error code from requested drive (if available)
|
---|
| 87 | ; Corrupts registers:
|
---|
[27] | 88 | ; AX, DL, DI
|
---|
[128] | 89 | ;--------------------------------------------------------------------
|
---|
[26] | 90 | ResetFloppyDrivesWithInt40h:
|
---|
[271] | 91 | call GetDriveNumberForForeignHardDiskHandlerToDL
|
---|
[27] | 92 | and dl, 7Fh ; Clear hard disk bit
|
---|
[26] | 93 | xor ah, ah ; Disk Controller Reset
|
---|
[148] | 94 | int BIOS_DISKETTE_INTERRUPT_40h
|
---|
[26] | 95 | jmp SHORT BackupErrorCodeFromTheRequestedDriveToBH
|
---|
[23] | 96 |
|
---|
| 97 |
|
---|
| 98 | ;--------------------------------------------------------------------
|
---|
[26] | 99 | ; ResetForeignHardDisks
|
---|
[23] | 100 | ; Parameters:
|
---|
| 101 | ; BL: Requested drive (DL when entering AH=00h)
|
---|
[3] | 102 | ; DS: RAMVARS segment
|
---|
| 103 | ; Returns:
|
---|
[23] | 104 | ; BH: Error code from requested drive (if available)
|
---|
[3] | 105 | ; Corrupts registers:
|
---|
[27] | 106 | ; AX, DL, DI
|
---|
[128] | 107 | ;--------------------------------------------------------------------
|
---|
[26] | 108 | ResetForeignHardDisks:
|
---|
[271] | 109 | call GetDriveNumberForForeignHardDiskHandlerToDL
|
---|
[27] | 110 | xor ah, ah ; Disk Controller Reset
|
---|
[32] | 111 | call Int13h_CallPreviousInt13hHandler
|
---|
[258] | 112 | ;;; fall-through to BackupErrorCodeFromTheRequestedDriveToBH
|
---|
[23] | 113 |
|
---|
[26] | 114 |
|
---|
[3] | 115 | ;--------------------------------------------------------------------
|
---|
[258] | 116 | ; BackupErrorCodeFromTheRequestedDriveToBH
|
---|
| 117 | ; Parameters:
|
---|
| 118 | ; AH: Error code from the last resetted drive
|
---|
| 119 | ; DL: Drive last resetted
|
---|
| 120 | ; BL: Requested drive (DL when entering AH=00h)
|
---|
| 121 | ; Returns:
|
---|
| 122 | ; BH: Backuped error code
|
---|
| 123 | ; Corrupts registers:
|
---|
| 124 | ; Nothing
|
---|
| 125 | ;--------------------------------------------------------------------
|
---|
| 126 | BackupErrorCodeFromTheRequestedDriveToBH:
|
---|
| 127 | cmp dl, bl ; Requested drive?
|
---|
| 128 | eCMOVE bh, ah
|
---|
| 129 | ret
|
---|
| 130 |
|
---|
[271] | 131 |
|
---|
[258] | 132 | ;--------------------------------------------------------------------
|
---|
[271] | 133 | ; GetDriveNumberForForeignHardDiskHandlerToDL
|
---|
[27] | 134 | ; Parameters:
|
---|
| 135 | ; BL: Requested drive (DL when entering AH=00h)
|
---|
| 136 | ; DS: RAMVARS segment
|
---|
| 137 | ; Returns:
|
---|
[275] | 138 | ; DS:DI: Ptr to DPT if our drive (or Null if foreign drive)
|
---|
[27] | 139 | ; DL: BL if foreign drive
|
---|
| 140 | ; 80h if our drive
|
---|
[128] | 141 | ;--------------------------------------------------------------------
|
---|
[271] | 142 | GetDriveNumberForForeignHardDiskHandlerToDL:
|
---|
[27] | 143 | mov dl, bl
|
---|
[275] | 144 | test di, di
|
---|
| 145 | jz SHORT .Return
|
---|
[271] | 146 | mov dl, 80h ; First possible Hard Disk should be safe value
|
---|
[275] | 147 | .Return:
|
---|
[27] | 148 | ret
|
---|
| 149 |
|
---|
[275] | 150 | AH0h_ResetAllOurHardDisksAtTheEndOfDriveInitialization equ ResetHardDisksHandledByOurBIOS.ErrorCodeNotUsed
|
---|
[27] | 151 |
|
---|
| 152 | ;--------------------------------------------------------------------
|
---|
[271] | 153 | ; ResetHardDisksHandledByOurBIOS
|
---|
| 154 | ; Parameters:
|
---|
| 155 | ; DS:DI: Ptr to DPT for requested drive
|
---|
[294] | 156 | ; If DPT pointer is not available, or error result in BH won't be used anyway,
|
---|
[282] | 157 | ; enter through .ErrorCodeNotUsed.
|
---|
[271] | 158 | ; SS:BP: Ptr to IDEPACK
|
---|
| 159 | ; Returns:
|
---|
[23] | 160 | ; BH: Error code from requested drive (if available)
|
---|
| 161 | ; Corrupts registers:
|
---|
[275] | 162 | ; AX, BX, CX, DX, SI, DI
|
---|
[23] | 163 | ;--------------------------------------------------------------------
|
---|
[271] | 164 | ResetHardDisksHandledByOurBIOS:
|
---|
[294] | 165 | xor bl, bl ; Assume Null IdevarsOffset for now, assuming foreign drive
|
---|
[282] | 166 | test di, di
|
---|
| 167 | jz .ErrorCodeNotUsed
|
---|
[264] | 168 | mov bl, [di+DPT.bIdevarsOffset] ; replace drive number with Idevars pointer for cmp with dl
|
---|
[294] | 169 |
|
---|
| 170 | .ErrorCodeNotUsed: ; BH will be garbage on exit if this entry point is used,
|
---|
[275] | 171 | ; but reset of all drives will still happen
|
---|
| 172 |
|
---|
[264] | 173 | mov dl, ROMVARS.ideVars0 ; starting Idevars offset
|
---|
| 174 |
|
---|
[316] | 175 | ; Get count of ALL Idevars structures, not just the ones that are configured. This may seem odd,
|
---|
| 176 | ; but it catches the .ideVarsSerialAuto structure, which would not be scanned if the count from
|
---|
| 177 | ; RamVars_GetIdeControllerCountToCX was used. Unused controllers won't make a difference, since no DPT
|
---|
| 178 | ; will point to them. Performance isn't an issue, as this is a reset operation.
|
---|
| 179 | ;
|
---|
| 180 | mov cx, (ROMVARS.ideVarsEnd - ROMVARS.ideVarsBegin) / IDEVARS_size
|
---|
| 181 |
|
---|
[262] | 182 | .loop:
|
---|
[271] | 183 | call FindDPT_ForIdevarsOffsetInDL ; look for the first drive on this controller, if any
|
---|
[262] | 184 | jc .notFound
|
---|
[264] | 185 |
|
---|
[262] | 186 | call AHDh_ResetDrive ; reset master and slave on that controller
|
---|
[264] | 187 | call BackupErrorCodeFromTheRequestedDriveToBH ; save error code if same controller as drive from entry
|
---|
| 188 |
|
---|
[262] | 189 | .notFound:
|
---|
[264] | 190 | add dl, IDEVARS_size ; move Idevars pointer forward
|
---|
| 191 | loop .loop
|
---|
| 192 |
|
---|
| 193 | .done:
|
---|
[259] | 194 | ret
|
---|