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

Last change on this file since 567 was 567, checked in by krille_n_@…, 10 years ago

Changes:

  • Renamed MODULE_FEATURE_SETS to MODULE_POWER_MANAGEMENT.
  • Renamed MODULE_VERY_LATE_INITIALIZATION to MODULE_VERY_LATE_INIT and removed it from the official builds.
  • Removed the code that skips detection of slave drives on XT-CF controllers since slave drives can be used with Lo-tech ISA CompactFlash boards.
  • Added autodetection of the SVC ADP50L controller to XTIDECFG.
  • The autodetection of XT-CF controllers now requires MODULE_8BIT_IDE_ADVANCED in the loaded BIOS.
  • Fixed a bug in XTIDECFG from r502 where the "Base (cmd block) address" menu option would be displayed when a serial device was selected as the IDE controller.
  • XTIDECFG would display the "Enable interrupt" menu option for the XTIDE r1 but not for the XTIDE r2. It's now displayed for both controller types.
  • Disabled the "Internal Write Cache" menu option in the Master/Slave Drive menus for serial device type drives.
  • Optimizations and other fixes.
File size: 9.4 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-2013 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 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, 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; Iteration routines for FindDPT_MasterOrSingleForIdevarsOffsetInDL and
139; FindDPT_SlaveForIdevarsOffsetInDL, for use with IterateAllDPTs
140;
141; Returns when DPT is found on the controller with Idevars offset in DL
142;
143; IterateFindSecondDPTforIdevars
144; IterateFindFirstDPTforIdevars
145;       DL:     Offset to IDEVARS to search from DPTs
146;       SI:     Offset to this callback function
147;       DS:DI:  Ptr to DPT to examine
148;   Returns:
149;       CF:     Cleared if wanted DPT found
150;               Set if wrong DPT
151;--------------------------------------------------------------------
152IterateFindSecondDPTforIdevars:
153    call    IterateFindFirstDPTforIdevars
154    jc      SHORT .WrongController
155    mov     si, IterateFindFirstDPTforIdevars
156.WrongController:
157    stc
158    ret
159
160IterateFindFirstDPTforIdevars:
161    cmp     dl, [di+DPT.bIdevarsOffset]         ; Clears CF if matched
162    je      .Done
163    stc                                         ; Set CF for not found
164.Done:
165    ret
166
167
168;--------------------------------------------------------------------
169; Finds pointer to first unused Disk Parameter Table.
170; Should only be used before DetectDrives is complete (not valid after this time).
171;
172; FindDPT_ForNewDriveToDSDI
173;   Parameters:
174;       DS:     RAMVARS segment
175;   Returns:
176;       DS:DI:  Ptr to first unused DPT
177;   Corrupts registers:
178;       AX
179;--------------------------------------------------------------------
180ALIGN JUMP_ALIGN
181FindDPT_ForNewDriveToDSDI:
182    push    dx
183
184%ifdef MODULE_SERIAL_FLOPPY
185    mov     dx, [RAMVARS.wDrvCntAndFlopCnt]
186    add     dl, dh
187%else
188    mov     dl, [RAMVARS.bDrvCnt]
189%endif
190
191    jmp     SHORT FindDPT_ForDriveNumberInDL.CalcDPTForNewDrive
192
193;--------------------------------------------------------------------
194; IterateToDptWithFlagsHighInBL
195;   Parameters:
196;       DS:DI:  Ptr to DPT to examine
197;       BL:     Bit(s) to test in DPT.bFlagsHigh
198;   Returns:
199;       CF:     Cleared if wanted DPT found
200;               Set if wrong DPT
201;   Corrupts registers:
202;       Nothing
203;--------------------------------------------------------------------
204%ifdef MODULE_SERIAL
205ALIGN JUMP_ALIGN
206IterateToDptWithFlagsHighInBL:
207    test    [di+DPT.bFlagsHigh], bl             ; Clears CF
208    jnz     SHORT .ReturnRightDPT
209    stc
210.ReturnRightDPT:
211    ret
212%endif
213
214;--------------------------------------------------------------------
215; FindDPT_ToDSDIforSerialDevice
216;   Parameters:
217;       DS:     RAMVARS segment
218;   Returns:
219;       DS:DI:  Ptr to DPT
220;       CF:     Cleared if wanted DPT found
221;               Set if DPT not found, or no DPTs present
222;   Corrupts registers:
223;       SI
224;--------------------------------------------------------------------
225%ifdef MODULE_SERIAL
226ALIGN JUMP_ALIGN
227FindDPT_ToDSDIforSerialDevice:
228    mov     bl, FLGH_DPT_SERIAL_DEVICE
229    ; Fall to FindDPT_ToDSDIforFlagsHighInBL
230%endif
231
232;--------------------------------------------------------------------
233; FindDPT_ToDSDIforFlagsHighInBL
234;   Parameters:
235;       DS:     RAMVARS segment
236;       BL:     Bit(s) to test in DPT.bFlagsHigh
237;   Returns:
238;       DS:DI:  Ptr to DPT
239;       CF:     Cleared if wanted DPT found
240;               Set if DPT not found, or no DPTs present
241;   Corrupts registers:
242;       SI
243;--------------------------------------------------------------------
244%ifdef MODULE_SERIAL
245;%ifdef MODULE_IRQ
246;ALIGN JUMP_ALIGN
247;FindDPT_ToDSDIforFlagsHighInBL:    ; This label is unused
248;%endif
249    mov     si, IterateToDptWithFlagsHighInBL
250    jmp     SHORT FindDPT_IterateAllDPTs
251%endif
252
253;--------------------------------------------------------------------
254; FindDPT_MasterOrSingleForIdevarsOffsetInDL
255;   Parameters:
256;       DL:     Offset to IDEVARS to search for
257;       DS:     RAMVARS segment
258;   Returns:
259;       DS:DI:  Ptr to first DPT with same IDEVARS as in DL
260;       CF:     Cleared if wanted DPT found
261;               Set if DPT not found, or no DPTs present
262;   Corrupts registers:
263;       SI
264;--------------------------------------------------------------------
265FindDPT_MasterOrSingleForIdevarsOffsetInDL:
266    mov     si, IterateFindFirstDPTforIdevars
267    jmp     SHORT FindDPT_IterateAllDPTs
268
269;--------------------------------------------------------------------
270; FindDPT_SlaveForIdevarsOffsetInDL
271;   Parameters:
272;       DL:     Offset to IDEVARS to search for
273;       DS:     RAMVARS segment
274;   Returns:
275;       DS:DI:  Ptr to second DPT with same IDEVARS as in DL
276;       CF:     Cleared if wanted DPT found
277;               Set if DPT not found, or no DPTs present
278;   Corrupts registers:
279;       SI
280;--------------------------------------------------------------------
281FindDPT_SlaveForIdevarsOffsetInDL:
282    mov     si, IterateFindSecondDPTforIdevars
283    ; Fall to FindDPT_IterateAllDPTs
284
285;--------------------------------------------------------------------
286; Iterates all Disk Parameter Tables.
287;
288; FindDPT_IterateAllDPTs
289;   Parameters:
290;       AX,BX,DX:   Parameters to callback function
291;       CS:SI:      Ptr to callback function
292;                   Callback routine should return CF=clear if found
293;       DS:         RAMVARS segment
294;   Returns:
295;       DS:DI:      Ptr to wanted DPT (if found)
296;                   If not found, points to first empty DPT
297;       CF:         Cleared if wanted DPT found
298;                   Set if DPT not found, or no DPTs present
299;   Corrupts registers:
300;       Nothing unless corrupted by callback function
301;--------------------------------------------------------------------
302ALIGN JUMP_ALIGN
303FindDPT_IterateAllDPTs:
304    push    cx
305
306    mov     di, RAMVARS_size            ; Point DS:DI to first DPT
307    eMOVZX  cx, [RAMVARS.bDrvCnt]
308    jcxz    .NotFound                   ; Return if no drives
309
310ALIGN JUMP_ALIGN
311.LoopWhileDPTsLeft:
312    call    si                          ; Is wanted DPT?
313    jnc     SHORT .Found                ;  If so, return
314    add     di, BYTE LARGEST_DPT_SIZE   ; Point to next DPT
315    loop    .LoopWhileDPTsLeft
316
317ALIGN JUMP_ALIGN
318.NotFound:
319    stc
320
321ALIGN JUMP_ALIGN
322.Found:
323    pop     cx
324    ret
Note: See TracBrowser for help on using the repository browser.