1 | ; Project name : XTIDE Universal BIOS
|
---|
2 | ; Description : Functions for finding Disk Parameter Table.
|
---|
3 |
|
---|
4 | ; Section containing code
|
---|
5 | SECTION .text
|
---|
6 |
|
---|
7 | ;--------------------------------------------------------------------
|
---|
8 | ; Finds pointer to first unused Disk Parameter Table.
|
---|
9 | ;
|
---|
10 | ; FindDPT_ForNewDriveToDSDI
|
---|
11 | ; Parameters:
|
---|
12 | ; DS: RAMVARS segment
|
---|
13 | ; Returns:
|
---|
14 | ; DS:DI: Ptr to first unused DPT
|
---|
15 | ; Corrupts registers:
|
---|
16 | ; DX
|
---|
17 | ;--------------------------------------------------------------------
|
---|
18 | ALIGN JUMP_ALIGN
|
---|
19 | FindDPT_ForNewDriveToDSDI:
|
---|
20 | mov ax, [RAMVARS.wDrvCntAndFirst]
|
---|
21 | add al, ah
|
---|
22 | %ifdef MODULE_SERIAL_FLOPPY
|
---|
23 | add al, [RAMVARS.xlateVars+XLATEVARS.bFlopCreateCnt]
|
---|
24 | %endif
|
---|
25 | xchg ax, dx
|
---|
26 | ; fall-through to FindDPT_ForDriveNumber
|
---|
27 |
|
---|
28 | ;--------------------------------------------------------------------
|
---|
29 | ; Finds Disk Parameter Table for drive number.
|
---|
30 | ; IDE Base Port address will be stored to RAMVARS if correct DPT is found.
|
---|
31 | ;
|
---|
32 | ; FindDPT_ForDriveNumber
|
---|
33 | ; Parameters:
|
---|
34 | ; DL: Drive number
|
---|
35 | ; DS: RAMVARS segment
|
---|
36 | ; Returns:
|
---|
37 | ; DS:DI: Ptr to DPT
|
---|
38 | ; Corrupts registers:
|
---|
39 | ; Nothing
|
---|
40 | ;--------------------------------------------------------------------
|
---|
41 | ALIGN JUMP_ALIGN
|
---|
42 | FindDPT_ForDriveNumber:
|
---|
43 | push dx
|
---|
44 | xchg di, ax ; Save the contents of AX in DI
|
---|
45 |
|
---|
46 | %ifdef MODULE_SERIAL_FLOPPY
|
---|
47 | mov ax, [RAMVARS.wDrvCntAndFirst]
|
---|
48 |
|
---|
49 | test dl, dl
|
---|
50 | js .harddisk
|
---|
51 |
|
---|
52 | call RamVars_UnpackFlopCntAndFirstToAL
|
---|
53 | add dl, ah ; add in end of hard disk DPT list, floppies start immediately after
|
---|
54 | .harddisk:
|
---|
55 | sub dl, al ; subtract off beginning of either hard disk or floppy list (as appropriate)
|
---|
56 | %else
|
---|
57 | sub dl, [RAMVARS.bFirstDrv] ; subtract off beginning of hard disk list
|
---|
58 | %endif
|
---|
59 |
|
---|
60 | mov al, LARGEST_DPT_SIZE
|
---|
61 |
|
---|
62 | mul dl
|
---|
63 | add ax, BYTE RAMVARS_size
|
---|
64 |
|
---|
65 | xchg di, ax ; Restore AX and put result in DI
|
---|
66 | pop dx
|
---|
67 |
|
---|
68 | ret
|
---|
69 |
|
---|
70 | ;--------------------------------------------------------------------
|
---|
71 | ; Consolidator for checking the result from RamVars_IsDriveHandledByThisBIOS
|
---|
72 | ; and then if it is our drive, getting the DPT with FindDPT_ForDriveNumber
|
---|
73 | ;
|
---|
74 | ; RamVars_IsDriveHandledByThisBIOS_And_FindDPT_ForDriveNumber
|
---|
75 | ; Parameters:
|
---|
76 | ; DL: Drive number
|
---|
77 | ; DS: RAMVARS segment
|
---|
78 | ; Returns:
|
---|
79 | ; DS:DI: Ptr to DPT, if it is our drive
|
---|
80 | ; CF: Set if not our drive, clear if it is our drive
|
---|
81 | ; Corrupts registers:
|
---|
82 | ; Nothing
|
---|
83 | ;--------------------------------------------------------------------
|
---|
84 | ALIGN JUMP_ALIGN
|
---|
85 | RamVars_IsDriveHandledByThisBIOS_And_FindDPT_ForDriveNumber:
|
---|
86 | call RamVars_IsDriveHandledByThisBIOS
|
---|
87 | jnc FindDPT_ForDriveNumber
|
---|
88 | ret
|
---|
89 |
|
---|
90 |
|
---|
91 | ;--------------------------------------------------------------------
|
---|
92 | ; Finds Disk Parameter Table for
|
---|
93 | ; Master or Slave drive at wanted port.
|
---|
94 | ;
|
---|
95 | ; FindDPT_ToDSDIForIdeMasterAtPortDX
|
---|
96 | ; FindDPT_ToDSDIForIdeSlaveAtPortDX
|
---|
97 | ; Parameters:
|
---|
98 | ; DX: IDE Base Port address
|
---|
99 | ; DS: RAMVARS segment
|
---|
100 | ; Returns:
|
---|
101 | ; DL: Drive number (if DPT found)
|
---|
102 | ; DS:DI: Ptr to DPT
|
---|
103 | ; CF: Set if wanted DPT found
|
---|
104 | ; Cleared if DPT not found
|
---|
105 | ; Corrupts registers:
|
---|
106 | ; SI
|
---|
107 | ;
|
---|
108 | ; Converted to macros since there is only once call site for each of these
|
---|
109 | ;
|
---|
110 | ;--------------------------------------------------------------------
|
---|
111 |
|
---|
112 | %macro FindDPT_ToDSDIForIdeMasterAtPortDX 0
|
---|
113 | mov si, IterateToMasterAtPortCallback
|
---|
114 | call IterateAllDPTs
|
---|
115 | %endmacro
|
---|
116 |
|
---|
117 | %macro FindDPT_ToDSDIForIdeSlaveAtPortDX 0
|
---|
118 | mov si, IterateToSlaveAtPortCallback
|
---|
119 | call IterateAllDPTs
|
---|
120 | %endmacro
|
---|
121 |
|
---|
122 |
|
---|
123 | ;--------------------------------------------------------------------
|
---|
124 | ; Iteration callback for finding DPT using
|
---|
125 | ; IDE base port for Master or Slave drive.
|
---|
126 | ;
|
---|
127 | ; IterateToSlaveAtPortCallback
|
---|
128 | ; IterateToMasterAtPortCallback
|
---|
129 | ; Parameters:
|
---|
130 | ; DX: IDE Base Port address
|
---|
131 | ; DS:DI: Ptr to DPT to examine
|
---|
132 | ; Returns:
|
---|
133 | ; CF: Set if wanted DPT found
|
---|
134 | ; Cleared if wrong DPT
|
---|
135 | ; Corrupts registers:
|
---|
136 | ; Nothing
|
---|
137 | ;--------------------------------------------------------------------
|
---|
138 | ALIGN JUMP_ALIGN
|
---|
139 | IterateToSlaveAtPortCallback:
|
---|
140 | test BYTE [di+DPT.bFlagsLow], FLGL_DPT_SLAVE ; Clears CF
|
---|
141 | jnz SHORT CompareBasePortAddress
|
---|
142 | ret ; Wrong DPT
|
---|
143 |
|
---|
144 | ALIGN JUMP_ALIGN
|
---|
145 | IterateToMasterAtPortCallback:
|
---|
146 | test BYTE [di+DPT.bFlagsLow], FLGL_DPT_SLAVE
|
---|
147 | jnz SHORT ReturnWrongDPT ; Return if slave drive
|
---|
148 |
|
---|
149 | CompareBasePortAddress:
|
---|
150 | push bx
|
---|
151 | eMOVZX bx, BYTE [di+DPT.bIdevarsOffset] ; CS:BX now points to IDEVARS
|
---|
152 | cmp dx, [cs:bx+IDEVARS.wPort] ; Wanted port?
|
---|
153 | pop bx
|
---|
154 | jne SHORT ReturnWrongDPT
|
---|
155 |
|
---|
156 | ReturnRightDPT:
|
---|
157 | stc ; Set CF since wanted DPT
|
---|
158 | ret
|
---|
159 |
|
---|
160 |
|
---|
161 | ;--------------------------------------------------------------------
|
---|
162 | ; IterateToDptWithFlagsHighInBL
|
---|
163 | ; Parameters:
|
---|
164 | ; DS:DI: Ptr to DPT to examine
|
---|
165 | ; BL: Bit(s) to test in DPT.bFlagsHigh
|
---|
166 | ; Returns:
|
---|
167 | ; CF: Set if wanted DPT found
|
---|
168 | ; Cleared if wrong DPT
|
---|
169 | ; Corrupts registers:
|
---|
170 | ; Nothing
|
---|
171 | ;--------------------------------------------------------------------
|
---|
172 | ALIGN JUMP_ALIGN
|
---|
173 | IterateToDptWithFlagsHighInBL:
|
---|
174 | test BYTE [di+DPT.bFlagsHigh], bl ; Clears CF (but we need the clc
|
---|
175 | ; below anyway for callers above)
|
---|
176 | jnz SHORT ReturnRightDPT
|
---|
177 |
|
---|
178 | ReturnWrongDPT:
|
---|
179 | clc ; Clear CF since wrong DPT
|
---|
180 | ret
|
---|
181 |
|
---|
182 | ;--------------------------------------------------------------------
|
---|
183 | ; FindDPT_ToDSDIforSerialDevice
|
---|
184 | ; Parameters:
|
---|
185 | ; DS: RAMVARS segment
|
---|
186 | ; Returns:
|
---|
187 | ; DS:DI: Ptr to DPT
|
---|
188 | ; CF: Set if wanted DPT found
|
---|
189 | ; Cleared if DPT not found
|
---|
190 | ; Corrupts registers:
|
---|
191 | ; SI
|
---|
192 | ;--------------------------------------------------------------------
|
---|
193 | ALIGN JUMP_ALIGN
|
---|
194 | FindDPT_ToDSDIforSerialDevice:
|
---|
195 | mov bl, FLGH_DPT_SERIAL_DEVICE
|
---|
196 | ; fall-through
|
---|
197 |
|
---|
198 | ;--------------------------------------------------------------------
|
---|
199 | ; FindDPT_ToDSDIforFlagsHigh
|
---|
200 | ; Parameters:
|
---|
201 | ; DS: RAMVARS segment
|
---|
202 | ; BL: Bit(s) to test in DPT.bFlagsHigh
|
---|
203 | ; Returns:
|
---|
204 | ; DS:DI: Ptr to DPT
|
---|
205 | ; CF: Set if wanted DPT found
|
---|
206 | ; Cleared if DPT not found
|
---|
207 | ; Corrupts registers:
|
---|
208 | ; SI
|
---|
209 | ;--------------------------------------------------------------------
|
---|
210 | ALIGN JUMP_ALIGN
|
---|
211 | FindDPT_ToDSDIforFlagsHighInBL:
|
---|
212 | mov si, IterateToDptWithFlagsHighInBL
|
---|
213 | ; Fall to IterateAllDPTs
|
---|
214 |
|
---|
215 | ;--------------------------------------------------------------------
|
---|
216 | ; Iterates all Disk Parameter Tables.
|
---|
217 | ;
|
---|
218 | ; IterateAllDPTs
|
---|
219 | ; Parameters:
|
---|
220 | ; AX,BX,DX: Parameters to callback function
|
---|
221 | ; CS:SI: Ptr to callback function
|
---|
222 | ; DS: RAMVARS segment
|
---|
223 | ; Returns:
|
---|
224 | ; DS:DI: Ptr to wanted DPT (if found)
|
---|
225 | ; If not found, points to first empty DPT
|
---|
226 | ; CF: Set if wanted DPT found
|
---|
227 | ; Cleared if DPT not found, or no DPTs present
|
---|
228 | ; Corrupts registers:
|
---|
229 | ; Nothing unless corrupted by callback function
|
---|
230 | ;--------------------------------------------------------------------
|
---|
231 | ALIGN JUMP_ALIGN
|
---|
232 | IterateAllDPTs:
|
---|
233 | push cx
|
---|
234 |
|
---|
235 | mov di, RAMVARS_size ; Point DS:DI to first DPT
|
---|
236 |
|
---|
237 | mov cl, [RAMVARS.bDrvCnt]
|
---|
238 | xor ch, ch ; Clears CF
|
---|
239 |
|
---|
240 | jcxz .AllDptsIterated ; Return if no drives, CF will be clear from xor above
|
---|
241 |
|
---|
242 | ALIGN JUMP_ALIGN
|
---|
243 | .LoopWhileDPTsLeft:
|
---|
244 | call si ; Is wanted DPT?
|
---|
245 | jc SHORT .AllDptsIterated ; If so, return
|
---|
246 | add di, BYTE LARGEST_DPT_SIZE ; Point to next DPT, clears CF
|
---|
247 | loop .LoopWhileDPTsLeft
|
---|
248 |
|
---|
249 | ; fall-through: DPT was not found, CF is already clear from ADD di inside the loop
|
---|
250 |
|
---|
251 | ALIGN JUMP_ALIGN
|
---|
252 | .AllDptsIterated:
|
---|
253 | pop cx
|
---|
254 | ret
|
---|
255 |
|
---|