Subversion Repositories Kolibri OS

Rev

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

Rev 889 Rev 897
Line 3... Line 3...
3
;; Copyright (C) KolibriOS team 2004-2007. All rights reserved. ;;
3
;; Copyright (C) KolibriOS team 2004-2007. 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
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Line 7... Line 7...
7
 
7
 
Line -... Line 8...
-
 
8
$Revision: 897 $
-
 
9
 
-
 
10
EFL_IF      equ 0x0200
-
 
11
EFL_IOPL1   equ 0x1000
Line 8... Line -...
8
$Revision: 889 $
-
 
Line 9... Line 12...
9
 
12
EFL_IOPL2   equ 0x2000
10
 
13
EFL_IOPL3   equ 0x3000
11
GREEDY_KERNEL  equ 0
14
 
12
 
15
 
Line 44... Line 47...
44
   xor eax, eax
47
   xor eax, eax
45
   cld
48
   cld
46
   rep stosd
49
   rep stosd
47
}
50
}
Line 48... Line -...
48
 
-
 
49
fs_execute_from_sysdir:
-
 
50
	xor	ebx, ebx
-
 
51
	xor	edx, edx
-
 
52
	mov	esi, sysdir_path
-
 
53
 
51
 
-
 
52
align 4
-
 
53
test_app_header:
-
 
54
	   virtual at eax
-
 
55
	     APP_HEADER_00 APP_HEADER_00
-
 
56
	   end virtual
-
 
57
	   virtual at eax
-
 
58
	     APP_HEADER_01 APP_HEADER_01
-
 
59
	   end virtual
-
 
60
 
-
 
61
	   cmp dword [eax], 'MENU'
-
 
62
	   jne .fail
54
align 4
63
	   cmp word [eax+4],'ET'
Line 55... Line 64...
55
proc fs_execute
64
	   jne .fail
-
 
65
 
Line -... Line 66...
-
 
66
	   cmp [eax+6], word '00'
-
 
67
	   jne	.check_01_header
-
 
68
 
-
 
69
	   mov	ecx,[APP_HEADER_00.start]
56
 
70
       mov  [ebx+0x08], ecx              ;app_eip
-
 
71
	   mov	edx,[APP_HEADER_00.mem_size]
-
 
72
       mov  [ebx+0x10], edx              ;app_mem
-
 
73
	   shr	edx,1
-
 
74
	   sub	edx,0x10
-
 
75
       mov  [ebx+0x0C], edx              ;app_esp
-
 
76
	   mov	ecx,[APP_HEADER_00.i_param]
-
 
77
       mov  [ebx], ecx                   ;app_cmdline
-
 
78
       mov  [ebx+4], dword 0             ;app_path
-
 
79
	   mov	edx, [APP_HEADER_00.i_end]
-
 
80
	   mov	[ebx+0x14], edx
-
 
81
	   ret
-
 
82
 
-
 
83
 .check_01_header:
-
 
84
 
-
 
85
	   cmp	[eax+6],word '01'
-
 
86
	   jne	.fail
-
 
87
 
-
 
88
	   mov	ecx,[APP_HEADER_01.start]
-
 
89
	   mov	[ebx+0x08], ecx 	       ;app_eip
-
 
90
	   mov	edx,[APP_HEADER_01.mem_size]
-
 
91
 
-
 
92
; \begin{diamond}[20.08.2006]
57
;fn_read:dword, file_size:dword, cluster:dword
93
; sanity check (functions 19,58 load app_i_end bytes and that must
-
 
94
; fit in allocated memory to prevent kernel faults)
-
 
95
	   cmp	edx,[APP_HEADER_01.i_end]
-
 
96
	   jb	.fail
-
 
97
; \end{diamond}[20.08.2006]
-
 
98
 
-
 
99
       mov  [ebx+0x10], edx                  ;app_mem
-
 
100
	   mov	ecx,[APP_HEADER_01.stack_top]
-
 
101
       mov  [ebx+0x0C], ecx                  ;app_esp
-
 
102
	   mov	edx,[APP_HEADER_01.i_param]
-
 
103
       mov  [ebx], edx                       ;app_cmdline
-
 
104
	   mov	ecx,[APP_HEADER_01.i_icon]
-
 
105
       mov  [ebx+4], ecx                     ;app_path
-
 
106
	   mov	edx, [APP_HEADER_01.i_end]
58
 
107
	   mov	[ebx+0x14], edx
-
 
108
	   ret
-
 
109
.fail:
-
 
110
	   xor eax, eax
-
 
111
	   ret
59
; ebx - cmdline
112
 
Line 60... Line 113...
60
; edx - flags
113
 
61
; ebp - full filename
114
proc mnt_exec stdcall file_base:dword, file_size:dword, \
62
; [esp+4] = procedure DoRead, [esp+8] = filesize & [esp+12]... - arguments for it
115
                      path:dword, cmd_line:dword, flags:dword
63
 
-
 
Line 64... Line 116...
64
           locals
116
 
65
             cmdline       rd 64    ;256/4
117
           locals
66
             filename      rd 256   ;1024/4
118
             cmdline       rb 256
67
             flags     dd ?
-
 
68
 
-
 
-
 
119
             filename      rb 1024
69
             save_cr3      dd ?
120
 
70
             slot      dd ?
121
             save_cr3      dd ?
71
             slot_base     dd ?
122
             slot      dd ?
72
             file_base     dd ?
123
             slot_base     dd ?
73
             file_size     dd ?
124
 
74
                          ;app header data
125
                          ;app header data
75
             hdr_cmdline   dd ? ;0x00
126
             hdr_cmdline   dd ? ;0x00
76
             hdr_path      dd ? ;0x04
127
             hdr_path      dd ? ;0x04
Line 77... Line 128...
77
             hdr_eip       dd ? ;0x08
128
             hdr_eip       dd ? ;0x08
78
             hdr_esp       dd ? ;0x0C
-
 
79
             hdr_mem       dd ? ;0x10
129
             hdr_esp       dd ? ;0x0C
80
             hdr_i_end     dd ? ;0x14
-
 
81
           endl
130
             hdr_mem       dd ? ;0x10
Line -... Line 131...
-
 
131
             hdr_i_end     dd ? ;0x14
82
 
132
           endl
83
           pushad
133
 
84
 
-
 
85
           mov [flags], edx
-
 
86
 
134
           push ebx
87
; [ebp]  pointer to filename
135
           push edi
88
 
136
           push esi
89
           lea edi, [filename]
137
 
90
           lea ecx, [edi+1024]
138
           mov esi, [path]
91
           mov al, '/'
139
           lea edi, [filename]
92
           stosb
140
           lea ecx, [edi+1024]
-
 
141
@@:
93
@@:
142
           cmp edi, ecx
94
           cmp edi, ecx
143
           jae .bigfilename
95
           jae .bigfilename
144
           lodsb
-
 
145
           stosb
-
 
146
           test al, al
96
           lodsb
147
           jnz @b
-
 
148
 
97
           stosb
149
           mov esi, [cmd_line]
98
           test al, al
150
           test esi, esi
99
           jnz @b
151
           jz .no_cmdline
-
 
152
 
100
           mov esi, [ebp]
153
           lea edi, [cmdline]
101
           test esi, esi
154
           lea ecx, [edi+255]
102
           jz .namecopied
155
           mov [edi+252], dword 0
103
           mov byte [edi-1], '/'
156
@@:
104
@@:
-
 
105
           cmp edi, ecx
-
 
106
           jae .bigfilename
-
 
107
           lodsb
-
 
108
           stosb
-
 
109
           test al, al
-
 
Line 110... Line 157...
110
           jnz @b
157
           cmp edi, ecx
111
           jmp .namecopied
-
 
112
.bigfilename:
-
 
113
           popad
-
 
114
           mov eax, -ERROR_FILE_NOT_FOUND
-
 
115
           ret
-
 
116
.namecopied:
-
 
117
 
-
 
118
           mov [cmdline], ebx
-
 
119
           test ebx, ebx
-
 
120
           jz @F
-
 
121
 
-
 
122
           lea eax, [cmdline]
-
 
123
           mov dword [eax+252], 0
-
 
124
           stdcall strncpy, eax, ebx, 255
-
 
125
@@:
-
 
Line -... Line 158...
-
 
158
           jae .no_cmdline
126
           lea eax, [filename]
159
 
127
           stdcall load_file, eax
160
           lodsb
128
           mov  ecx, -ERROR_FILE_NOT_FOUND
161
           stosb
129
           test eax, eax
162
           test al, al
130
           jz .err_file
163
           jnz @b
Line 131... Line 164...
131
 
164
 
Line 132... Line -...
132
           mov [file_base], eax
-
 
133
           mov [file_size], ebx
-
 
134
 
-
 
135
           lea ebx, [hdr_cmdline]
-
 
136
           call test_app_header
-
 
137
           mov ecx, -0x1F
-
 
138
           test eax, eax
-
 
139
           jz .err_hdr
-
 
140
 
165
.no_cmdline:
141
           DEBUGF 1,"%s",new_process_loading
-
 
142
 
166
 
Line 143... Line 167...
143
.wait_lock:
167
           mov eax, [file_base]
Line 144... Line 168...
144
           cmp [application_table_status],0
168
           lea ebx, [hdr_cmdline]
145
           je .get_lock
169
           call test_app_header
Line 220... Line 244...
220
           stdcall set_app_params ,[slot],eax,ebx,ecx,[flags]
244
           stdcall set_app_params ,[slot],eax,ebx,ecx,[flags]
Line 221... Line 245...
221
 
245
 
222
           mov eax, [save_cr3]
246
           mov eax, [save_cr3]
Line 223... Line -...
223
           call set_cr3
-
 
224
 
247
           call set_cr3
225
           xor ebx, ebx
248
 
-
 
249
           mov [application_table_status], 0 ;unlock application_table_status mutex
-
 
250
           mov eax,[process_number]  ;set result
-
 
251
 
-
 
252
           pop edi
-
 
253
           pop esi
-
 
254
           pop ebx
-
 
255
 
-
 
256
           ret
-
 
257
 
-
 
258
.bigfilename:
-
 
259
           pop edi
-
 
260
           pop esi
226
           mov [application_table_status],ebx ;unlock application_table_status mutex
261
           pop ebx
227
           mov eax,[process_number]  ;set result
262
           mov eax, -ERROR_FILE_NOT_FOUND
228
           ret
263
           ret
229
.failed:
264
.failed:
230
           mov eax, [save_cr3]
265
           mov eax, [save_cr3]
231
           call set_cr3
266
           call set_cr3
232
.err:
267
.err:
233
.err_hdr:
268
.err_hdr:
-
 
269
           mov ecx, [file_base]
-
 
270
           call @mem_free@4
-
 
271
 
234
           mov ecx, [file_base]
272
           pop edi
-
 
273
           pop esi
235
           call @mem_free@4
274
           pop ebx
236
.err_file:
275
 
237
           xor eax, eax
276
           xor eax, eax
238
           mov [application_table_status],eax
277
           mov [application_table_status],eax
239
           mov eax, ecx
278
           mov eax, ecx
Line 240... Line 279...
240
           ret
279
           ret
241
endp
-
 
242
 
-
 
243
align 4
-
 
244
test_app_header:
-
 
245
	   virtual at eax
-
 
246
	     APP_HEADER_00 APP_HEADER_00
280
endp
247
	   end virtual
-
 
Line 248... Line 281...
248
	   virtual at eax
281
 
249
	     APP_HEADER_01 APP_HEADER_01
282
align 4
250
	   end virtual
283
proc pe_app_param stdcall path:dword, raw:dword, ex_pg_dir:dword, ex_stack_page:dword
251
 
284
 
Line -... Line 285...
-
 
285
           locals
252
	   cmp dword [eax], 'MENU'
286
             slot        dd ?
253
	   jne .fail
287
             slot_base   dd ?
Line 254... Line -...
254
	   cmp word [eax+4],'ET'
-
 
255
	   jne .fail
-
 
256
 
288
           endl
257
	   cmp [eax+6], word '00'
-
 
258
	   jne	.check_01_header
-
 
259
 
-
 
260
	   mov	ecx,[APP_HEADER_00.start]
-
 
261
	   mov	[ebx+0x08], ecx 	       ;app_eip
-
 
262
	   mov	edx,[APP_HEADER_00.mem_size]
-
 
263
	   mov	[ebx+0x10], edx 	       ;app_mem
-
 
264
	   shr	edx,1
-
 
265
	   sub	edx,0x10
289
 
266
	   mov	[ebx+0x0C], edx 	       ;app_esp
-
 
Line 267... Line 290...
267
	   mov	ecx,[APP_HEADER_00.i_param]
290
           push ebx
Line -... Line 291...
-
 
291
           push esi
268
	   mov	[ebx], ecx		       ;app_cmdline
292
           push edi
-
 
293
 
269
	   mov	[ebx+4], dword 0	       ;app_path
294
           lea ebx, [application_table_status]
Line 270... Line 295...
270
	   mov	edx, [APP_HEADER_00.i_end]
295
           call wait_mutex
-
 
296
 
271
	   mov	[ebx+0x14], edx
297
           call set_application_table_status
272
	   ret
298
 
-
 
299
           call get_new_process_place
-
 
300
           test eax, eax
Line 273... Line 301...
273
 
301
           mov ecx, -0x20      ; too many processes
-
 
302
           jz .err
274
 .check_01_header:
303
 
-
 
304
           mov [slot], eax
-
 
305
           shl eax, 8
-
 
306
           add eax, SLOT_BASE
-
 
307
           mov [slot_base], eax
-
 
308
           mov edi, eax
-
 
309
           _clear_ 256     ;clean extended information about process
-
 
310
 
-
 
311
; write application name
-
 
312
           lea eax, [path]
-
 
313
           stdcall strrchr,  eax, '/'  ; now eax points to name without path
-
 
314
           lea esi, [eax+1]
-
 
315
           test eax, eax
-
 
316
           jnz @F
-
 
317
           lea esi, [path]
275
 
318
@@:
-
 
319
           mov ecx, 8  ; 8 chars for name
-
 
320
           mov edi, [slot_base]
-
 
321
.copy_process_name_loop:
-
 
322
           lodsb
-
 
323
           cmp al, '.'
-
 
324
           jz .copy_process_name_done
-
 
325
           test al, al
-
 
326
           jz .copy_process_name_done
-
 
327
           stosb
-
 
328
           loop .copy_process_name_loop
-
 
329
.copy_process_name_done:
-
 
330
 
-
 
331
           mov eax, [ex_pg_dir]
-
 
332
           mov ebx, [slot_base]
-
 
333
           mov [ebx+APPDATA.dir_table],eax
-
 
334
 
-
 
335
           ;mov   eax,[hdr_mem]
-
 
336
           ;mov   [ebx+APPDATA.mem_size],eax
-
 
337
 
276
	   cmp	[eax+6],word '01'
338
           lea edi, [eax+OS_BASE+8192]
-
 
339
 
-
 
340
           mov [ebx+APPDATA.pl0_stack], edi
-
 
341
           add edi, RING0_STACK_SIZE
-
 
342
           mov [ebx+APPDATA.saved_esp0], edi
-
 
343
           mov [ebx+APPDATA.fpu_state],  edi
-
 
344
           mov [ebx+APPDATA.fpu_handler], 0
-
 
345
           mov [ebx+APPDATA.sse_handler], 0
-
 
346
 
-
 
347
;set default io permission map
-
 
348
           mov [ebx+APPDATA.io_map],\
277
	   jne	.fail
349
               (tss._io_map_0-OS_BASE+PG_MAP)
-
 
350
           mov [ebx+APPDATA.io_map+4],\
-
 
351
               (tss._io_map_1-OS_BASE+PG_MAP)
-
 
352
 
-
 
353
           mov esi, fpu_data
-
 
354
           mov ecx, 512/4
-
 
355
           rep movsd
-
 
356
 
-
 
357
           mov eax, [slot]
-
 
358
           cmp eax,[TASK_COUNT]
-
 
359
           jle .noinc
-
 
360
           inc dword [TASK_COUNT]       ;update number of processes
-
 
361
.noinc:
-
 
362
           lea edx, [ebx+APP_EV_OFFSET]
-
 
363
           mov [ebx+APPDATA.fd_ev],edx
-
 
364
           mov [ebx+APPDATA.bk_ev],edx
-
 
365
 
-
 
366
           add edx, APP_OBJ_OFFSET-APP_EV_OFFSET
-
 
367
           mov [ebx+APPDATA.fd_obj],edx
-
 
368
           mov [ebx+APPDATA.bk_obj],edx
278
 
369
 
-
 
370
           mov ecx, [def_cursor]
-
 
371
           mov [ebx+APPDATA.cursor],ecx
-
 
372
 
-
 
373
           xor ecx, ecx
-
 
374
           call @core_alloc@4
-
 
375
 
-
 
376
           add eax, OS_BASE                              ;FIXME
-
 
377
           mov esi,[current_slot]
-
 
378
           mov esi,[esi+APPDATA.cur_dir]
-
 
379
           mov ecx,0x1000/4
-
 
380
           mov edi,eax
-
 
381
           mov [ebx+APPDATA.cur_dir],eax
-
 
382
           rep movsd
-
 
383
 
-
 
384
           mov ebx, [slot]
-
 
385
           mov eax, ebx
-
 
386
           shl ebx, 5
-
 
387
           mov dword [CURRENT_TASK+ebx+0x10], 0
-
 
388
 
-
 
389
           lea    ecx,[draw_data+ebx]  ;ecx - pointer to draw data
-
 
390
 
-
 
391
; set window state to 'normal' (non-minimized/maximized/rolled-up) state
-
 
392
           mov     [ebx+window_data+WDATA.fl_wstate], WSTATE_NORMAL
-
 
393
           mov     [ebx+window_data+WDATA.fl_redraw], 1
-
 
394
           add    ebx,CURRENT_TASK        ;ebx - pointer to information about process
-
 
395
           mov    [ebx+TASKDATA.wnd_number],al;set window number on screen = process slot
-
 
396
 
-
 
397
           mov    [ebx+TASKDATA.event_mask],dword 1+2+4 ;set default event flags (see 40 function)
-
 
398
 
-
 
399
           inc    dword [process_number]
-
 
400
           mov    eax,[process_number]
-
 
401
           mov    [ebx+4],eax       ;set PID
-
 
402
 
-
 
403
;set draw data to full screen
-
 
404
 
-
 
405
           mov    [ecx+0],dword 0
-
 
406
           mov    [ecx+4],dword 0
-
 
407
           mov    eax,[Screen_Max_X]
-
 
408
           mov    [ecx+8],eax
-
 
409
           mov    eax,[Screen_Max_Y]
-
 
410
           mov    [ecx+12],eax
-
 
411
 
-
 
412
           mov ebx, [ex_pg_dir]
-
 
413
           add ebx, OS_BASE+8192-16
-
 
414
 
-
 
415
           mov [ebx],  dword _sys_app_entry
-
 
416
           mov eax,   [raw]
-
 
417
           mov edx,   [ex_stack_page]
-
 
418
           mov [ebx+8], eax
-
 
419
           mov [ebx+12], edx
-
 
420
 
-
 
421
           mov ecx, [slot]
-
 
422
           shl ecx, 5
-
 
423
           mov [ecx*8+SLOT_BASE+APPDATA.saved_esp], ebx
-
 
424
           xor  ebx, ebx    ; process state - running
Line 279... Line -...
279
	   mov	ecx,[APP_HEADER_01.start]
-
 
280
	   mov	[ebx+0x08], ecx 	       ;app_eip
-
 
281
	   mov	edx,[APP_HEADER_01.mem_size]
-
 
282
 
-
 
283
; \begin{diamond}[20.08.2006]
-
 
284
; sanity check (functions 19,58 load app_i_end bytes and that must
-
 
285
; fit in allocated memory to prevent kernel faults)
-
 
286
	   cmp	edx,[APP_HEADER_01.i_end]
-
 
287
	   jb	.fail
-
 
288
; \end{diamond}[20.08.2006]
-
 
289
 
-
 
290
	   mov	[ebx+0x10], edx 	       ;app_mem
-
 
291
	   mov	ecx,[APP_HEADER_01.stack_top]
425
           mov  [CURRENT_TASK+ecx+TASKDATA.state], bl
-
 
426
 
-
 
427
       ;    DEBUGF 1,"%s",new_process_running
Line 292... Line 428...
292
	   mov	[ebx+0x0C], ecx 	       ;app_esp
428
.err:
293
	   mov	edx,[APP_HEADER_01.i_param]
429
           mov [application_table_status], 0 ;unlock application_table_status mutex
294
	   mov	[ebx], edx		       ;app_cmdline
430
           mov eax,[process_number]  ;set result
295
	   mov	ecx,[APP_HEADER_01.i_icon]
431
 
Line 453... Line 589...
453
           xor eax, eax
589
           xor eax, eax
454
           ret
590
           ret
455
endp
591
endp
Line 456... Line 592...
456
 
592
 
-
 
593
align 4
-
 
594
_new_app_space:
-
 
595
           mov ecx, 2
-
 
596
           call @core_alloc@4
-
 
597
           test eax, eax
-
 
598
           jz .fail
-
 
599
 
-
 
600
           push esi
-
 
601
           push edi
-
 
602
 
-
 
603
           mov edx, eax
-
 
604
           mov ecx, 512
-
 
605
           lea edi, [eax + OS_BASE]
-
 
606
           xor eax, eax
-
 
607
           cld
-
 
608
           rep stosd
-
 
609
 
-
 
610
           mov ecx, 512
-
 
611
           mov esi, _sys_pdbr+(HEAP_BASE shr 20)
-
 
612
           rep movsd
-
 
613
 
-
 
614
           lea eax, [edx+PG_SW]
-
 
615
           mov [edx+OS_BASE+(page_tabs shr 20)], eax
-
 
616
 
-
 
617
           add eax, 4096
-
 
618
           mov [edx+OS_BASE+0x7FC], eax
-
 
619
 
-
 
620
           lea edi, [edx+OS_BASE+8192]
-
 
621
           mov ecx, 2048
-
 
622
           xor eax, eax
-
 
623
           rep stosd
-
 
624
 
-
 
625
           mov eax, edx
-
 
626
.fail:
-
 
627
           pop edi
-
 
628
           pop esi
-
 
629
           ret
-
 
630
 
457
align 4
631
align 4
Line 458... Line 632...
458
set_cr3:
632
set_cr3:
459
 
633
 
460
           mov ebx, [current_slot]
634
           mov ebx, [current_slot]
Line 915... Line 1089...
915
 
1089
 
916
           pop ebx
1090
           pop ebx
917
           pop eax
1091
           pop eax
Line 918... Line -...
918
           ret
-
 
919
 
-
 
920
EFL_IF	    equ 0x0200
-
 
921
EFL_IOPL1   equ 0x1000
-
 
Line 922... Line 1092...
922
EFL_IOPL2   equ 0x2000
1092
           ret
923
EFL_IOPL3   equ 0x3000
1093
 
924
 
1094