[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 | ; |
---|
| 10 | ; AH0h_HandlerForDiskControllerReset |
---|
| 11 | ; Parameters: |
---|
[148] | 12 | ; DL: Translated Drive number (ignored so all drives are reset) |
---|
[3] | 13 | ; If bit 7 is set all hard disks and floppy disks reset. |
---|
[148] | 14 | ; DS:DI: Ptr to DPT (in RAMVARS segment) |
---|
[150] | 15 | ; SS:BP: Ptr to IDEPACK |
---|
| 16 | ; Returns with INTPACK: |
---|
[23] | 17 | ; AH: Int 13h return status (from drive requested in DL) |
---|
[3] | 18 | ; CF: 0 if succesfull, 1 if error |
---|
| 19 | ;-------------------------------------------------------------------- |
---|
| 20 | ALIGN JUMP_ALIGN |
---|
| 21 | AH0h_HandlerForDiskControllerReset: |
---|
[23] | 22 | eMOVZX bx, dl ; Copy requested drive to BL, zero BH to assume no errors |
---|
[26] | 23 | call ResetFloppyDrivesWithInt40h |
---|
| 24 | call ResetForeignHardDisks |
---|
[27] | 25 | call AH0h_ResetHardDisksHandledByOurBIOS |
---|
[26] | 26 | .SkipHardDiskReset: |
---|
[148] | 27 | mov ah, bh |
---|
| 28 | jmp Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH |
---|
[3] | 29 | |
---|
| 30 | |
---|
| 31 | ;-------------------------------------------------------------------- |
---|
[26] | 32 | ; ResetFloppyDrivesWithInt40h |
---|
[3] | 33 | ; Parameters: |
---|
[23] | 34 | ; BL: Requested drive (DL when entering AH=00h) |
---|
| 35 | ; Returns: |
---|
| 36 | ; BH: Error code from requested drive (if available) |
---|
| 37 | ; Corrupts registers: |
---|
[27] | 38 | ; AX, DL, DI |
---|
[128] | 39 | ;-------------------------------------------------------------------- |
---|
[23] | 40 | ALIGN JUMP_ALIGN |
---|
[26] | 41 | ResetFloppyDrivesWithInt40h: |
---|
[27] | 42 | call GetDriveNumberForForeignBiosesToDL |
---|
| 43 | and dl, 7Fh ; Clear hard disk bit |
---|
[26] | 44 | xor ah, ah ; Disk Controller Reset |
---|
[148] | 45 | int BIOS_DISKETTE_INTERRUPT_40h |
---|
[26] | 46 | jmp SHORT BackupErrorCodeFromTheRequestedDriveToBH |
---|
[23] | 47 | |
---|
| 48 | |
---|
| 49 | ;-------------------------------------------------------------------- |
---|
[26] | 50 | ; ResetForeignHardDisks |
---|
[23] | 51 | ; Parameters: |
---|
| 52 | ; BL: Requested drive (DL when entering AH=00h) |
---|
[3] | 53 | ; DS: RAMVARS segment |
---|
| 54 | ; Returns: |
---|
[23] | 55 | ; BH: Error code from requested drive (if available) |
---|
[3] | 56 | ; Corrupts registers: |
---|
[27] | 57 | ; AX, DL, DI |
---|
[128] | 58 | ;-------------------------------------------------------------------- |
---|
[23] | 59 | ALIGN JUMP_ALIGN |
---|
[26] | 60 | ResetForeignHardDisks: |
---|
[27] | 61 | call GetDriveNumberForForeignBiosesToDL |
---|
| 62 | xor ah, ah ; Disk Controller Reset |
---|
[32] | 63 | call Int13h_CallPreviousInt13hHandler |
---|
[258] | 64 | ;;; fall-through to BackupErrorCodeFromTheRequestedDriveToBH |
---|
[23] | 65 | |
---|
[26] | 66 | |
---|
[3] | 67 | ;-------------------------------------------------------------------- |
---|
[258] | 68 | ; BackupErrorCodeFromTheRequestedDriveToBH |
---|
| 69 | ; Parameters: |
---|
| 70 | ; AH: Error code from the last resetted drive |
---|
| 71 | ; DL: Drive last resetted |
---|
| 72 | ; BL: Requested drive (DL when entering AH=00h) |
---|
| 73 | ; Returns: |
---|
| 74 | ; BH: Backuped error code |
---|
| 75 | ; Corrupts registers: |
---|
| 76 | ; Nothing |
---|
| 77 | ;-------------------------------------------------------------------- |
---|
| 78 | ALIGN JUMP_ALIGN |
---|
| 79 | BackupErrorCodeFromTheRequestedDriveToBH: |
---|
| 80 | cmp dl, bl ; Requested drive? |
---|
| 81 | eCMOVE bh, ah |
---|
| 82 | ret |
---|
| 83 | |
---|
| 84 | |
---|
| 85 | ;-------------------------------------------------------------------- |
---|
[27] | 86 | ; GetDriveNumberForForeignBiosesToDL |
---|
| 87 | ; Parameters: |
---|
| 88 | ; BL: Requested drive (DL when entering AH=00h) |
---|
| 89 | ; DS: RAMVARS segment |
---|
| 90 | ; Returns: |
---|
| 91 | ; DL: BL if foreign drive |
---|
| 92 | ; 80h if our drive |
---|
| 93 | ; Corrupts registers: |
---|
| 94 | ; DI |
---|
[128] | 95 | ;-------------------------------------------------------------------- |
---|
[27] | 96 | ALIGN JUMP_ALIGN |
---|
| 97 | GetDriveNumberForForeignBiosesToDL: |
---|
| 98 | mov dl, bl |
---|
| 99 | call RamVars_IsDriveHandledByThisBIOS |
---|
[258] | 100 | jc SHORT .Return ; Return what was in BL unmodified |
---|
[84] | 101 | mov dl, 80h |
---|
| 102 | .Return: |
---|
[27] | 103 | ret |
---|
| 104 | |
---|
| 105 | |
---|
| 106 | ;-------------------------------------------------------------------- |
---|
[150] | 107 | ; AH0h_ResetHardDisksHandledByOurBIOS |
---|
[23] | 108 | ; Parameters: |
---|
| 109 | ; BL: Requested drive (DL when entering AH=00h) |
---|
| 110 | ; DS: RAMVARS segment |
---|
[150] | 111 | ; SS:BP: Ptr to IDEPACK |
---|
[23] | 112 | ; Returns: |
---|
| 113 | ; BH: Error code from requested drive (if available) |
---|
| 114 | ; Corrupts registers: |
---|
[150] | 115 | ; AX, CX, DX, SI, DI |
---|
[23] | 116 | ;-------------------------------------------------------------------- |
---|
[3] | 117 | ALIGN JUMP_ALIGN |
---|
[27] | 118 | AH0h_ResetHardDisksHandledByOurBIOS: |
---|
[258] | 119 | mov dx, [RAMVARS.wDrvCntAndFirst] ; DL = drive number, DH = drive count |
---|
[26] | 120 | test dh, dh |
---|
| 121 | jz SHORT .AllDrivesReset ; Return if no drives |
---|
| 122 | add dh, dl ; DH = one past last drive to reset |
---|
[3] | 123 | ALIGN JUMP_ALIGN |
---|
[26] | 124 | .DriveResetLoop: |
---|
| 125 | call AHDh_ResetDrive |
---|
[27] | 126 | call .BackupErrorCodeFromMasterOrSlaveToBH |
---|
[26] | 127 | inc dx |
---|
| 128 | cmp dl, dh ; All done? |
---|
| 129 | jb SHORT .DriveResetLoop ; If not, reset next drive |
---|
| 130 | .AllDrivesReset: |
---|
[258] | 131 | %ifdef MODULE_SERIAL_FLOPPY |
---|
| 132 | ; |
---|
| 133 | ; "Reset" emulatd serial floppy drives, if any. There is nothing to actually do for this reset, |
---|
| 134 | ; but record the proper error return code if one of these floppy drives is the drive requested. |
---|
| 135 | ; |
---|
| 136 | call RamVars_UnpackFlopCntAndFirstToAL |
---|
| 137 | |
---|
| 138 | cbw ; Clears AH (there are flop drives) or ffh (there are not) |
---|
| 139 | ; Either AH has success code (flop drives are present) |
---|
| 140 | ; or it doesn't matter because we won't match drive ffh |
---|
| 141 | |
---|
| 142 | cwd ; clears DX (there are flop drives) or ffffh (there are not) |
---|
| 143 | |
---|
| 144 | adc dl, al ; second drive (CF set) if present |
---|
| 145 | ; If no drive is present, this will result in ffh which |
---|
| 146 | ; won't match a drive |
---|
| 147 | call BackupErrorCodeFromTheRequestedDriveToBH |
---|
| 148 | mov dl, al ; We may end up doing the first drive twice (if there is |
---|
| 149 | jmp BackupErrorCodeFromTheRequestedDriveToBH ; only one drive), but doing it again is not harmful. |
---|
| 150 | %else |
---|
[3] | 151 | ret |
---|
[258] | 152 | %endif |
---|
| 153 | |
---|
[3] | 154 | ;-------------------------------------------------------------------- |
---|
[27] | 155 | ; .BackupErrorCodeFromMasterOrSlaveToBH |
---|
[3] | 156 | ; Parameters: |
---|
[27] | 157 | ; AH: Error code for drive DL reset |
---|
| 158 | ; BL: Requested drive (DL when entering AH=00h) |
---|
[26] | 159 | ; DL: Drive just resetted |
---|
[3] | 160 | ; DS: RAMVARS segment |
---|
| 161 | ; Returns: |
---|
[27] | 162 | ; BH: Backuped error code |
---|
[26] | 163 | ; DL: Incremented if next drive is slave drive |
---|
| 164 | ; (=already resetted) |
---|
[3] | 165 | ; Corrupts registers: |
---|
[27] | 166 | ; CX, DI |
---|
[3] | 167 | ;-------------------------------------------------------------------- |
---|
| 168 | ALIGN JUMP_ALIGN |
---|
[27] | 169 | .BackupErrorCodeFromMasterOrSlaveToBH: |
---|
| 170 | call BackupErrorCodeFromTheRequestedDriveToBH |
---|
[150] | 171 | call GetBasePortToCX ; Load base port for resetted drive |
---|
| 172 | push cx |
---|
[27] | 173 | inc dx ; DL to next drive |
---|
[150] | 174 | call GetBasePortToCX |
---|
| 175 | pop di |
---|
| 176 | cmp cx, di ; Next drive is from same controller? |
---|
[27] | 177 | je SHORT BackupErrorCodeFromTheRequestedDriveToBH |
---|
| 178 | .NoMoreDrivesOrNoSlaveDrive: |
---|
| 179 | dec dx |
---|
[3] | 180 | ret |
---|
| 181 | |
---|
[258] | 182 | |
---|
[150] | 183 | ;-------------------------------------------------------------------- |
---|
| 184 | ; GetBasePortToCX |
---|
| 185 | ; Parameters: |
---|
| 186 | ; DL: Drive number |
---|
| 187 | ; DS: RAMVARS segment |
---|
| 188 | ; Returns: |
---|
| 189 | ; CX: Base port address |
---|
| 190 | ; CF: Set if valid drive number |
---|
| 191 | ; Cleared if invalid drive number |
---|
| 192 | ; Corrupts registers: |
---|
| 193 | ; DI |
---|
| 194 | ;-------------------------------------------------------------------- |
---|
| 195 | ALIGN JUMP_ALIGN |
---|
| 196 | GetBasePortToCX: |
---|
| 197 | xchg cx, bx |
---|
| 198 | xor bx, bx |
---|
| 199 | call FindDPT_ForDriveNumber |
---|
| 200 | mov bl, [di+DPT.bIdevarsOffset] |
---|
| 201 | mov bx, [cs:bx+IDEVARS.wPort] |
---|
| 202 | xchg bx, cx |
---|
| 203 | ret |
---|
[3] | 204 | |
---|
[150] | 205 | |
---|