[128] | 1 | ; Project name : XTIDE Universal BIOS |
---|
[3] | 2 | ; Description : Int 13h function AH=0h, Disk Controller Reset. |
---|
| 3 | |
---|
| 4 | ; Section containing code |
---|
| 5 | SECTION .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. |
---|
[271] | 17 | ; DS:DI: Ptr to DPT (only if DL is our drive) |
---|
[150] | 18 | ; SS:BP: Ptr to IDEPACK |
---|
| 19 | ; Returns with INTPACK: |
---|
[23] | 20 | ; AH: Int 13h return status (from drive requested in DL) |
---|
[3] | 21 | ; CF: 0 if succesfull, 1 if error |
---|
| 22 | ;-------------------------------------------------------------------- |
---|
| 23 | ALIGN JUMP_ALIGN |
---|
| 24 | AH0h_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 | ; |
---|
| 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 | |
---|
[26] | 51 | call ResetForeignHardDisks |
---|
[264] | 52 | |
---|
| 53 | ; Resetting our hard disks will modify dl and bl such that this call must be the last in the list |
---|
[271] | 54 | call GetDriveNumberForForeignHardDiskHandlerToDL ; Load DPT for our drive |
---|
| 55 | jc SHORT .SkipHardDiskReset ; Our drive not requested so let's not reset them |
---|
| 56 | call ResetHardDisksHandledByOurBIOS |
---|
[264] | 57 | |
---|
[26] | 58 | .SkipHardDiskReset: |
---|
[148] | 59 | mov ah, bh |
---|
| 60 | jmp Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH |
---|
[3] | 61 | |
---|
| 62 | |
---|
| 63 | ;-------------------------------------------------------------------- |
---|
[26] | 64 | ; ResetFloppyDrivesWithInt40h |
---|
[3] | 65 | ; Parameters: |
---|
[23] | 66 | ; BL: Requested drive (DL when entering AH=00h) |
---|
| 67 | ; Returns: |
---|
| 68 | ; BH: Error code from requested drive (if available) |
---|
| 69 | ; Corrupts registers: |
---|
[27] | 70 | ; AX, DL, DI |
---|
[128] | 71 | ;-------------------------------------------------------------------- |
---|
[26] | 72 | ResetFloppyDrivesWithInt40h: |
---|
[271] | 73 | call GetDriveNumberForForeignHardDiskHandlerToDL |
---|
[27] | 74 | and dl, 7Fh ; Clear hard disk bit |
---|
[26] | 75 | xor ah, ah ; Disk Controller Reset |
---|
[148] | 76 | int BIOS_DISKETTE_INTERRUPT_40h |
---|
[26] | 77 | jmp SHORT BackupErrorCodeFromTheRequestedDriveToBH |
---|
[23] | 78 | |
---|
| 79 | |
---|
| 80 | ;-------------------------------------------------------------------- |
---|
[26] | 81 | ; ResetForeignHardDisks |
---|
[23] | 82 | ; Parameters: |
---|
| 83 | ; BL: Requested drive (DL when entering AH=00h) |
---|
[3] | 84 | ; DS: RAMVARS segment |
---|
| 85 | ; Returns: |
---|
[23] | 86 | ; BH: Error code from requested drive (if available) |
---|
[3] | 87 | ; Corrupts registers: |
---|
[27] | 88 | ; AX, DL, DI |
---|
[128] | 89 | ;-------------------------------------------------------------------- |
---|
[26] | 90 | ResetForeignHardDisks: |
---|
[271] | 91 | call GetDriveNumberForForeignHardDiskHandlerToDL |
---|
[27] | 92 | xor ah, ah ; Disk Controller Reset |
---|
[32] | 93 | call Int13h_CallPreviousInt13hHandler |
---|
[258] | 94 | ;;; fall-through to BackupErrorCodeFromTheRequestedDriveToBH |
---|
[23] | 95 | |
---|
[26] | 96 | |
---|
[3] | 97 | ;-------------------------------------------------------------------- |
---|
[258] | 98 | ; BackupErrorCodeFromTheRequestedDriveToBH |
---|
| 99 | ; Parameters: |
---|
| 100 | ; AH: Error code from the last resetted drive |
---|
| 101 | ; DL: Drive last resetted |
---|
| 102 | ; BL: Requested drive (DL when entering AH=00h) |
---|
| 103 | ; Returns: |
---|
| 104 | ; BH: Backuped error code |
---|
| 105 | ; Corrupts registers: |
---|
| 106 | ; Nothing |
---|
| 107 | ;-------------------------------------------------------------------- |
---|
| 108 | BackupErrorCodeFromTheRequestedDriveToBH: |
---|
| 109 | cmp dl, bl ; Requested drive? |
---|
| 110 | eCMOVE bh, ah |
---|
| 111 | ret |
---|
| 112 | |
---|
[271] | 113 | |
---|
[258] | 114 | ;-------------------------------------------------------------------- |
---|
[271] | 115 | ; GetDriveNumberForForeignHardDiskHandlerToDL |
---|
[27] | 116 | ; Parameters: |
---|
| 117 | ; BL: Requested drive (DL when entering AH=00h) |
---|
| 118 | ; DS: RAMVARS segment |
---|
| 119 | ; Returns: |
---|
[271] | 120 | ; DS:DI: Ptr to DPT if our drive |
---|
[27] | 121 | ; DL: BL if foreign drive |
---|
| 122 | ; 80h if our drive |
---|
[271] | 123 | ; CF: Set if foreign drive |
---|
| 124 | ; Cleared if our drive |
---|
[27] | 125 | ; Corrupts registers: |
---|
[271] | 126 | ; (DI) |
---|
[128] | 127 | ;-------------------------------------------------------------------- |
---|
[271] | 128 | GetDriveNumberForForeignHardDiskHandlerToDL: |
---|
[27] | 129 | mov dl, bl |
---|
[271] | 130 | call FindDPT_ForDriveNumberInDL |
---|
| 131 | jc SHORT .ReturnWithForeignDriveInDL |
---|
| 132 | mov dl, 80h ; First possible Hard Disk should be safe value |
---|
| 133 | .ReturnWithForeignDriveInDL: |
---|
[27] | 134 | ret |
---|
| 135 | |
---|
| 136 | |
---|
| 137 | ;-------------------------------------------------------------------- |
---|
[271] | 138 | ; AH0h_ResetAllOurHardDisksAtTheEndOfDriveInitialization |
---|
[23] | 139 | ; Parameters: |
---|
| 140 | ; DS: RAMVARS segment |
---|
[150] | 141 | ; SS:BP: Ptr to IDEPACK |
---|
[23] | 142 | ; Returns: |
---|
[271] | 143 | ; Nothing |
---|
| 144 | ; Corrupts registers: |
---|
| 145 | ; AX, BX, CX, DX, SI, DI |
---|
| 146 | ;-------------------------------------------------------------------- |
---|
| 147 | AH0h_ResetAllOurHardDisksAtTheEndOfDriveInitialization: |
---|
| 148 | mov bl, [RAMVARS.bFirstDrv] |
---|
| 149 | call GetDriveNumberForForeignHardDiskHandlerToDL |
---|
| 150 | ; Fall to ResetHardDisksHandledByOurBIOS |
---|
| 151 | |
---|
| 152 | ;-------------------------------------------------------------------- |
---|
| 153 | ; ResetHardDisksHandledByOurBIOS |
---|
| 154 | ; Parameters: |
---|
| 155 | ; BL: Requested drive (DL when entering AH=00h) |
---|
| 156 | ; DS:DI: Ptr to DPT for requested drive |
---|
| 157 | ; SS:BP: Ptr to IDEPACK |
---|
| 158 | ; Returns: |
---|
[23] | 159 | ; BH: Error code from requested drive (if available) |
---|
| 160 | ; Corrupts registers: |
---|
[150] | 161 | ; AX, CX, DX, SI, DI |
---|
[23] | 162 | ;-------------------------------------------------------------------- |
---|
[271] | 163 | ResetHardDisksHandledByOurBIOS: |
---|
[264] | 164 | mov bl, [di+DPT.bIdevarsOffset] ; replace drive number with Idevars pointer for cmp with dl |
---|
| 165 | mov dl, ROMVARS.ideVars0 ; starting Idevars offset |
---|
| 166 | |
---|
[271] | 167 | call RamVars_GetIdeControllerCountToCX ; get count of ide controllers |
---|
[264] | 168 | jcxz .done ; just in case bIdeCnt is zero (shouldn't be) |
---|
[262] | 169 | .loop: |
---|
[271] | 170 | call FindDPT_ForIdevarsOffsetInDL ; look for the first drive on this controller, if any |
---|
[262] | 171 | jc .notFound |
---|
[264] | 172 | |
---|
[262] | 173 | call AHDh_ResetDrive ; reset master and slave on that controller |
---|
[264] | 174 | call BackupErrorCodeFromTheRequestedDriveToBH ; save error code if same controller as drive from entry |
---|
| 175 | |
---|
[262] | 176 | .notFound: |
---|
[264] | 177 | add dl, IDEVARS_size ; move Idevars pointer forward |
---|
| 178 | loop .loop |
---|
| 179 | |
---|
| 180 | .done: |
---|
[259] | 181 | ret |
---|