[3] | 1 | ; File name : AH0h_HReset.asm |
---|
| 2 | ; Project name : IDE BIOS |
---|
| 3 | ; Created date : 27.9.2007 |
---|
[28] | 4 | ; Last update : 29.7.2010 |
---|
[3] | 5 | ; Author : Tomi Tilli |
---|
| 6 | ; Description : Int 13h function AH=0h, Disk Controller Reset. |
---|
| 7 | |
---|
| 8 | RETRIES_IF_RESET_FAILS EQU 3 |
---|
| 9 | TIMEOUT_BEFORE_RESET_RETRY EQU 5 ; System timer ticks |
---|
| 10 | |
---|
| 11 | ; Section containing code |
---|
| 12 | SECTION .text |
---|
| 13 | |
---|
| 14 | ;-------------------------------------------------------------------- |
---|
| 15 | ; Int 13h function AH=0h, Disk Controller Reset. |
---|
| 16 | ; |
---|
| 17 | ; AH0h_HandlerForDiskControllerReset |
---|
| 18 | ; Parameters: |
---|
| 19 | ; AH: Bios function 0h |
---|
| 20 | ; DL: Drive number (ignored so all drives are reset) |
---|
| 21 | ; If bit 7 is set all hard disks and floppy disks reset. |
---|
| 22 | ; Parameters loaded by Int13h_Jump: |
---|
| 23 | ; DS: RAMVARS segment |
---|
| 24 | ; Returns: |
---|
[23] | 25 | ; AH: Int 13h return status (from drive requested in DL) |
---|
[3] | 26 | ; CF: 0 if succesfull, 1 if error |
---|
| 27 | ; IF: 1 |
---|
| 28 | ; Corrupts registers: |
---|
| 29 | ; Flags |
---|
| 30 | ;-------------------------------------------------------------------- |
---|
| 31 | ALIGN JUMP_ALIGN |
---|
| 32 | AH0h_HandlerForDiskControllerReset: |
---|
| 33 | push dx |
---|
| 34 | push cx |
---|
| 35 | push bx |
---|
| 36 | push ax |
---|
| 37 | |
---|
[23] | 38 | eMOVZX bx, dl ; Copy requested drive to BL, zero BH to assume no errors |
---|
[26] | 39 | call ResetFloppyDrivesWithInt40h |
---|
| 40 | test bl, 80h |
---|
| 41 | jz SHORT .SkipHardDiskReset |
---|
| 42 | call ResetForeignHardDisks |
---|
[27] | 43 | call AH0h_ResetHardDisksHandledByOurBIOS |
---|
[23] | 44 | ALIGN JUMP_ALIGN |
---|
[26] | 45 | .SkipHardDiskReset: |
---|
[23] | 46 | mov ah, bh ; Copy error code to AH |
---|
| 47 | xor al, al ; Zero AL... |
---|
[27] | 48 | cmp al, bh ; ...and set CF if error |
---|
[28] | 49 | jmp Int13h_StoreErrorCodeToBDAandPopXRegsAndReturn |
---|
[3] | 50 | |
---|
| 51 | |
---|
| 52 | ;-------------------------------------------------------------------- |
---|
[26] | 53 | ; ResetFloppyDrivesWithInt40h |
---|
[3] | 54 | ; Parameters: |
---|
[23] | 55 | ; BL: Requested drive (DL when entering AH=00h) |
---|
| 56 | ; Returns: |
---|
| 57 | ; BH: Error code from requested drive (if available) |
---|
| 58 | ; Corrupts registers: |
---|
[27] | 59 | ; AX, DL, DI |
---|
[23] | 60 | ;-------------------------------------------------------------------- |
---|
| 61 | ALIGN JUMP_ALIGN |
---|
[26] | 62 | ResetFloppyDrivesWithInt40h: |
---|
[27] | 63 | call GetDriveNumberForForeignBiosesToDL |
---|
| 64 | and dl, 7Fh ; Clear hard disk bit |
---|
[26] | 65 | xor ah, ah ; Disk Controller Reset |
---|
[23] | 66 | int INTV_FLOPPY_FUNC |
---|
[26] | 67 | jmp SHORT BackupErrorCodeFromTheRequestedDriveToBH |
---|
[23] | 68 | |
---|
| 69 | |
---|
| 70 | ;-------------------------------------------------------------------- |
---|
[26] | 71 | ; ResetForeignHardDisks |
---|
[23] | 72 | ; Parameters: |
---|
| 73 | ; BL: Requested drive (DL when entering AH=00h) |
---|
[3] | 74 | ; DS: RAMVARS segment |
---|
| 75 | ; Returns: |
---|
[23] | 76 | ; BH: Error code from requested drive (if available) |
---|
[3] | 77 | ; Corrupts registers: |
---|
[27] | 78 | ; AX, DL, DI |
---|
[23] | 79 | ;-------------------------------------------------------------------- |
---|
| 80 | ALIGN JUMP_ALIGN |
---|
[26] | 81 | ResetForeignHardDisks: |
---|
[27] | 82 | call GetDriveNumberForForeignBiosesToDL |
---|
| 83 | xor ah, ah ; Disk Controller Reset |
---|
[23] | 84 | pushf ; Push flags to simulate INT |
---|
| 85 | cli ; Disable interrupts since INT does that |
---|
| 86 | call FAR [RAMVARS.fpOldI13h] |
---|
| 87 | sti ; Make sure interrupts are enabled again (some BIOSes fails to enable it) |
---|
[26] | 88 | jmp SHORT BackupErrorCodeFromTheRequestedDriveToBH |
---|
[23] | 89 | |
---|
[26] | 90 | |
---|
[3] | 91 | ;-------------------------------------------------------------------- |
---|
[27] | 92 | ; GetDriveNumberForForeignBiosesToDL |
---|
| 93 | ; Parameters: |
---|
| 94 | ; BL: Requested drive (DL when entering AH=00h) |
---|
| 95 | ; DS: RAMVARS segment |
---|
| 96 | ; Returns: |
---|
| 97 | ; DL: BL if foreign drive |
---|
| 98 | ; 80h if our drive |
---|
| 99 | ; Corrupts registers: |
---|
| 100 | ; DI |
---|
| 101 | ;-------------------------------------------------------------------- |
---|
| 102 | ALIGN JUMP_ALIGN |
---|
| 103 | GetDriveNumberForForeignBiosesToDL: |
---|
| 104 | mov dl, bl |
---|
| 105 | call RamVars_IsDriveHandledByThisBIOS |
---|
| 106 | jc SHORT .GetFirstDriveForForeignBios |
---|
| 107 | ret ; Return what was in BL unmodified |
---|
| 108 | ALIGN JUMP_ALIGN |
---|
| 109 | .GetFirstDriveForForeignBios: |
---|
| 110 | mov dl, 80h |
---|
| 111 | ret |
---|
| 112 | |
---|
| 113 | |
---|
| 114 | ;-------------------------------------------------------------------- |
---|
[26] | 115 | ; ResetHardDisksHandledByOurBIOS |
---|
[23] | 116 | ; Parameters: |
---|
| 117 | ; BL: Requested drive (DL when entering AH=00h) |
---|
| 118 | ; DS: RAMVARS segment |
---|
| 119 | ; Returns: |
---|
| 120 | ; BH: Error code from requested drive (if available) |
---|
| 121 | ; Corrupts registers: |
---|
[27] | 122 | ; AX, CX, DX, DI |
---|
[23] | 123 | ;-------------------------------------------------------------------- |
---|
[3] | 124 | ALIGN JUMP_ALIGN |
---|
[27] | 125 | AH0h_ResetHardDisksHandledByOurBIOS: |
---|
[26] | 126 | mov dh, [RAMVARS.bDrvCnt] ; Load drive count to DH |
---|
| 127 | test dh, dh |
---|
| 128 | jz SHORT .AllDrivesReset ; Return if no drives |
---|
| 129 | mov dl, [RAMVARS.bFirstDrv] ; Load number of first our drive |
---|
| 130 | add dh, dl ; DH = one past last drive to reset |
---|
[3] | 131 | ALIGN JUMP_ALIGN |
---|
[26] | 132 | .DriveResetLoop: |
---|
| 133 | call AHDh_ResetDrive |
---|
[27] | 134 | call .BackupErrorCodeFromMasterOrSlaveToBH |
---|
[26] | 135 | inc dx |
---|
| 136 | cmp dl, dh ; All done? |
---|
| 137 | jb SHORT .DriveResetLoop ; If not, reset next drive |
---|
| 138 | .AllDrivesReset: |
---|
[3] | 139 | ret |
---|
| 140 | |
---|
| 141 | ;-------------------------------------------------------------------- |
---|
[27] | 142 | ; .BackupErrorCodeFromMasterOrSlaveToBH |
---|
[3] | 143 | ; Parameters: |
---|
[27] | 144 | ; AH: Error code for drive DL reset |
---|
| 145 | ; BL: Requested drive (DL when entering AH=00h) |
---|
[26] | 146 | ; DL: Drive just resetted |
---|
[3] | 147 | ; DS: RAMVARS segment |
---|
| 148 | ; Returns: |
---|
[27] | 149 | ; BH: Backuped error code |
---|
[26] | 150 | ; DL: Incremented if next drive is slave drive |
---|
| 151 | ; (=already resetted) |
---|
[3] | 152 | ; Corrupts registers: |
---|
[27] | 153 | ; CX, DI |
---|
[3] | 154 | ;-------------------------------------------------------------------- |
---|
| 155 | ALIGN JUMP_ALIGN |
---|
[27] | 156 | .BackupErrorCodeFromMasterOrSlaveToBH: |
---|
| 157 | call BackupErrorCodeFromTheRequestedDriveToBH |
---|
| 158 | mov cx, [RAMVARS.wIdeBase] ; Load base port for resetted drive |
---|
[26] | 159 | |
---|
[27] | 160 | inc dx ; DL to next drive |
---|
| 161 | call FindDPT_ForDriveNumber ; Get DPT to DS:DI, store port to RAMVARS |
---|
| 162 | jnc SHORT .NoMoreDrivesOrNoSlaveDrive |
---|
| 163 | cmp cx, [RAMVARS.wIdeBase] ; Next drive is from same controller? |
---|
| 164 | je SHORT BackupErrorCodeFromTheRequestedDriveToBH |
---|
| 165 | .NoMoreDrivesOrNoSlaveDrive: |
---|
| 166 | dec dx |
---|
[3] | 167 | ret |
---|
| 168 | |
---|
| 169 | |
---|
| 170 | ;-------------------------------------------------------------------- |
---|
[26] | 171 | ; BackupErrorCodeFromTheRequestedDriveToBH |
---|
[3] | 172 | ; Parameters: |
---|
[23] | 173 | ; AH: Error code from the last resetted drive |
---|
| 174 | ; DL: Drive last resetted |
---|
| 175 | ; BL: Requested drive (DL when entering AH=00h) |
---|
[3] | 176 | ; Returns: |
---|
[23] | 177 | ; BH: Backuped error code |
---|
[3] | 178 | ; Corrupts registers: |
---|
| 179 | ; Nothing |
---|
| 180 | ;-------------------------------------------------------------------- |
---|
| 181 | ALIGN JUMP_ALIGN |
---|
[26] | 182 | BackupErrorCodeFromTheRequestedDriveToBH: |
---|
| 183 | cmp dl, bl ; Requested drive? |
---|
[23] | 184 | jne SHORT .Return |
---|
| 185 | mov bh, ah |
---|
| 186 | ALIGN JUMP_ALIGN |
---|
| 187 | .Return: |
---|
[3] | 188 | ret |
---|