Subversion Repositories Kolibri OS

Rev

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

Rev 262 Rev 269
Line 70... Line 70...
70
   cld
70
   cld
71
   rep stosd
71
   rep stosd
72
}
72
}
Line 73... Line 73...
73
 
73
 
74
align 4
74
align 4
75
proc fs_exec_EX stdcall file_name:dword, cmd_line:dword, flags:dword
75
proc fs_exec stdcall file_name:dword, cmd_line:dword, flags:dword
76
           locals
76
           locals
77
             save_cr3      dd ?
77
             save_cr3      dd ?
78
             slot          dd ?
78
             slot          dd ?
79
             slot_base     dd ?
79
             slot_base     dd ?
Line 83... Line 83...
83
             app_cmdline   dd ? ;0x00
83
             app_cmdline   dd ? ;0x00
84
             app_path      dd ? ;0x04
84
             app_path      dd ? ;0x04
85
             app_eip       dd ? ;0x08
85
             app_eip       dd ? ;0x08
86
             app_esp       dd ? ;0x0C
86
             app_esp       dd ? ;0x0C
87
             app_mem       dd ? ;0x10
87
             app_mem       dd ? ;0x10
-
 
88
             app_i_end     dd ? ;0x14
88
           endl
89
           endl
Line 89... Line 90...
89
 
90
 
90
           stdcall load_file,[file_name]
91
           stdcall load_file,[file_name]
91
           mov  ecx, -ERROR_FILE_NOT_FOUND
92
           mov  ecx, -ERROR_FILE_NOT_FOUND
92
           test eax, eax
93
           test eax, eax
Line 93... Line 94...
93
           jz .err_file
94
           jz .err_file
94
 
95
 
Line 95... Line -...
95
           mov [file_base], eax
-
 
96
           mov [file_size], ebx
-
 
97
 
-
 
98
           pushfd
96
           mov [file_base], eax
99
           cli
97
           mov [file_size], ebx
100
 
98
 
101
           lea ebx, [app_cmdline]
99
           lea ebx, [app_cmdline]
102
           call test_app_header
100
           call test_app_header
Line 117... Line 115...
117
           mov eax, 1
115
           mov eax, 1
118
           xchg eax, [application_table_status]
116
           xchg eax, [application_table_status]
119
           cmp eax, 0
117
           cmp eax, 0
120
           jne .wait_lock
118
           jne .wait_lock
Line -... Line 119...
-
 
119
 
-
 
120
           pushfd
-
 
121
           cli
121
 
122
 
Line 122... Line 123...
122
           call set_application_table_status
123
           call set_application_table_status
123
 
124
 
124
           call get_new_process_place
125
           call get_new_process_place
125
           test eax, eax
126
           test eax, eax
Line 126... Line 127...
126
           mov ecx, -0x20      ; too many processes
127
           mov ecx, -0x20      ; too many processes
127
           jz .err_hdr
128
           jz .err
128
 
129
 
129
           mov [slot], eax
130
           mov [slot], eax
Line 155... Line 156...
155
           loop .copy_process_name_loop
156
           loop .copy_process_name_loop
156
.copy_process_name_done:
157
.copy_process_name_done:
Line 157... Line 158...
157
 
158
 
158
           mov ebx, cr3
159
           mov ebx, cr3
159
           mov [save_cr3], ebx
-
 
160
     if GREEDY_KERNEL
-
 
161
           stdcall create_app_space,[app_mem],[file_size]
160
           mov [save_cr3], ebx
162
     else
161
 
163
           stdcall create_app_space,[app_mem],[app_mem]
-
 
164
     end if
162
           stdcall create_app_space,[app_mem],[file_base],[file_size]
165
           test eax, eax
163
           test eax, eax
Line 166... Line 164...
166
           jz .failed
164
           jz .failed
167
 
165
 
168
           mov   ebx,[slot_base]
166
           mov   ebx,[slot_base]
169
           mov   [ebx+APPDATA.dir_table],eax
167
           mov   [ebx+APPDATA.dir_table],eax
Line -... Line 168...
-
 
168
           mov   eax,[app_mem]
-
 
169
           mov   [ebx+APPDATA.mem_size],eax
170
           mov   eax,[app_mem]
170
 
171
           mov   [ebx+APPDATA.mem_size],eax
171
if not GREEDY_KERNEL
-
 
172
           mov ecx, [app_i_end]
172
 
173
           mov edi, [file_size]
-
 
174
           add edi, 4095
-
 
175
           and edi, not 4095
173
           mov ecx, [file_size]
176
           sub ecx, edi
174
           mov eax, ecx
177
           jna @F
175
           shr ecx, 2
178
 
176
           mov esi, [file_base]
-
 
177
           mov edi, new_app_base
-
 
178
           cld
-
 
179
           rep movsd
-
 
180
           and eax, 3
179
           xor eax, eax
181
           jz @F
180
           add edi, new_app_base
-
 
181
           cld
-
 
182
           rep stosb
-
 
183
@@:
-
 
184
end if
182
           mov ecx, eax
185
 
183
           rep movsb
186
; release only virtual space, not phisical memory
184
@@:
187
 
185
           stdcall kernel_free, [file_base]
188
           stdcall free_kernel_space, [file_base]
Line 186... Line 189...
186
           lea eax, [app_cmdline]
189
           lea eax, [app_cmdline]
Line 196... Line 199...
196
           mov eax,[process_number]  ;set result
199
           mov eax,[process_number]  ;set result
197
           ret
200
           ret
198
.failed:
201
.failed:
199
           mov eax, [save_cr3]
202
           mov eax, [save_cr3]
200
           call set_cr3
203
           call set_cr3
-
 
204
.err:
-
 
205
           popfd
201
.err_hdr:
206
.err_hdr:
202
           stdcall kernel_free,[file_base]
207
           stdcall kernel_free,[file_base]
203
           popfd
-
 
204
.err_file:
208
.err_file:
205
           xor eax, eax
209
           xor eax, eax
206
           mov [application_table_status],eax
210
           mov [application_table_status],eax
207
           ret
211
           ret
208
endp
212
endp
Line 232... Line 236...
232
           sub  edx,0x10
236
           sub  edx,0x10
233
           mov  [ebx+0x0C], edx                ;app_esp
237
           mov  [ebx+0x0C], edx                ;app_esp
234
           mov  ecx,[APP_HEADER_00.i_param]
238
           mov  ecx,[APP_HEADER_00.i_param]
235
           mov  [ebx], ecx                     ;app_cmdline
239
           mov  [ebx], ecx                     ;app_cmdline
236
           mov  [ebx+4], dword 0               ;app_path
240
           mov  [ebx+4], dword 0               ;app_path
-
 
241
           mov  edx, [APP_HEADER_00.i_end]
-
 
242
           mov  [ebx+0x14], edx
237
           ret
243
           ret
Line 238... Line 244...
238
 
244
 
Line 239... Line 245...
239
 .check_01_header:
245
 .check_01_header:
Line 249... Line 255...
249
           mov  [ebx+0x0C], ecx                ;app_esp
255
           mov  [ebx+0x0C], ecx                ;app_esp
250
           mov  edx,[APP_HEADER_01.i_param]
256
           mov  edx,[APP_HEADER_01.i_param]
251
           mov  [ebx], edx                     ;app_cmdline
257
           mov  [ebx], edx                     ;app_cmdline
252
           mov  ecx,[APP_HEADER_01.i_icon]
258
           mov  ecx,[APP_HEADER_01.i_icon]
253
           mov  [ebx+4], ecx                   ;app_path
259
           mov  [ebx+4], ecx                   ;app_path
-
 
260
           mov  edx, [APP_HEADER_01.i_end]
-
 
261
           mov  [ebx+0x14], edx
254
           ret
262
           ret
255
.fail:
263
.fail:
256
           xor eax, eax
264
           xor eax, eax
257
           ret
265
           ret
Line 290... Line 298...
290
.failed:
298
.failed:
291
           xor    eax,eax
299
           xor    eax,eax
292
           ret
300
           ret
293
endp
301
endp
Line -... Line 302...
-
 
302
 
294
 
303
 
295
align 4
304
align 4
296
proc create_app_space stdcall, app_size:dword,img_size:dword
305
proc create_app_space stdcall, app_size:dword,img_base:dword,img_size:dword
297
           locals
306
           locals
298
             app_pages   dd ?
307
             app_pages   dd ?
299
             img_pages   dd ?
308
             img_pages   dd ?
300
             dir_addr    dd ?
309
             dir_addr    dd ?
Line 377... Line 386...
377
           jnz @B
386
           jnz @B
Line 378... Line 387...
378
 
387
 
379
           mov edi, new_app_base
388
           mov edi, new_app_base
380
           shr edi, 10
389
           shr edi, 10
-
 
390
           add edi, pages_tab
381
           add edi, pages_tab
391
 
382
           mov ecx, [app_tabs]
392
           mov ecx, [app_tabs]
383
           shl ecx, 10
393
           shl ecx, 10
384
           xor eax, eax
394
           xor eax, eax
Line -... Line 395...
-
 
395
           rep stosd
-
 
396
 
385
           rep stosd
397
           mov ecx, [img_pages]
-
 
398
           mov ebx, PG_UW
-
 
399
           mov edx, new_app_base
-
 
400
           mov esi, [img_base]
-
 
401
           mov edi, new_app_base
-
 
402
           shr esi, 10
-
 
403
           shr edi, 10
-
 
404
           add esi, pages_tab
-
 
405
           add edi, pages_tab
-
 
406
.remap:
-
 
407
           lodsd
-
 
408
           or eax, ebx      ; force user level r/w access
-
 
409
           stosd
-
 
410
           add edx, 0x1000
-
 
411
           dec [app_pages]
-
 
412
           dec ecx
-
 
413
           jnz .remap
-
 
414
 
-
 
415
           mov ecx, [app_pages]
-
 
416
           test ecx, ecx
-
 
417
           jz .done
-
 
418
 
-
 
419
if GREEDY_KERNEL
-
 
420
           mov eax, 0x02
-
 
421
.reserve:
-
 
422
           stosd
-
 
423
           invlpg [edx]
-
 
424
           add edx, 4096
-
 
425
           dec ecx
-
 
426
           jnz .reserve
386
 
427
else
387
           mov edx, new_app_base
428
 
388
.alloc:
429
.alloc:
389
           call alloc_page
430
           call alloc_page
Line 390... Line 431...
390
           test eax, eax
431
           test eax, eax
391
           jz .fail
432
           jz .fail
392
 
433
 
393
           stdcall map_page,edx,eax,dword PG_UW
-
 
394
           add edx, 0x1000
434
           stdcall map_page,edx,eax,dword PG_UW
Line 395... Line -...
395
           sub [app_pages], 1
-
 
396
           sub [img_pages], 1
-
 
397
           jnz .alloc
-
 
398
 
-
 
399
           mov ecx, [app_pages]
-
 
400
           and ecx, ecx
-
 
401
           jz .next
-
 
402
 
-
 
403
           mov ebx, edx
-
 
404
           shr edx, 12
-
 
405
.reserve:
-
 
406
           mov dword [pages_tab+edx*4], 0x02
-
 
407
           invlpg [ebx]
435
           add edx, 0x1000
408
           inc edx
-
 
409
           dec ecx
-
 
410
           jnz .reserve
-
 
411
.next:
-
 
412
           mov edi, new_app_base
-
 
413
           mov ecx, [img_size]
-
 
Line -... Line 436...
-
 
436
           dec [app_pages]
414
           shr ecx, 2
437
           jnz .alloc
Line 415... Line 438...
415
           xor eax, eax
438
 
416
           cld
439
end if
417
           rep stosd
440
 
Line 429... Line 452...
429
@@:
452
@@:
430
           xor eax, eax
453
           xor eax, eax
431
           ret
454
           ret
432
endp
455
endp
Line -... Line 456...
-
 
456
 
-
 
457
 
433
 
458
 
434
align 4
459
align 4
435
set_cr3:
460
set_cr3:
436
           mov esi, [CURRENT_TASK]
461
           mov esi, [CURRENT_TASK]
437
           mov ebx, esi
462
           mov ebx, esi
Line 547... Line 572...
547
           mov [filename], eax
572
           mov [filename], eax
Line 548... Line 573...
548
 
573
 
Line 549... Line 574...
549
           stdcall wait_mutex, pg_data.tmp_task_mutex
574
           stdcall wait_mutex, pg_data.tmp_task_mutex
550
 
575
 
551
           mov edi, [tmp_task_data]
576
           mov edi, [tmp_task_data]
552
           mov ecx, (2048+256)/4
577
           mov ecx, (1024+256)/4
Line 553... Line 578...
553
           xor eax, eax
578
           xor eax, eax
554
           rep stosd
579
           rep stosd
555
 
-
 
556
           mov esi, [filename]
-
 
557
           mov edi, [tmp_task_data]
-
 
558
           add edi, TMP_FILE_NAME
-
 
559
           mov ecx, 1024
-
 
560
           rep movsb
-
 
561
 
-
 
562
           mov esi, [filename]
580
 
563
           mov edi, [tmp_task_data]
581
           mov esi, [filename]
Line 564... Line 582...
564
           add edi, TMP_ICON_OFFS
582
           mov edi, [tmp_task_data]
565
           mov ecx, 1024
583
           mov ecx, 1024
566
           rep movsb
584
           rep movsb
567
 
-
 
568
           mov esi, [cmdline]
-
 
569
           test esi, esi
585
 
570
           jz @f
586
           mov esi, [cmdline]
571
           mov edi, [tmp_task_data]
587
           test esi, esi
572
           add edi, TMP_CMD_LINE
-
 
573
           mov ecx, 256
588
           jz @f
574
           rep movsb
589
           mov ecx, 256
575
@@:
-
 
Line 576... Line 590...
576
           mov eax, TMP_FILE_NAME
590
           rep movsb
Line 577... Line -...
577
           add eax, [tmp_task_data]
-
 
578
           mov ebx, [tmp_task_data]    ;cmd line
-
 
579
           add ebx, TMP_CMD_LINE
591
@@:
580
 
592
           mov eax, [tmp_task_data]
581
           stdcall fs_exec_EX, eax, ebx, [flags]
593
           lea ebx, [eax+1024]        ;cmd line
582
 
594
 
583
;           stdcall fs_exec, eax, ebx, [flags], [ebp+8],\
595
           stdcall fs_exec, eax, ebx, [flags]
Line 1066... Line 1078...
1066
           mov esi,[params]
1078
           mov esi,[params]
1067
           mov eax, [esi+0x08]       ;app_eip
1079
           mov eax, [esi+0x08]       ;app_eip
1068
           mov [edi+TSS._eip],eax    ;set eip in TSS
1080
           mov [edi+TSS._eip],eax    ;set eip in TSS
1069
           mov eax, [esi+0x0C]       ;app_esp
1081
           mov eax, [esi+0x0C]       ;app_esp
1070
           mov [edi+TSS._esp],eax    ;set stack in TSS
1082
           mov [edi+TSS._esp],eax    ;set stack in TSS
1071
           mov [edi+TSS._eflags],dword 0x1202
1083
           mov [edi+TSS._eflags],dword 0x3202
Line 1072... Line 1084...
1072
 
1084
 
1073
           mov [edi+TSS._cs],app_code  ;selector of code segment
1085
           mov [edi+TSS._cs],app_code  ;selector of code segment
1074
           mov [edi+TSS._ss],app_data
1086
           mov [edi+TSS._ss],app_data
1075
           mov [edi+TSS._ds],app_data
1087
           mov [edi+TSS._ds],app_data