[88] | 1 | ; Project name : XTIDE Universal BIOS |
---|
[3] | 2 | ; Description : Int 13h function AH=Dh, Reset Hard Disk (Alternate reset). |
---|
| 3 | |
---|
| 4 | ; Section containing code |
---|
| 5 | SECTION .text |
---|
| 6 | |
---|
| 7 | ;-------------------------------------------------------------------- |
---|
| 8 | ; Int 13h function AH=Dh, Reset Hard Disk (Alternate reset). |
---|
| 9 | ; |
---|
| 10 | ; AHDh_HandlerForResetHardDisk |
---|
| 11 | ; Parameters: |
---|
| 12 | ; AH: Bios function Dh |
---|
| 13 | ; DL: Drive number |
---|
| 14 | ; Returns: |
---|
| 15 | ; AH: Int 13h return status |
---|
| 16 | ; CF: 0 if succesfull, 1 if error |
---|
| 17 | ; IF: 1 |
---|
| 18 | ; Corrupts registers: |
---|
| 19 | ; Flags |
---|
| 20 | ;-------------------------------------------------------------------- |
---|
| 21 | ALIGN JUMP_ALIGN |
---|
| 22 | AHDh_HandlerForResetHardDisk: |
---|
[84] | 23 | %ifndef USE_186 |
---|
[3] | 24 | call AHDh_ResetDrive |
---|
[35] | 25 | jmp Int13h_PopDiDsAndReturn |
---|
[84] | 26 | %else |
---|
| 27 | push Int13h_PopDiDsAndReturn |
---|
| 28 | ; Fall through to AHDh_ResetDrive |
---|
| 29 | %endif |
---|
[3] | 30 | |
---|
| 31 | |
---|
| 32 | ;-------------------------------------------------------------------- |
---|
| 33 | ; Resets hard disk. |
---|
| 34 | ; |
---|
| 35 | ; AHDh_ResetDrive |
---|
| 36 | ; Parameters: |
---|
| 37 | ; DL: Drive number |
---|
| 38 | ; DS: RAMVARS segment |
---|
| 39 | ; Returns: |
---|
| 40 | ; AH: Int 13h return status |
---|
| 41 | ; CF: 0 if succesfull, 1 if error |
---|
| 42 | ; Corrupts registers: |
---|
[27] | 43 | ; DI |
---|
[3] | 44 | ;-------------------------------------------------------------------- |
---|
| 45 | ALIGN JUMP_ALIGN |
---|
| 46 | AHDh_ResetDrive: |
---|
[26] | 47 | push dx |
---|
| 48 | push cx |
---|
| 49 | push bx |
---|
| 50 | push ax |
---|
| 51 | |
---|
[3] | 52 | call FindDPT_ForDriveNumber ; DS:DI now points to DPT |
---|
[33] | 53 | call Interrupts_UnmaskInterruptControllerForDriveInDSDI |
---|
[3] | 54 | call AHDh_ResetMasterAndSlave |
---|
| 55 | ;jc SHORT .ReturnError ; CF would be set if slave drive present without master |
---|
| 56 | ; (error register has special values after reset) |
---|
| 57 | |
---|
| 58 | ; Initialize Master and Slave drives |
---|
| 59 | mov dx, [RAMVARS.wIdeBase] ; Load base port address |
---|
| 60 | call AHDh_InitializeMasterAndSlave |
---|
[26] | 61 | |
---|
| 62 | pop bx ; Pop old AX |
---|
| 63 | mov al, bl ; Restore AL |
---|
| 64 | pop bx |
---|
| 65 | pop cx |
---|
| 66 | pop dx |
---|
[3] | 67 | ret |
---|
| 68 | |
---|
| 69 | |
---|
| 70 | ;-------------------------------------------------------------------- |
---|
| 71 | ; Resets Master and Slave drives at wanted port. |
---|
| 72 | ; Both IDE drives will be reset. It is not possible to reset |
---|
| 73 | ; Master or Slave only. |
---|
| 74 | ; |
---|
| 75 | ; AHDh_ResetMasterAndSlave |
---|
| 76 | ; Parameters: |
---|
| 77 | ; DS:DI: Ptr to DPT for Master or Slave drive |
---|
| 78 | ; Returns: |
---|
| 79 | ; CF: 0 if reset succesfull |
---|
| 80 | ; 1 if any error |
---|
| 81 | ; Corrupts registers: |
---|
| 82 | ; AX, BX, CX, DX |
---|
| 83 | ;-------------------------------------------------------------------- |
---|
| 84 | ALIGN JUMP_ALIGN |
---|
| 85 | AHDh_ResetMasterAndSlave: |
---|
| 86 | ; Reset controller |
---|
| 87 | ; HSR0: Set_SRST |
---|
| 88 | mov al, [di+DPT.bDrvCtrl] ; Load value for ACR |
---|
| 89 | or al, FLG_IDE_CTRL_SRST ; Set Reset bit |
---|
| 90 | call HDrvSel_OutputDeviceControlByte |
---|
[88] | 91 | mov ax, 5 ; Delay at least 5us |
---|
[143] | 92 | call HTimer_MicrosecondsFromAX |
---|
[3] | 93 | |
---|
| 94 | ; HSR1: Clear_wait |
---|
[88] | 95 | mov al, [di+DPT.bDrvCtrl] ; Load value for ACR |
---|
[3] | 96 | out dx, al ; End Reset |
---|
[88] | 97 | mov ax, 2000 ; Delay at least 2ms |
---|
[143] | 98 | call HTimer_MicrosecondsFromAX |
---|
[3] | 99 | |
---|
| 100 | ; HSR2: Check_status |
---|
| 101 | mov cl, B_TIMEOUT_RESET ; Reset timeout delay |
---|
[116] | 102 | jmp HStatus_WaitBsy |
---|
[3] | 103 | |
---|
| 104 | |
---|
| 105 | ;-------------------------------------------------------------------- |
---|
| 106 | ; Initializes Master and Slave drive. |
---|
| 107 | ; |
---|
| 108 | ; AHDh_InitializeMasterAndSlave |
---|
| 109 | ; Parameters: |
---|
| 110 | ; DX: IDE Base Port address |
---|
| 111 | ; Returns: |
---|
[26] | 112 | ; AH: Error code |
---|
[3] | 113 | ; CF: 0 if initialization succesfull |
---|
| 114 | ; 1 if any error |
---|
| 115 | ; Corrupts registers: |
---|
[26] | 116 | ; AL, BX, CX, DX, DI |
---|
[3] | 117 | ;-------------------------------------------------------------------- |
---|
| 118 | ALIGN JUMP_ALIGN |
---|
| 119 | AHDh_InitializeMasterAndSlave: |
---|
| 120 | push dx ; Store base port address |
---|
| 121 | xor cx, cx ; Assume no errors |
---|
| 122 | call FindDPT_ForIdeMasterAtPort |
---|
| 123 | jnc SHORT .InitializeSlave ; Master drive not present |
---|
| 124 | call AH9h_InitializeDriveForUse |
---|
| 125 | mov cl, ah ; Copy error code to CL |
---|
| 126 | .InitializeSlave: |
---|
| 127 | pop dx ; Restore base port address |
---|
| 128 | call FindDPT_ForIdeSlaveAtPort |
---|
| 129 | jnc SHORT .CombineErrors ; Slave drive not present |
---|
| 130 | call AH9h_InitializeDriveForUse |
---|
| 131 | mov ch, ah ; Copy error code to CH |
---|
| 132 | .CombineErrors: |
---|
| 133 | or cl, ch ; OR error codes, clear CF |
---|
[116] | 134 | jz SHORT .Return |
---|
[26] | 135 | mov ah, RET_HD_RESETFAIL ; Load Reset Failed error code |
---|
[3] | 136 | stc |
---|
[116] | 137 | .Return: |
---|
[3] | 138 | ret |
---|