Subversion Repositories Kolibri OS

Rev

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

Rev 6263 Rev 6333
Line 3... Line 3...
3
;; Copyright (C) KolibriOS team 2004-2015. All rights reserved. ;;
3
;; Copyright (C) KolibriOS team 2004-2015. 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 8... Line 8...
8
$Revision: 6263 $
8
$Revision: 6333 $
Line 9... Line 9...
9
 
9
 
Line 28... Line 28...
28
        stack_top       dd ?    ;+24
28
        stack_top       dd ?    ;+24
29
        i_param         dd ?    ;+28
29
        i_param         dd ?    ;+28
30
        i_icon          dd ?    ;+32
30
        i_icon          dd ?    ;+32
31
ends
31
ends
Line 32... Line -...
32
 
-
 
33
 
32
 
34
struct  APP_PARAMS
33
struct  APP_HDR
35
        app_cmdline     dd ?    ;0x00
34
        cmdline         rd 1    ;0x00
36
        app_path        dd ?    ;0x04
35
        path            rd 1    ;0x04
37
        app_eip         dd ?    ;0x08
36
        eip             rd 1    ;0x08
-
 
37
        esp             rd 1    ;0x0C
38
        app_esp         dd ?    ;0x0C
38
        _edata          rd 1    ;0x10
-
 
39
        _emem           rd 1    ;0x14
-
 
40
        img_base        rd 1    ;0x18
-
 
41
        img_size        rd 1
-
 
42
        filename_size   rd 1
39
        app_mem         dd ?    ;0x10
43
        cmdline_size    rd 1
Line 40... Line 44...
40
ends
44
ends
41
 
45
 
42
macro _clear_ op
46
macro _clear_ op
43
{  mov ecx, op/4
47
{  mov ecx, op/4
44
        xor     eax, eax
48
        xor     eax, eax
45
        cld
49
        cld
Line -... Line 50...
-
 
50
        rep stosd
-
 
51
}
-
 
52
 
-
 
53
align 4
-
 
54
_strnlen:
-
 
55
        mov     edx, ecx
-
 
56
        xor     eax, eax
-
 
57
        repne scasb
-
 
58
        jne     @F
-
 
59
        inc     ecx
-
 
60
@@:
-
 
61
        mov     eax, edx
46
        rep stosd
62
        sub     eax, ecx
47
}
63
        retn
48
 
64
 
49
fs_execute_from_sysdir:
65
fs_execute_from_sysdir:
50
        xor     ebx, ebx
-
 
Line 51... Line 66...
51
fs_execute_from_sysdir_param:
66
        xor     ebx, ebx
52
        xor     edx, edx
67
fs_execute_from_sysdir_param:
53
        mov     esi, sysdir_path
-
 
54
 
-
 
55
align 4
-
 
56
proc fs_execute
68
        xor     edx, edx
57
 
69
 
58
;fn_read:dword, file_size:dword, cluster:dword
70
align 4
59
 
-
 
Line 60... Line 71...
60
; ebx - cmdline
71
proc fs_execute
61
; edx - flags
-
 
62
; ebp - full filename
-
 
63
; [esp+4] = procedure DoRead, [esp+8] = filesize & [esp+12]... - arguments for it
-
 
64
 
-
 
65
       locals
72
; ebx - cmdline
66
         cmdline_size  dd ? ; +0 ; cmdline -12
73
; edx - flags
67
         cmdline_adr   dd ? ; +4 ; cmdline -8
-
 
68
         cmdline_flag  dd ? ; +8 ; cmdline -4
-
 
69
         cmdline       rd 64    ;256/4
74
; ebp - full filename
70
         filename      rd 256   ;1024/4
-
 
71
         flags         dd ?
-
 
72
 
-
 
73
         save_proc     dd ?
-
 
74
         slot          dd ?
-
 
75
         slot_base     dd ?
-
 
76
         file_base     dd ?
-
 
77
         file_size     dd ?
-
 
78
;         handle        dd ? ;temp. for default cursor handle for curr. thread
-
 
79
                      ;app header data
-
 
80
         hdr_cmdline   dd ? ;0x00
-
 
81
         hdr_path      dd ? ;0x04
-
 
82
         hdr_eip       dd ? ;0x08
-
 
83
         hdr_esp       dd ? ;0x0C
-
 
84
         hdr_mem       dd ? ;0x10
-
 
85
         hdr_i_end     dd ? ;0x14
-
 
86
       endl
-
 
87
 
-
 
88
        pushad
-
 
89
 
-
 
90
;        cmp     [SCR_MODE], word 0x13
-
 
91
;        jbe     @f
-
 
92
;        pushad
-
 
93
;        stdcall set_cursor, [def_cursor_clock]
-
 
94
;        mov     [handle], eax
-
 
Line 95... Line 75...
95
;        mov     [redrawmouse_unconditional], 1
75
 
-
 
76
       locals
Line 96... Line -...
96
;        call    wakeup_osloop
-
 
97
;        popad
-
 
98
;@@:
-
 
99
        mov     [flags], edx
-
 
100
 
-
 
101
; [ebp]  pointer to filename
-
 
102
 
-
 
103
        lea     edi, [filename]
-
 
104
        lea     ecx, [edi+1024]
-
 
105
        mov     al, '/'
77
         filename      rd 1
106
        stosb
-
 
107
@@:
-
 
108
        cmp     edi, ecx
-
 
109
        jae     .bigfilename
-
 
110
        lodsb
-
 
111
        stosb
-
 
112
        test    al, al
-
 
113
        jnz     @b
-
 
114
        mov     esi, [ebp]
-
 
115
        test    esi, esi
-
 
116
        jz      .namecopied
-
 
117
        mov     byte [edi-1], '/'
-
 
118
@@:
-
 
119
        cmp     edi, ecx
-
 
120
        jae     .bigfilename
-
 
121
        lodsb
-
 
Line -... Line 78...
-
 
78
         cmdline       rd 1
-
 
79
         flags         rd 1
-
 
80
 
122
        stosb
81
         slot          rd 1
-
 
82
         slot_base     rd 1
-
 
83
 
-
 
84
;app header data
-
 
85
 
-
 
86
         hdr_cmdline   rd 1 ;0x00
-
 
87
         hdr_path      rd 1 ;0x04
Line 123... Line 88...
123
        test    al, al
88
         hdr_eip       rd 1 ;0x08
124
        jnz     @b
-
 
125
        jmp     .namecopied
-
 
126
.bigfilename:
-
 
127
        popad
-
 
Line -... Line 89...
-
 
89
         hdr_esp       rd 1 ;0x0C
-
 
90
         hdr_edata     rd 1 ;0x10
128
        mov     eax, -ERROR_FILE_NOT_FOUND
91
         hdr_emem      rd 1 ;0x14
129
 
-
 
130
        jmp     .final
-
 
131
 
-
 
132
.namecopied:
-
 
133
        xor     eax, eax
-
 
134
        mov     [cmdline_flag], eax
-
 
135
        mov     [cmdline_adr], eax
-
 
136
        mov     [cmdline_size], eax
-
 
137
 
-
 
138
        mov     [cmdline], ebx
-
 
139
        test    ebx, ebx
-
 
140
        jz      .no_copy
-
 
141
;--------------------------------------
-
 
142
        pushad
-
 
143
        pushfd
-
 
144
        mov     esi, ebx
-
 
145
        mov     ecx, 65536 ; 64 Kb max for ext.cmdline
-
 
146
        cld
-
 
147
@@:
-
 
148
        dec     ecx
-
 
149
        jz      .end_string
-
 
150
 
-
 
151
        lodsb
-
 
152
        test    al, al
-
 
153
        jnz     @b
-
 
154
 
-
 
155
.end_string:
-
 
156
        mov     eax, 65536 ; 64 Kb max for ext.cmdline
-
 
157
        sub     eax, ecx
-
 
158
        mov     [cmdline_size], eax
-
 
159
        cmp     eax, 255
-
 
160
        ja      @f
-
 
161
 
-
 
162
        popfd
-
 
163
        popad
-
 
164
        jmp     .old_copy
-
 
165
 
-
 
166
@@:
-
 
167
        xor     eax, eax
92
         file_base     rd 1 ;0x18
168
        dec     eax
-
 
169
        mov     [cmdline_flag], eax
-
 
170
        popfd
-
 
171
        popad
-
 
172
; get memory for the extended command line
-
 
173
        stdcall kernel_alloc, [cmdline_size] ;eax
-
 
174
        test    eax, eax
-
 
175
        jz      .old_copy ; get memory failed
-
 
176
 
-
 
177
        mov     [cmdline_adr], eax
-
 
178
 
-
 
Line 179... Line -...
179
        pushad
-
 
180
        pushfd
-
 
181
        mov     esi, ebx
-
 
182
        mov     edi, eax
-
 
183
        mov     ecx, [cmdline_size]
-
 
184
        cld
-
 
185
        rep movsb
-
 
186
        popfd
-
 
187
        popad
-
 
188
        jmp     .no_copy
-
 
189
 
93
         file_size     rd 1 ;0x1c
190
.old_copy:
94
         filename_size rd 1 ;0x20
191
; clear flag because old method with 256 bytes
-
 
192
        xor     eax, eax
95
         cmdline_size  rd 1 ;0x24
193
        mov     [cmdline_flag], eax
96
 
194
;--------------------------------------
97
       endl
Line 195... Line 98...
195
        lea     eax, [cmdline]
98
 
Line 214... Line 117...
214
        jz      .err_hdr
117
        jz      .err_hdr
Line 215... Line 118...
215
 
118
 
Line 216... Line 119...
216
        call    lock_application_table
119
        call    lock_application_table
217
 
-
 
218
        call    alloc_thread_slot
120
 
-
 
121
        call    alloc_thread_slot
219
        test    eax, eax
122
        mov     esi, -0x20 ; too many processes
Line 220... Line 123...
220
        mov     esi, -0x20 ; too many processes
123
        test    eax, eax
221
        jz      .err
124
        jz      .err_0
222
 
125
 
223
        mov     [slot], eax
126
        mov     [slot], eax
-
 
127
        shl     eax, 8
-
 
128
        lea     edi, [SLOT_BASE+eax]
224
        shl     eax, 8
129
        mov     [slot_base], edi
225
        add     eax, SLOT_BASE
130
 
-
 
131
;clean extended information about process
-
 
132
        mov     ecx, 256/4
Line 226... Line 133...
226
        mov     [slot_base], eax
133
        xor     eax, eax
227
        mov     edi, eax
-
 
228
       _clear_ 256     ;clean extended information about process
134
        cld
Line 229... Line 135...
229
 
135
        rep stosd
230
; write application name
136
 
231
        lea     eax, [filename]
137
; write application name
232
        stdcall strrchr, eax, '/'  ; now eax points to name without path
138
        stdcall strrchr, [filename], '/'  ; now eax points to name without path
233
 
139
 
234
        lea     esi, [eax+1]
140
        lea     esi, [eax+1]
235
        test    eax, eax
141
        test    eax, eax
236
        jnz     @F
142
        jnz     @F
237
        lea     esi, [filename]
143
        mov     esi, [filename]
Line 244... Line 150...
244
        jz      .copy_process_name_done
150
        jz      .copy_process_name_done
245
        test    al, al
151
        test    al, al
246
        jz      .copy_process_name_done
152
        jz      .copy_process_name_done
247
        stosb
153
        stosb
248
        loop    .copy_process_name_loop
154
        loop    .copy_process_name_loop
-
 
155
 
249
.copy_process_name_done:
156
.copy_process_name_done:
Line 250... Line 157...
250
 
157
 
-
 
158
        mov     edi, [cmdline]
-
 
159
        xor     eax, eax
-
 
160
        test    edi, edi
-
 
161
        jz      @F
-
 
162
 
-
 
163
        mov     ecx, 65535
-
 
164
        call    _strnlen
-
 
165
        cmp     eax, 256
-
 
166
        jb      @F
-
 
167
        lea     ebx, [eax+1]
-
 
168
        add     [hdr_emem], ebx
251
        mov     ebx, [current_process]
169
@@:
-
 
170
        mov     [cmdline_size], eax
-
 
171
 
Line 252... Line -...
252
        mov     [save_proc], ebx
-
 
253
 
172
        stdcall create_process, [hdr_emem]
254
        stdcall create_process, [hdr_mem], [file_base], [file_size]
173
 
255
        mov     esi, -30; no memory
174
        mov     esi, -30; no memory
Line 256... Line 175...
256
        test    eax, eax
175
        test    eax, eax
257
        jz      .failed
176
        jz      .err_hdr
Line 258... Line 177...
258
 
177
 
259
        mov     ebx, [sys_proc+LHEAD.prev]
178
        mov     ebx, [sys_proc+LHEAD.prev]
Line 260... Line 179...
260
        __list_add eax, ebx, sys_proc
179
        __list_add eax, ebx, sys_proc
261
 
180
 
Line 262... Line 181...
262
        mov     ebx, [hdr_mem]
181
        mov     ebx, [hdr_emem]
263
        mov     [eax+PROC.mem_used], ebx
182
        mov     [eax+PROC.mem_used], ebx
264
 
183
 
Line 265... Line 184...
265
        mov     ebx, [slot_base]
184
        mov     ebx, [slot_base]
266
        mov     [ebx+APPDATA.process], eax
185
        mov     [ebx+APPDATA.process], eax
267
 
-
 
268
        lea     edx, [ebx+APPDATA.list]
-
 
269
        lea     ecx, [eax+PROC.thr_list]
-
 
270
        list_add_tail edx, ecx
-
 
271
 
-
 
Line 272... Line -...
272
        xor     edx, edx
-
 
273
        cmp     word [6], '02'
186
 
274
        jne     @f
187
        lea     edx, [ebx+APPDATA.list]
275
 
188
        lea     ecx, [eax+PROC.thr_list]
276
        not     edx
189
        list_add_tail edx, ecx
277
@@:
190
 
Line -... Line 191...
-
 
191
        mov     esi, sizeof.APP_HDR
-
 
192
        add     esi, [cmdline_size]
278
        mov     [ebx+APPDATA.tls_base], edx
193
 
279
 
194
        mov     edi, [filename]
-
 
195
        mov     ecx, 1023
280
        mov     ecx, [hdr_mem]
196
        call    _strnlen
281
        mov     edi, [file_size]
-
 
Line -... Line 197...
-
 
197
        add     esi, eax
282
        add     edi, 4095
198
        mov     [filename_size], eax
-
 
199
 
-
 
200
        stdcall kernel_alloc, esi
-
 
201
        mov     [ebx+APPDATA.exec_params], eax
-
 
202
        mov     edi, eax
Line 283... Line -...
283
        and     edi, not 4095
-
 
284
        sub     ecx, edi
203
        lea     esi, [hdr_cmdline]
285
        jna     @F
-
 
286
 
-
 
287
        xor     eax, eax
204
        mov     ecx, sizeof.APP_HDR/4
288
        cld
-
 
289
        rep stosb
-
 
290
@@:
-
 
Line 291... Line 205...
291
 
205
        rep movsd
292
; release only virtual space, not phisical memory
206
 
-
 
207
        mov     esi, [filename]
Line -... Line 208...
-
 
208
        mov     ecx, [filename_size]
293
 
209
        rep movsb
Line 294... Line -...
294
        stdcall free_kernel_space, [file_base]
-
 
295
        lea     eax, [hdr_cmdline]
-
 
296
        lea     ebx, [cmdline]
-
 
297
        lea     ecx, [filename]
-
 
298
        stdcall set_app_params , [slot], eax, ebx, ecx, [flags]
210
        mov     ecx, [cmdline_size]
299
 
211
        mov     esi, [cmdline]
300
        mov     eax, [save_proc]
212
        rep movsb
301
        call    set_cr3
-
 
302
 
213
 
303
        mov     eax, [process_number];set result
-
 
304
        call    unlock_application_table
-
 
305
 
-
 
306
        jmp     .final
-
 
307
 
-
 
308
.failed:
-
 
309
        mov     eax, [save_proc]
-
 
310
        call    set_cr3
-
 
311
.err:
-
 
312
.err_hdr:
214
        lea     eax, [hdr_cmdline]
313
        stdcall kernel_free, [file_base]
215
        stdcall set_app_params , [slot], eax, [flags]
Line 314... Line 216...
314
.err_file:
216
 
315
        call    unlock_application_table
217
        mov     eax, [process_number]       ;set result
Line 342... Line 244...
342
 
244
 
343
        cmp     [eax+6], word '00'
245
        cmp     [eax+6], word '00'
Line 344... Line 246...
344
        jne     .check_01_header
246
        jne     .check_01_header
345
 
247
 
346
        mov     ecx, [APP_HEADER_00.start]
248
        mov     ecx, [APP_HEADER_00.start]
347
        mov     [ebx+0x08], ecx             ;app_eip
249
        mov     [ebx+APP_HDR.eip], ecx
348
        mov     edx, [APP_HEADER_00.mem_size]
250
        mov     edx, [APP_HEADER_00.mem_size]
349
        mov     [ebx+0x10], edx             ;app_mem
251
        mov     [ebx+APP_HDR._emem], edx
350
        shr     edx, 1
252
        shr     edx, 1
351
        sub     edx, 0x10
253
        sub     edx, 0x10
352
        mov     [ebx+0x0C], edx             ;app_esp
254
        mov     [ebx+APP_HDR.esp], edx
353
        mov     ecx, [APP_HEADER_00.i_param]
255
        mov     ecx, [APP_HEADER_00.i_param]
354
        mov     [ebx], ecx                  ;app_cmdline
256
        mov     [ebx+APP_HDR.cmdline], ecx
355
        mov     [ebx+4], dword 0            ;app_path
257
        mov     [ebx+APP_HDR.path], 0
356
        mov     edx, [APP_HEADER_00.i_end]
258
        mov     edx, [APP_HEADER_00.i_end]
Line 357... Line 259...
357
        mov     [ebx+0x14], edx
259
        mov     [ebx+APP_HDR._edata], edx
Line 358... Line 260...
358
        ret
260
        ret
359
 
261
 
360
 .check_01_header:
262
 .check_01_header:
361
 
263
 
362
        cmp     [eax+6], word '01'
264
        cmp     [eax+6], word '01'
363
        je      @f
265
        je      @f
364
        cmp     [eax+6], word '02'
266
        cmp     [eax+6], word '02'
365
        jne     .fail
267
        jne     .fail
Line 366... Line 268...
366
@@:
268
@@:
367
        mov     ecx, [APP_HEADER_01.start]
269
        mov     ecx, [APP_HEADER_01.start]
368
        mov     [ebx+0x08], ecx             ;app_eip
270
        mov     [ebx+0x08], ecx
369
        mov     edx, [APP_HEADER_01.mem_size]
271
        mov     edx, [APP_HEADER_01.mem_size]
370
 
272
 
371
; \begin{diamond}[20.08.2006]
273
; \begin{diamond}[20.08.2006]
Line 372... Line 274...
372
; sanity check (functions 19,58 load app_i_end bytes and that must
274
; sanity check (functions 19,58 load app_i_end bytes and that must
373
; fit in allocated memory to prevent kernel faults)
275
; fit in allocated memory to prevent kernel faults)
374
        cmp     edx, [APP_HEADER_01.i_end]
276
        cmp     edx, [APP_HEADER_01.i_end]
375
        jb      .fail
277
        jb      .fail
376
; \end{diamond}[20.08.2006]
278
; \end{diamond}[20.08.2006]
377
 
279
 
378
        mov     [ebx+0x10], edx             ;app_mem
280
        mov     [ebx+APP_HDR._emem], edx
379
        mov     ecx, [APP_HEADER_01.stack_top]
281
        mov     ecx, [APP_HEADER_01.stack_top]
380
        mov     [ebx+0x0C], ecx             ;app_esp
282
        mov     [ebx+APP_HDR.esp], ecx
381
        mov     edx, [APP_HEADER_01.i_param]
283
        mov     edx, [APP_HEADER_01.i_param]
382
        mov     [ebx], edx                  ;app_cmdline
284
        mov     [ebx+APP_HDR.cmdline], edx
383
        mov     ecx, [APP_HEADER_01.i_icon]
285
        mov     ecx, [APP_HEADER_01.i_icon]
384
        mov     [ebx+4], ecx                ;app_path
286
        mov     [ebx+APP_HDR.path], ecx
Line 418... Line 320...
418
        sub     edx, thr_slot_map
320
        sub     edx, thr_slot_map
419
        lea     eax, [eax+edx*8]
321
        lea     eax, [eax+edx*8]
420
        popfd
322
        popfd
421
        ret
323
        ret
Line 422... Line -...
422
 
-
 
423
 
324
 
424
align 4
325
align 4
425
proc create_process stdcall, app_size:dword,img_base:dword,img_size:dword
326
proc create_process stdcall, app_size:dword
426
       locals
-
 
427
         app_pages   dd ?
-
 
428
         img_pages   dd ?
327
       locals
429
         process     dd ?
328
         process     dd ?
430
         app_tabs    dd ?
329
         app_tabs    dd ?
Line 431... Line 330...
431
       endl
330
       endl
432
 
331
 
433
        push    ebx
332
        push    ebx
Line 434... Line -...
434
        push    esi
-
 
435
        push    edi
-
 
436
 
-
 
437
        mov     ecx, pg_data.mutex
333
        push    esi
438
        call    mutex_lock
334
        push    edi
Line 439... Line 335...
439
 
335
 
440
        xor     eax, eax
-
 
441
        mov     [process], eax
-
 
442
 
-
 
443
        mov     eax, [app_size]
-
 
444
        add     eax, 4095
-
 
445
        and     eax, NOT(4095)
-
 
446
        mov     [app_size], eax
-
 
447
        mov     ebx, eax
336
        xor     eax, eax
448
        shr     eax, 12
-
 
449
        mov     [app_pages], eax
337
        mov     [process], eax
450
 
338
 
451
        add     ebx, 0x3FFFFF
-
 
452
        and     ebx, NOT(0x3FFFFF)
-
 
453
        shr     ebx, 22
-
 
454
        mov     [app_tabs], ebx
-
 
455
 
-
 
456
        mov     ecx, [img_size]
-
 
457
        add     ecx, 4095
-
 
458
        and     ecx, NOT(4095)
-
 
459
 
-
 
460
        mov     [img_size], ecx
-
 
461
        shr     ecx, 12
-
 
462
        mov     [img_pages], ecx
-
 
463
 
-
 
Line 464... Line 339...
464
        lea     eax, [eax+ebx+2];all requested memory
339
        mov     eax, [app_size]
465
 
340
        add     eax, 0x3FFFFF
466
        cmp     eax, [pg_data.pages_free]
341
        shr     eax, 22
467
        ja      .fail
342
        mov     [app_tabs], eax
Line 507... Line 382...
507
 
382
 
508
        mov     eax, [edi-8192+PROC.pdt_0_phys]
383
        mov     eax, [edi-8192+PROC.pdt_0_phys]
509
        or      eax, PG_SWR
384
        or      eax, PG_SWR
Line 510... Line 385...
510
        mov     [edi-4096+(page_tabs shr 20)], eax
385
        mov     [edi-4096+(page_tabs shr 20)], eax
511
 
386
 
Line 512... Line -...
512
        lea     eax, [edi-8192]
-
 
513
        call    set_cr3
387
        lea     edx, [edi-4096]
514
 
-
 
515
        mov     edx, [app_tabs]
388
        mov     esi, [app_tabs]
516
        xor     edi, edi
389
 
517
@@:
390
.alloc_page_dir:
-
 
391
        call    alloc_page
-
 
392
        test    eax, eax
Line 518... Line -...
518
        call    alloc_page
-
 
519
        test    eax, eax
-
 
520
        jz      .fail
-
 
521
 
-
 
522
        stdcall map_page_table, edi, eax
-
 
523
        add     edi, 0x00400000
393
        jz      .fail
524
        dec     edx
-
 
525
        jnz     @B
394
        or      eax, PG_UWR
526
 
395
        mov     [edx], eax
527
        mov     edi, page_tabs
396
 
528
 
397
        mov     edi, [tmp_task_ptab]
Line 529... Line -...
529
        mov     ecx, [app_tabs]
-
 
530
        shl     ecx, 10
-
 
531
        xor     eax, eax
-
 
532
        rep stosd
-
 
533
 
-
 
534
        mov     ecx, [img_pages]
-
 
535
        mov     ebx, PG_UWR
-
 
536
        xor     edx, edx
-
 
537
        mov     esi, [img_base]
-
 
538
        shr     esi, 10
-
 
539
        add     esi, page_tabs
-
 
540
        mov     edi, page_tabs
-
 
541
.remap:
398
        stdcall map_page, edi, eax, PG_SWR
542
        lodsd
-
 
543
        and     eax, 0xFFFFF000
399
        mov     ecx, 1024
544
        or      eax, ebx; force user level r/w access
-
 
545
        stosd
-
 
546
        add     edx, 0x1000
-
 
547
        dec     [app_pages]
-
 
548
        dec     ecx
-
 
549
        jnz     .remap
-
 
550
 
-
 
551
        mov     ecx, [app_pages]
400
        xor     eax, eax
552
        test    ecx, ecx
-
 
553
        jz      .done
-
 
554
 
-
 
555
.alloc:
-
 
556
        call    alloc_page
-
 
557
        test    eax, eax
-
 
558
        jz      .fail
-
 
Line 559... Line -...
559
 
-
 
560
        stdcall map_page, edx, eax, dword PG_UWR
401
        rep stosd
561
        add     edx, 0x1000
-
 
562
        dec     [app_pages]
402
 
Line 563... Line 403...
563
        jnz     .alloc
403
        add     edx, 4
564
 
404
        dec     esi
565
.done:
405
        jnz     .alloc_page_dir
566
        mov     ecx, pg_data.mutex
406
 
567
        call    mutex_unlock
407
        stdcall map_page, [tmp_task_ptab], 0, PG_UNMAP
568
        mov     eax, [process]
-
 
569
 
-
 
570
        pop     edi
408
        mov     eax, [process]
571
        pop     esi
409
 
-
 
410
        pop     edi
572
        pop     ebx
411
        pop     esi
573
        ret
412
        pop     ebx
574
.fail:
413
        ret
575
        mov     ecx, pg_data.mutex
414
.fail:
576
        call    mutex_unlock
415
        mov     ecx, [process]
577
        cmp     [process], 0
416
        jcxz    @F
578
        je      @f
417
 
579
;;        stdcall destroy_app_space, [dir_addr], 0
418
        call    destroy_process
Line 580... Line 419...
580
@@:
419
@@:
581
        xor     eax, eax
-
 
582
        pop     edi
-
 
583
        pop     esi
-
 
584
        pop     ebx
-
 
585
        ret
-
 
586
endp
-
 
587
 
-
 
588
align 4
-
 
589
set_cr3:
-
 
590
        pushfd
-
 
591
        cli
-
 
592
        mov     ebx, [current_slot]
-
 
593
        mov     [current_process], eax
420
        xor     eax, eax
Line 594... Line 421...
594
        mov     [ebx+APPDATA.process], eax
421
        pop     edi
Line 595... Line 422...
595
        mov     eax, [eax+PROC.pdt_0_phys]
422
        pop     esi
Line 854... Line 681...
854
        cmp     ecx, 0x8000
681
        cmp     ecx, 0x8000
855
        jna     @F
682
        jna     @F
856
        mov     ecx, 0x8000
683
        mov     ecx, 0x8000
857
@@:
684
@@:
858
        mov     ebx, [offset]
685
        mov     ebx, [offset]
859
      ;     add ebx, new_app_base
-
 
860
        push    ecx
686
        push    ecx
861
        stdcall map_memEx, [proc_mem_map], \
687
        stdcall map_memEx, [proc_mem_map], \
862
                [slot], ebx, ecx, PG_SWR
688
                [slot], ebx, ecx, PG_SWR
863
        pop     ecx
689
        pop     ecx
Line 956... Line 782...
956
        lea     ebx, [edx+APPDATA.list]
782
        lea     ebx, [edx+APPDATA.list]
957
        lea     ecx, [eax+PROC.thr_list]
783
        lea     ecx, [eax+PROC.thr_list]
958
        list_add_tail ebx, ecx               ;add thread to process child's list
784
        list_add_tail ebx, ecx               ;add thread to process child's list
Line 959... Line 785...
959
 
785
 
960
        lea     eax, [app_cmdline]
786
        lea     eax, [app_cmdline]
961
        stdcall set_app_params , [slot], eax, dword 0, \
-
 
Line 962... Line 787...
962
                dword 0, [flags]
787
        stdcall set_app_params , [slot], eax, [flags]
963
 
788
 
964
        mov     eax, [process_number]           ;set result
789
        mov     eax, [process_number]           ;set result
965
        call    unlock_application_table
790
        call    unlock_application_table
Line 970... Line 795...
970
        call    unlock_application_table
795
        call    unlock_application_table
971
        dec     eax     ;-1
796
        dec     eax     ;-1
972
        ret
797
        ret
973
endp
798
endp
Line -... Line 799...
-
 
799
 
-
 
800
proc map_process_image stdcall, img_size:dword, file_base:dword, file_size:dword
-
 
801
 
-
 
802
        mov     edx, [img_size]
-
 
803
        mov     esi, [file_base]
-
 
804
        mov     ecx, [file_size]
-
 
805
        add     edx, 4095
-
 
806
        add     ecx, 4095
-
 
807
        shr     edx, 12        ; total pages
-
 
808
        shr     ecx, 12        ; image pages
-
 
809
 
-
 
810
        mov     edi, page_tabs
-
 
811
        shr     esi, 10
-
 
812
        add     esi, edi
-
 
813
 
-
 
814
.map_image:
-
 
815
        lodsd
-
 
816
        and     eax, -4096
-
 
817
        or      eax, PG_UWR
-
 
818
        stosd
-
 
819
        dec     edx
-
 
820
        loop    .map_image
-
 
821
 
-
 
822
        test    edx, edx
-
 
823
        jz      .done
-
 
824
.map_bss:
-
 
825
        call    alloc_page
-
 
826
        test    eax, eax
-
 
827
        jz      .fail
-
 
828
 
-
 
829
        or      eax, PG_UWR
-
 
830
        stosd
-
 
831
        dec     edx
-
 
832
        jnz     .map_bss
-
 
833
 
-
 
834
        mov     edi, [file_size]
-
 
835
        mov     ecx, [img_size]
-
 
836
        add     edi, 4095
-
 
837
        and     edi, -4096
-
 
838
        add     ecx, 4095
-
 
839
        and     ecx, -4096
-
 
840
        sub     ecx, edi
-
 
841
        shr     ecx, 2
-
 
842
        xor     eax, eax
-
 
843
        rep stosd
-
 
844
.done:
-
 
845
.fail:
-
 
846
        ret
-
 
847
endp
974
 
848
 
975
align 4
849
align 4
-
 
850
common_app_entry:
-
 
851
 
-
 
852
        mov     ebp, [current_slot]
-
 
853
        mov     ebp, [ebp+APPDATA.exec_params]
-
 
854
        test    ebp, ebp
-
 
855
        jz      .exit
-
 
856
 
-
 
857
        stdcall map_process_image, [ebp+APP_HDR._emem],\
-
 
858
                [ebp+APP_HDR.img_base], [ebp+APP_HDR.img_size]
-
 
859
 
-
 
860
        xor     eax, eax
-
 
861
        mov     edi, [ebp+APP_HDR.path]
-
 
862
        lea     esi, [ebp+sizeof.APP_HDR]
-
 
863
        mov     ecx, [ebp+APP_HDR.filename_size]
-
 
864
        test    edi, edi
-
 
865
        jnz     .copy_filename
-
 
866
 
-
 
867
        add     esi, ecx
-
 
868
        jmp     .check_cmdline
-
 
869
 
-
 
870
.copy_filename:
-
 
871
        rep movsb
-
 
872
        stosb
-
 
873
 
-
 
874
.check_cmdline:
-
 
875
        mov     edi, [ebp+APP_HDR.cmdline]
-
 
876
        mov     ecx, [ebp+APP_HDR.cmdline_size]
-
 
877
        test    edi, edi
-
 
878
        jz      .check_tls_header
-
 
879
 
-
 
880
        cmp     ecx, 256
-
 
881
        jb      .copy_cmdline
-
 
882
 
-
 
883
        mov     edi, [ebp+APP_HDR._emem]
-
 
884
        add     edi, 4095
-
 
885
        and     edi, -4096
-
 
886
        sub     edi, ecx
-
 
887
        dec     edi
-
 
888
 
-
 
889
        cmp     word [6], '00'
-
 
890
        jne     @F
-
 
891
        mov     [APP_HEADER_00_.i_param], edi
-
 
892
        jmp     .copy_cmdline
-
 
893
@@:
-
 
894
        mov     [APP_HEADER_01_.i_param], edi
-
 
895
 
-
 
896
.copy_cmdline:
-
 
897
        rep movsb
-
 
898
        stosb
-
 
899
 
-
 
900
.check_tls_header:
-
 
901
        cmp     word [6], '02'
Line 976... Line 902...
976
tls_app_entry:
902
        jne     .cleanup
977
 
903
 
Line 978... Line 904...
978
        call    init_heap
904
        call    init_heap
Line 984... Line 910...
984
        shr     eax, 16
910
        shr     eax, 16
985
        mov     [tls_data_l+4], al
911
        mov     [tls_data_l+4], al
986
        mov     [tls_data_l+7], ah
912
        mov     [tls_data_l+7], ah
987
        mov     dx, app_tls
913
        mov     dx, app_tls
988
        mov     fs, dx
914
        mov     fs, dx
-
 
915
 
-
 
916
.cleanup:
-
 
917
        stdcall free_kernel_space, [ebp+APP_HDR.img_base]
-
 
918
        stdcall kernel_free, ebp
-
 
919
.exit:
989
        popad
920
        popad
990
        iretd
921
        iretd
Line 991... Line -...
991
 
-
 
992
 
922
 
993
EFL_IF      equ 0x0200
923
EFL_IF      equ 0x0200
994
EFL_IOPL1   equ 0x1000
924
EFL_IOPL1   equ 0x1000
995
EFL_IOPL2   equ 0x2000
925
EFL_IOPL2   equ 0x2000
Line 996... Line -...
996
EFL_IOPL3   equ 0x3000
-
 
997
 
926
EFL_IOPL3   equ 0x3000
998
 
927
 
999
align 4
-
 
Line 1000... Line 928...
1000
proc set_app_params stdcall,slot:dword, params:dword,\
928
align 4
1001
            cmd_line:dword, app_path:dword, flags:dword
929
proc set_app_params stdcall,slot:dword, params:dword, flags:dword
1002
 
930
 
Line 1057... Line 985...
1057
        mov     edi, eax
985
        mov     edi, eax
1058
        mov     [ebx+SLOT_BASE+APPDATA.cur_dir], eax
986
        mov     [ebx+SLOT_BASE+APPDATA.cur_dir], eax
1059
        rep movsd
987
        rep movsd
Line 1060... Line 988...
1060
 
988
 
1061
        shr     ebx, 3
-
 
1062
        mov     eax, new_app_base
989
        shr     ebx, 3
1063
        mov     dword [CURRENT_TASK+ebx+0x10], eax
-
 
1064
 
-
 
1065
.add_command_line:
-
 
1066
        mov     edx, [params]
-
 
1067
        mov     edx, [edx] ;app_cmdline
-
 
1068
        test    edx, edx
-
 
1069
        jz      @f     ;application doesn't need parameters
-
 
1070
 
-
 
1071
        mov     eax, edx
-
 
1072
        add     eax, 256
-
 
1073
        jc      @f
-
 
1074
 
-
 
1075
;        cmp     eax, [SLOT_BASE+APPDATA.mem_size+ebx*8]
-
 
Line 1076... Line -...
1076
;        ja      @f
-
 
1077
 
-
 
1078
        mov     eax, [cmd_line]
-
 
1079
 
-
 
1080
        cmp     [edx], dword 0xffffffff ; extended destination tag
-
 
1081
        jne     .no_ext_dest
-
 
1082
 
-
 
1083
        mov     edx, [edx+4] ; extended destination for cmdline
-
 
1084
        jmp     .continue
-
 
1085
 
-
 
1086
.no_ext_dest:
-
 
1087
        mov     [eax-12], dword 255
-
 
1088
.continue:
-
 
1089
        mov     byte [edx], 0  ;force empty string if no cmdline given
-
 
1090
 
-
 
1091
        test    eax, eax
-
 
1092
        jz      @f
-
 
1093
;--------------------------------------
-
 
1094
        cmp     [eax-4], dword 0xffffffff ; cmdline_flag
-
 
1095
        jne     .old_copy
-
 
1096
 
-
 
1097
        push    eax
-
 
1098
        stdcall strncpy, edx, [eax-8], [eax-12]
-
 
1099
        pop     eax
-
 
1100
 
-
 
1101
        stdcall kernel_free, [eax-8]
-
 
1102
        jmp     @f
-
 
1103
 
-
 
1104
.old_copy:
-
 
1105
;--------------------------------------
-
 
1106
        stdcall strncpy, edx, eax, 256
-
 
1107
@@:
-
 
1108
        mov     edx, [params]
-
 
1109
        mov     edx, [edx+4];app_path
-
 
1110
        test    edx, edx
-
 
1111
        jz      @F     ;application don't need path of file
-
 
1112
        mov     eax, edx
-
 
1113
        add     eax, 1024
-
 
1114
        jc      @f
-
 
1115
;        cmp     eax, [SLOT_BASE+APPDATA.mem_size+ebx*8]
-
 
1116
;        ja      @f
-
 
1117
        stdcall strncpy, edx, [app_path], 1024
990
        mov     dword [CURRENT_TASK+ebx+0x10], 0
1118
@@:
991
 
1119
        mov     ebx, [slot]
992
        mov     ebx, [slot]
1120
        mov     eax, ebx
993
        mov     eax, ebx
Line 1121... Line -...
1121
        shl     ebx, 5
-
 
1122
        lea     ecx, [draw_data+ebx];ecx - pointer to draw data
-
 
1123
 
-
 
1124
        mov     edx, irq0.return
-
 
1125
        cmp     [ebx*8+SLOT_BASE+APPDATA.tls_base], -1
-
 
1126
        jne     @F
994
        shl     ebx, 5
1127
        mov     edx, tls_app_entry
995
        lea     ecx, [draw_data+ebx];ecx - pointer to draw data
1128
@@:
996
 
1129
; set window state to 'normal' (non-minimized/maximized/rolled-up) state
997
; set window state to 'normal' (non-minimized/maximized/rolled-up) state
1130
        mov     [ebx+window_data+WDATA.fl_wstate], WSTATE_NORMAL
998
        mov     [ebx+window_data+WDATA.fl_wstate], WSTATE_NORMAL
Line 1150... Line 1018...
1150
        mov     ebx, [pl0_stack]
1018
        mov     ebx, [pl0_stack]
1151
        mov     esi, [params]
1019
        mov     esi, [params]
1152
        lea     ecx, [ebx+REG_EIP]
1020
        lea     ecx, [ebx+REG_EIP]
1153
        xor     eax, eax
1021
        xor     eax, eax
Line 1154... Line 1022...
1154
 
1022
 
1155
        mov     [ebx+REG_RET], edx
1023
        mov     [ebx+REG_RET], dword common_app_entry
1156
        mov     [ebx+REG_EDI], eax
1024
        mov     [ebx+REG_EDI], eax
1157
        mov     [ebx+REG_ESI], eax
1025
        mov     [ebx+REG_ESI], eax
1158
        mov     [ebx+REG_EBP], eax
1026
        mov     [ebx+REG_EBP], eax
1159
        mov     [ebx+REG_ESP], ecx;ebx+REG_EIP
1027
        mov     [ebx+REG_ESP], ecx;ebx+REG_EIP
1160
        mov     [ebx+REG_EBX], eax
1028
        mov     [ebx+REG_EBX], eax
1161
        mov     [ebx+REG_EDX], eax
1029
        mov     [ebx+REG_EDX], eax
1162
        mov     [ebx+REG_ECX], eax
1030
        mov     [ebx+REG_ECX], eax
Line 1163... Line 1031...
1163
        mov     [ebx+REG_EAX], eax
1031
        mov     [ebx+REG_EAX], eax
1164
 
1032
 
1165
        mov     eax, [esi+0x08]             ;app_eip
1033
        mov     eax, [esi+APP_HDR.eip]
1166
        mov     [ebx+REG_EIP], eax          ;app_entry
1034
        mov     [ebx+REG_EIP], eax
Line 1167... Line 1035...
1167
        mov     [ebx+REG_CS], dword app_code
1035
        mov     [ebx+REG_CS], dword app_code
1168
        mov     ecx, USER_PRIORITY
1036
        mov     ecx, USER_PRIORITY
Line 1169... Line 1037...
1169
 
1037
 
1170
        test    byte [flags], 2
1038
        test    byte [flags], 2
1171
        jz      @F
-
 
1172
 
1039
        jz      @F
1173
        mov     [ebx+REG_CS], dword os_code ; kernel thread
1040
 
Line 1174... Line 1041...
1174
        mov     ecx, MAX_PRIORITY
1041
        mov     [ebx+REG_CS], dword os_code ; kernel thread
1175
 
1042
        mov     ecx, MAX_PRIORITY
1176
@@:
1043
@@:
Line 1177... Line 1044...
1177
        mov     [ebx+REG_EFLAGS], dword EFL_IOPL1+EFL_IF
1044
        mov     [ebx+REG_EFLAGS], dword EFL_IOPL1+EFL_IF
1178
 
1045
 
1179
        mov     eax, [esi+0x0C]  ;app_esp
1046
        mov     eax, [esi+APP_HDR.esp]
Line 1197... Line 1064...
1197
        lea     edx, [SLOT_BASE+ebx*8]
1064
        lea     edx, [SLOT_BASE+ebx*8]
1198
        call    scheduler_add_thread
1065
        call    scheduler_add_thread
1199
        ret
1066
        ret
1200
endp
1067
endp
Line 1201... Line -...
1201
 
-
 
1202
 
1068
 
1203
align 4
-
 
1204
 
1069
align 4
1205
get_stack_base:
1070
get_stack_base:
1206
        mov     eax, [current_slot]
1071
        mov     eax, [current_slot]
1207
        mov     eax, [eax+APPDATA.pl0_stack]
1072
        mov     eax, [eax+APPDATA.pl0_stack]