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