[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 |
---|
[262] | 123 | test di, di |
---|
| 124 | jz 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: |
---|
[262] | 143 | mov bl, [di+DPT.bIdevarsOffset] ; replace drive number with Idevars pointer for comparisons |
---|
| 144 | mov cl, [cs:ROMVARS.bIdeCnt] ; get count of ide controllers |
---|
| 145 | mov ch, 0 |
---|
| 146 | mov dl, 0 ; starting Idevars offset |
---|
| 147 | mov si, IterateFindFirstDPTforIdevars ; iteration routine |
---|
| 148 | .loop: |
---|
| 149 | call IterateAllDPTs ; look for the first drive on this controller, if any |
---|
| 150 | jc .notFound |
---|
| 151 | call AHDh_ResetDrive ; reset master and slave on that controller |
---|
| 152 | call BackupErrorCodeFromTheRequestedDriveToBH ; save error code if same controller as initial request |
---|
| 153 | .notFound: |
---|
| 154 | add dl, IDEVARS_size ; move pointer forward |
---|
| 155 | loop .loop ; and repeat |
---|
[259] | 156 | ret |
---|
[258] | 157 | |
---|
[3] | 158 | ;-------------------------------------------------------------------- |
---|
[262] | 159 | ; Iteration routine for AH0h_ResetHardDisksHandledByOurBIOS, |
---|
| 160 | ; for use with IterateAllDPTs |
---|
| 161 | ; |
---|
| 162 | ; Returns when DPT is found on the controller with Idevars offset in DL |
---|
[3] | 163 | ;-------------------------------------------------------------------- |
---|
[262] | 164 | IterateFindFirstDPTforIdevars: |
---|
| 165 | cmp dl, [di+DPT.bIdevarsOffset] ; Clears CF if matched |
---|
| 166 | jz .done |
---|
| 167 | stc ; Set CF for not found |
---|
| 168 | .done: |
---|
[3] | 169 | ret |
---|