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