Subversion Repositories Kolibri OS

Rev

Rev 2540 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2540 Rev 3187
Line 16... Line 16...
16
fs_read32_sys:
16
fs_read32_sys:
17
; Compatibility hack: if PARTITION.Disk is 'old', there is no DISK structure,
17
; Compatibility hack: if PARTITION.Disk is 'old', there is no DISK structure,
18
; this request should be processed by hd_read.
18
; this request should be processed by hd_read.
19
        cmp     [ebp+PARTITION.Disk], 'old'
19
        cmp     [ebp+PARTITION.Disk], 'old'
20
        jnz     @f
20
        jnz     @f
-
 
21
        add     eax, dword [ebp+PARTITION.FirstSector]
21
        mov     [hdd_appl_data], 0
22
        mov     [hdd_appl_data], 0
22
        call    hd_read
23
        call    hd_read
23
        mov     [hdd_appl_data], 1      ; restore to default state
24
        mov     [hdd_appl_data], 1      ; restore to default state
-
 
25
        mov     eax, [hd_error]
24
        ret
26
        ret
25
@@:
27
@@:
26
; In the normal case, save ecx, set ecx to SysCache and let the common part
28
; In the normal case, save ecx, set ecx to SysCache and let the common part
27
; do its work.
29
; do its work.
28
        push    ecx
30
        push    ecx
Line 39... Line 41...
39
fs_read32_app:
41
fs_read32_app:
40
; Compatibility hack: if PARTITION.Disk is 'old', there is no DISK structure,
42
; Compatibility hack: if PARTITION.Disk is 'old', there is no DISK structure,
41
; this request should be processed by hd_read.
43
; this request should be processed by hd_read.
42
        cmp     [ebp+PARTITION.Disk], 'old'
44
        cmp     [ebp+PARTITION.Disk], 'old'
43
        jnz     @f
45
        jnz     @f
-
 
46
        add     eax, dword [ebp+PARTITION.FirstSector]
44
        mov     [hdd_appl_data], 1
47
        mov     [hdd_appl_data], 1
45
        jmp     hd_read
48
        call    hd_read
-
 
49
        mov     eax, [hd_error]
-
 
50
        ret
46
@@:
51
@@:
47
; In the normal case, save ecx, set ecx to AppCache and let the common part
52
; In the normal case, save ecx, set ecx to AppCache and let the common part
48
; do its work.
53
; do its work.
49
        push    ecx
54
        push    ecx
50
        mov     ecx, [ebp+PARTITION.Disk]
55
        mov     ecx, [ebp+PARTITION.Disk]
Line 61... Line 66...
61
        mov     eax, DISK_STATUS_END_OF_MEDIA
66
        mov     eax, DISK_STATUS_END_OF_MEDIA
62
        pop     ecx
67
        pop     ecx
63
        ret
68
        ret
64
@@:
69
@@:
65
; 2. Get the absolute sector on the disk.
70
; 2. Get the absolute sector on the disk.
66
        push    edx
71
        push    edx esi
67
        xor     edx, edx
72
        xor     edx, edx
68
        add     eax, dword [ebp+PARTITION.FirstSector]
73
        add     eax, dword [ebp+PARTITION.FirstSector]
69
        adc     edx, dword [ebp+PARTITION.FirstSector+4]
74
        adc     edx, dword [ebp+PARTITION.FirstSector+4]
70
; 3. If there is no cache for this disk, just pass the request to the driver.
75
; 3. If there is no cache for this disk, just pass the request to the driver.
71
        cmp     [ecx+DISKCACHE.pointer], 0
76
        cmp     [ecx+DISKCACHE.pointer], 0
Line 73... Line 78...
73
        push    1
78
        push    1
74
        push    esp     ; numsectors
79
        push    esp     ; numsectors
75
        push    edx     ; startsector
80
        push    edx     ; startsector
76
        push    eax     ; startsector
81
        push    eax     ; startsector
77
        push    ebx     ; buffer
82
        push    ebx     ; buffer
-
 
83
        mov     esi, [ebp+PARTITION.Disk]
78
        mov     al, DISKFUNC.read
84
        mov     al, DISKFUNC.read
79
        call    disk_call_driver
85
        call    disk_call_driver
80
        pop     ecx
86
        pop     ecx
81
        pop     edx
87
        pop     esi edx
82
        pop     ecx
88
        pop     ecx
83
        ret
89
        ret
84
.scancache:
90
.scancache:
85
; 4. Scan the cache.
91
; 4. Scan the cache.
86
        push    esi edi ecx ; scan cache
92
        push    edi ecx ; scan cache
87
        push    edx eax
93
        push    edx eax
88
virtual at esp
94
virtual at esp
89
.sector_lo      dd      ?
95
.sector_lo      dd      ?
90
.sector_hi      dd      ?
96
.sector_hi      dd      ?
91
.cache          dd      ?
97
.cache          dd      ?
Line 127... Line 133...
127
 
133
 
128
        push    1
134
        push    1
129
        push    esp
135
        push    esp
130
        push    edx
136
        push    edx
131
        push    [.sector_lo+12]
137
        push    [.sector_lo+12]
132
        mov     ecx, [.cache]
138
        mov     ecx, [.cache+16]
133
        mov     eax, edi
139
        mov     eax, edi
134
        shl     eax, 9
140
        shl     eax, 9
135
        add     eax, [ecx+DISKCACHE.data]
141
        add     eax, [ecx+DISKCACHE.data]
136
        push    eax
142
        push    eax
Line 181... Line 187...
181
fs_write32_sys:
187
fs_write32_sys:
182
; Compatibility hack: if PARTITION.Disk is 'old', there is no DISK structure,
188
; Compatibility hack: if PARTITION.Disk is 'old', there is no DISK structure,
183
; this request should be processed by hd_write.
189
; this request should be processed by hd_write.
184
        cmp     [ebp+PARTITION.Disk], 'old'
190
        cmp     [ebp+PARTITION.Disk], 'old'
185
        jnz     @f
191
        jnz     @f
-
 
192
        add     eax, dword [ebp+PARTITION.FirstSector]
186
        mov     [hdd_appl_data], 0
193
        mov     [hdd_appl_data], 0
187
        call    hd_write
194
        call    hd_write
188
        mov     [hdd_appl_data], 1      ; restore to default state
195
        mov     [hdd_appl_data], 1      ; restore to default state
-
 
196
        mov     eax, [hd_error]
189
        ret
197
        ret
190
@@:
198
@@:
191
; In the normal case, save ecx, set ecx to SysCache and let the common part
199
; In the normal case, save ecx, set ecx to SysCache and let the common part
192
; do its work.
200
; do its work.
193
        push    ecx
201
        push    ecx
Line 204... Line 212...
204
fs_write32_app:
212
fs_write32_app:
205
; Compatibility hack: if PARTITION.Disk is 'old', there is no DISK structure,
213
; Compatibility hack: if PARTITION.Disk is 'old', there is no DISK structure,
206
; this request should be processed by hd_write.
214
; this request should be processed by hd_write.
207
        cmp     [ebp+PARTITION.Disk], 'old'
215
        cmp     [ebp+PARTITION.Disk], 'old'
208
        jnz     @f
216
        jnz     @f
-
 
217
        add     eax, dword [ebp+PARTITION.FirstSector]
209
        mov     [hdd_appl_data], 1
218
        mov     [hdd_appl_data], 1
210
        jmp     hd_write
219
        call    hd_write
-
 
220
        mov     eax, [hd_error]
-
 
221
        ret
211
@@:
222
@@:
212
; In the normal case, save ecx, set ecx to AppCache and let the common part
223
; In the normal case, save ecx, set ecx to AppCache and let the common part
213
; do its work.
224
; do its work.
214
        push    ecx
225
        push    ecx
215
        mov     ecx, [ebp+PARTITION.Disk]
226
        mov     ecx, [ebp+PARTITION.Disk]
Line 225... Line 236...
225
        ja      @f
236
        ja      @f
226
        mov     eax, DISK_STATUS_END_OF_MEDIA
237
        mov     eax, DISK_STATUS_END_OF_MEDIA
227
        pop     ecx
238
        pop     ecx
228
        ret
239
        ret
229
@@:
240
@@:
230
        push    edx
241
        push    edx esi
231
; 2. Get the absolute sector on the disk.
242
; 2. Get the absolute sector on the disk.
232
        xor     edx, edx
243
        xor     edx, edx
233
        add     eax, dword [ebp+PARTITION.FirstSector]
244
        add     eax, dword [ebp+PARTITION.FirstSector]
234
        adc     edx, dword [ebp+PARTITION.FirstSector+4]
245
        adc     edx, dword [ebp+PARTITION.FirstSector+4]
235
; 3. If there is no cache for this disk, just pass request to the driver.
246
; 3. If there is no cache for this disk, just pass request to the driver.
Line 238... Line 249...
238
        push    1
249
        push    1
239
        push    esp     ; numsectors
250
        push    esp     ; numsectors
240
        push    edx     ; startsector
251
        push    edx     ; startsector
241
        push    eax     ; startsector
252
        push    eax     ; startsector
242
        push    ebx     ; buffer
253
        push    ebx     ; buffer
-
 
254
        mov     esi, [ebp+PARTITION.Disk]
243
        mov     al, DISKFUNC.write
255
        mov     al, DISKFUNC.write
244
        call    disk_call_driver
256
        call    disk_call_driver
245
        pop     ecx
257
        pop     ecx
246
        pop     edx
258
        pop     esi edx
247
        pop     ecx
259
        pop     ecx
248
        ret
260
        ret
249
.scancache:
261
.scancache:
250
; 4. Scan the cache.
262
; 4. Scan the cache.
251
        push    esi edi ecx ; scan cache
263
        push    edi ecx ; scan cache
252
        push    edx eax
264
        push    edx eax
253
virtual at esp
265
virtual at esp
254
.sector_lo      dd      ?
266
.sector_lo      dd      ?
255
.sector_hi      dd      ?
267
.sector_hi      dd      ?
256
.cache          dd      ?
268
.cache          dd      ?
Line 303... Line 315...
303
        mov     [esi], eax      ; sector number
315
        mov     [esi], eax      ; sector number
304
        mov     [esi+4], edx    ; sector number
316
        mov     [esi+4], edx    ; sector number
Line 305... Line 317...
305
 
317
 
Line 306... Line 318...
306
.yes_in_cache_write:
318
.yes_in_cache_write:
Line 307... Line 319...
307
 
319
 
308
        mov     dword [esi+4], 2        ; write - differs from hd
320
        mov     dword [esi+8], 2        ; write - differs from hd
309
 
321
 
Line 346... Line 358...
346
        add     eax, [esi+DISKCACHE.pointer]
358
        add     eax, [esi+DISKCACHE.pointer]
347
        cmp     dword [eax+8], 2
359
        cmp     dword [eax+8], 2
348
        jb      .found_slot             ; it's empty or read
360
        jb      .found_slot             ; it's empty or read
349
        dec     ecx
361
        dec     ecx
350
        jnz     .search_for_empty
362
        jnz     .search_for_empty
351
        call    write_cache64           ; no empty slots found, write all
363
        stdcall write_cache64, [ebp+PARTITION.Disk] ; no empty slots found, write all
352
        test    eax, eax
364
        test    eax, eax
353
        jne     .found_slot_access_denied
365
        jne     .found_slot_access_denied
354
        jmp     .search_again           ; and start again
366
        jmp     .search_again           ; and start again
355
.found_slot:
367
.found_slot:
356
        mov     [esi+DISKCACHE.search_start], edi
368
        mov     [esi+DISKCACHE.search_start], edi
357
        xor     eax, eax        ; success
369
        xor     eax, eax        ; success
358
.found_slot_access_denied:
370
.found_slot_access_denied:
359
        ret
371
        ret
Line 360... Line 372...
360
 
372
 
361
; This function is intended to replace the old 'write_cache' function.
373
; This function is intended to replace the old 'write_cache' function.
362
proc write_cache64 uses ecx edx esi edi
374
proc write_cache64 uses ecx edx esi edi, disk:dword
363
locals
375
locals
364
cache_chain_started     dd      ?
376
cache_chain_started     dd      0
365
cache_chain_size        dd      ?
377
cache_chain_size        dd      ?
366
cache_chain_pos         dd      ?
378
cache_chain_pos         dd      ?
367
cache_chain_ptr         dd      ?
379
cache_chain_ptr         dd      ?
-
 
380
endl
368
endl
381
saved_esi_pos = 16+12 ; size of local variables + size of registers before esi
369
; If there is no cache for this disk, nothing to do.
382
; If there is no cache for this disk, nothing to do.
370
        cmp     [esi+DISKCACHE.pointer], 0
383
        cmp     [esi+DISKCACHE.pointer], 0
371
        jz      .flush
384
        jz      .flush
372
;-----------------------------------------------------------
385
;-----------------------------------------------------------
Line 430... Line 443...
430
        jnz     .write_cache_more
443
        jnz     .write_cache_more
431
        call    .flush_cache_chain
444
        call    .flush_cache_chain
432
        test    eax, eax
445
        test    eax, eax
433
        jnz     .nothing
446
        jnz     .nothing
434
.flush:
447
.flush:
435
        mov     esi, [ebp]
448
        mov     esi, [disk]
436
        mov     esi, [esi+PARTITION.Disk]
-
 
437
        mov     al, DISKFUNC.flush
449
        mov     al, DISKFUNC.flush
438
        call    disk_call_driver
450
        call    disk_call_driver
439
.nothing:
451
.nothing:
440
        ret
452
        ret
Line 452... Line 464...
452
        mov     [cache_chain_size], 1
464
        mov     [cache_chain_size], 1
453
        mov     [cache_chain_pos], edi
465
        mov     [cache_chain_pos], edi
454
.write_cache_chain:
466
.write_cache_chain:
455
        pusha
467
        pusha
456
        mov     edi, [cache_chain_pos]
468
        mov     edi, [cache_chain_pos]
457
        mov     ecx, [ebp-12]
469
        mov     ecx, [ebp-saved_esi_pos]
458
        shl     edi, 9
470
        shl     edi, 9
459
        add     edi, [ecx+DISKCACHE.data]
471
        add     edi, [ecx+DISKCACHE.data]
460
        mov     ecx, [cache_chain_size]
472
        mov     ecx, [cache_chain_size]
461
        push    ecx
473
        push    ecx
462
        push    esp     ; numsectors
474
        push    esp     ; numsectors
Line 536... Line 548...
536
        mov     [esi+DISK.AppCache.data_size], eax
548
        mov     [esi+DISK.AppCache.data_size], eax
537
        mov     [esi+DISK.AppCache.pointer], edx
549
        mov     [esi+DISK.AppCache.pointer], edx
Line 538... Line 550...
538
 
550
 
539
        mov     eax, [esi+DISK.SysCache.data_size]
551
        mov     eax, [esi+DISK.SysCache.data_size]
540
        push    ebx
552
        push    ebx
541
        call    calculate_for_hd
553
        call    calculate_for_hd64
542
        pop     ebx
554
        pop     ebx
543
        add     eax, [esi+DISK.SysCache.pointer]
555
        add     eax, [esi+DISK.SysCache.pointer]
544
        mov     [esi+DISK.SysCache.data], eax
556
        mov     [esi+DISK.SysCache.data], eax
Line 551... Line 563...
551
        rep stosd
563
        rep stosd
552
        pop     edi
564
        pop     edi
Line 553... Line 565...
553
 
565
 
554
        mov     eax, [esi+DISK.AppCache.data_size]
566
        mov     eax, [esi+DISK.AppCache.data_size]
555
        push    ebx
567
        push    ebx
556
        call    calculate_for_hd
568
        call    calculate_for_hd64
557
        pop     ebx
569
        pop     ebx
558
        add     eax, [esi+DISK.AppCache.pointer]
570
        add     eax, [esi+DISK.AppCache.pointer]
559
        mov     [esi+DISK.AppCache.data], eax
571
        mov     [esi+DISK.AppCache.data], eax
Line 577... Line 589...
577
        mov     [esi+DISK.SysCache.pointer], eax
589
        mov     [esi+DISK.SysCache.pointer], eax
578
        mov     [esi+DISK.AppCache.pointer], eax
590
        mov     [esi+DISK.AppCache.pointer], eax
579
        mov     al, 1
591
        mov     al, 1
580
        ret
592
        ret
Line -... Line 593...
-
 
593
 
-
 
594
calculate_for_hd64:
-
 
595
        push    eax
-
 
596
        mov     ebx, eax
-
 
597
        shr     eax, 9
-
 
598
        lea     eax, [eax*3]
-
 
599
        shl     eax, 2
-
 
600
        sub     ebx, eax
-
 
601
        shr     ebx, 9
-
 
602
        mov     ecx, ebx
-
 
603
        shl     ebx, 9
-
 
604
        pop     eax
-
 
605
        sub     eax, ebx
-
 
606
        dec     ecx
-
 
607
        ret
-
 
608
 
581
 
609
 
582
; This internal function is called from disk_media_dereference to free the
610
; This internal function is called from disk_media_dereference to free the
583
; allocated cache, if there is one.
611
; allocated cache, if there is one.
584
; esi = pointer to DISK structure
612
; esi = pointer to DISK structure
585
disk_free_cache:
613
disk_free_cache:
Line 588... Line 616...
588
        test    eax, eax
616
        test    eax, eax
589
        jz      .nothing
617
        jz      .nothing
590
        stdcall kernel_free, eax
618
        stdcall kernel_free, eax
591
.nothing:
619
.nothing:
592
        ret
620
        ret
-
 
621
 
-
 
622
; This function flushes all modified data from both caches for the given DISK.
-
 
623
; esi = pointer to DISK
-
 
624
disk_sync:
-
 
625
; Compatibility hack: if PARTITION.Disk is 'old', there is no DISK structure,
-
 
626
; this request should be processed by write_cache.
-
 
627
        cmp     esi, 'old'
-
 
628
        jnz     @f
-
 
629
        mov     [hdd_appl_data], 0
-
 
630
        call    write_cache
-
 
631
        mov     [hdd_appl_data], 1
-
 
632
        jmp     write_cache
-
 
633
@@:
-
 
634
; The algorithm is straightforward.
-
 
635
        push    esi
-
 
636
        push    esi     ; for second write_cache64
-
 
637
        push    esi     ; for first write_cache64
-
 
638
        add     esi, DISK.SysCache
-
 
639
        call    write_cache64
-
 
640
        add     esi, DISK.AppCache - DISK.SysCache
-
 
641
        call    write_cache64
-
 
642
        pop     esi
-
 
643
        ret