Subversion Repositories Kolibri OS

Rev

Rev 5565 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
431 serge 1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                              ;;
5565 serge 3
;; Copyright (C) KolibriOS team 2004-2015. All rights reserved. ;;
431 serge 4
;; Distributed under terms of the GNU General Public License    ;;
5
;;                                                              ;;
6
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
593 mikedld 7
 
8
$Revision: 5984 $
9
 
3908 Serge 10
search_partitions:
5201 serge 11
        push    ecx
3908 Serge 12
; 1. Fill missing parameters in HD_DATA structures.
5201 serge 13
        xor     eax, eax
14
        mov     edx, IDE_controller_1
15
        mov     ax, [edx + IDE_DATA.BAR0_val]
5984 serge 16
        mov     [hd0_data.hdbase], ax
17
        mov     [hd1_data.hdbase], ax
5201 serge 18
        mov     ax, [edx + IDE_DATA.BAR2_val]
5984 serge 19
        mov     [hd2_data.hdbase], ax
20
        mov     [hd3_data.hdbase], ax
5201 serge 21
 
22
        mov     edx, IDE_controller_2
23
        mov     ax, [edx + IDE_DATA.BAR0_val]
5984 serge 24
        mov     [hd4_data.hdbase], ax
25
        mov     [hd5_data.hdbase], ax
5201 serge 26
        mov     ax, [edx + IDE_DATA.BAR2_val]
5984 serge 27
        mov     [hd6_data.hdbase], ax
28
        mov     [hd7_data.hdbase], ax
5201 serge 29
 
30
        mov     edx, IDE_controller_3
31
        mov     ax, [edx + IDE_DATA.BAR0_val]
5984 serge 32
        mov     [hd8_data.hdbase], ax
33
        mov     [hd9_data.hdbase], ax
5201 serge 34
        mov     ax, [edx + IDE_DATA.BAR2_val]
5984 serge 35
        mov     [hd10_data.hdbase], ax
36
        mov     [hd11_data.hdbase], ax
3908 Serge 37
; 2. Notify the system about /hd* disks.
38
; For every existing disk, call ide_disk_add with correct parameters.
39
; Generate name "hdN" on the stack; this is 4 bytes including terminating zero.
5201 serge 40
;-----------------------------------------------------------------------------
3908 Serge 41
; 2a. /hd0: exists if mask 0x40 in [DRIVE_DATA+1] is set,
42
;     data: hd0_data,
43
;     number of partitions: [DRIVE_DATA+2]
2434 Serge 44
        test    [DRIVE_DATA+1], byte 0x40
3908 Serge 45
        jz      @f
5201 serge 46
 
3908 Serge 47
        push    'hd0'
48
        mov     eax, esp        ; name
49
        mov     edx, hd0_data
50
        call    ide_disk_add
51
        mov     [DRIVE_DATA+2], al
52
        pop     ecx             ; restore the stack
5201 serge 53
;-----------------------------------------------------------------------------
3908 Serge 54
@@:
55
; 2b. /hd1: exists if mask 0x10 in [DRIVE_DATA+1] is set,
56
;     data: hd1_data,
57
;     number of partitions: [DRIVE_DATA+3]
2434 Serge 58
        test    [DRIVE_DATA+1], byte 0x10
3908 Serge 59
        jz      @f
5201 serge 60
 
3908 Serge 61
        push    'hd1'
62
        mov     eax, esp
63
        mov     edx, hd1_data
64
        call    ide_disk_add
65
        mov     [DRIVE_DATA+3], al
709 diamond 66
        pop     ecx
5201 serge 67
;-----------------------------------------------------------------------------
3908 Serge 68
@@:
69
; 2c. /hd2: exists if mask 4 in [DRIVE_DATA+1] is set,
70
;     data: hd2_data,
71
;     number of partitions: [DRIVE_DATA+4]
72
        test    [DRIVE_DATA+1], byte 4
73
        jz      @f
5201 serge 74
 
3908 Serge 75
        push    'hd2'
76
        mov     eax, esp
77
        mov     edx, hd2_data
78
        call    ide_disk_add
79
        mov     [DRIVE_DATA+4], al
80
        pop     ecx
5201 serge 81
;-----------------------------------------------------------------------------
3908 Serge 82
@@:
83
; 2d. /hd3: exists if mask 1 in [DRIVE_DATA+1] is set,
84
;     data: hd3_data,
85
;     number of partitions: [DRIVE_DATA+5]
86
        test    [DRIVE_DATA+1], byte 1
87
        jz      @f
5201 serge 88
 
3908 Serge 89
        push    'hd3'
90
        mov     eax, esp
91
        mov     edx, hd3_data
92
        call    ide_disk_add
93
        mov     [DRIVE_DATA+5], al
94
        pop     ecx
5201 serge 95
;-----------------------------------------------------------------------------
3908 Serge 96
@@:
5201 serge 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
;-----------------------------------------------------------------------------
208
@@:
3908 Serge 209
; 3. Notify the system about /bd* disks.
210
; 3a. Check whether there are BIOS disks. If no, skip step 3.
211
        xor     esi, esi
212
        cmp     esi, [NumBiosDisks]
213
        jz      .nobd
214
; Loop over all disks.
215
        push    0
216
        push    'bd'
217
.bdloop:
218
; 3b. Get the drive number for using in /bd* name.
219
        movzx   eax, byte [BiosDisksData+esi*4]
220
        sub     al, 80h
221
; 3c. Convert eax to decimal and store starting with [esp+3].
222
; First 2 bytes in [esp] are "bd".
223
        lea     edi, [esp+2]
224
; store digits in the stack, ending with -'0'
225
        push    -'0'
226
@@:
227
        xor     edx, edx
228
iglobal
229
align 4
230
_10     dd      10
231
endg
232
        div     [_10]
233
        push    edx
234
        test    eax, eax
235
        jnz     @b
236
; restore digits from the stack, this reverses the order;
237
; add '0', stop, when zero is reached
238
@@:
239
        pop     eax
240
        add     al, '0'
241
        stosb
242
        jnz     @b
243
; 3e. Call the API with userdata = 80h + ecx.
244
        mov     eax, esp
245
        lea     edx, [esi+80h]
246
        stdcall disk_add, bd_callbacks, eax, edx, 0
247
        test    eax, eax
248
        jz      @f
249
        stdcall disk_media_changed, eax, 1
250
@@:
251
; 3f. Continue the loop.
252
        inc     esi
253
        cmp     esi, [NumBiosDisks]
254
        jnz     .bdloop
255
        pop     ecx ecx ; restore stack after name
256
.nobd:
709 diamond 257
        jmp     end_search_partitions
5201 serge 258
;-----------------------------------------------------------------------------
3908 Serge 259
; Helper procedure for search_partitions, adds one IDE disk.
5201 serge 260
; For compatibility, number of partitions for IDE disks is kept in a separate
261
; variable, so the procedure returns number of partitions.
3908 Serge 262
; eax -> name, edx -> disk data
263
proc ide_disk_add
264
        stdcall disk_add, ide_callbacks, eax, edx, 0
265
        test    eax, eax
266
        jz      @f
267
        push    eax
268
        stdcall disk_media_changed, eax, 1
269
        pop     eax
270
        mov     eax, [eax+DISK.NumPartitions]
271
        cmp     eax, 255
272
        jbe     @f
273
        mov     eax, 255
274
@@:
2434 Serge 275
        ret
3908 Serge 276
endp
5201 serge 277
;-----------------------------------------------------------------------------
278
end_search_partitions:
279
        pop     ecx