Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
2288 clevermous 1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                              ;;
10051 ace_dent 3
;; Copyright (C) KolibriOS team 2004-2024. All rights reserved. ;;
2288 clevermous 4
;; Distributed under terms of the GNU General Public License    ;;
5
;;                                                              ;;
6
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7
 
8
 
3742 clevermous 9
search_partitions:
4700 mario79 10
        push    ecx
3742 clevermous 11
; 1. Fill missing parameters in HD_DATA structures.
4700 mario79 12
        xor     eax, eax
13
        mov     edx, IDE_controller_1
14
        mov     ax, [edx + IDE_DATA.BAR0_val]
5852 pathoswith 15
        mov     [hd0_data.hdbase], ax
16
        mov     [hd1_data.hdbase], ax
4700 mario79 17
        mov     ax, [edx + IDE_DATA.BAR2_val]
5852 pathoswith 18
        mov     [hd2_data.hdbase], ax
19
        mov     [hd3_data.hdbase], ax
4700 mario79 20
 
21
        mov     edx, IDE_controller_2
22
        mov     ax, [edx + IDE_DATA.BAR0_val]
5852 pathoswith 23
        mov     [hd4_data.hdbase], ax
24
        mov     [hd5_data.hdbase], ax
4700 mario79 25
        mov     ax, [edx + IDE_DATA.BAR2_val]
5852 pathoswith 26
        mov     [hd6_data.hdbase], ax
27
        mov     [hd7_data.hdbase], ax
4700 mario79 28
 
29
        mov     edx, IDE_controller_3
30
        mov     ax, [edx + IDE_DATA.BAR0_val]
5852 pathoswith 31
        mov     [hd8_data.hdbase], ax
32
        mov     [hd9_data.hdbase], ax
4700 mario79 33
        mov     ax, [edx + IDE_DATA.BAR2_val]
5852 pathoswith 34
        mov     [hd10_data.hdbase], ax
35
        mov     [hd11_data.hdbase], ax
3742 clevermous 36
; 2. Notify the system about /hd* disks.
37
; For every existing disk, call ide_disk_add with correct parameters.
38
; Generate name "hdN" on the stack; this is 4 bytes including terminating zero.
4700 mario79 39
;-----------------------------------------------------------------------------
3742 clevermous 40
; 2a. /hd0: exists if mask 0x40 in [DRIVE_DATA+1] is set,
41
;     data: hd0_data,
42
;     number of partitions: [DRIVE_DATA+2]
2288 clevermous 43
        test    [DRIVE_DATA+1], byte 0x40
3742 clevermous 44
        jz      @f
4711 mario79 45
 
3742 clevermous 46
        push    'hd0'
47
        mov     eax, esp        ; name
48
        mov     edx, hd0_data
49
        call    ide_disk_add
50
        mov     [DRIVE_DATA+2], al
51
        pop     ecx             ; restore the stack
4700 mario79 52
;-----------------------------------------------------------------------------
3742 clevermous 53
@@:
54
; 2b. /hd1: exists if mask 0x10 in [DRIVE_DATA+1] is set,
55
;     data: hd1_data,
56
;     number of partitions: [DRIVE_DATA+3]
2288 clevermous 57
        test    [DRIVE_DATA+1], byte 0x10
3742 clevermous 58
        jz      @f
4711 mario79 59
 
3742 clevermous 60
        push    'hd1'
61
        mov     eax, esp
62
        mov     edx, hd1_data
63
        call    ide_disk_add
64
        mov     [DRIVE_DATA+3], al
2288 clevermous 65
        pop     ecx
4700 mario79 66
;-----------------------------------------------------------------------------
3742 clevermous 67
@@:
68
; 2c. /hd2: exists if mask 4 in [DRIVE_DATA+1] is set,
69
;     data: hd2_data,
70
;     number of partitions: [DRIVE_DATA+4]
71
        test    [DRIVE_DATA+1], byte 4
72
        jz      @f
4711 mario79 73
 
3742 clevermous 74
        push    'hd2'
75
        mov     eax, esp
76
        mov     edx, hd2_data
77
        call    ide_disk_add
78
        mov     [DRIVE_DATA+4], al
79
        pop     ecx
4700 mario79 80
;-----------------------------------------------------------------------------
3742 clevermous 81
@@:
82
; 2d. /hd3: exists if mask 1 in [DRIVE_DATA+1] is set,
83
;     data: hd3_data,
84
;     number of partitions: [DRIVE_DATA+5]
85
        test    [DRIVE_DATA+1], byte 1
86
        jz      @f
4711 mario79 87
 
3742 clevermous 88
        push    'hd3'
89
        mov     eax, esp
90
        mov     edx, hd3_data
91
        call    ide_disk_add
92
        mov     [DRIVE_DATA+5], al
93
        pop     ecx
4700 mario79 94
;-----------------------------------------------------------------------------
3742 clevermous 95
@@:
4700 mario79 96
; 2e. /hd4: exists if mask 0x40 in [DRIVE_DATA+6] is set,
97
;     data: hd4_data,
98
;     number of partitions: [DRIVE_DATA+7]
99
        test    [DRIVE_DATA+6], byte 0x40
100
        jz      @f
4711 mario79 101
 
4700 mario79 102
        push    'hd4'
103
        mov     eax, esp        ; name
104
        mov     edx, hd4_data
105
        call    ide_disk_add
106
        mov     [DRIVE_DATA+7], al
107
        pop     ecx
108
;-----------------------------------------------------------------------------
109
@@:
110
; 2f. /hd5: exists if mask 0x10 in [DRIVE_DATA+6] is set,
111
;     data: hd5_data,
112
;     number of partitions: [DRIVE_DATA+8]
113
        test    [DRIVE_DATA+6], byte 0x10
114
        jz      @f
4711 mario79 115
 
4700 mario79 116
        push    'hd5'
117
        mov     eax, esp
118
        mov     edx, hd5_data
119
        call    ide_disk_add
120
        mov     [DRIVE_DATA+8], al
121
        pop     ecx
122
;-----------------------------------------------------------------------------
123
@@:
124
; 2g. /hd6: exists if mask 4 in [DRIVE_DATA+6] is set,
125
;     data: hd6_data,
126
;     number of partitions: [DRIVE_DATA+9]
127
        test    [DRIVE_DATA+6], byte 4
128
        jz      @f
4711 mario79 129
 
4700 mario79 130
        push    'hd6'
131
        mov     eax, esp
132
        mov     edx, hd6_data
133
        call    ide_disk_add
134
        mov     [DRIVE_DATA+9], al
135
        pop     ecx
136
;-----------------------------------------------------------------------------
137
@@:
138
; 2h. /hd7: exists if mask 1 in [DRIVE_DATA+6] is set,
139
;     data: hd7_data,
140
;     number of partitions: [DRIVE_DATA+10]
141
        test    [DRIVE_DATA+6], byte 1
142
        jz      @f
4711 mario79 143
 
4700 mario79 144
        push    'hd7'
145
        mov     eax, esp
146
        mov     edx, hd7_data
147
        call    ide_disk_add
148
        mov     [DRIVE_DATA+10], al
149
        pop     ecx
150
;-----------------------------------------------------------------------------
151
@@:
152
; 2i. /hd8: exists if mask 0x40 in [DRIVE_DATA+11] is set,
153
;     data: hd8_data,
154
;     number of partitions: [DRIVE_DATA+12]
155
        test    [DRIVE_DATA+11], byte 0x40
156
        jz      @f
4711 mario79 157
 
4700 mario79 158
        push    'hd8'
159
        mov     eax, esp        ; name
160
        mov     edx, hd8_data
161
        call    ide_disk_add
162
        mov     [DRIVE_DATA+12], al
163
        pop     ecx
164
;-----------------------------------------------------------------------------
165
@@:
166
; 2j. /hd9: exists if mask 0x10 in [DRIVE_DATA+11] is set,
167
;     data: hd9_data,
168
;     number of partitions: [DRIVE_DATA+13]
169
        test    [DRIVE_DATA+11], byte 0x10
170
        jz      @f
4711 mario79 171
 
4700 mario79 172
        push    'hd9'
173
        mov     eax, esp
174
        mov     edx, hd9_data
175
        call    ide_disk_add
176
        mov     [DRIVE_DATA+13], al
177
        pop     ecx
178
;-----------------------------------------------------------------------------
179
@@:
180
; 2k. /hd10: exists if mask 4 in [DRIVE_DATA+11] is set,
181
;     data: hd10_data,
182
;     number of partitions: [DRIVE_DATA+14]
183
        test    [DRIVE_DATA+14], byte 4
184
        jz      @f
4711 mario79 185
 
4700 mario79 186
        push    'hd10'
187
        mov     eax, esp
188
        mov     edx, hd10_data
189
        call    ide_disk_add
190
        mov     [DRIVE_DATA+9], al
191
        pop     ecx
192
;-----------------------------------------------------------------------------
193
@@:
194
; 2l. /hd11: exists if mask 1 in [DRIVE_DATA+11] is set,
195
;     data: hd11_data,
196
;     number of partitions: [DRIVE_DATA+15]
197
        test    [DRIVE_DATA+11], byte 1
198
        jz      @f
4711 mario79 199
 
4700 mario79 200
        push    'hd11'
201
        mov     eax, esp
202
        mov     edx, hd11_data
203
        call    ide_disk_add
204
        mov     [DRIVE_DATA+15], al
205
        pop     ecx
206
;-----------------------------------------------------------------------------
207
@@:
3742 clevermous 208
; 3. Notify the system about /bd* disks.
209
; 3a. Check whether there are BIOS disks. If no, skip step 3.
210
        xor     esi, esi
211
        cmp     esi, [NumBiosDisks]
212
        jz      .nobd
213
; Loop over all disks.
214
        push    0
215
        push    'bd'
216
.bdloop:
217
; 3b. Get the drive number for using in /bd* name.
6843 dunkaist 218
        lea     eax, [esi*4]
219
        movzx   eax, [BiosDisksData+eax*4+BiosDiskData.DriveNumber]
3742 clevermous 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:
2288 clevermous 257
        jmp     end_search_partitions
4700 mario79 258
;-----------------------------------------------------------------------------
3742 clevermous 259
; Helper procedure for search_partitions, adds one IDE disk.
4700 mario79 260
; For compatibility, number of partitions for IDE disks is kept in a separate
261
; variable, so the procedure returns number of partitions.
3742 clevermous 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
@@:
2288 clevermous 275
        ret
3742 clevermous 276
endp
4700 mario79 277
;-----------------------------------------------------------------------------
278
end_search_partitions:
279
        pop     ecx