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 | ; 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 | ;--------------------------------------------------------------------
|
---|
22 | ALIGN JUMP_ALIGN
|
---|
23 | FindDPT_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 |
|
---|
39 | ALIGN 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 | ;--------------------------------------------------------------------
|
---|
76 | ALIGN 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 |
|
---|
89 | ALIGN 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 |
|
---|
107 | ALIGN 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 | ; Finds pointer to first unused Disk Parameter Table.
|
---|
120 | ; Should only be used before DetectDrives is complete (not valid after this time).
|
---|
121 | ;
|
---|
122 | ; FindDPT_ForNewDriveToDSDI
|
---|
123 | ; Parameters:
|
---|
124 | ; DS: RAMVARS segment
|
---|
125 | ; Returns:
|
---|
126 | ; DS:DI: Ptr to first unused DPT
|
---|
127 | ; Corrupts registers:
|
---|
128 | ; AX
|
---|
129 | ;--------------------------------------------------------------------
|
---|
130 | ALIGN JUMP_ALIGN
|
---|
131 | FindDPT_ForNewDriveToDSDI:
|
---|
132 | push dx
|
---|
133 |
|
---|
134 | %ifdef MODULE_SERIAL_FLOPPY
|
---|
135 | mov dx, [RAMVARS.wDrvCntAndFlopCnt]
|
---|
136 | add dl, dh
|
---|
137 | %else
|
---|
138 | mov dl, [RAMVARS.bDrvCnt]
|
---|
139 | %endif
|
---|
140 |
|
---|
141 | jmp short FindDPT_ForDriveNumberInDL.CalcDPTForNewDrive
|
---|
142 |
|
---|
143 | ;--------------------------------------------------------------------
|
---|
144 | ; IterateToDptWithFlagsHighInBL
|
---|
145 | ; Parameters:
|
---|
146 | ; DS:DI: Ptr to DPT to examine
|
---|
147 | ; BL: Bit(s) to test in DPT.bFlagsHigh
|
---|
148 | ; Returns:
|
---|
149 | ; CF: Clear if wanted DPT found
|
---|
150 | ; Set if wrong DPT
|
---|
151 | ; Corrupts registers:
|
---|
152 | ; Nothing
|
---|
153 | ;--------------------------------------------------------------------
|
---|
154 | ALIGN JUMP_ALIGN
|
---|
155 | IterateToDptWithFlagsHighInBL:
|
---|
156 | test BYTE [di+DPT.bFlagsHigh], bl ; Clears CF
|
---|
157 | jnz SHORT .ReturnRightDPT
|
---|
158 | stc
|
---|
159 | .ReturnRightDPT:
|
---|
160 | ret
|
---|
161 |
|
---|
162 | ;--------------------------------------------------------------------
|
---|
163 | ; FindDPT_ToDSDIforSerialDevice
|
---|
164 | ; Parameters:
|
---|
165 | ; DS: RAMVARS segment
|
---|
166 | ; Returns:
|
---|
167 | ; DS:DI: Ptr to DPT
|
---|
168 | ; CF: Set if wanted DPT found
|
---|
169 | ; Cleared if DPT not found
|
---|
170 | ; Corrupts registers:
|
---|
171 | ; SI
|
---|
172 | ;--------------------------------------------------------------------
|
---|
173 | ALIGN JUMP_ALIGN
|
---|
174 | FindDPT_ToDSDIforSerialDevice:
|
---|
175 | mov bl, FLGH_DPT_SERIAL_DEVICE
|
---|
176 | ; fall-through
|
---|
177 |
|
---|
178 | ;--------------------------------------------------------------------
|
---|
179 | ; FindDPT_ToDSDIforFlagsHigh
|
---|
180 | ; Parameters:
|
---|
181 | ; DS: RAMVARS segment
|
---|
182 | ; BL: Bit(s) to test in DPT.bFlagsHigh
|
---|
183 | ; Returns:
|
---|
184 | ; DS:DI: Ptr to DPT
|
---|
185 | ; CF: Set if wanted DPT found
|
---|
186 | ; Cleared if DPT not found
|
---|
187 | ; Corrupts registers:
|
---|
188 | ; SI
|
---|
189 | ;--------------------------------------------------------------------
|
---|
190 | ALIGN JUMP_ALIGN
|
---|
191 | FindDPT_ToDSDIforFlagsHighInBL:
|
---|
192 | mov si, IterateToDptWithFlagsHighInBL
|
---|
193 | ; Fall to IterateAllDPTs
|
---|
194 |
|
---|
195 | ;--------------------------------------------------------------------
|
---|
196 | ; Iterates all Disk Parameter Tables.
|
---|
197 | ;
|
---|
198 | ; IterateAllDPTs
|
---|
199 | ; Parameters:
|
---|
200 | ; AX,BX,DX: Parameters to callback function
|
---|
201 | ; CS:SI: Ptr to callback function
|
---|
202 | ; Callback routine should return CF=clear if found
|
---|
203 | ; DS: RAMVARS segment
|
---|
204 | ; Returns:
|
---|
205 | ; DS:DI: Ptr to wanted DPT (if found)
|
---|
206 | ; If not found, points to first empty DPT
|
---|
207 | ; CF: Clear if wanted DPT found
|
---|
208 | ; Set if DPT not found, or no DPTs present
|
---|
209 | ; Corrupts registers:
|
---|
210 | ; Nothing unless corrupted by callback function
|
---|
211 | ;--------------------------------------------------------------------
|
---|
212 | ALIGN JUMP_ALIGN
|
---|
213 | IterateAllDPTs:
|
---|
214 | push cx
|
---|
215 |
|
---|
216 | mov di, RAMVARS_size ; Point DS:DI to first DPT
|
---|
217 |
|
---|
218 | mov cl, [RAMVARS.bDrvCnt]
|
---|
219 | xor ch, ch ; Clears CF
|
---|
220 |
|
---|
221 | jcxz .NotFound ; Return if no drives
|
---|
222 |
|
---|
223 | ALIGN JUMP_ALIGN
|
---|
224 | .LoopWhileDPTsLeft:
|
---|
225 | call si ; Is wanted DPT?
|
---|
226 | jnc SHORT .Found ; If so, return
|
---|
227 | add di, BYTE LARGEST_DPT_SIZE ; Point to next DPT
|
---|
228 | loop .LoopWhileDPTsLeft
|
---|
229 |
|
---|
230 | ALIGN JUMP_ALIGN
|
---|
231 | .NotFound:
|
---|
232 | stc
|
---|
233 |
|
---|
234 | ALIGN JUMP_ALIGN
|
---|
235 | .Found:
|
---|
236 | pop cx
|
---|
237 | ret
|
---|
238 |
|
---|