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

Last change on this file since 190 was 181, checked in by krille_n_@…, 13 years ago

Changes to all parts of the project:

  • Size optimizations.
  • Added a define (EXCLUDE_FROM_XTIDECFG) to exclude unused library code from XTIDECFG.
  • Tried to minimize time spent with interrupts disabled.
  • Some minor attempts to improve speed (reordering instructions etc).
  • Tried to improve readability, did some cleanup and fixed some errors in comments.
File size: 5.4 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; Finds pointer to first unused Disk Parameter Table.
9;
10; FindDPT_ForNewDriveToDSDI
11; Parameters:
12; DS: RAMVARS segment
13; Returns:
14; DS:DI: Ptr to first unused DPT
15; Corrupts registers:
16; DL
17;--------------------------------------------------------------------
18ALIGN JUMP_ALIGN
19FindDPT_ForNewDriveToDSDI:
20 mov dl, [RAMVARS.bFirstDrv]
21 add dl, [RAMVARS.bDrvCnt]
22 ; Fall to FindDPT_ForDriveNumber
23
24
25;--------------------------------------------------------------------
26; Finds Disk Parameter Table for drive number.
27; IDE Base Port address will be stored to RAMVARS if correct DPT is found.
28;
29; FindDPT_ForDriveNumber
30; Parameters:
31; DL: Drive number
32; DS: RAMVARS segment
33; Returns:
34; DS:DI: Ptr to DPT
35; Corrupts registers:
36; Nothing
37;--------------------------------------------------------------------
38ALIGN JUMP_ALIGN
39FindDPT_ForDriveNumber:
40 push dx
41 xchg di, ax ; Save the contents of AX in DI
42
43 mov al, LARGEST_DPT_SIZE
44 sub dl, [RAMVARS.bFirstDrv]
45 mul dl
46 add ax, BYTE RAMVARS_size
47
48 xchg di, ax ; Restore AX and put result in DI
49 pop dx
50 ret
51
52
53;--------------------------------------------------------------------
54; Finds Disk Parameter Table for
55; Master or Slave drive at wanted port.
56;
57; FindDPT_ToDSDIForIdeMasterAtPortDX
58; FindDPT_ToDSDIForIdeSlaveAtPortDX
59; Parameters:
60; DX: IDE Base Port address
61; DS: RAMVARS segment
62; Returns:
63; DL: Drive number (if DPT found)
64; DS:DI: Ptr to DPT
65; CF: Set if wanted DPT found
66; Cleared if DPT not found
67; Corrupts registers:
68; SI
69;--------------------------------------------------------------------
70ALIGN JUMP_ALIGN
71FindDPT_ToDSDIForIdeMasterAtPortDX:
72 mov si, IterateToMasterAtPortCallback
73 jmp SHORT IterateAllDPTs
74
75ALIGN JUMP_ALIGN
76FindDPT_ToDSDIForIdeSlaveAtPortDX:
77 mov si, IterateToSlaveAtPortCallback
78 jmp SHORT IterateAllDPTs
79
80;--------------------------------------------------------------------
81; Iteration callback for finding DPT using
82; IDE base port for Master or Slave drive.
83;
84; IterateToSlaveAtPortCallback
85; IterateToMasterAtPortCallback
86; Parameters:
87; CH: Drive number
88; DX: IDE Base Port address
89; DS:DI: Ptr to DPT to examine
90; Returns:
91; DL: Drive number if correct DPT
92; CF: Set if wanted DPT found
93; Cleared if wrong DPT
94; Corrupts registers:
95; Nothing
96;--------------------------------------------------------------------
97ALIGN JUMP_ALIGN
98IterateToSlaveAtPortCallback:
99 test BYTE [di+DPT.bFlagsLow], FLGL_DPT_SLAVE ; Clears CF
100 jnz SHORT CompareBasePortAddress
101 ret ; Wrong DPT
102
103ALIGN JUMP_ALIGN
104IterateToMasterAtPortCallback:
105 test BYTE [di+DPT.bFlagsLow], FLGL_DPT_SLAVE
106 jnz SHORT ReturnWrongDPT ; Return if slave drive
107
108CompareBasePortAddress:
109 push bx
110 eMOVZX bx, BYTE [di+DPT.bIdevarsOffset] ; CS:BX now points to IDEVARS
111 cmp dx, [cs:bx+IDEVARS.wPort] ; Wanted port?
112 pop bx
113 jne SHORT ReturnWrongDPT
114 mov dl, ch ; Return drive number in DL
115 stc ; Set CF since wanted DPT
116 ret
117
118
119;--------------------------------------------------------------------
120; IterateToDptWithInterruptInServiceFlagSet
121; Parameters:
122; DS:DI: Ptr to DPT to examine
123; Returns:
124; CF: Set if wanted DPT found
125; Cleared if wrong DPT
126; Corrupts registers:
127; Nothing
128;--------------------------------------------------------------------
129ALIGN JUMP_ALIGN
130IterateToDptWithInterruptInServiceFlagSet:
131 test BYTE [di+DPT.bFlagsHigh], FLGH_DPT_INTERRUPT_IN_SERVICE
132 jz SHORT ReturnWrongDPT
133 stc ; Set CF since wanted DPT
134 ret
135ReturnWrongDPT:
136 clc ; Clear CF since wrong DPT
137 ret
138
139
140;--------------------------------------------------------------------
141; FindDPT_ToDSDIforInterruptInService
142; Parameters:
143; DS: RAMVARS segment
144; Returns:
145; DS:DI: Ptr to DPT
146; CF: Set if wanted DPT found
147; Cleared if DPT not found
148; Corrupts registers:
149; SI
150;--------------------------------------------------------------------
151ALIGN JUMP_ALIGN
152FindDPT_ToDSDIforInterruptInService:
153 mov si, IterateToDptWithInterruptInServiceFlagSet
154 ; Fall to IterateAllDPTs
155
156
157;--------------------------------------------------------------------
158; Iterates all Disk Parameter Tables.
159;
160; IterateAllDPTs
161; Parameters:
162; AX,BX,DX: Parameters to callback function
163; CS:SI: Ptr to callback function
164; DS: RAMVARS segment
165; Returns:
166; DS:DI: Ptr to wanted DPT (if found)
167; CF: Set if wanted DPT found
168; Cleared if DPT not found
169; Unchanged if no drives
170; Corrupts registers:
171; Nothing unless corrupted by callback function
172;--------------------------------------------------------------------
173ALIGN JUMP_ALIGN
174IterateAllDPTs:
175 push cx
176 mov cx, [RAMVARS.wDrvCntAndFirst]
177 jcxz .AllDptsIterated ; Return if no drives
178 mov di, RAMVARS_size ; Point DS:DI to first DPT
179ALIGN JUMP_ALIGN
180.LoopWhileDPTsLeft:
181 call si ; Is wanted DPT?
182 jc SHORT .AllDptsIterated ; If so, return
183 inc ch ; Increment drive number
184 add di, BYTE LARGEST_DPT_SIZE ; Point to next DPT
185 dec cl ; Decrement drives left
186 jnz SHORT .LoopWhileDPTsLeft
187 clc ; Clear CF since DPT not found
188ALIGN JUMP_ALIGN
189.AllDptsIterated:
190 pop cx
191 ret
Note: See TracBrowser for help on using the repository browser.