Rev 3908 | Rev 5565 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 3908 | Rev 5201 | ||
---|---|---|---|
1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;; ;; |
2 | ;; ;; |
3 | ;; Copyright (C) KolibriOS team 2004-2013. All rights reserved. ;; |
3 | ;; Copyright (C) KolibriOS team 2004-2013. All rights reserved. ;; |
4 | ;; Distributed under terms of the GNU General Public License ;; |
4 | ;; Distributed under terms of the GNU General Public License ;; |
5 | ;; ;; |
5 | ;; ;; |
6 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
6 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
7 | 7 | ||
8 | $Revision: 3908 $ |
8 | $Revision: 5201 $ |
- | 9 | ||
9 | 10 | search_partitions: |
|
- | 11 | push ecx |
|
10 | search_partitions: |
12 | ; 1. Fill missing parameters in HD_DATA structures. |
- | 13 | xor eax, eax |
|
11 | ; 1. Fill missing parameters in HD_DATA structures. |
14 | mov edx, IDE_controller_1 |
12 | mov eax, [hd_address_table] |
15 | mov ax, [edx + IDE_DATA.BAR0_val] |
13 | mov [hd0_data.hdbase], eax ;0x1f0 |
16 | mov [hd0_data.hdbase], eax |
14 | mov [hd1_data.hdbase], eax |
17 | mov [hd1_data.hdbase], eax |
15 | mov eax, [hd_address_table+16] |
18 | mov ax, [edx + IDE_DATA.BAR2_val] |
- | 19 | mov [hd2_data.hdbase], eax |
|
- | 20 | mov [hd3_data.hdbase], eax |
|
- | 21 | ||
- | 22 | mov edx, IDE_controller_2 |
|
- | 23 | mov ax, [edx + IDE_DATA.BAR0_val] |
|
- | 24 | mov [hd4_data.hdbase], eax |
|
- | 25 | mov [hd5_data.hdbase], eax |
|
- | 26 | mov ax, [edx + IDE_DATA.BAR2_val] |
|
- | 27 | mov [hd6_data.hdbase], eax |
|
- | 28 | mov [hd7_data.hdbase], eax |
|
- | 29 | ||
- | 30 | mov edx, IDE_controller_3 |
|
- | 31 | mov ax, [edx + IDE_DATA.BAR0_val] |
|
- | 32 | mov [hd8_data.hdbase], eax |
|
- | 33 | mov [hd9_data.hdbase], eax |
|
- | 34 | mov ax, [edx + IDE_DATA.BAR2_val] |
|
16 | mov [hd2_data.hdbase], eax |
35 | mov [hd10_data.hdbase], eax |
17 | mov [hd3_data.hdbase], eax |
36 | mov [hd11_data.hdbase], eax |
18 | ; 2. Notify the system about /hd* disks. |
37 | ; 2. Notify the system about /hd* disks. |
19 | ; For every existing disk, call ide_disk_add with correct parameters. |
38 | ; For every existing disk, call ide_disk_add with correct parameters. |
20 | ; Generate name "hdN" on the stack; this is 4 bytes including terminating zero. |
39 | ; Generate name "hdN" on the stack; this is 4 bytes including terminating zero. |
- | 40 | ;----------------------------------------------------------------------------- |
|
21 | ; 2a. /hd0: exists if mask 0x40 in [DRIVE_DATA+1] is set, |
41 | ; 2a. /hd0: exists if mask 0x40 in [DRIVE_DATA+1] is set, |
22 | ; data: hd0_data, |
42 | ; data: hd0_data, |
23 | ; number of partitions: [DRIVE_DATA+2] |
43 | ; number of partitions: [DRIVE_DATA+2] |
24 | test [DRIVE_DATA+1], byte 0x40 |
44 | test [DRIVE_DATA+1], byte 0x40 |
25 | jz @f |
45 | jz @f |
- | 46 | ||
26 | push 'hd0' |
47 | push 'hd0' |
27 | mov eax, esp ; name |
48 | mov eax, esp ; name |
28 | mov edx, hd0_data |
49 | mov edx, hd0_data |
29 | call ide_disk_add |
50 | call ide_disk_add |
30 | mov [DRIVE_DATA+2], al |
51 | mov [DRIVE_DATA+2], al |
31 | pop ecx ; restore the stack |
52 | pop ecx ; restore the stack |
- | 53 | ;----------------------------------------------------------------------------- |
|
32 | @@: |
54 | @@: |
33 | ; 2b. /hd1: exists if mask 0x10 in [DRIVE_DATA+1] is set, |
55 | ; 2b. /hd1: exists if mask 0x10 in [DRIVE_DATA+1] is set, |
34 | ; data: hd1_data, |
56 | ; data: hd1_data, |
35 | ; number of partitions: [DRIVE_DATA+3] |
57 | ; number of partitions: [DRIVE_DATA+3] |
36 | test [DRIVE_DATA+1], byte 0x10 |
58 | test [DRIVE_DATA+1], byte 0x10 |
37 | jz @f |
59 | jz @f |
- | 60 | ||
38 | push 'hd1' |
61 | push 'hd1' |
39 | mov eax, esp |
62 | mov eax, esp |
40 | mov edx, hd1_data |
63 | mov edx, hd1_data |
41 | call ide_disk_add |
64 | call ide_disk_add |
42 | mov [DRIVE_DATA+3], al |
65 | mov [DRIVE_DATA+3], al |
43 | pop ecx |
66 | pop ecx |
- | 67 | ;----------------------------------------------------------------------------- |
|
44 | @@: |
68 | @@: |
45 | ; 2c. /hd2: exists if mask 4 in [DRIVE_DATA+1] is set, |
69 | ; 2c. /hd2: exists if mask 4 in [DRIVE_DATA+1] is set, |
46 | ; data: hd2_data, |
70 | ; data: hd2_data, |
47 | ; number of partitions: [DRIVE_DATA+4] |
71 | ; number of partitions: [DRIVE_DATA+4] |
48 | test [DRIVE_DATA+1], byte 4 |
72 | test [DRIVE_DATA+1], byte 4 |
49 | jz @f |
73 | jz @f |
- | 74 | ||
50 | push 'hd2' |
75 | push 'hd2' |
51 | mov eax, esp |
76 | mov eax, esp |
52 | mov edx, hd2_data |
77 | mov edx, hd2_data |
53 | call ide_disk_add |
78 | call ide_disk_add |
54 | mov [DRIVE_DATA+4], al |
79 | mov [DRIVE_DATA+4], al |
55 | pop ecx |
80 | pop ecx |
- | 81 | ;----------------------------------------------------------------------------- |
|
56 | @@: |
82 | @@: |
57 | ; 2d. /hd3: exists if mask 1 in [DRIVE_DATA+1] is set, |
83 | ; 2d. /hd3: exists if mask 1 in [DRIVE_DATA+1] is set, |
58 | ; data: hd3_data, |
84 | ; data: hd3_data, |
59 | ; number of partitions: [DRIVE_DATA+5] |
85 | ; number of partitions: [DRIVE_DATA+5] |
60 | test [DRIVE_DATA+1], byte 1 |
86 | test [DRIVE_DATA+1], byte 1 |
61 | jz @f |
87 | jz @f |
- | 88 | ||
62 | push 'hd3' |
89 | push 'hd3' |
63 | mov eax, esp |
90 | mov eax, esp |
64 | mov edx, hd3_data |
91 | mov edx, hd3_data |
65 | call ide_disk_add |
92 | call ide_disk_add |
66 | mov [DRIVE_DATA+5], al |
93 | mov [DRIVE_DATA+5], al |
67 | pop ecx |
94 | pop ecx |
- | 95 | ;----------------------------------------------------------------------------- |
|
- | 96 | @@: |
|
- | 97 | ; 2e. /hd4: exists if mask 0x40 in [DRIVE_DATA+6] is set, |
|
- | 98 | ; data: hd4_data, |
|
- | 99 | ; number of partitions: [DRIVE_DATA+7] |
|
- | 100 | test [DRIVE_DATA+6], byte 0x40 |
|
- | 101 | jz @f |
|
- | 102 | ||
- | 103 | push 'hd4' |
|
- | 104 | mov eax, esp ; name |
|
- | 105 | mov edx, hd4_data |
|
- | 106 | call ide_disk_add |
|
- | 107 | mov [DRIVE_DATA+7], al |
|
- | 108 | pop ecx |
|
- | 109 | ;----------------------------------------------------------------------------- |
|
- | 110 | @@: |
|
- | 111 | ; 2f. /hd5: exists if mask 0x10 in [DRIVE_DATA+6] is set, |
|
- | 112 | ; data: hd5_data, |
|
- | 113 | ; number of partitions: [DRIVE_DATA+8] |
|
- | 114 | test [DRIVE_DATA+6], byte 0x10 |
|
- | 115 | jz @f |
|
- | 116 | ||
- | 117 | push 'hd5' |
|
- | 118 | mov eax, esp |
|
- | 119 | mov edx, hd5_data |
|
- | 120 | call ide_disk_add |
|
- | 121 | mov [DRIVE_DATA+8], al |
|
- | 122 | pop ecx |
|
- | 123 | ;----------------------------------------------------------------------------- |
|
- | 124 | @@: |
|
- | 125 | ; 2g. /hd6: exists if mask 4 in [DRIVE_DATA+6] is set, |
|
- | 126 | ; data: hd6_data, |
|
- | 127 | ; number of partitions: [DRIVE_DATA+9] |
|
- | 128 | test [DRIVE_DATA+6], byte 4 |
|
- | 129 | jz @f |
|
- | 130 | ||
- | 131 | push 'hd6' |
|
- | 132 | mov eax, esp |
|
- | 133 | mov edx, hd6_data |
|
- | 134 | call ide_disk_add |
|
- | 135 | mov [DRIVE_DATA+9], al |
|
- | 136 | pop ecx |
|
- | 137 | ;----------------------------------------------------------------------------- |
|
- | 138 | @@: |
|
- | 139 | ; 2h. /hd7: exists if mask 1 in [DRIVE_DATA+6] is set, |
|
- | 140 | ; data: hd7_data, |
|
- | 141 | ; number of partitions: [DRIVE_DATA+10] |
|
- | 142 | test [DRIVE_DATA+6], byte 1 |
|
- | 143 | jz @f |
|
- | 144 | ||
- | 145 | push 'hd7' |
|
- | 146 | mov eax, esp |
|
- | 147 | mov edx, hd7_data |
|
- | 148 | call ide_disk_add |
|
- | 149 | mov [DRIVE_DATA+10], al |
|
- | 150 | pop ecx |
|
- | 151 | ;----------------------------------------------------------------------------- |
|
- | 152 | @@: |
|
- | 153 | ; 2i. /hd8: exists if mask 0x40 in [DRIVE_DATA+11] is set, |
|
- | 154 | ; data: hd8_data, |
|
- | 155 | ; number of partitions: [DRIVE_DATA+12] |
|
- | 156 | test [DRIVE_DATA+11], byte 0x40 |
|
- | 157 | jz @f |
|
- | 158 | ||
- | 159 | push 'hd8' |
|
- | 160 | mov eax, esp ; name |
|
- | 161 | mov edx, hd8_data |
|
- | 162 | call ide_disk_add |
|
- | 163 | mov [DRIVE_DATA+12], al |
|
- | 164 | pop ecx |
|
- | 165 | ;----------------------------------------------------------------------------- |
|
- | 166 | @@: |
|
- | 167 | ; 2j. /hd9: exists if mask 0x10 in [DRIVE_DATA+11] is set, |
|
- | 168 | ; data: hd9_data, |
|
- | 169 | ; number of partitions: [DRIVE_DATA+13] |
|
- | 170 | test [DRIVE_DATA+11], byte 0x10 |
|
- | 171 | jz @f |
|
- | 172 | ||
- | 173 | push 'hd9' |
|
- | 174 | mov eax, esp |
|
- | 175 | mov edx, hd9_data |
|
- | 176 | call ide_disk_add |
|
- | 177 | mov [DRIVE_DATA+13], al |
|
- | 178 | pop ecx |
|
- | 179 | ;----------------------------------------------------------------------------- |
|
- | 180 | @@: |
|
- | 181 | ; 2k. /hd10: exists if mask 4 in [DRIVE_DATA+11] is set, |
|
- | 182 | ; data: hd10_data, |
|
- | 183 | ; number of partitions: [DRIVE_DATA+14] |
|
- | 184 | test [DRIVE_DATA+14], byte 4 |
|
- | 185 | jz @f |
|
- | 186 | ||
- | 187 | push 'hd10' |
|
- | 188 | mov eax, esp |
|
- | 189 | mov edx, hd10_data |
|
- | 190 | call ide_disk_add |
|
- | 191 | mov [DRIVE_DATA+9], al |
|
- | 192 | pop ecx |
|
- | 193 | ;----------------------------------------------------------------------------- |
|
- | 194 | @@: |
|
- | 195 | ; 2l. /hd11: exists if mask 1 in [DRIVE_DATA+11] is set, |
|
- | 196 | ; data: hd11_data, |
|
- | 197 | ; number of partitions: [DRIVE_DATA+15] |
|
- | 198 | test [DRIVE_DATA+11], byte 1 |
|
- | 199 | jz @f |
|
- | 200 | ||
- | 201 | push 'hd11' |
|
- | 202 | mov eax, esp |
|
- | 203 | mov edx, hd11_data |
|
- | 204 | call ide_disk_add |
|
- | 205 | mov [DRIVE_DATA+15], al |
|
- | 206 | pop ecx |
|
- | 207 | ;----------------------------------------------------------------------------- |
|
68 | @@: |
208 | @@: |
69 | ; 3. Notify the system about /bd* disks. |
209 | ; 3. Notify the system about /bd* disks. |
70 | ; 3a. Check whether there are BIOS disks. If no, skip step 3. |
210 | ; 3a. Check whether there are BIOS disks. If no, skip step 3. |
71 | xor esi, esi |
211 | xor esi, esi |
72 | cmp esi, [NumBiosDisks] |
212 | cmp esi, [NumBiosDisks] |
73 | jz .nobd |
213 | jz .nobd |
74 | ; Loop over all disks. |
214 | ; Loop over all disks. |
75 | push 0 |
215 | push 0 |
76 | push 'bd' |
216 | push 'bd' |
77 | .bdloop: |
217 | .bdloop: |
78 | ; 3b. Get the drive number for using in /bd* name. |
218 | ; 3b. Get the drive number for using in /bd* name. |
79 | movzx eax, byte [BiosDisksData+esi*4] |
219 | movzx eax, byte [BiosDisksData+esi*4] |
80 | sub al, 80h |
220 | sub al, 80h |
81 | ; 3c. Convert eax to decimal and store starting with [esp+3]. |
221 | ; 3c. Convert eax to decimal and store starting with [esp+3]. |
82 | ; First 2 bytes in [esp] are "bd". |
222 | ; First 2 bytes in [esp] are "bd". |
83 | lea edi, [esp+2] |
223 | lea edi, [esp+2] |
84 | ; store digits in the stack, ending with -'0' |
224 | ; store digits in the stack, ending with -'0' |
85 | push -'0' |
225 | push -'0' |
86 | @@: |
226 | @@: |
87 | xor edx, edx |
227 | xor edx, edx |
88 | iglobal |
228 | iglobal |
89 | align 4 |
229 | align 4 |
90 | _10 dd 10 |
230 | _10 dd 10 |
91 | endg |
231 | endg |
92 | div [_10] |
232 | div [_10] |
93 | push edx |
233 | push edx |
94 | test eax, eax |
234 | test eax, eax |
95 | jnz @b |
235 | jnz @b |
96 | ; restore digits from the stack, this reverses the order; |
236 | ; restore digits from the stack, this reverses the order; |
97 | ; add '0', stop, when zero is reached |
237 | ; add '0', stop, when zero is reached |
98 | @@: |
238 | @@: |
99 | pop eax |
239 | pop eax |
100 | add al, '0' |
240 | add al, '0' |
101 | stosb |
241 | stosb |
102 | jnz @b |
242 | jnz @b |
103 | ; 3e. Call the API with userdata = 80h + ecx. |
243 | ; 3e. Call the API with userdata = 80h + ecx. |
104 | mov eax, esp |
244 | mov eax, esp |
105 | lea edx, [esi+80h] |
245 | lea edx, [esi+80h] |
106 | stdcall disk_add, bd_callbacks, eax, edx, 0 |
246 | stdcall disk_add, bd_callbacks, eax, edx, 0 |
107 | test eax, eax |
247 | test eax, eax |
108 | jz @f |
248 | jz @f |
109 | stdcall disk_media_changed, eax, 1 |
249 | stdcall disk_media_changed, eax, 1 |
110 | @@: |
250 | @@: |
111 | ; 3f. Continue the loop. |
251 | ; 3f. Continue the loop. |
112 | inc esi |
252 | inc esi |
113 | cmp esi, [NumBiosDisks] |
253 | cmp esi, [NumBiosDisks] |
114 | jnz .bdloop |
254 | jnz .bdloop |
115 | pop ecx ecx ; restore stack after name |
255 | pop ecx ecx ; restore stack after name |
116 | .nobd: |
256 | .nobd: |
117 | jmp end_search_partitions |
257 | jmp end_search_partitions |
118 | - | ||
- | 258 | ;----------------------------------------------------------------------------- |
|
119 | ; Helper procedure for search_partitions, adds one IDE disk. |
259 | ; Helper procedure for search_partitions, adds one IDE disk. |
120 | ; For compatibility, number of partitions for IDE disks is kept in a separate variable, |
260 | ; For compatibility, number of partitions for IDE disks is kept in a separate |
121 | ; so the procedure returns number of partitions. |
261 | ; variable, so the procedure returns number of partitions. |
122 | ; eax -> name, edx -> disk data |
262 | ; eax -> name, edx -> disk data |
123 | proc ide_disk_add |
263 | proc ide_disk_add |
124 | stdcall disk_add, ide_callbacks, eax, edx, 0 |
264 | stdcall disk_add, ide_callbacks, eax, edx, 0 |
125 | test eax, eax |
265 | test eax, eax |
126 | jz @f |
266 | jz @f |
127 | push eax |
267 | push eax |
128 | stdcall disk_media_changed, eax, 1 |
268 | stdcall disk_media_changed, eax, 1 |
129 | pop eax |
269 | pop eax |
130 | mov eax, [eax+DISK.NumPartitions] |
270 | mov eax, [eax+DISK.NumPartitions] |
131 | cmp eax, 255 |
271 | cmp eax, 255 |
132 | jbe @f |
272 | jbe @f |
133 | mov eax, 255 |
273 | mov eax, 255 |
134 | @@: |
274 | @@: |
135 | ret |
275 | ret |
136 | endp |
276 | endp |
137 | - | ||
- | 277 | ;----------------------------------------------------------------------------- |
|
138 | end_search_partitions: |
278 | end_search_partitions: |
139 | - | ||
- | 279 | pop ecx |