1 | ; File name : AH0h_HReset.asm
|
---|
2 | ; Project name : IDE BIOS
|
---|
3 | ; Created date : 27.9.2007
|
---|
4 | ; Last update : 29.7.2010
|
---|
5 | ; Author : Tomi Tilli
|
---|
6 | ; Description : Int 13h function AH=0h, Disk Controller Reset.
|
---|
7 |
|
---|
8 | RETRIES_IF_RESET_FAILS EQU 3
|
---|
9 | TIMEOUT_BEFORE_RESET_RETRY EQU 5 ; System timer ticks
|
---|
10 |
|
---|
11 | ; Section containing code
|
---|
12 | SECTION .text
|
---|
13 |
|
---|
14 | ;--------------------------------------------------------------------
|
---|
15 | ; Int 13h function AH=0h, Disk Controller Reset.
|
---|
16 | ;
|
---|
17 | ; AH0h_HandlerForDiskControllerReset
|
---|
18 | ; Parameters:
|
---|
19 | ; AH: Bios function 0h
|
---|
20 | ; DL: Drive number (ignored so all drives are reset)
|
---|
21 | ; If bit 7 is set all hard disks and floppy disks reset.
|
---|
22 | ; Parameters loaded by Int13h_Jump:
|
---|
23 | ; DS: RAMVARS segment
|
---|
24 | ; Returns:
|
---|
25 | ; AH: Int 13h return status (from drive requested in DL)
|
---|
26 | ; CF: 0 if succesfull, 1 if error
|
---|
27 | ; IF: 1
|
---|
28 | ; Corrupts registers:
|
---|
29 | ; Flags
|
---|
30 | ;--------------------------------------------------------------------
|
---|
31 | ALIGN JUMP_ALIGN
|
---|
32 | AH0h_HandlerForDiskControllerReset:
|
---|
33 | push dx
|
---|
34 | push cx
|
---|
35 | push bx
|
---|
36 | push ax
|
---|
37 |
|
---|
38 | eMOVZX bx, dl ; Copy requested drive to BL, zero BH to assume no errors
|
---|
39 | call ResetFloppyDrivesWithInt40h
|
---|
40 | test bl, 80h
|
---|
41 | jz SHORT .SkipHardDiskReset
|
---|
42 | call ResetForeignHardDisks
|
---|
43 | call AH0h_ResetHardDisksHandledByOurBIOS
|
---|
44 | ALIGN JUMP_ALIGN
|
---|
45 | .SkipHardDiskReset:
|
---|
46 | mov ah, bh ; Copy error code to AH
|
---|
47 | xor al, al ; Zero AL...
|
---|
48 | cmp al, bh ; ...and set CF if error
|
---|
49 | jmp Int13h_StoreErrorCodeToBDAandPopXRegsAndReturn
|
---|
50 |
|
---|
51 |
|
---|
52 | ;--------------------------------------------------------------------
|
---|
53 | ; ResetFloppyDrivesWithInt40h
|
---|
54 | ; Parameters:
|
---|
55 | ; BL: Requested drive (DL when entering AH=00h)
|
---|
56 | ; Returns:
|
---|
57 | ; BH: Error code from requested drive (if available)
|
---|
58 | ; Corrupts registers:
|
---|
59 | ; AX, DL, DI
|
---|
60 | ;--------------------------------------------------------------------
|
---|
61 | ALIGN JUMP_ALIGN
|
---|
62 | ResetFloppyDrivesWithInt40h:
|
---|
63 | call GetDriveNumberForForeignBiosesToDL
|
---|
64 | and dl, 7Fh ; Clear hard disk bit
|
---|
65 | xor ah, ah ; Disk Controller Reset
|
---|
66 | int INTV_FLOPPY_FUNC
|
---|
67 | jmp SHORT BackupErrorCodeFromTheRequestedDriveToBH
|
---|
68 |
|
---|
69 |
|
---|
70 | ;--------------------------------------------------------------------
|
---|
71 | ; ResetForeignHardDisks
|
---|
72 | ; Parameters:
|
---|
73 | ; BL: Requested drive (DL when entering AH=00h)
|
---|
74 | ; DS: RAMVARS segment
|
---|
75 | ; Returns:
|
---|
76 | ; BH: Error code from requested drive (if available)
|
---|
77 | ; Corrupts registers:
|
---|
78 | ; AX, DL, DI
|
---|
79 | ;--------------------------------------------------------------------
|
---|
80 | ALIGN JUMP_ALIGN
|
---|
81 | ResetForeignHardDisks:
|
---|
82 | call GetDriveNumberForForeignBiosesToDL
|
---|
83 | xor ah, ah ; Disk Controller Reset
|
---|
84 | pushf ; Push flags to simulate INT
|
---|
85 | cli ; Disable interrupts since INT does that
|
---|
86 | call FAR [RAMVARS.fpOldI13h]
|
---|
87 | sti ; Make sure interrupts are enabled again (some BIOSes fails to enable it)
|
---|
88 | jmp SHORT BackupErrorCodeFromTheRequestedDriveToBH
|
---|
89 |
|
---|
90 |
|
---|
91 | ;--------------------------------------------------------------------
|
---|
92 | ; GetDriveNumberForForeignBiosesToDL
|
---|
93 | ; Parameters:
|
---|
94 | ; BL: Requested drive (DL when entering AH=00h)
|
---|
95 | ; DS: RAMVARS segment
|
---|
96 | ; Returns:
|
---|
97 | ; DL: BL if foreign drive
|
---|
98 | ; 80h if our drive
|
---|
99 | ; Corrupts registers:
|
---|
100 | ; DI
|
---|
101 | ;--------------------------------------------------------------------
|
---|
102 | ALIGN JUMP_ALIGN
|
---|
103 | GetDriveNumberForForeignBiosesToDL:
|
---|
104 | mov dl, bl
|
---|
105 | call RamVars_IsDriveHandledByThisBIOS
|
---|
106 | jc SHORT .GetFirstDriveForForeignBios
|
---|
107 | ret ; Return what was in BL unmodified
|
---|
108 | ALIGN JUMP_ALIGN
|
---|
109 | .GetFirstDriveForForeignBios:
|
---|
110 | mov dl, 80h
|
---|
111 | ret
|
---|
112 |
|
---|
113 |
|
---|
114 | ;--------------------------------------------------------------------
|
---|
115 | ; ResetHardDisksHandledByOurBIOS
|
---|
116 | ; Parameters:
|
---|
117 | ; BL: Requested drive (DL when entering AH=00h)
|
---|
118 | ; DS: RAMVARS segment
|
---|
119 | ; Returns:
|
---|
120 | ; BH: Error code from requested drive (if available)
|
---|
121 | ; Corrupts registers:
|
---|
122 | ; AX, CX, DX, DI
|
---|
123 | ;--------------------------------------------------------------------
|
---|
124 | ALIGN JUMP_ALIGN
|
---|
125 | AH0h_ResetHardDisksHandledByOurBIOS:
|
---|
126 | mov dh, [RAMVARS.bDrvCnt] ; Load drive count to DH
|
---|
127 | test dh, dh
|
---|
128 | jz SHORT .AllDrivesReset ; Return if no drives
|
---|
129 | mov dl, [RAMVARS.bFirstDrv] ; Load number of first our drive
|
---|
130 | add dh, dl ; DH = one past last drive to reset
|
---|
131 | ALIGN JUMP_ALIGN
|
---|
132 | .DriveResetLoop:
|
---|
133 | call AHDh_ResetDrive
|
---|
134 | call .BackupErrorCodeFromMasterOrSlaveToBH
|
---|
135 | inc dx
|
---|
136 | cmp dl, dh ; All done?
|
---|
137 | jb SHORT .DriveResetLoop ; If not, reset next drive
|
---|
138 | .AllDrivesReset:
|
---|
139 | ret
|
---|
140 |
|
---|
141 | ;--------------------------------------------------------------------
|
---|
142 | ; .BackupErrorCodeFromMasterOrSlaveToBH
|
---|
143 | ; Parameters:
|
---|
144 | ; AH: Error code for drive DL reset
|
---|
145 | ; BL: Requested drive (DL when entering AH=00h)
|
---|
146 | ; DL: Drive just resetted
|
---|
147 | ; DS: RAMVARS segment
|
---|
148 | ; Returns:
|
---|
149 | ; BH: Backuped error code
|
---|
150 | ; DL: Incremented if next drive is slave drive
|
---|
151 | ; (=already resetted)
|
---|
152 | ; Corrupts registers:
|
---|
153 | ; CX, DI
|
---|
154 | ;--------------------------------------------------------------------
|
---|
155 | ALIGN JUMP_ALIGN
|
---|
156 | .BackupErrorCodeFromMasterOrSlaveToBH:
|
---|
157 | call BackupErrorCodeFromTheRequestedDriveToBH
|
---|
158 | mov cx, [RAMVARS.wIdeBase] ; Load base port for resetted drive
|
---|
159 |
|
---|
160 | inc dx ; DL to next drive
|
---|
161 | call FindDPT_ForDriveNumber ; Get DPT to DS:DI, store port to RAMVARS
|
---|
162 | jnc SHORT .NoMoreDrivesOrNoSlaveDrive
|
---|
163 | cmp cx, [RAMVARS.wIdeBase] ; Next drive is from same controller?
|
---|
164 | je SHORT BackupErrorCodeFromTheRequestedDriveToBH
|
---|
165 | .NoMoreDrivesOrNoSlaveDrive:
|
---|
166 | dec dx
|
---|
167 | ret
|
---|
168 |
|
---|
169 |
|
---|
170 | ;--------------------------------------------------------------------
|
---|
171 | ; BackupErrorCodeFromTheRequestedDriveToBH
|
---|
172 | ; Parameters:
|
---|
173 | ; AH: Error code from the last resetted drive
|
---|
174 | ; DL: Drive last resetted
|
---|
175 | ; BL: Requested drive (DL when entering AH=00h)
|
---|
176 | ; Returns:
|
---|
177 | ; BH: Backuped error code
|
---|
178 | ; Corrupts registers:
|
---|
179 | ; Nothing
|
---|
180 | ;--------------------------------------------------------------------
|
---|
181 | ALIGN JUMP_ALIGN
|
---|
182 | BackupErrorCodeFromTheRequestedDriveToBH:
|
---|
183 | cmp dl, bl ; Requested drive?
|
---|
184 | jne SHORT .Return
|
---|
185 | mov bh, ah
|
---|
186 | ALIGN JUMP_ALIGN
|
---|
187 | .Return:
|
---|
188 | ret
|
---|