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

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

Changes to XTIDE Universal BIOS:

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