Subversion Repositories Kolibri OS

Rev

Rev 3539 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3539 Rev 3742
1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                              ;;
2
;;                                                              ;;
3
;; Copyright (C) KolibriOS team 2004-2011. All rights reserved. ;;
3
;; Copyright (C) KolibriOS team 2004-2011. 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
;; System service for filesystem call                           ;;
7
;; System service for filesystem call                           ;;
8
;; (C) 2004 Ville Turjanmaa, License: GPL                       ;;
8
;; (C) 2004 Ville Turjanmaa, License: GPL                       ;;
9
;; 29.04.2006 Elimination of hangup after the                   ;;
9
;; 29.04.2006 Elimination of hangup after the                   ;;
10
;;            expiration hd_wait_timeout (for LBA) -  Mario79   ;;
10
;;            expiration hd_wait_timeout (for LBA) -  Mario79   ;;
11
;; 15.01.2005 get file size/attr/date,                          ;;
11
;; 15.01.2005 get file size/attr/date,                          ;;
12
;;            file_append (only for hd) - ATV                   ;;
12
;;            file_append (only for hd) - ATV                   ;;
13
;; 23.11.2004 test if hd/partition is set - ATV                 ;;
13
;; 23.11.2004 test if hd/partition is set - ATV                 ;;
14
;; 18.11.2004 get_disk_info and more error codes - ATV          ;;
14
;; 18.11.2004 get_disk_info and more error codes - ATV          ;;
15
;; 08.11.2004 expand_pathz and rename (only for hd) - ATV       ;;
15
;; 08.11.2004 expand_pathz and rename (only for hd) - ATV       ;;
16
;; 20.10.2004 Makedir/Removedir (only for hd) - ATV             ;;
16
;; 20.10.2004 Makedir/Removedir (only for hd) - ATV             ;;
17
;;                                                              ;;
17
;;                                                              ;;
18
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
18
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
19
 
19
 
20
$Revision: 3539 $
20
$Revision: 3742 $
21
 
21
 
22
 
22
 
23
iglobal
23
iglobal
24
 
24
 
25
if lang eq sp
25
if lang eq sp
26
include 'fs/fs-sp.inc'
26
include 'fs/fs-sp.inc'
27
else
27
else
28
dir0:
28
dir0:
29
             db  'HARDDISK   '
29
             db  'HARDDISK   '
30
             db  'RAMDISK    '
30
             db  'RAMDISK    '
31
             db  'FLOPPYDISK '
31
             db  'FLOPPYDISK '
32
             db  0
32
             db  0
33
 
33
 
34
dir1:
34
dir1:
35
             db  'FIRST      '
35
             db  'FIRST      '
36
             db  'SECOND     '
36
             db  'SECOND     '
37
             db  'THIRD      '
37
             db  'THIRD      '
38
             db  'FOURTH     '
38
             db  'FOURTH     '
39
             db  0
39
             db  0
40
end if
40
end if
41
 
41
 
42
not_select_IDE db 0
42
not_select_IDE db 0
43
 
43
 
44
hd_address_table:
44
hd_address_table:
45
                   dd  0x1f0,0x00,0x1f0,0x10
45
                   dd  0x1f0,0x00,0x1f0,0x10
46
                   dd  0x170,0x00,0x170,0x10
46
                   dd  0x170,0x00,0x170,0x10
47
endg
47
endg
48
 
48
 
49
file_system:
49
file_system:
50
 
50
 
51
; IN:
51
; IN:
52
;
52
;
53
; eax = 0  ; read file          /RamDisk/First  6
53
; eax = 0  ; read file          /RamDisk/First  6
54
; eax = 8  ; lba read
54
; eax = 8  ; lba read
55
; eax = 15 ; get_disk_info
55
; eax = 15 ; get_disk_info
56
;
56
;
57
; OUT:
57
; OUT:
58
;
58
;
59
; eax = 0  : read ok
59
; eax = 0  : read ok
60
; eax = 1  : no hd base and/or partition defined
60
; eax = 1  : no hd base and/or partition defined
61
; eax = 2  : function is unsupported for this FS
61
; eax = 2  : function is unsupported for this FS
62
; eax = 3  : unknown FS
62
; eax = 3  : unknown FS
63
; eax = 4  : partition not defined at hd
63
; eax = 4  : partition not defined at hd
64
; eax = 5  : file not found
64
; eax = 5  : file not found
65
; eax = 6  : end of file
65
; eax = 6  : end of file
66
; eax = 7  : memory pointer not in application area
66
; eax = 7  : memory pointer not in application area
67
; eax = 8  : disk full
67
; eax = 8  : disk full
68
; eax = 9  : fat table corrupted
68
; eax = 9  : fat table corrupted
69
; eax = 10 : access denied
69
; eax = 10 : access denied
70
; eax = 11 : disk error
70
; eax = 11 : disk error
71
;
71
;
72
; ebx = size
72
; ebx = size
73
 
73
 
74
; \begin{diamond}[18.03.2006]
74
; \begin{diamond}[18.03.2006]
75
; for subfunction 16 (start application) error codes must be negative
75
; for subfunction 16 (start application) error codes must be negative
76
;    because positive values are valid PIDs
76
;    because positive values are valid PIDs
77
; so possible return values are:
77
; so possible return values are:
78
; eax > 0 : process created, eax=PID
78
; eax > 0 : process created, eax=PID
79
 
79
 
80
; -0x10 <= eax < 0 : -eax is filesystem error code:
80
; -0x10 <= eax < 0 : -eax is filesystem error code:
81
; eax = -1  = 0xFFFFFFFF : no hd base and/or partition defined
81
; eax = -1  = 0xFFFFFFFF : no hd base and/or partition defined
82
; eax = -3  = 0xFFFFFFFD : unknown FS
82
; eax = -3  = 0xFFFFFFFD : unknown FS
83
; eax = -5  = 0xFFFFFFFB : file not found
83
; eax = -5  = 0xFFFFFFFB : file not found
84
; eax = -6  = 0xFFFFFFFA : unexpected end of file (probably not executable file)
84
; eax = -6  = 0xFFFFFFFA : unexpected end of file (probably not executable file)
85
; eax = -9  = 0xFFFFFFF7 : fat table corrupted
85
; eax = -9  = 0xFFFFFFF7 : fat table corrupted
86
; eax = -10 = 0xFFFFFFF6 : access denied
86
; eax = -10 = 0xFFFFFFF6 : access denied
87
 
87
 
88
; -0x20 <= eax < -0x10: eax is process creation error code:
88
; -0x20 <= eax < -0x10: eax is process creation error code:
89
; eax = -0x20 = 0xFFFFFFE0 : too many processes
89
; eax = -0x20 = 0xFFFFFFE0 : too many processes
90
; eax = -0x1F = 0xFFFFFFE1 : not Menuet/Kolibri executable
90
; eax = -0x1F = 0xFFFFFFE1 : not Menuet/Kolibri executable
91
; eax = -0x1E = 0xFFFFFFE2 : no memory
91
; eax = -0x1E = 0xFFFFFFE2 : no memory
92
 
92
 
93
; ebx is not changed
93
; ebx is not changed
94
 
94
 
95
; \end{diamond}[18.03.2006]
95
; \end{diamond}[18.03.2006]
96
 
96
 
97
    ; Extract parameters
97
    ; Extract parameters
98
 ;   add    eax, std_application_base_address    ; abs start of info block
98
 ;   add    eax, std_application_base_address    ; abs start of info block
99
 
99
 
100
        cmp     dword [eax+0], 15; GET_DISK_INFO
100
        cmp     dword [eax+0], 15; GET_DISK_INFO
101
        je      fs_info
101
        je      fs_info
102
 
102
 
103
        cmp     dword [CURRENT_TASK], 1; no memory checks for kernel requests
103
        cmp     dword [CURRENT_TASK], 1; no memory checks for kernel requests
104
        jz      no_checks_for_kernel
104
        jz      no_checks_for_kernel
105
        mov     edx, eax
105
        mov     edx, eax
106
        cmp     dword [eax+0], 1
106
        cmp     dword [eax+0], 1
107
        jnz     .usual_check
107
        jnz     .usual_check
108
        mov     ebx, [eax+12]
108
        mov     ebx, [eax+12]
109
 ;   add   ebx,std_application_base_address
109
 ;   add   ebx,std_application_base_address
110
        mov     ecx, [eax+8]
110
        mov     ecx, [eax+8]
111
        call    check_region
111
        call    check_region
112
        test    eax, eax
112
        test    eax, eax
113
        jnz     area_in_app_mem
113
        jnz     area_in_app_mem
114
 
114
 
115
.error_output:
115
.error_output:
116
        mov     esi, buffer_failed
116
        mov     esi, buffer_failed
117
        call    sys_msg_board_str
117
        call    sys_msg_board_str
118
;    mov   eax,7
118
;    mov   eax,7
119
        mov     dword [esp+36], 7
119
        mov     dword [esp+36], 7
120
        ret
120
        ret
121
iglobal
121
iglobal
122
  buffer_failed db 'K : Buffer check failed',13,10,0
122
  buffer_failed db 'K : Buffer check failed',13,10,0
123
endg
123
endg
124
.usual_check:
124
.usual_check:
125
        cmp     dword [eax+0], 0
125
        cmp     dword [eax+0], 0
126
        mov     ecx, 512
126
        mov     ecx, 512
127
        jnz     .small_size
127
        jnz     .small_size
128
        mov     ecx, [eax+8]
128
        mov     ecx, [eax+8]
129
        shl     ecx, 9
129
        shl     ecx, 9
130
.small_size:
130
.small_size:
131
        mov     ebx, [eax+12]
131
        mov     ebx, [eax+12]
132
 ;   add   ebx,std_application_base_address
132
 ;   add   ebx,std_application_base_address
133
        call    check_region
133
        call    check_region
134
        test    eax, eax
134
        test    eax, eax
135
        jz      .error_output
135
        jz      .error_output
136
  area_in_app_mem:
136
  area_in_app_mem:
137
        mov     eax, edx
137
        mov     eax, edx
138
  no_checks_for_kernel:
138
  no_checks_for_kernel:
139
 
139
 
140
  fs_read:
140
  fs_read:
141
 
141
 
142
        mov     ebx, [eax+20]   ; program wants root directory ?
142
        mov     ebx, [eax+20]   ; program wants root directory ?
143
        test    bl, bl
143
        test    bl, bl
144
        je      fs_getroot
144
        je      fs_getroot
145
        test    bh, bh
145
        test    bh, bh
146
        jne     fs_noroot
146
        jne     fs_noroot
147
  fs_getroot:
147
  fs_getroot:
148
; \begin{diamond}[18.03.2006]
148
; \begin{diamond}[18.03.2006]
149
; root - only read is allowed
149
; root - only read is allowed
150
; other operations return "access denied", eax=10
150
; other operations return "access denied", eax=10
151
; (execute operation returns eax=-10)
151
; (execute operation returns eax=-10)
152
        cmp     dword [eax], 0
152
        cmp     dword [eax], 0
153
        jz      .read_root
153
        jz      .read_root
154
        mov     dword [esp+36], 10
154
        mov     dword [esp+36], 10
155
        ret
155
        ret
156
.read_root:
156
.read_root:
157
; \end{diamond}[18.03.2006]
157
; \end{diamond}[18.03.2006]
158
        mov     esi, dir0
158
        mov     esi, dir0
159
        mov     edi, [eax+12]
159
        mov     edi, [eax+12]
160
 ;   add   edi,std_application_base_address
160
 ;   add   edi,std_application_base_address
161
        mov     ecx, 11
161
        mov     ecx, 11
162
        push    ecx
162
        push    ecx
163
;    cld    ; already is
163
;    cld    ; already is
164
        rep movsb
164
        rep movsb
165
        mov     al, 0x10
165
        mov     al, 0x10
166
        stosb
166
        stosb
167
        add     edi, 32-11-1
167
        add     edi, 32-11-1
168
        pop     ecx
168
        pop     ecx
169
        rep movsb
169
        rep movsb
170
        stosb
170
        stosb
171
        and     dword [esp+36], 0; ok read
171
        and     dword [esp+36], 0; ok read
172
        mov     dword [esp+24], 32*2; size of root
172
        mov     dword [esp+24], 32*2; size of root
173
        ret
173
        ret
174
 
174
 
175
  fs_info:                      ;start of code - Mihasik
175
  fs_info:                      ;start of code - Mihasik
176
        push    eax
176
        push    eax
177
        cmp     [eax+21], byte 'r'
177
        cmp     [eax+21], byte 'r'
178
        je      fs_info_r
178
        je      fs_info_r
179
        cmp     [eax+21], byte 'R'
179
        cmp     [eax+21], byte 'R'
180
        je      fs_info_r
180
        je      fs_info_r
181
        mov     eax, 3          ;if unknown disk
181
        mov     eax, 3          ;if unknown disk
182
        xor     ebx, ebx
182
        xor     ebx, ebx
183
        xor     ecx, ecx
183
        xor     ecx, ecx
184
        xor     edx, edx
184
        xor     edx, edx
185
        jmp     fs_info1
185
        jmp     fs_info1
186
  fs_info_r:
186
  fs_info_r:
187
        call    ramdisk_free_space;if ramdisk
187
        call    ramdisk_free_space;if ramdisk
188
        mov     ecx, edi        ;free space in ecx
188
        mov     ecx, edi        ;free space in ecx
189
        shr     ecx, 9          ;free clusters
189
        shr     ecx, 9          ;free clusters
190
        mov     ebx, 2847       ;total clusters
190
        mov     ebx, 2847       ;total clusters
191
        mov     edx, 512        ;cluster size
191
        mov     edx, 512        ;cluster size
192
        xor     eax, eax        ;always 0
192
        xor     eax, eax        ;always 0
193
  fs_info1:
193
  fs_info1:
194
        pop     edi
194
        pop     edi
195
        mov     [esp+36], eax
195
        mov     [esp+36], eax
196
        mov     [esp+24], ebx    ; total clusters on disk
196
        mov     [esp+24], ebx    ; total clusters on disk
197
        mov     [esp+32], ecx    ; free clusters on disk
197
        mov     [esp+32], ecx    ; free clusters on disk
198
        mov     [edi], edx       ; cluster size in bytes
198
        mov     [edi], edx       ; cluster size in bytes
199
        ret                      ;end of code - Mihasik
199
        ret                      ;end of code - Mihasik
200
 
200
 
201
  fs_noroot:
201
  fs_noroot:
202
 
202
 
203
        push    dword [eax+0]   ; read/write/delete/.../makedir/rename/lba/run
203
        push    dword [eax+0]   ; read/write/delete/.../makedir/rename/lba/run
204
        push    dword [eax+4]   ; 512 block number to read
204
        push    dword [eax+4]   ; 512 block number to read
205
        push    dword [eax+8]   ; bytes to write/append or 512 blocks to read
205
        push    dword [eax+8]   ; bytes to write/append or 512 blocks to read
206
        mov     ebx, [eax+12]
206
        mov     ebx, [eax+12]
207
 ;   add   ebx,std_application_base_address
207
 ;   add   ebx,std_application_base_address
208
        push    ebx             ; abs start of return/save area
208
        push    ebx             ; abs start of return/save area
209
 
209
 
210
        lea     esi, [eax+20]   ; abs start of dir + filename
210
        lea     esi, [eax+20]   ; abs start of dir + filename
211
        mov     edi, [eax+16]
211
        mov     edi, [eax+16]
212
 ;   add   edi,std_application_base_address    ; abs start of work area
212
 ;   add   edi,std_application_base_address    ; abs start of work area
213
 
213
 
214
        call    expand_pathz
214
        call    expand_pathz
215
 
215
 
216
        push    edi             ; dir start
216
        push    edi             ; dir start
217
        push    ebx             ; name of file start
217
        push    ebx             ; name of file start
218
 
218
 
219
        mov     eax, [edi+1]
219
        mov     eax, [edi+1]
220
        cmp     eax, 'RD  '
220
        cmp     eax, 'RD  '
221
        je      fs_yesramdisk
221
        je      fs_yesramdisk
222
        cmp     eax, 'RAMD'
222
        cmp     eax, 'RAMD'
223
        jne     fs_noramdisk
223
        jne     fs_noramdisk
224
 
224
 
225
  fs_yesramdisk:
225
  fs_yesramdisk:
226
 
226
 
227
        cmp     byte [edi+1+11], 0
227
        cmp     byte [edi+1+11], 0
228
        je      fs_give_dir1
228
        je      fs_give_dir1
229
 
229
 
230
        mov     eax, [edi+1+12]
230
        mov     eax, [edi+1+12]
231
        cmp     eax, '1   '
231
        cmp     eax, '1   '
232
        je      fs_yesramdisk_first
232
        je      fs_yesramdisk_first
233
        cmp     eax, 'FIRS'
233
        cmp     eax, 'FIRS'
234
        jne     fs_noramdisk
234
        jne     fs_noramdisk
235
 
235
 
236
  fs_yesramdisk_first:
236
  fs_yesramdisk_first:
237
 
237
 
238
        cmp     dword [esp+20], 8; LBA read ramdisk
238
        cmp     dword [esp+20], 8; LBA read ramdisk
239
        jne     fs_no_LBA_read_ramdisk
239
        jne     fs_no_LBA_read_ramdisk
240
 
240
 
241
        mov     eax, [esp+16]   ; LBA block to read
241
        mov     eax, [esp+16]   ; LBA block to read
242
        mov     ecx, [esp+8]    ; abs pointer to return area
242
        mov     ecx, [esp+8]    ; abs pointer to return area
243
 
243
 
244
        call    LBA_read_ramdisk
244
        call    LBA_read_ramdisk
245
        jmp     file_system_return
245
        jmp     file_system_return
246
 
246
 
247
 
247
 
248
  fs_no_LBA_read_ramdisk:
248
  fs_no_LBA_read_ramdisk:
249
 
249
 
250
        cmp     dword [esp+20], 0; READ
250
        cmp     dword [esp+20], 0; READ
251
        jne     fs_noramdisk_read
251
        jne     fs_noramdisk_read
252
 
252
 
253
        mov     eax, [esp+4]    ; fname
253
        mov     eax, [esp+4]    ; fname
254
        add     eax, 2*12+1
254
        add     eax, 2*12+1
255
        mov     ebx, [esp+16]   ; block start
255
        mov     ebx, [esp+16]   ; block start
256
        inc     ebx
256
        inc     ebx
257
        mov     ecx, [esp+12]   ; block count
257
        mov     ecx, [esp+12]   ; block count
258
        mov     edx, [esp+8]    ; return
258
        mov     edx, [esp+8]    ; return
259
        mov     esi, [esp+0]
259
        mov     esi, [esp+0]
260
        sub     esi, eax
260
        sub     esi, eax
261
        add     esi, 12+1       ; file name length
261
        add     esi, 12+1       ; file name length
262
        call    fileread
262
        call    fileread
263
 
263
 
264
        jmp     file_system_return
264
        jmp     file_system_return
265
 
265
 
266
 
266
 
267
  fs_noramdisk_read:
267
  fs_noramdisk_read:
268
  fs_noramdisk:
268
  fs_noramdisk:
269
 
269
 
270
  ;********************************************************************
270
  ;********************************************************************
271
        mov     eax, [edi+1]
271
        mov     eax, [edi+1]
272
        cmp     eax, 'FD  '
272
        cmp     eax, 'FD  '
273
        je      fs_yesflpdisk
273
        je      fs_yesflpdisk
274
        cmp     eax, 'FLOP'
274
        cmp     eax, 'FLOP'
275
        jne     fs_noflpdisk
275
        jne     fs_noflpdisk
276
 
276
 
277
  fs_yesflpdisk:
277
  fs_yesflpdisk:
278
        call    reserve_flp
278
        call    reserve_flp
279
 
279
 
280
        cmp     byte [edi+1+11], 0
280
        cmp     byte [edi+1+11], 0
281
        je      fs_give_dir1
281
        je      fs_give_dir1
282
 
282
 
283
        mov     eax, [edi+1+12]
283
        mov     eax, [edi+1+12]
284
        cmp     eax, '1   '
284
        cmp     eax, '1   '
285
        je      fs_yesflpdisk_first
285
        je      fs_yesflpdisk_first
286
        cmp     eax, 'FIRS'
286
        cmp     eax, 'FIRS'
287
        je      fs_yesflpdisk_first
287
        je      fs_yesflpdisk_first
288
        cmp     eax, '2   '
288
        cmp     eax, '2   '
289
        je      fs_yesflpdisk_second
289
        je      fs_yesflpdisk_second
290
        cmp     eax, 'SECO'
290
        cmp     eax, 'SECO'
291
        jne     fs_noflpdisk
291
        jne     fs_noflpdisk
292
        jmp     fs_yesflpdisk_second
292
        jmp     fs_yesflpdisk_second
293
 
293
 
294
  fs_yesflpdisk_first:
294
  fs_yesflpdisk_first:
295
        mov     [flp_number], 1
295
        mov     [flp_number], 1
296
        jmp     fs_yesflpdisk_start
296
        jmp     fs_yesflpdisk_start
297
  fs_yesflpdisk_second:
297
  fs_yesflpdisk_second:
298
        mov     [flp_number], 2
298
        mov     [flp_number], 2
299
  fs_yesflpdisk_start:
299
  fs_yesflpdisk_start:
300
        cmp     dword [esp+20], 0; READ
300
        cmp     dword [esp+20], 0; READ
301
        jne     fs_noflpdisk_read
301
        jne     fs_noflpdisk_read
302
 
302
 
303
        mov     eax, [esp+4]    ; fname
303
        mov     eax, [esp+4]    ; fname
304
        add     eax, 2*12+1
304
        add     eax, 2*12+1
305
        mov     ebx, [esp+16]   ; block start
305
        mov     ebx, [esp+16]   ; block start
306
        inc     ebx
306
        inc     ebx
307
        mov     ecx, [esp+12]   ; block count
307
        mov     ecx, [esp+12]   ; block count
308
        mov     edx, [esp+8]    ; return
308
        mov     edx, [esp+8]    ; return
309
        mov     esi, [esp+0]
309
        mov     esi, [esp+0]
310
        sub     esi, eax
310
        sub     esi, eax
311
        add     esi, 12+1       ; file name length
311
        add     esi, 12+1       ; file name length
312
        call    floppy_fileread
312
        call    floppy_fileread
313
 
313
 
314
        jmp     file_system_return
314
        jmp     file_system_return
315
 
315
 
316
 
316
 
317
  fs_noflpdisk_read:
317
  fs_noflpdisk_read:
318
  fs_noflpdisk:
318
  fs_noflpdisk:
319
  ;*****************************************************************
319
  ;*****************************************************************
320
 
-
 
321
        mov     eax, [edi+1]
-
 
322
        cmp     eax, 'HD0 '
-
 
323
        je      fs_yesharddisk_IDE0
-
 
324
        cmp     eax, 'HD1 '
-
 
325
        je      fs_yesharddisk_IDE1
-
 
326
        cmp     eax, 'HD2 '
-
 
327
        je      fs_yesharddisk_IDE2
-
 
328
        cmp     eax, 'HD3 '
-
 
329
        je      fs_yesharddisk_IDE3
-
 
330
        jmp     old_path_harddisk
-
 
331
fs_yesharddisk_IDE0:
-
 
332
        call    reserve_hd1
-
 
333
        mov     [hdbase], 0x1f0
-
 
334
        mov     [hdid], 0x0
-
 
335
        mov     [hdpos], 1
-
 
336
        jmp     fs_yesharddisk_partition
-
 
337
fs_yesharddisk_IDE1:
-
 
338
        call    reserve_hd1
-
 
339
        mov     [hdbase], 0x1f0
-
 
340
        mov     [hdid], 0x10
-
 
341
        mov     [hdpos], 2
-
 
342
        jmp     fs_yesharddisk_partition
-
 
343
fs_yesharddisk_IDE2:
-
 
344
        call    reserve_hd1
-
 
345
        mov     [hdbase], 0x170
-
 
346
        mov     [hdid], 0x0
-
 
347
        mov     [hdpos], 3
-
 
348
        jmp     fs_yesharddisk_partition
-
 
349
fs_yesharddisk_IDE3:
-
 
350
        call    reserve_hd1
-
 
351
        mov     [hdbase], 0x170
-
 
352
        mov     [hdid], 0x10
-
 
353
        mov     [hdpos], 4
-
 
354
fs_yesharddisk_partition:
-
 
355
        call    reserve_hd_channel
-
 
356
;    call  choice_necessity_partition
-
 
357
;    jmp   fs_yesharddisk_all
-
 
358
        jmp     fs_for_new_semantic
-
 
359
 
-
 
360
choice_necessity_partition:
-
 
361
        mov     eax, [edi+1+12]
-
 
362
        call    StringToNumber
-
 
363
        mov     [fat32part], eax
-
 
364
choice_necessity_partition_1:
-
 
365
        mov     ecx, [hdpos]
-
 
366
        xor     eax, eax
-
 
367
        mov     [hd_entries], eax; entries in hd cache
-
 
368
        mov     edx, DRIVE_DATA+2
-
 
369
        cmp     ecx, 0x80
-
 
370
        jb      search_partition_array
-
 
371
        mov     ecx, 4
-
 
372
 search_partition_array:
-
 
373
        mov     bl, [edx]
-
 
374
        movzx   ebx, bl
-
 
375
        add     eax, ebx
-
 
376
        inc     edx
-
 
377
        loop    search_partition_array
-
 
378
        mov     ecx, [hdpos]
-
 
379
        mov     edx, BiosDiskPartitions
-
 
380
        sub     ecx, 0x80
-
 
381
        jb      .s
-
 
382
        je      .f
-
 
383
 @@:
-
 
384
        mov     ebx, [edx]
-
 
385
        add     edx, 4
-
 
386
        add     eax, ebx
-
 
387
        loop    @b
-
 
388
        jmp     .f
-
 
389
 .s:
-
 
390
        sub     eax, ebx
-
 
391
 .f:
-
 
392
        add     eax, [known_part];   add   eax,[fat32part]
-
 
393
        dec     eax
-
 
394
        xor     edx, edx
-
 
395
        imul    eax, 100
-
 
396
        add     eax, DRIVE_DATA+0xa
-
 
397
        mov     [transfer_adress], eax
-
 
398
        call    partition_data_transfer_1
-
 
399
        ret
-
 
400
 
320
 
401
 old_path_harddisk:
321
 old_path_harddisk:
402
        mov     eax, [edi+1]
322
        mov     eax, [edi+1]
403
        cmp     eax, 'HD  '
323
        cmp     eax, 'HD  '
404
        je      fs_yesharddisk
324
        je      fs_yesharddisk
405
        cmp     eax, 'HARD'
325
        cmp     eax, 'HARD'
406
        jne     fs_noharddisk
326
        jne     fs_noharddisk
407
 
327
 
408
  fs_yesharddisk:
328
  fs_yesharddisk:
409
        cmp     dword [esp+20], 8; LBA read
329
        cmp     dword [esp+20], 8; LBA read
410
        jne     fs_no_LBA_read
330
        jne     fs_no_LBA_read
411
        mov     eax, [esp+16]   ; LBA block to read
331
        mov     eax, [esp+16]   ; LBA block to read
412
        lea     ebx, [edi+1+12] ; pointer to FIRST/SECOND/THIRD/FOURTH
332
        lea     ebx, [edi+1+12] ; pointer to FIRST/SECOND/THIRD/FOURTH
413
        mov     ecx, [esp+8]    ; abs pointer to return area
333
        mov     ecx, [esp+8]    ; abs pointer to return area
414
        call    LBA_read
334
        call    LBA_read
415
        jmp     file_system_return
335
        jmp     file_system_return
416
 
336
 
417
  fs_no_LBA_read:
337
  fs_no_LBA_read:
418
 
-
 
419
        cmp     byte [edi+1+11], 0; directory read
-
 
420
        je      fs_give_dir1
-
 
421
        call    reserve_hd1
-
 
422
 fs_for_new_semantic:
-
 
423
        call    choice_necessity_partition
-
 
424
 
-
 
425
  fs_yesharddisk_all:
-
 
426
        mov     eax, 1
-
 
427
        mov     ebx, [esp+24+24]
-
 
428
        cmp     [hdpos], 0      ; is hd base set?
-
 
429
        jz      hd_err_return
-
 
430
        cmp     [fat32part], 0  ; is partition set?
-
 
431
        jnz     @f
338
 
432
hd_err_return:
-
 
433
        call    free_hd_channel
-
 
434
        and     [hd1_status], 0
-
 
435
        jmp     file_system_return
-
 
436
@@:
-
 
437
 
-
 
438
        call    free_hd_channel
-
 
439
        and     [hd1_status], 0
339
hd_err_return:
440
 
340
 
441
  fs_noharddisk:
341
  fs_noharddisk:
442
; \begin{diamond}[18.03.2006]
342
; \begin{diamond}[18.03.2006]
443
        mov     eax, 5   ; file not found
343
        mov     eax, 5   ; file not found
444
; а может быть, возвращать другой код ошибки?
344
; а может быть, возвращать другой код ошибки?
445
        mov     ebx, [esp+24+24]; do not change ebx in application
345
        mov     ebx, [esp+24+24]; do not change ebx in application
446
; \end{diamond}[18.03.2006]
346
; \end{diamond}[18.03.2006]
447
 
347
 
448
  file_system_return:
348
  file_system_return:
449
 
349
 
450
        add     esp, 24
350
        add     esp, 24
451
 
351
 
452
        mov     [esp+36], eax
352
        mov     [esp+36], eax
453
        mov     [esp+24], ebx
353
        mov     [esp+24], ebx
454
        ret
354
        ret
455
 
355
 
456
 
356
 
457
  fs_give_dir1:
357
  fs_give_dir1:
458
 
358
 
459
; \begin{diamond}[18.03.2006]
359
; \begin{diamond}[18.03.2006]
460
; /RD,/FD,/HD - only read is allowed
360
; /RD,/FD,/HD - only read is allowed
461
; other operations return "access denied", eax=10
361
; other operations return "access denied", eax=10
462
; (execute operation returns eax=-10)
362
; (execute operation returns eax=-10)
463
        cmp     dword [esp+20], 0
363
        cmp     dword [esp+20], 0
464
        jz      .read
364
        jz      .read
465
        add     esp, 20
365
        add     esp, 20
466
        pop     ecx
366
        pop     ecx
467
        mov     dword [esp+36], 10
367
        mov     dword [esp+36], 10
468
        ret
368
        ret
469
.read:
369
.read:
470
; \end{diamond}[18.03.2006]
370
; \end{diamond}[18.03.2006]
471
        mov     al, 0x10
371
        mov     al, 0x10
472
        mov     ebx, 1
372
        mov     ebx, 1
473
        mov     edi, [esp+8]
373
        mov     edi, [esp+8]
474
        mov     esi, dir1
374
        mov     esi, dir1
475
  fs_d1_new:
375
  fs_d1_new:
476
        mov     ecx, 11
376
        mov     ecx, 11
477
;    cld
377
;    cld
478
        rep movsb
378
        rep movsb
479
        stosb
379
        stosb
480
        add     edi, 32-11-1
380
        add     edi, 32-11-1
481
        dec     ebx
381
        dec     ebx
482
        jne     fs_d1_new
382
        jne     fs_d1_new
483
 
383
 
484
        add     esp, 24
384
        add     esp, 24
485
 
385
 
486
        and     dword [esp+36], 0; ok read
386
        and     dword [esp+36], 0; ok read
487
        mov     dword [esp+24], 32*1; dir/data size
387
        mov     dword [esp+24], 32*1; dir/data size
488
        ret
388
        ret
489
 
389
 
490
 
390
 
491
 
391
 
492
LBA_read_ramdisk:
392
LBA_read_ramdisk:
493
 
393
 
494
        cmp     [lba_read_enabled], 1
394
        cmp     [lba_read_enabled], 1
495
        je      lbarrl1
395
        je      lbarrl1
496
 
396
 
497
        xor     ebx, ebx
397
        xor     ebx, ebx
498
        mov     eax, 2
398
        mov     eax, 2
499
        ret
399
        ret
500
 
400
 
501
  lbarrl1:
401
  lbarrl1:
502
 
402
 
503
        cmp     eax, 18*2*80
403
        cmp     eax, 18*2*80
504
        jb      lbarrl2
404
        jb      lbarrl2
505
        xor     ebx, ebx
405
        xor     ebx, ebx
506
        mov     eax, 3
406
        mov     eax, 3
507
        ret
407
        ret
508
 
408
 
509
  lbarrl2:
409
  lbarrl2:
510
 
410
 
511
        pushad
411
        pushad
512
 
412
 
513
        call    restorefatchain
413
        call    restorefatchain
514
 
414
 
515
        mov     edi, ecx
415
        mov     edi, ecx
516
        mov     esi, eax
416
        mov     esi, eax
517
 
417
 
518
        shl     esi, 9
418
        shl     esi, 9
519
        add     esi, RAMDISK
419
        add     esi, RAMDISK
520
        mov     ecx, 512/4
420
        mov     ecx, 512/4
521
;    cld
421
;    cld
522
        rep movsd
422
        rep movsd
523
 
423
 
524
        popad
424
        popad
525
 
425
 
526
        xor     ebx, ebx
426
        xor     ebx, ebx
527
        xor     eax, eax
427
        xor     eax, eax
528
        ret
428
        ret
529
 
429
 
530
LBA_read:
430
LBA_read:
531
 
431
 
532
; IN:
432
; IN:
533
;
433
;
534
; eax = LBA block to read
434
; eax = LBA block to read
535
; ebx = pointer to FIRST/SECOND/THIRD/FOURTH
435
; ebx = pointer to FIRST/SECOND/THIRD/FOURTH
536
; ecx = abs pointer to return area
436
; ecx = abs pointer to return area
537
 
437
 
538
        cmp     [lba_read_enabled], 1
438
        cmp     [lba_read_enabled], 1
539
        je      lbarl1
439
        je      lbarl1
540
        mov     eax, 2
440
        mov     eax, 2
541
        ret
441
        ret
542
 
442
 
543
  lbarl1:
443
  lbarl1:
-
 
444
 
-
 
445
        pushad
544
 
446
        mov     ecx, ide_mutex
-
 
447
        call    mutex_lock
545
        call    reserve_hd1
448
        popad
546
 
449
 
547
        push    eax
450
        push    eax
548
        push    ecx
451
        push    ecx
549
 
452
 
550
        mov     edi, hd_address_table
453
        mov     edi, hd_address_table
551
        mov     esi, dir1
454
        mov     esi, dir1
552
        mov     eax, [ebx]
455
        mov     eax, [ebx]
553
        mov     edx, '1   '
456
        mov     edx, '1   '
554
        mov     ecx, 4
457
        mov     ecx, 4
555
  blar0:
458
  blar0:
556
        cmp     eax, [esi]
459
        cmp     eax, [esi]
557
        je      blar2
460
        je      blar2
558
        cmp     eax, edx
461
        cmp     eax, edx
559
        je      blar2
462
        je      blar2
560
        inc     edx
463
        inc     edx
561
        add     edi, 8
464
        add     edi, 8
562
        add     esi, 11
465
        add     esi, 11
563
        dec     ecx
466
        dec     ecx
564
        jnz     blar0
467
        jnz     blar0
565
 
468
 
566
        mov     eax, 1
469
        mov     eax, 1
567
        mov     ebx, 1
470
        mov     ebx, 1
568
        jmp     LBA_read_ret
471
        jmp     LBA_read_ret
569
 
472
 
570
  blar2:
473
  blar2:
571
        mov     eax, [edi+0]
474
        mov     eax, [edi+0]
572
        mov     ebx, [edi+4]
475
        mov     ebx, [edi+4]
573
 
476
 
574
        mov     [hdbase], eax
477
        mov     [hdbase], eax
575
        mov     [hdid], ebx
478
        mov     [hdid], ebx
576
 
479
 
577
        call    wait_for_hd_idle
480
        call    wait_for_hd_idle
578
        cmp     [hd_error], 0
481
        cmp     [hd_error], 0
579
        jne     hd_lba_error
482
        jne     hd_lba_error
580
 
483
 
581
    ; eax = hd port
484
    ; eax = hd port
582
    ; ebx = set for primary (0x00) or slave (0x10)
485
    ; ebx = set for primary (0x00) or slave (0x10)
583
 
486
 
584
        cli
487
        cli
585
 
488
 
586
        mov     edx, eax
489
        mov     edx, eax
587
        inc     edx
490
        inc     edx
588
        xor     eax, eax
491
        xor     eax, eax
589
        out     dx, al
492
        out     dx, al
590
        inc     edx
493
        inc     edx
591
        inc     eax
494
        inc     eax
592
        out     dx, al
495
        out     dx, al
593
        inc     edx
496
        inc     edx
594
        mov     eax, [esp+4]
497
        mov     eax, [esp+4]
595
        out     dx, al
498
        out     dx, al
596
        shr     eax, 8
499
        shr     eax, 8
597
        inc     edx
500
        inc     edx
598
        out     dx, al
501
        out     dx, al
599
        shr     eax, 8
502
        shr     eax, 8
600
        inc     edx
503
        inc     edx
601
        out     dx, al
504
        out     dx, al
602
        shr     eax, 8
505
        shr     eax, 8
603
        inc     edx
506
        inc     edx
604
        and     al, 1+2+4+8
507
        and     al, 1+2+4+8
605
        add     al, bl
508
        add     al, bl
606
        add     al, 128+64+32
509
        add     al, 128+64+32
607
        out     dx, al
510
        out     dx, al
608
 
511
 
609
        inc     edx
512
        inc     edx
610
        mov     al, 20h
513
        mov     al, 20h
611
        out     dx, al
514
        out     dx, al
612
 
515
 
613
        sti
516
        sti
614
 
517
 
615
        call    wait_for_sector_buffer
518
        call    wait_for_sector_buffer
616
        cmp     [hd_error], 0
519
        cmp     [hd_error], 0
617
        jne     hd_lba_error
520
        jne     hd_lba_error
618
 
521
 
619
        cli
522
        cli
620
 
523
 
621
        mov     edi, [esp+0]
524
        mov     edi, [esp+0]
622
        mov     ecx, 256
525
        mov     ecx, 256
623
        sub     edx, 7
526
        sub     edx, 7
624
        cld
527
        cld
625
        rep insw
528
        rep insw
626
 
529
 
627
        sti
530
        sti
628
 
531
 
629
        xor     eax, eax
532
        xor     eax, eax
630
        xor     ebx, ebx
533
        xor     ebx, ebx
631
 
534
 
632
  LBA_read_ret:
535
  LBA_read_ret:
633
        mov     [hd_error], 0
536
        mov     [hd_error], 0
634
        mov     [hd1_status], 0
537
        mov     [hd1_status], 0
635
        add     esp, 2*4
538
        add     esp, 2*4
-
 
539
        pushad
-
 
540
        mov     ecx, ide_mutex
-
 
541
        call    mutex_unlock
-
 
542
        popad
636
 
543
 
637
        ret
544
        ret
638
 
545
 
639
 
546
 
640
expand_pathz:
547
expand_pathz:
641
; IN:
548
; IN:
642
;   esi = asciiz path & file
549
;   esi = asciiz path & file
643
;   edi = buffer for path & file name
550
;   edi = buffer for path & file name
644
; OUT:
551
; OUT:
645
;   edi = directory & file : / 11 + / 11 + / 11 - zero terminated
552
;   edi = directory & file : / 11 + / 11 + / 11 - zero terminated
646
;   ebx = /file name - zero terminated
553
;   ebx = /file name - zero terminated
647
;   esi = pointer after source
554
;   esi = pointer after source
648
 
555
 
649
        push    eax
556
        push    eax
650
        push    ecx
557
        push    ecx
651
        push    edi;[esp+0]
558
        push    edi;[esp+0]
652
 
559
 
653
  pathz_start:
560
  pathz_start:
654
        mov     byte [edi], '/'
561
        mov     byte [edi], '/'
655
        inc     edi
562
        inc     edi
656
        mov     al, 32
563
        mov     al, 32
657
        mov     ecx, 11
564
        mov     ecx, 11
658
        cld
565
        cld
659
        rep stosb               ; clear filename area
566
        rep stosb               ; clear filename area
660
        sub     edi, 11
567
        sub     edi, 11
661
        mov     ebx, edi        ; start of dir/file name
568
        mov     ebx, edi        ; start of dir/file name
662
 
569
 
663
  pathz_new_char:
570
  pathz_new_char:
664
        mov     al, [esi]
571
        mov     al, [esi]
665
        inc     esi
572
        inc     esi
666
        cmp     al, 0
573
        cmp     al, 0
667
        je      pathz_end
574
        je      pathz_end
668
 
575
 
669
        cmp     al, '/'
576
        cmp     al, '/'
670
        jne     pathz_not_path
577
        jne     pathz_not_path
671
        cmp     edi, ebx        ; skip first '/'
578
        cmp     edi, ebx        ; skip first '/'
672
        jz      pathz_new_char
579
        jz      pathz_new_char
673
        lea     edi, [ebx+11]   ; start of next directory
580
        lea     edi, [ebx+11]   ; start of next directory
674
        jmp     pathz_start
581
        jmp     pathz_start
675
 
582
 
676
  pathz_not_path:
583
  pathz_not_path:
677
        cmp     al, '.'
584
        cmp     al, '.'
678
        jne     pathz_not_ext
585
        jne     pathz_not_ext
679
        lea     edi, [ebx+8]    ; start of extension
586
        lea     edi, [ebx+8]    ; start of extension
680
        jmp     pathz_new_char
587
        jmp     pathz_new_char
681
 
588
 
682
  pathz_not_ext:
589
  pathz_not_ext:
683
        cmp     al, 'a'
590
        cmp     al, 'a'
684
        jb      pathz_not_low
591
        jb      pathz_not_low
685
        cmp     al, 'z'
592
        cmp     al, 'z'
686
        ja      pathz_not_low
593
        ja      pathz_not_low
687
        sub     al, 0x20        ; char to uppercase
594
        sub     al, 0x20        ; char to uppercase
688
 
595
 
689
  pathz_not_low:
596
  pathz_not_low:
690
        mov     [edi], al
597
        mov     [edi], al
691
        inc     edi
598
        inc     edi
692
        mov     eax, [esp+0]    ; start_of_dest_path
599
        mov     eax, [esp+0]    ; start_of_dest_path
693
        add     eax, 512        ; keep maximum path under 512 bytes
600
        add     eax, 512        ; keep maximum path under 512 bytes
694
        cmp     edi, eax
601
        cmp     edi, eax
695
        jb      pathz_new_char
602
        jb      pathz_new_char
696
 
603
 
697
  pathz_end:
604
  pathz_end:
698
        cmp     ebx, edi        ; if path end with '/'
605
        cmp     ebx, edi        ; if path end with '/'
699
        jnz     pathz_put_zero  ; go back 1 level
606
        jnz     pathz_put_zero  ; go back 1 level
700
        sub     ebx, 12
607
        sub     ebx, 12
701
 
608
 
702
  pathz_put_zero:
609
  pathz_put_zero:
703
        mov     byte [ebx+11], 0
610
        mov     byte [ebx+11], 0
704
        dec     ebx             ; include '/' char into file name
611
        dec     ebx             ; include '/' char into file name
705
        pop     edi
612
        pop     edi
706
        pop     ecx
613
        pop     ecx
707
        pop     eax
614
        pop     eax
708
        ret
615
        ret
709
 
616
 
710
;*******************************************
617
;*******************************************
711
;* string to number
618
;* string to number
712
;* input eax - 4 byte string
619
;* input eax - 4 byte string
713
;* output eax - number
620
;* output eax - number
714
;*******************************************
621
;*******************************************
715
StringToNumber:
622
StringToNumber:
716
;    ПЕРЕВОД СТРОКОВОГО ЧИСЛА В ЧИСЛОВОЙ ВИД
623
;    ПЕРЕВОД СТРОКОВОГО ЧИСЛА В ЧИСЛОВОЙ ВИД
717
;    Вход:
624
;    Вход:
718
;        EDI - адрес строки с числом. Конец числа отмечен кодом 0Dh
625
;        EDI - адрес строки с числом. Конец числа отмечен кодом 0Dh
719
;    Выход:
626
;    Выход:
720
;        CF - индикатор ошибок:
627
;        CF - индикатор ошибок:
721
;            0 - ошибок нет;
628
;            0 - ошибок нет;
722
;            1 - ошибка
629
;            1 - ошибка
723
;        Если CF=0, то AX - число.
630
;        Если CF=0, то AX - число.
724
 
631
 
725
        push    bx
632
        push    bx
726
        push    cx
633
        push    cx
727
        push    dx
634
        push    dx
728
        push    edi
635
        push    edi
729
        mov     [partition_string], eax
636
        mov     [partition_string], eax
730
        mov     edi, partition_string
637
        mov     edi, partition_string
731
        xor     cx, cx
638
        xor     cx, cx
732
i1:
639
i1:
733
        mov     al, [edi]
640
        mov     al, [edi]
734
        cmp     al, 32;13
641
        cmp     al, 32;13
735
        je      i_exit
642
        je      i_exit
736
;    cmp    al,'0'
643
;    cmp    al,'0'
737
;    jb    err
644
;    jb    err
738
;    cmp    al,'9'
645
;    cmp    al,'9'
739
;    ja    err
646
;    ja    err
740
        sub     al, 48
647
        sub     al, 48
741
        shl     cx, 1
648
        shl     cx, 1
742
        jc      error
649
        jc      error
743
        mov     bx, cx
650
        mov     bx, cx
744
        shl     cx, 1
651
        shl     cx, 1
745
        jc      error
652
        jc      error
746
        shl     cx, 1
653
        shl     cx, 1
747
        jc      error
654
        jc      error
748
        add     cx, bx
655
        add     cx, bx
749
        jc      error
656
        jc      error
750
        cbw
657
        cbw
751
        add     cx, ax
658
        add     cx, ax
752
        jc      error
659
        jc      error
753
i3:
660
i3:
754
        inc     edi
661
        inc     edi
755
        jmp     i1
662
        jmp     i1
756
i_exit:
663
i_exit:
757
        mov     ax, cx
664
        mov     ax, cx
758
        clc
665
        clc
759
i4:
666
i4:
760
        movzx   eax, ax
667
        movzx   eax, ax
761
        pop     edi
668
        pop     edi
762
        pop     dx
669
        pop     dx
763
        pop     cx
670
        pop     cx
764
        pop     bx
671
        pop     bx
765
        ret
672
        ret
766
 
673
 
767
error:
674
error:
768
        stc
675
        stc
769
        jmp     i4
676
        jmp     i4
770
 
677
 
771
partition_string:
678
partition_string:
772
                  dd 0
679
                  dd 0
773
                  db 32
680
                  db 32