[128] | 1 | ; Project name : XTIDE Universal BIOS |
---|
[3] | 2 | ; Description : Int 13h function AH=0h, Disk Controller Reset. |
---|
| 3 | |
---|
[376] | 4 | ; |
---|
[491] | 5 | ; XTIDE Universal BIOS and Associated Tools |
---|
[376] | 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. |
---|
[491] | 12 | ; |
---|
[376] | 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 |
---|
[491] | 16 | ; GNU General Public License for more details. |
---|
[376] | 17 | ; Visit http://www.gnu.org/licenses/old-licenses/gpl-2.0.html |
---|
[491] | 18 | ; |
---|
[376] | 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: |
---|
[503] | 40 | ; Reset foreign Floppy and Hard Drives (those handled by other BIOSes) |
---|
[505] | 41 | eMOVZX bx, dl ; Copy requested drive to BL and zero BH to assume no errors |
---|
| 42 | |
---|
[503] | 43 | xor ah, ah ; Disk Controller Reset |
---|
| 44 | call Int13h_CallPreviousInt13hHandler ; Reset floppy drives only or floppy drives and foreign hard disks |
---|
| 45 | call BackupErrorCodeFromTheRequestedDriveToBH |
---|
[259] | 46 | |
---|
| 47 | %ifdef MODULE_SERIAL_FLOPPY |
---|
| 48 | ; |
---|
[294] | 49 | ; "Reset" emulated serial floppy drives, if any. There is nothing to actually do for this reset, |
---|
[259] | 50 | ; but record the proper error return code if one of these floppy drives is the drive requested. |
---|
| 51 | ; |
---|
| 52 | call RamVars_UnpackFlopCntAndFirstToAL |
---|
| 53 | cbw ; Clears AH (there are flop drives) or ffh (there are not) |
---|
| 54 | ; Either AH has success code (flop drives are present) |
---|
| 55 | ; or it doesn't matter because we won't match drive ffh |
---|
| 56 | |
---|
| 57 | cwd ; clears DX (there are flop drives) or ffffh (there are not) |
---|
| 58 | |
---|
| 59 | adc dl, al ; second drive (CF set) if present |
---|
[294] | 60 | ; If no drive is present, this will result in ffh which |
---|
[259] | 61 | ; won't match a drive |
---|
| 62 | call BackupErrorCodeFromTheRequestedDriveToBH |
---|
| 63 | mov dl, al ; We may end up doing the first drive twice (if there is |
---|
| 64 | call BackupErrorCodeFromTheRequestedDriveToBH ; only one drive), but doing it again is not harmful. |
---|
| 65 | %endif |
---|
| 66 | test bl, bl ; If we were called with a floppy disk, then we are done, |
---|
| 67 | jns SHORT .SkipHardDiskReset ; don't do hard disks. |
---|
[264] | 68 | |
---|
[294] | 69 | ; Resetting our hard disks will modify dl and bl to be idevars offset based instead of drive number based, |
---|
[275] | 70 | ; such that this call must be the last in the list of reset routines called. |
---|
| 71 | ; |
---|
[501] | 72 | ; This needs to happen after ResetForeignDrives, as that call may have set the error code for 80h, |
---|
[282] | 73 | ; and we need to override that value if we are xlate'd into 80h with one of our drives. |
---|
| 74 | ; |
---|
[294] | 75 | call ResetHardDisksHandledByOurBIOS |
---|
[264] | 76 | |
---|
[26] | 77 | .SkipHardDiskReset: |
---|
[148] | 78 | mov ah, bh |
---|
| 79 | jmp Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH |
---|
[3] | 80 | |
---|
| 81 | |
---|
| 82 | ;-------------------------------------------------------------------- |
---|
[258] | 83 | ; BackupErrorCodeFromTheRequestedDriveToBH |
---|
| 84 | ; Parameters: |
---|
| 85 | ; AH: Error code from the last resetted drive |
---|
| 86 | ; DL: Drive last resetted |
---|
| 87 | ; BL: Requested drive (DL when entering AH=00h) |
---|
| 88 | ; Returns: |
---|
| 89 | ; BH: Backuped error code |
---|
| 90 | ; Corrupts registers: |
---|
| 91 | ; Nothing |
---|
| 92 | ;-------------------------------------------------------------------- |
---|
| 93 | BackupErrorCodeFromTheRequestedDriveToBH: |
---|
| 94 | cmp dl, bl ; Requested drive? |
---|
| 95 | eCMOVE bh, ah |
---|
| 96 | ret |
---|
| 97 | |
---|
[271] | 98 | |
---|
[27] | 99 | |
---|
[433] | 100 | ; This defines what is called when resetting our drives at the end of drive detection. |
---|
[275] | 101 | AH0h_ResetAllOurHardDisksAtTheEndOfDriveInitialization equ ResetHardDisksHandledByOurBIOS.ErrorCodeNotUsed |
---|
[27] | 102 | |
---|
| 103 | ;-------------------------------------------------------------------- |
---|
[271] | 104 | ; ResetHardDisksHandledByOurBIOS |
---|
| 105 | ; Parameters: |
---|
[501] | 106 | ; BL: Requested drive (DL when entering AH=00h) |
---|
[271] | 107 | ; DS:DI: Ptr to DPT for requested drive |
---|
[294] | 108 | ; If DPT pointer is not available, or error result in BH won't be used anyway, |
---|
[282] | 109 | ; enter through .ErrorCodeNotUsed. |
---|
[271] | 110 | ; SS:BP: Ptr to IDEPACK |
---|
| 111 | ; Returns: |
---|
[23] | 112 | ; BH: Error code from requested drive (if available) |
---|
| 113 | ; Corrupts registers: |
---|
[275] | 114 | ; AX, BX, CX, DX, SI, DI |
---|
[23] | 115 | ;-------------------------------------------------------------------- |
---|
[271] | 116 | ResetHardDisksHandledByOurBIOS: |
---|
[294] | 117 | xor bl, bl ; Assume Null IdevarsOffset for now, assuming foreign drive |
---|
[282] | 118 | test di, di |
---|
[433] | 119 | jz SHORT .ErrorCodeNotUsed |
---|
[264] | 120 | mov bl, [di+DPT.bIdevarsOffset] ; replace drive number with Idevars pointer for cmp with dl |
---|
[507] | 121 | .ErrorCodeNotUsed: |
---|
[294] | 122 | |
---|
[507] | 123 | mov si, ControllerResetForDPTinDSDI |
---|
[520] | 124 | call .CallSIforEveryController ; Reset all drives to power on settings |
---|
| 125 | mov si, ControllerInitForMasterOrSingleDPTinDSDI |
---|
| 126 | ; Fall to .CallSIforEveryController ; Initialize all controllers (Master and Slave drives) |
---|
[507] | 127 | |
---|
[520] | 128 | .CallSIforEveryController: ; BH will be garbage on exit if this entry point is used, |
---|
[275] | 129 | ; but reset of all drives will still happen |
---|
| 130 | |
---|
[264] | 131 | mov dl, ROMVARS.ideVars0 ; starting Idevars offset |
---|
| 132 | |
---|
[491] | 133 | ; Get count of ALL Idevars structures, not just the ones that are configured. This may seem odd, |
---|
[316] | 134 | ; but it catches the .ideVarsSerialAuto structure, which would not be scanned if the count from |
---|
| 135 | ; RamVars_GetIdeControllerCountToCX was used. Unused controllers won't make a difference, since no DPT |
---|
| 136 | ; will point to them. Performance isn't an issue, as this is a reset operation. |
---|
| 137 | ; |
---|
[507] | 138 | mov cx, NUMBER_OF_IDEVARS |
---|
[316] | 139 | |
---|
[262] | 140 | .loop: |
---|
[507] | 141 | push si |
---|
[271] | 142 | call FindDPT_ForIdevarsOffsetInDL ; look for the first drive on this controller, if any |
---|
[507] | 143 | pop si |
---|
[433] | 144 | jc SHORT .notFound |
---|
[264] | 145 | |
---|
[507] | 146 | push bx |
---|
| 147 | push cx |
---|
| 148 | push dx |
---|
| 149 | call si ; Reset Master AND Slave or initialize Master OR Slave drive |
---|
| 150 | pop dx |
---|
| 151 | pop cx |
---|
| 152 | pop bx |
---|
[264] | 153 | call BackupErrorCodeFromTheRequestedDriveToBH ; save error code if same controller as drive from entry |
---|
| 154 | |
---|
[262] | 155 | .notFound: |
---|
[264] | 156 | add dl, IDEVARS_size ; move Idevars pointer forward |
---|
| 157 | loop .loop |
---|
[507] | 158 | ret |
---|
[264] | 159 | |
---|
[507] | 160 | |
---|
| 161 | ;-------------------------------------------------------------------- |
---|
| 162 | ; ControllerResetForDPTinDSDI |
---|
| 163 | ; Parameters: |
---|
| 164 | ; DS:DI: Ptr to DPT for drive to reset (resets both Master and Slave drive) |
---|
| 165 | ; SS:BP: Ptr to IDEPACK |
---|
| 166 | ; Returns: |
---|
| 167 | ; AH: Int 13h return status |
---|
| 168 | ; Corrupts registers: |
---|
| 169 | ; AL, BX, CX, DX |
---|
| 170 | ;-------------------------------------------------------------------- |
---|
| 171 | ControllerResetForDPTinDSDI: |
---|
| 172 | %ifdef MODULE_IRQ |
---|
| 173 | call Interrupts_UnmaskInterruptControllerForDriveInDSDI |
---|
| 174 | %endif |
---|
| 175 | %ifdef MODULE_ADVANCED_ATA |
---|
| 176 | call Device_ResetMasterAndSlaveController |
---|
| 177 | jmp AdvAtaInit_InitializeControllerForDPTinDSDI |
---|
| 178 | %else |
---|
| 179 | jmp Device_ResetMasterAndSlaveController |
---|
| 180 | %endif |
---|
[520] | 181 | |
---|
| 182 | |
---|
| 183 | ;-------------------------------------------------------------------- |
---|
| 184 | ; ControllerInitForMasterOrSingleDPTinDSDI |
---|
| 185 | ; Parameters: |
---|
| 186 | ; DS:DI: Ptr to DPT for Master or Single Drive (initializes both Master and Slave drive) |
---|
| 187 | ; SS:BP: Ptr to IDEPACK |
---|
| 188 | ; Returns: |
---|
| 189 | ; AH: Int 13h return status |
---|
| 190 | ; Corrupts registers: |
---|
| 191 | ; AL, BX, CX, DX |
---|
| 192 | ;-------------------------------------------------------------------- |
---|
| 193 | ControllerInitForMasterOrSingleDPTinDSDI: |
---|
| 194 | call AH9h_InitializeDriveForUse ; Init Master or Single drive |
---|
| 195 | push ax ; Store error code |
---|
| 196 | |
---|
| 197 | eMOVZX ax, BYTE [di+DPT.bIdevarsOffset] ; Clear AH |
---|
| 198 | add di, BYTE LARGEST_DPT_SIZE ; Slave drive or next controller |
---|
| 199 | cmp [di+DPT.bIdevarsOffset], al |
---|
| 200 | jne SHORT .NoSlaveDrivePresent |
---|
| 201 | |
---|
| 202 | call AH9h_InitializeDriveForUse ; Init Slave drive |
---|
| 203 | .NoSlaveDrivePresent: |
---|
| 204 | pop bx |
---|
| 205 | MAX_U ah, bh ; Return error code from either drive |
---|
| 206 | ret |
---|