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