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