[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: |
---|
[148] | 12 | ; DL: Translated Drive number |
---|
| 13 | ; DS:DI: Ptr to DPT (in RAMVARS segment) |
---|
[150] | 14 | ; SS:BP: Ptr to IDEPACK |
---|
| 15 | ; Returns with INTPACK: |
---|
[3] | 16 | ; AH: Int 13h return status |
---|
[294] | 17 | ; CF: 0 if successful, 1 if error |
---|
[3] | 18 | ;-------------------------------------------------------------------- |
---|
| 19 | AHDh_HandlerForResetHardDisk: |
---|
[84] | 20 | %ifndef USE_186 |
---|
[3] | 21 | call AHDh_ResetDrive |
---|
[148] | 22 | jmp Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH |
---|
[84] | 23 | %else |
---|
[148] | 24 | push Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH |
---|
[162] | 25 | ; Fall to AHDh_ResetDrive |
---|
[84] | 26 | %endif |
---|
[3] | 27 | |
---|
| 28 | |
---|
| 29 | ;-------------------------------------------------------------------- |
---|
| 30 | ; Resets hard disk. |
---|
| 31 | ; |
---|
| 32 | ; AHDh_ResetDrive |
---|
| 33 | ; Parameters: |
---|
[271] | 34 | ; DS:DI: Ptr to DPT |
---|
[150] | 35 | ; SS:BP: Ptr to IDEPACK |
---|
[3] | 36 | ; Returns: |
---|
| 37 | ; AH: Int 13h return status |
---|
[294] | 38 | ; CF: 0 if successful, 1 if error |
---|
[3] | 39 | ; Corrupts registers: |
---|
[271] | 40 | ; AL, SI |
---|
[3] | 41 | ;-------------------------------------------------------------------- |
---|
| 42 | AHDh_ResetDrive: |
---|
[26] | 43 | push dx |
---|
[271] | 44 | push cx |
---|
[26] | 45 | push bx |
---|
[262] | 46 | push di |
---|
[26] | 47 | |
---|
[33] | 48 | call Interrupts_UnmaskInterruptControllerForDriveInDSDI |
---|
[150] | 49 | call Device_ResetMasterAndSlaveController |
---|
[262] | 50 | ;jc SHORT .ReturnError ; CF would be set if slave drive present without master |
---|
| 51 | ; (error register has special values after reset) |
---|
[3] | 52 | |
---|
| 53 | ; Initialize Master and Slave drives |
---|
[370] | 54 | eMOVZX ax, [di+DPT.bIdevarsOffset] ; (AL) pointer to controller we are looking to reset |
---|
[294] | 55 | ; (AH) initialize error code, assume success |
---|
| 56 | |
---|
[363] | 57 | mov si, IterateAndResetDrives ; Callback function for FindDPT_IterateAllDPTs |
---|
[271] | 58 | call FindDPT_IterateAllDPTs |
---|
[26] | 59 | |
---|
[262] | 60 | shr ah, 1 ; Move error code and CF into proper position |
---|
| 61 | |
---|
| 62 | pop di |
---|
[26] | 63 | pop bx |
---|
[271] | 64 | pop cx |
---|
[26] | 65 | pop dx |
---|
[3] | 66 | ret |
---|
| 67 | |
---|
| 68 | ;-------------------------------------------------------------------- |
---|
[262] | 69 | ; IterateAndResetDrives: Iteration routine for use with IterateAllDPTs. |
---|
| 70 | ; |
---|
[294] | 71 | ; When a drive on the controller is found, it is reset, and the error code |
---|
[262] | 72 | ; merged into overall error code for this controller. Master will be reset |
---|
| 73 | ; first. Note that the iteration will go until the end of the DPT list. |
---|
[363] | 74 | ; |
---|
| 75 | ; Parameters: |
---|
| 76 | ; AL: Offset to IDEVARS for drives to initialize |
---|
| 77 | ; AH: Error status from previous initialization |
---|
| 78 | ; DS:DI: Ptr to DPT to examine |
---|
| 79 | ; Returns: |
---|
| 80 | ; AH: Error status from initialization |
---|
| 81 | ; CF: Set to iterate all DPTs |
---|
| 82 | ; Corrupts registers: |
---|
| 83 | ; AL, BX, DX |
---|
[3] | 84 | ;-------------------------------------------------------------------- |
---|
[262] | 85 | IterateAndResetDrives: |
---|
| 86 | cmp al, [di+DPT.bIdevarsOffset] ; The right controller? |
---|
[370] | 87 | jne .Done |
---|
| 88 | push cx |
---|
[262] | 89 | push ax |
---|
| 90 | call AH9h_InitializeDriveForUse ; Reset Master and Slave (Master will come first in DPT list) |
---|
[363] | 91 | |
---|
| 92 | %ifdef MODULE_ADVANCED_ATA |
---|
| 93 | jc SHORT .SkipControllerInitSinceError |
---|
[370] | 94 | ; Here we initialize the more advanced controllers (VLB and PCI) to get better performance for systems with 32-bit bus. |
---|
| 95 | ; This step is optional since the controllers use slowest possible settings by default if they are not initialized. |
---|
| 96 | |
---|
| 97 | pop ax |
---|
| 98 | push ax |
---|
| 99 | cmp al, [di+LARGEST_DPT_SIZE+DPT.bIdevarsOffset] ; We check if next DPT is for the same IDE controller. |
---|
| 100 | je SHORT .SkipInitializationUntilNextDrive ; If it is, we skip the initialization. |
---|
| 101 | call AdvAtaInit_InitializeControllerForDPTinDSDI ; Done after drive init so drives are first set to advanced PIO mode, then the controller |
---|
| 102 | .SkipInitializationUntilNextDrive: |
---|
[363] | 103 | .SkipControllerInitSinceError: |
---|
[370] | 104 | %endif ; MODULE_ADVANCED_ATA |
---|
[363] | 105 | |
---|
[370] | 106 | pop ax |
---|
[363] | 107 | pop cx |
---|
[370] | 108 | jnc .Done |
---|
[262] | 109 | or ah, (RET_HD_RESETFAIL << 1) | 1 ; OR in Reset Failed error code and CF, will SHR into position later |
---|
[370] | 110 | .Done: |
---|
[271] | 111 | stc ; From IterateAllDPTs perspective, the DPT is never found (continue iteration) |
---|
[3] | 112 | ret |
---|
[363] | 113 | |
---|