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