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

Last change on this file since 261 was 259, checked in by gregli@…, 12 years ago

For function int13/0h, restored the code to only reset the floppy drives if a floppy drive was passed in for reset. Other minor optimizations. Better create new floppy support in Serial Server.

File size: 7.1 KB
RevLine 
[150]1; Project name : XTIDE Universal BIOS
[3]2; Description : Functions for finding Disk Parameter Table.
3
4; Section containing code
5SECTION .text
6
7;--------------------------------------------------------------------
8; Finds pointer to first unused Disk Parameter Table.
9;
[150]10; FindDPT_ForNewDriveToDSDI
[3]11; Parameters:
12; DS: RAMVARS segment
13; Returns:
14; DS:DI: Ptr to first unused DPT
15; Corrupts registers:
[258]16; DX
[150]17;--------------------------------------------------------------------
18ALIGN JUMP_ALIGN
19FindDPT_ForNewDriveToDSDI:
[258]20 mov ax, [RAMVARS.wDrvCntAndFirst]
21 add al, ah
22%ifdef MODULE_SERIAL_FLOPPY
23 add al, [RAMVARS.xlateVars+XLATEVARS.bFlopCreateCnt]
24%endif
[259]25 xchg ax, dx
26 ; fall-through to FindDPT_ForDriveNumber
[150]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:
[3]39; Nothing
40;--------------------------------------------------------------------
41ALIGN JUMP_ALIGN
[150]42FindDPT_ForDriveNumber:
43 push dx
[161]44 xchg di, ax ; Save the contents of AX in DI
[3]45
[258]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
[150]60 mov al, LARGEST_DPT_SIZE
[258]61
[150]62 mul dl
63 add ax, BYTE RAMVARS_size
[3]64
[258]65 xchg di, ax ; Restore AX and put result in DI
[150]66 pop dx
[259]67
[150]68 ret
69
[3]70;--------------------------------------------------------------------
[259]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;--------------------------------------------------------------------
84ALIGN JUMP_ALIGN
85RamVars_IsDriveHandledByThisBIOS_And_FindDPT_ForDriveNumber:
86 call RamVars_IsDriveHandledByThisBIOS
87 jnc FindDPT_ForDriveNumber
88 ret
89
90
91;--------------------------------------------------------------------
[3]92; Finds Disk Parameter Table for
93; Master or Slave drive at wanted port.
94;
[150]95; FindDPT_ToDSDIForIdeMasterAtPortDX
96; FindDPT_ToDSDIForIdeSlaveAtPortDX
[3]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:
[150]106; SI
[200]107;
108; Converted to macros since there is only once call site for each of these
109;
[3]110;--------------------------------------------------------------------
[200]111
112%macro FindDPT_ToDSDIForIdeMasterAtPortDX 0
[152]113 mov si, IterateToMasterAtPortCallback
[200]114 call IterateAllDPTs
115%endmacro
[3]116
[200]117%macro FindDPT_ToDSDIForIdeSlaveAtPortDX 0
[152]118 mov si, IterateToSlaveAtPortCallback
[200]119 call IterateAllDPTs
120%endmacro
[3]121
[200]122
[3]123;--------------------------------------------------------------------
124; Iteration callback for finding DPT using
125; IDE base port for Master or Slave drive.
126;
[152]127; IterateToSlaveAtPortCallback
128; IterateToMasterAtPortCallback
[3]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;--------------------------------------------------------------------
138ALIGN JUMP_ALIGN
[152]139IterateToSlaveAtPortCallback:
[158]140 test BYTE [di+DPT.bFlagsLow], FLGL_DPT_SLAVE ; Clears CF
[150]141 jnz SHORT CompareBasePortAddress
142 ret ; Wrong DPT
[3]143
144ALIGN JUMP_ALIGN
[152]145IterateToMasterAtPortCallback:
[158]146 test BYTE [di+DPT.bFlagsLow], FLGL_DPT_SLAVE
[150]147 jnz SHORT ReturnWrongDPT ; Return if slave drive
[3]148
[150]149CompareBasePortAddress:
[3]150 push bx
[150]151 eMOVZX bx, BYTE [di+DPT.bIdevarsOffset] ; CS:BX now points to IDEVARS
152 cmp dx, [cs:bx+IDEVARS.wPort] ; Wanted port?
[3]153 pop bx
[150]154 jne SHORT ReturnWrongDPT
[200]155
156ReturnRightDPT:
[150]157 stc ; Set CF since wanted DPT
[3]158 ret
[152]159
160
161;--------------------------------------------------------------------
[233]162; IterateToDptWithFlagsHighInBL
[152]163; Parameters:
164; DS:DI: Ptr to DPT to examine
[233]165; BL: Bit(s) to test in DPT.bFlagsHigh
[152]166; Returns:
167; CF: Set if wanted DPT found
168; Cleared if wrong DPT
169; Corrupts registers:
170; Nothing
171;--------------------------------------------------------------------
172ALIGN JUMP_ALIGN
[233]173IterateToDptWithFlagsHighInBL:
174 test BYTE [di+DPT.bFlagsHigh], bl ; Clears CF (but we need the clc
175 ; below anyway for callers above)
[200]176 jnz SHORT ReturnRightDPT
177
[150]178ReturnWrongDPT:
[152]179 clc ; Clear CF since wrong DPT
[3]180 ret
181
182;--------------------------------------------------------------------
[233]183; FindDPT_ToDSDIforSerialDevice
[161]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:
[203]191; SI
[161]192;--------------------------------------------------------------------
[233]193ALIGN JUMP_ALIGN
194FindDPT_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;--------------------------------------------------------------------
[161]210ALIGN JUMP_ALIGN
[233]211FindDPT_ToDSDIforFlagsHighInBL:
212 mov si, IterateToDptWithFlagsHighInBL
[161]213 ; Fall to IterateAllDPTs
214
215;--------------------------------------------------------------------
[3]216; Iterates all Disk Parameter Tables.
217;
[150]218; IterateAllDPTs
[3]219; Parameters:
[152]220; AX,BX,DX: Parameters to callback function
221; CS:SI: Ptr to callback function
222; DS: RAMVARS segment
[3]223; Returns:
[152]224; DS:DI: Ptr to wanted DPT (if found)
[258]225; If not found, points to first empty DPT
[152]226; CF: Set if wanted DPT found
[200]227; Cleared if DPT not found, or no DPTs present
[3]228; Corrupts registers:
[150]229; Nothing unless corrupted by callback function
[3]230;--------------------------------------------------------------------
231ALIGN JUMP_ALIGN
[150]232IterateAllDPTs:
[3]233 push cx
[258]234
235 mov di, RAMVARS_size ; Point DS:DI to first DPT
236
[259]237 mov cl, [RAMVARS.bDrvCnt]
238 xor ch, ch ; Clears CF
[258]239
[259]240 jcxz .AllDptsIterated ; Return if no drives, CF will be clear from xor above
241
[3]242ALIGN JUMP_ALIGN
243.LoopWhileDPTsLeft:
244 call si ; Is wanted DPT?
[150]245 jc SHORT .AllDptsIterated ; If so, return
[259]246 add di, BYTE LARGEST_DPT_SIZE ; Point to next DPT, clears CF
[258]247 loop .LoopWhileDPTsLeft
[259]248
249 ; fall-through: DPT was not found, CF is already clear from ADD di inside the loop
[258]250
[3]251ALIGN JUMP_ALIGN
[150]252.AllDptsIterated:
[3]253 pop cx
254 ret
[259]255
Note: See TracBrowser for help on using the repository browser.