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 | ; 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 | ;-------------------------------------------------------------------- |
---|
18 | ALIGN JUMP_ALIGN |
---|
19 | FindDPT_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 | ;-------------------------------------------------------------------- |
---|
38 | ALIGN JUMP_ALIGN |
---|
39 | FindDPT_ForDriveNumber: |
---|
40 | push dx |
---|
41 | push ax |
---|
42 | |
---|
43 | mov al, LARGEST_DPT_SIZE |
---|
44 | sub dl, [RAMVARS.bFirstDrv] |
---|
45 | mul dl |
---|
46 | add ax, BYTE RAMVARS_size |
---|
47 | xchg di, ax |
---|
48 | |
---|
49 | pop ax |
---|
50 | pop dx |
---|
51 | ret |
---|
52 | |
---|
53 | |
---|
54 | ;-------------------------------------------------------------------- |
---|
55 | ; Finds Disk Parameter Table for |
---|
56 | ; Master or Slave drive at wanted port. |
---|
57 | ; |
---|
58 | ; FindDPT_ToDSDIForIdeMasterAtPortDX |
---|
59 | ; FindDPT_ToDSDIForIdeSlaveAtPortDX |
---|
60 | ; Parameters: |
---|
61 | ; DX: IDE Base Port address |
---|
62 | ; DS: RAMVARS segment |
---|
63 | ; Returns: |
---|
64 | ; DL: Drive number (if DPT found) |
---|
65 | ; DS:DI: Ptr to DPT |
---|
66 | ; CF: Set if wanted DPT found |
---|
67 | ; Cleared if DPT not found |
---|
68 | ; Corrupts registers: |
---|
69 | ; SI |
---|
70 | ;-------------------------------------------------------------------- |
---|
71 | ALIGN JUMP_ALIGN |
---|
72 | FindDPT_ToDSDIForIdeMasterAtPortDX: |
---|
73 | mov si, FindDPT_IterateToMasterAtPortCallback |
---|
74 | jmp SHORT IterateAllDPTs |
---|
75 | |
---|
76 | ALIGN JUMP_ALIGN |
---|
77 | FindDPT_ToDSDIForIdeSlaveAtPortDX: |
---|
78 | mov si, FindDPT_IterateToSlaveAtPortCallback |
---|
79 | jmp SHORT IterateAllDPTs |
---|
80 | |
---|
81 | ;-------------------------------------------------------------------- |
---|
82 | ; Iteration callback for finding DPT using |
---|
83 | ; IDE base port for Master or Slave drive. |
---|
84 | ; |
---|
85 | ; FindDPT_IterateToSlaveAtPortCallback |
---|
86 | ; FindDPT_IterateToMasterAtPortCallback |
---|
87 | ; Parameters: |
---|
88 | ; CH: Drive number |
---|
89 | ; DX: IDE Base Port address |
---|
90 | ; DS:DI: Ptr to DPT to examine |
---|
91 | ; Returns: |
---|
92 | ; DL: Drive number if correct DPT |
---|
93 | ; CF: Set if wanted DPT found |
---|
94 | ; Cleared if wrong DPT |
---|
95 | ; Corrupts registers: |
---|
96 | ; Nothing |
---|
97 | ;-------------------------------------------------------------------- |
---|
98 | ALIGN JUMP_ALIGN |
---|
99 | FindDPT_IterateToSlaveAtPortCallback: |
---|
100 | test BYTE [di+DPT.wFlags], FLG_DPT_SLAVE ; Clears CF |
---|
101 | jnz SHORT CompareBasePortAddress |
---|
102 | ret ; Wrong DPT |
---|
103 | |
---|
104 | ALIGN JUMP_ALIGN |
---|
105 | FindDPT_IterateToMasterAtPortCallback: |
---|
106 | test BYTE [di+DPT.wFlags], FLG_DPT_SLAVE |
---|
107 | jnz SHORT ReturnWrongDPT ; Return if slave drive |
---|
108 | |
---|
109 | CompareBasePortAddress: |
---|
110 | push bx |
---|
111 | eMOVZX bx, BYTE [di+DPT.bIdevarsOffset] ; CS:BX now points to IDEVARS |
---|
112 | cmp dx, [cs:bx+IDEVARS.wPort] ; Wanted port? |
---|
113 | pop bx |
---|
114 | jne SHORT ReturnWrongDPT |
---|
115 | mov dl, ch ; Return drive number in DL |
---|
116 | stc ; Set CF since wanted DPT |
---|
117 | ret |
---|
118 | ReturnWrongDPT: |
---|
119 | clc ; Clear CF since wrong DPT |
---|
120 | ret |
---|
121 | |
---|
122 | |
---|
123 | ;-------------------------------------------------------------------- |
---|
124 | ; Iterates all Disk Parameter Tables. |
---|
125 | ; |
---|
126 | ; IterateAllDPTs |
---|
127 | ; Parameters: |
---|
128 | ; BX,DX: Parameters to callback function |
---|
129 | ; CS:SI: Ptr to callback function |
---|
130 | ; DS: RAMVARS segment |
---|
131 | ; Returns: |
---|
132 | ; DS:DI: Ptr to wanted DPT (if found) |
---|
133 | ; CF: Set if wanted DPT found |
---|
134 | ; Cleared if DPT not found |
---|
135 | ; Corrupts registers: |
---|
136 | ; Nothing unless corrupted by callback function |
---|
137 | ;-------------------------------------------------------------------- |
---|
138 | ALIGN JUMP_ALIGN |
---|
139 | IterateAllDPTs: |
---|
140 | push cx |
---|
141 | mov cx, [RAMVARS.wDrvCntAndFirst] |
---|
142 | jcxz .AllDptsIterated ; Return if no drives |
---|
143 | call FindDPT_PointToFirstDPT ; Point DS:DI to first DPT |
---|
144 | ALIGN JUMP_ALIGN |
---|
145 | .LoopWhileDPTsLeft: |
---|
146 | call si ; Is wanted DPT? |
---|
147 | jc SHORT .AllDptsIterated ; If so, return |
---|
148 | inc ch ; Increment drive number |
---|
149 | add di, BYTE LARGEST_DPT_SIZE ; Point to next DPT |
---|
150 | dec cl ; Decrement drives left |
---|
151 | jnz SHORT .LoopWhileDPTsLeft |
---|
152 | clc ; Clear CF since DPT not found |
---|
153 | ALIGN JUMP_ALIGN |
---|
154 | .AllDptsIterated: |
---|
155 | pop cx |
---|
156 | ret |
---|
157 | |
---|
158 | |
---|
159 | ;-------------------------------------------------------------------- |
---|
160 | ; Sets DI to point to first Disk Parameter Table. |
---|
161 | ; |
---|
162 | ; FindDPT_PointToFirstDPT |
---|
163 | ; Parameters: |
---|
164 | ; Nothing |
---|
165 | ; Returns: |
---|
166 | ; DI: Offset to first DPT (even if unused) |
---|
167 | ; Corrupts registers: |
---|
168 | ; Nothing |
---|
169 | ;-------------------------------------------------------------------- |
---|
170 | ALIGN JUMP_ALIGN |
---|
171 | FindDPT_PointToFirstDPT: |
---|
172 | mov di, RAMVARS_size |
---|
173 | ret |
---|