source: xtideuniversalbios/trunk/XTIDE_Universal_BIOS/Src/VariablesAndDPTs/FindDPT.asm@ 271

Last change on this file since 271 was 271, checked in by aitotat@…, 13 years ago

Changes to XTIDE Universal BIOS:

  • AH=0h (Reset) should now work but our drives are no longer reset if DL belongs to foreign drive.
File size: 7.9 KB
Line 
1; Project name : XTIDE Universal BIOS
2; Description : Functions for finding Disk Parameter Table.
3
4; Section containing code
5SECTION .text
6
7;--------------------------------------------------------------------
8; Checks if drive is handled by this BIOS, and return DPT pointer.
9;
10; FindDPT_ForDriveNumberInDL
11; Parameters:
12; DL: Drive number
13; DS: RAMVARS segment
14; Returns:
15; CF: Cleared if drive is handled by this BIOS
16; Set if drive belongs to some other BIOS
17; DI: DPT Pointer if drive is handled by this BIOS
18; Zero if drive belongs to some other BIOS
19; Corrupts registers:
20; Nothing
21;--------------------------------------------------------------------
22ALIGN JUMP_ALIGN
23FindDPT_ForDriveNumberInDL:
24 xchg di, ax ; Save the contents of AX in DI
25
26;
27; Check Our Hard Disks
28;
29 mov ax, [RAMVARS.wDrvCntAndFirst] ; Drive count to AH, First number to AL
30 add ah, al ; One past last drive to AH
31
32%ifdef MODULE_SERIAL_FLOPPY
33 cmp dl, ah ; Above last supported?
34 jae SHORT .HardDiskNotHandledByThisBIOS
35
36 cmp dl, al ; Below first supported?
37 jae SHORT .CalcDPTForDriveNumber
38
39ALIGN JUMP_ALIGN
40.HardDiskNotHandledByThisBIOS:
41;
42; Check Our Floppy Disks
43;
44 call RamVars_UnpackFlopCntAndFirstToAL
45 cbw ; normally 0h, could be ffh if no drives present
46 adc ah, al ; if no drives present, still ffh (ffh + ffh + 1 = ffh)
47 js SHORT .DiskIsNotHandledByThisBIOS
48 cmp ah, dl ; Check second drive if two, first drive if only one
49 jz SHORT .CalcDPTForDriveNumber
50 cmp al, dl ; Check first drive in all cases, redundant but OK to repeat
51 jnz SHORT .DiskIsNotHandledByThisBIOS
52%else
53 cmp dl, ah ; Above last supported?
54 jae SHORT .DiskIsNotHandledByThisBIOS
55
56 cmp dl, al ; Below first supported?
57 jb SHORT .DiskIsNotHandledByThisBIOS
58%endif
59 ; fall-through to CalcDPTForDriveNumber
60
61;--------------------------------------------------------------------
62; Finds Disk Parameter Table for drive number.
63; Note intended to be called except by FindDPT_ForDriveNumber
64;
65; CalcDPTForDriveNumber
66; Parameters:
67; DL: Drive number
68; DS: RAMVARS segment
69; DI: Saved copy of AX from entry at FindDPT_ForDriveNumber
70; Returns:
71; DS:DI: Ptr to DPT
72; CF: Clear
73; Corrupts registers:
74; Nothing
75;--------------------------------------------------------------------
76ALIGN JUMP_ALIGN
77.CalcDPTForDriveNumber:
78 push dx
79
80%ifdef MODULE_SERIAL_FLOPPY
81 mov ax, [RAMVARS.wDrvCntAndFirst]
82
83 test dl, dl
84 js .harddisk
85
86 call RamVars_UnpackFlopCntAndFirstToAL
87 add dl, ah ; add in end of hard disk DPT list, floppies start immediately after
88
89ALIGN JUMP_ALIGN
90.harddisk:
91 sub dl, al ; subtract off beginning of either hard disk or floppy list (as appropriate)
92%else
93 sub dl, [RAMVARS.bFirstDrv] ; subtract off beginning of hard disk list
94%endif
95
96.CalcDPTForNewDrive:
97 mov al, LARGEST_DPT_SIZE
98
99 mul dl
100 add ax, BYTE RAMVARS_size ; Clears CF (will not oveflow)
101
102 pop dx
103
104 xchg di, ax ; Restore AX from entry at FindDPT_ForDriveNumber, put DPT pointer in DI
105 ret
106
107ALIGN JUMP_ALIGN
108.DiskIsNotHandledByThisBIOS:
109;
110; Drive not found...
111;
112 xor ax, ax ; Clear DPT pointer
113 stc ; Is not supported by our BIOS
114
115 xchg di, ax ; Restore AX from save at top
116 ret
117
118
119;--------------------------------------------------------------------
120; FindDPT_ForIdevarsOffsetInDL
121; Parameters:
122; DL: Offset to IDEVARS to search for
123; DS: RAMVARS segment
124; Returns:
125; DS:DI: Ptr to first DPT with same IDEVARS as in DL
126; CF: Clear if wanted DPT found
127; Set if DPT not found, or no DPTs present
128; Corrupts registers:
129; SI
130;--------------------------------------------------------------------
131FindDPT_ForIdevarsOffsetInDL:
132 mov si, IterateFindFirstDPTforIdevars ; iteration routine (see below)
133 jmp SHORT FindDPT_IterateAllDPTs ; look for the first drive on this controller, if any
134
135;--------------------------------------------------------------------
136; Iteration routine for FindDPT_ForIdevarsOffsetInDL,
137; for use with IterateAllDPTs
138;
139; Returns when DPT is found on the controller with Idevars offset in DL
140;
141; IterateFindFirstDPTforIdevars
142; DL: Offset to IDEVARS to search from DPTs
143; DS:DI: Ptr to DPT to examine
144; Returns:
145; CF: Clear if wanted DPT found
146; Set if wrong DPT
147;--------------------------------------------------------------------
148IterateFindFirstDPTforIdevars:
149 cmp dl, [di+DPT.bIdevarsOffset] ; Clears CF if matched
150 je .done
151 stc ; Set CF for not found
152.done:
153 ret
154
155
156;--------------------------------------------------------------------
157; Finds pointer to first unused Disk Parameter Table.
158; Should only be used before DetectDrives is complete (not valid after this time).
159;
160; FindDPT_ForNewDriveToDSDI
161; Parameters:
162; DS: RAMVARS segment
163; Returns:
164; DS:DI: Ptr to first unused DPT
165; Corrupts registers:
166; AX
167;--------------------------------------------------------------------
168ALIGN JUMP_ALIGN
169FindDPT_ForNewDriveToDSDI:
170 push dx
171
172%ifdef MODULE_SERIAL_FLOPPY
173 mov dx, [RAMVARS.wDrvCntAndFlopCnt]
174 add dl, dh
175%else
176 mov dl, [RAMVARS.bDrvCnt]
177%endif
178
179 jmp short FindDPT_ForDriveNumberInDL.CalcDPTForNewDrive
180
181;--------------------------------------------------------------------
182; IterateToDptWithFlagsHighInBL
183; Parameters:
184; DS:DI: Ptr to DPT to examine
185; BL: Bit(s) to test in DPT.bFlagsHigh
186; Returns:
187; CF: Clear if wanted DPT found
188; Set if wrong DPT
189; Corrupts registers:
190; Nothing
191;--------------------------------------------------------------------
192ALIGN JUMP_ALIGN
193IterateToDptWithFlagsHighInBL:
194 test BYTE [di+DPT.bFlagsHigh], bl ; Clears CF
195 jnz SHORT .ReturnRightDPT
196 stc
197.ReturnRightDPT:
198 ret
199
200;--------------------------------------------------------------------
201; FindDPT_ToDSDIforSerialDevice
202; Parameters:
203; DS: RAMVARS segment
204; Returns:
205; DS:DI: Ptr to DPT
206; CF: Set if wanted DPT found
207; Cleared if DPT not found
208; Corrupts registers:
209; SI
210;--------------------------------------------------------------------
211%ifdef MODULE_SERIAL
212ALIGN JUMP_ALIGN
213FindDPT_ToDSDIforSerialDevice:
214 mov bl, FLGH_DPT_SERIAL_DEVICE
215; fall-through
216%endif
217
218;--------------------------------------------------------------------
219; FindDPT_ToDSDIforFlagsHigh
220; Parameters:
221; DS: RAMVARS segment
222; BL: Bit(s) to test in DPT.bFlagsHigh
223; Returns:
224; DS:DI: Ptr to DPT
225; CF: Set if wanted DPT found
226; Cleared if DPT not found
227; Corrupts registers:
228; SI
229;--------------------------------------------------------------------
230ALIGN JUMP_ALIGN
231FindDPT_ToDSDIforFlagsHighInBL:
232 mov si, IterateToDptWithFlagsHighInBL
233 ; Fall to IterateAllDPTs
234
235;--------------------------------------------------------------------
236; Iterates all Disk Parameter Tables.
237;
238; FindDPT_IterateAllDPTs
239; Parameters:
240; AX,BX,DX: Parameters to callback function
241; CS:SI: Ptr to callback function
242; Callback routine should return CF=clear if found
243; DS: RAMVARS segment
244; Returns:
245; DS:DI: Ptr to wanted DPT (if found)
246; If not found, points to first empty DPT
247; CF: Clear if wanted DPT found
248; Set if DPT not found, or no DPTs present
249; Corrupts registers:
250; Nothing unless corrupted by callback function
251;--------------------------------------------------------------------
252ALIGN JUMP_ALIGN
253FindDPT_IterateAllDPTs:
254 push cx
255
256 mov di, RAMVARS_size ; Point DS:DI to first DPT
257
258 mov cl, [RAMVARS.bDrvCnt]
259 xor ch, ch ; Clears CF
260
261 jcxz .NotFound ; Return if no drives
262
263ALIGN JUMP_ALIGN
264.LoopWhileDPTsLeft:
265 call si ; Is wanted DPT?
266 jnc SHORT .Found ; If so, return
267 add di, BYTE LARGEST_DPT_SIZE ; Point to next DPT
268 loop .LoopWhileDPTsLeft
269
270ALIGN JUMP_ALIGN
271.NotFound:
272 stc
273
274ALIGN JUMP_ALIGN
275.Found:
276 pop cx
277 ret
278
Note: See TracBrowser for help on using the repository browser.