Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
2288 clevermous 1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                              ;;
5363 yogev_ezra 3
;; Copyright (C) KolibriOS team 2004-2015. All rights reserved. ;;
2288 clevermous 4
;; Distributed under terms of the GNU General Public License    ;;
5
;;                                                              ;;
6
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7
 
8
$Revision: 6843 $
9
 
3742 clevermous 10
search_partitions:
4700 mario79 11
        push    ecx
3742 clevermous 12
; 1. Fill missing parameters in HD_DATA structures.
4700 mario79 13
        xor     eax, eax
14
        mov     edx, IDE_controller_1
15
        mov     ax, [edx + IDE_DATA.BAR0_val]
5852 pathoswith 16
        mov     [hd0_data.hdbase], ax
17
        mov     [hd1_data.hdbase], ax
4700 mario79 18
        mov     ax, [edx + IDE_DATA.BAR2_val]
5852 pathoswith 19
        mov     [hd2_data.hdbase], ax
20
        mov     [hd3_data.hdbase], ax
4700 mario79 21
 
22
        mov     edx, IDE_controller_2
23
        mov     ax, [edx + IDE_DATA.BAR0_val]
5852 pathoswith 24
        mov     [hd4_data.hdbase], ax
25
        mov     [hd5_data.hdbase], ax
4700 mario79 26
        mov     ax, [edx + IDE_DATA.BAR2_val]
5852 pathoswith 27
        mov     [hd6_data.hdbase], ax
28
        mov     [hd7_data.hdbase], ax
4700 mario79 29
 
30
        mov     edx, IDE_controller_3
31
        mov     ax, [edx + IDE_DATA.BAR0_val]
5852 pathoswith 32
        mov     [hd8_data.hdbase], ax
33
        mov     [hd9_data.hdbase], ax
4700 mario79 34
        mov     ax, [edx + IDE_DATA.BAR2_val]
5852 pathoswith 35
        mov     [hd10_data.hdbase], ax
36
        mov     [hd11_data.hdbase], ax
3742 clevermous 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.
4700 mario79 40
;-----------------------------------------------------------------------------
3742 clevermous 41
; 2a. /hd0: exists if mask 0x40 in [DRIVE_DATA+1] is set,
42
;     data: hd0_data,
43
;     number of partitions: [DRIVE_DATA+2]
2288 clevermous 44
        test    [DRIVE_DATA+1], byte 0x40
3742 clevermous 45
        jz      @f
4711 mario79 46
 
3742 clevermous 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
4700 mario79 53
;-----------------------------------------------------------------------------
3742 clevermous 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]
2288 clevermous 58
        test    [DRIVE_DATA+1], byte 0x10
3742 clevermous 59
        jz      @f
4711 mario79 60
 
3742 clevermous 61
        push    'hd1'
62
        mov     eax, esp
63
        mov     edx, hd1_data
64
        call    ide_disk_add
65
        mov     [DRIVE_DATA+3], al
2288 clevermous 66
        pop     ecx
4700 mario79 67
;-----------------------------------------------------------------------------
3742 clevermous 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
4711 mario79 74
 
3742 clevermous 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
4700 mario79 81
;-----------------------------------------------------------------------------
3742 clevermous 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
4711 mario79 88
 
3742 clevermous 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
4700 mario79 95
;-----------------------------------------------------------------------------
3742 clevermous 96
@@:
4700 mario79 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
4711 mario79 102
 
4700 mario79 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
4711 mario79 116
 
4700 mario79 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
4711 mario79 130
 
4700 mario79 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
4711 mario79 144
 
4700 mario79 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
4711 mario79 158
 
4700 mario79 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
4711 mario79 172
 
4700 mario79 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
4711 mario79 186
 
4700 mario79 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
4711 mario79 200
 
4700 mario79 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
@@:
3742 clevermous 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.
6843 dunkaist 219
        lea     eax, [esi*4]
220
        movzx   eax, [BiosDisksData+eax*4+BiosDiskData.DriveNumber]
3742 clevermous 221
        sub     al, 80h
222
; 3c. Convert eax to decimal and store starting with [esp+3].
223
; First 2 bytes in [esp] are "bd".
224
        lea     edi, [esp+2]
225
; store digits in the stack, ending with -'0'
226
        push    -'0'
227
@@:
228
        xor     edx, edx
229
iglobal
230
align 4
231
_10     dd      10
232
endg
233
        div     [_10]
234
        push    edx
235
        test    eax, eax
236
        jnz     @b
237
; restore digits from the stack, this reverses the order;
238
; add '0', stop, when zero is reached
239
@@:
240
        pop     eax
241
        add     al, '0'
242
        stosb
243
        jnz     @b
244
; 3e. Call the API with userdata = 80h + ecx.
245
        mov     eax, esp
246
        lea     edx, [esi+80h]
247
        stdcall disk_add, bd_callbacks, eax, edx, 0
248
        test    eax, eax
249
        jz      @f
250
        stdcall disk_media_changed, eax, 1
251
@@:
252
; 3f. Continue the loop.
253
        inc     esi
254
        cmp     esi, [NumBiosDisks]
255
        jnz     .bdloop
256
        pop     ecx ecx ; restore stack after name
257
.nobd:
2288 clevermous 258
        jmp     end_search_partitions
4700 mario79 259
;-----------------------------------------------------------------------------
3742 clevermous 260
; Helper procedure for search_partitions, adds one IDE disk.
4700 mario79 261
; For compatibility, number of partitions for IDE disks is kept in a separate
262
; variable, so the procedure returns number of partitions.
3742 clevermous 263
; eax -> name, edx -> disk data
264
proc ide_disk_add
265
        stdcall disk_add, ide_callbacks, eax, edx, 0
266
        test    eax, eax
267
        jz      @f
268
        push    eax
269
        stdcall disk_media_changed, eax, 1
270
        pop     eax
271
        mov     eax, [eax+DISK.NumPartitions]
272
        cmp     eax, 255
273
        jbe     @f
274
        mov     eax, 255
275
@@:
2288 clevermous 276
        ret
3742 clevermous 277
endp
4700 mario79 278
;-----------------------------------------------------------------------------
279
end_search_partitions:
280
        pop     ecx