1 | ; Project name : XTIDE Universal BIOS
|
---|
2 | ; Description : Int 13h function AH=Dh, Reset Hard Disk (Alternate reset).
|
---|
3 |
|
---|
4 | ;
|
---|
5 | ; XTIDE Universal BIOS and Associated Tools
|
---|
6 | ; Copyright (C) 2009-2010 by Tomi Tilli, 2011-2012 by XTIDE Universal BIOS Team.
|
---|
7 | ;
|
---|
8 | ; This program is free software; you can redistribute it and/or modify
|
---|
9 | ; it under the terms of the GNU General Public License as published by
|
---|
10 | ; the Free Software Foundation; either version 2 of the License, or
|
---|
11 | ; (at your option) any later version.
|
---|
12 | ;
|
---|
13 | ; This program is distributed in the hope that it will be useful,
|
---|
14 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
15 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
16 | ; GNU General Public License for more details.
|
---|
17 | ; Visit http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
---|
18 | ;
|
---|
19 |
|
---|
20 | ; Section containing code
|
---|
21 | SECTION .text
|
---|
22 |
|
---|
23 | ;--------------------------------------------------------------------
|
---|
24 | ; Int 13h function AH=Dh, Reset Hard Disk (Alternate reset).
|
---|
25 | ;
|
---|
26 | ; AHDh_HandlerForResetHardDisk
|
---|
27 | ; Parameters:
|
---|
28 | ; DL: Translated Drive number
|
---|
29 | ; DS:DI: Ptr to DPT (in RAMVARS segment)
|
---|
30 | ; SS:BP: Ptr to IDEPACK
|
---|
31 | ; Returns with INTPACK:
|
---|
32 | ; AH: Int 13h return status
|
---|
33 | ; CF: 0 if successful, 1 if error
|
---|
34 | ;--------------------------------------------------------------------
|
---|
35 | AHDh_HandlerForResetHardDisk:
|
---|
36 | %ifndef USE_186
|
---|
37 | call AHDh_ResetDrive
|
---|
38 | jmp Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH
|
---|
39 | %else
|
---|
40 | push Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH
|
---|
41 | ; Fall to AHDh_ResetDrive
|
---|
42 | %endif
|
---|
43 |
|
---|
44 |
|
---|
45 | ;--------------------------------------------------------------------
|
---|
46 | ; Resets hard disk.
|
---|
47 | ;
|
---|
48 | ; AHDh_ResetDrive
|
---|
49 | ; Parameters:
|
---|
50 | ; DS:DI: Ptr to DPT
|
---|
51 | ; SS:BP: Ptr to IDEPACK
|
---|
52 | ; Returns:
|
---|
53 | ; AH: Int 13h return status
|
---|
54 | ; CF: 0 if successful, 1 if error
|
---|
55 | ; Corrupts registers:
|
---|
56 | ; AL, SI
|
---|
57 | ;--------------------------------------------------------------------
|
---|
58 | AHDh_ResetDrive:
|
---|
59 | push dx
|
---|
60 | push cx
|
---|
61 | push bx
|
---|
62 | push di
|
---|
63 |
|
---|
64 | %ifdef MODULE_IRQ
|
---|
65 | call Interrupts_UnmaskInterruptControllerForDriveInDSDI
|
---|
66 | %endif
|
---|
67 | call Device_ResetMasterAndSlaveController
|
---|
68 | ;jc SHORT .ReturnError ; CF would be set if slave drive present without master
|
---|
69 | ; (error register has special values after reset)
|
---|
70 |
|
---|
71 | ; Initialize Master and Slave drives
|
---|
72 | eMOVZX ax, [di+DPT.bIdevarsOffset] ; (AL) pointer to controller we are looking to reset
|
---|
73 | ; (AH) initialize error code, assume success
|
---|
74 |
|
---|
75 | mov si, IterateAndResetDrives ; Callback function for FindDPT_IterateAllDPTs
|
---|
76 | call FindDPT_IterateAllDPTs
|
---|
77 |
|
---|
78 | shr ah, 1 ; Move error code and CF into proper position
|
---|
79 |
|
---|
80 | pop di
|
---|
81 | pop bx
|
---|
82 | pop cx
|
---|
83 | pop dx
|
---|
84 | ret
|
---|
85 |
|
---|
86 | ;--------------------------------------------------------------------
|
---|
87 | ; IterateAndResetDrives: Iteration routine for use with IterateAllDPTs.
|
---|
88 | ;
|
---|
89 | ; When a drive on the controller is found, it is reset, and the error code
|
---|
90 | ; merged into overall error code for this controller. Master will be reset
|
---|
91 | ; first. Note that the iteration will go until the end of the DPT list.
|
---|
92 | ;
|
---|
93 | ; Parameters:
|
---|
94 | ; AL: Offset to IDEVARS for drives to initialize
|
---|
95 | ; AH: Error status from previous initialization
|
---|
96 | ; DS:DI: Ptr to DPT to examine
|
---|
97 | ; Returns:
|
---|
98 | ; AH: Error status from initialization
|
---|
99 | ; CF: Set to iterate all DPTs
|
---|
100 | ; Corrupts registers:
|
---|
101 | ; AL, BX, DX
|
---|
102 | ;--------------------------------------------------------------------
|
---|
103 | IterateAndResetDrives:
|
---|
104 | cmp al, [di+DPT.bIdevarsOffset] ; The right controller?
|
---|
105 | jne .Done
|
---|
106 | push cx
|
---|
107 | push ax
|
---|
108 | call AHDh_WaitUnilDriveMotorHasReachedFullSpeed
|
---|
109 | call AH9h_InitializeDriveForUse ; Initialize Master or Slave (Master will come first in DPT list)
|
---|
110 |
|
---|
111 | %ifdef MODULE_ADVANCED_ATA
|
---|
112 | jc SHORT .SkipControllerInitSinceError
|
---|
113 | ; Here we initialize the more advanced controllers (VLB and PCI) to get better performance for systems with 32-bit bus.
|
---|
114 | ; This step is optional since the controllers use slowest possible settings by default if they are not initialized.
|
---|
115 |
|
---|
116 | pop ax
|
---|
117 | push ax
|
---|
118 | cmp al, [di+LARGEST_DPT_SIZE+DPT.bIdevarsOffset] ; We check if next DPT is for the same IDE controller.
|
---|
119 | je SHORT .SkipInitializationUntilNextDrive ; If it is, we skip the initialization.
|
---|
120 | call AdvAtaInit_InitializeControllerForDPTinDSDI ; Done after drive init so drives are first set to advanced PIO mode, then the controller
|
---|
121 | .SkipInitializationUntilNextDrive:
|
---|
122 | .SkipControllerInitSinceError:
|
---|
123 | %endif ; MODULE_ADVANCED_ATA
|
---|
124 |
|
---|
125 | pop ax
|
---|
126 | pop cx
|
---|
127 | jnc .Done
|
---|
128 | or ah, (RET_HD_RESETFAIL << 1) | 1 ; OR in Reset Failed error code and CF, will SHR into position later
|
---|
129 | .Done:
|
---|
130 | stc ; From IterateAllDPTs perspective, the DPT is never found (continue iteration)
|
---|
131 | ret
|
---|
132 |
|
---|
133 |
|
---|
134 | ;--------------------------------------------------------------------
|
---|
135 | ; AHDh_WaitUnilDriveMotorHasReachedFullSpeed
|
---|
136 | ; Parameters:
|
---|
137 | ; DS:DI: Ptr to DPT
|
---|
138 | ; Returns:
|
---|
139 | ; AH: Int 13h return status
|
---|
140 | ; CF: 0 if successful, 1 if error
|
---|
141 | ; Corrupts registers:
|
---|
142 | ; AL, BX, CX, DX
|
---|
143 | ;--------------------------------------------------------------------
|
---|
144 | AHDh_WaitUnilDriveMotorHasReachedFullSpeed:
|
---|
145 | %ifdef MODULE_SERIAL
|
---|
146 | test BYTE [di+DPT.bFlagsHigh], FLGH_DPT_SERIAL_DEVICE
|
---|
147 | jz SHORT .WaitSinceRealHardDisk
|
---|
148 | ret
|
---|
149 | .WaitSinceRealHardDisk:
|
---|
150 | %endif
|
---|
151 |
|
---|
152 | mov bx, TIMEOUT_AND_STATUS_TO_WAIT(TIMEOUT_MOTOR_STARTUP, FLG_STATUS_DRDY)
|
---|
153 | jmp IdeWait_PollStatusFlagInBLwithTimeoutInBH
|
---|