Rev 3240 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
431 | serge | 1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;; ;; |
||
2540 | hidnplayr | 3 | ;; Copyright (C) KolibriOS team 2004-2012. All rights reserved. ;; |
431 | serge | 4 | ;; Distributed under terms of the GNU General Public License ;; |
5 | ;; ;; |
||
6 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
||
7 | |||
3359 | hidnplayr | 8 | $Revision: 3359 $ |
593 | mikedld | 9 | |
2540 | hidnplayr | 10 | |
11 | GREEDY_KERNEL equ 0 |
||
12 | |||
13 | struct APP_HEADER_00_ |
||
14 | banner dq ? |
||
15 | version dd ? ;+8 |
||
16 | start dd ? ;+12 |
||
17 | i_end dd ? ;+16 |
||
18 | mem_size dd ? ;+20 |
||
19 | i_param dd ? ;+24 |
||
20 | ends |
||
21 | |||
22 | struct APP_HEADER_01_ |
||
23 | banner dq ? |
||
24 | version dd ? ;+8 |
||
25 | start dd ? ;+12 |
||
26 | i_end dd ? ;+16 |
||
27 | mem_size dd ? ;+20 |
||
28 | stack_top dd ? ;+24 |
||
29 | i_param dd ? ;+28 |
||
30 | i_icon dd ? ;+32 |
||
31 | ends |
||
32 | |||
33 | |||
3240 | johnfound | 34 | hdrVersion1 = 1 ; it is the old version of the header, without console fields |
35 | hdrVersionConsole = 2 ; it is the new version of the header, containing 2 mode dword fields |
||
36 | |||
37 | struct APP_HEADER_02_ |
||
38 | banner dq ? ; 'MENUET01' |
||
39 | version dd ? ;+8 ; == hdrVersionConsole |
||
40 | start dd ? ;+12 |
||
41 | i_end dd ? ;+16 |
||
42 | mem_size dd ? ;+20 |
||
43 | stack_top dd ? ;+24 |
||
44 | i_param dd ? ;+28 |
||
45 | i_icon dd ? ;+32 |
||
46 | |||
47 | stdio dd ? |
||
48 | stderr dd ? |
||
49 | ends |
||
50 | |||
51 | |||
2540 | hidnplayr | 52 | struct APP_PARAMS |
53 | app_cmdline dd ? ;0x00 |
||
54 | app_path dd ? ;0x04 |
||
55 | app_eip dd ? ;0x08 |
||
56 | app_esp dd ? ;0x0C |
||
57 | app_mem dd ? ;0x10 |
||
58 | ends |
||
59 | |||
3240 | johnfound | 60 | ; not needed |
61 | ;macro _clear_ op |
||
62 | ;{ mov ecx, op/4 |
||
63 | ; xor eax, eax |
||
64 | ; cld |
||
65 | ; rep stosd |
||
66 | ;} |
||
237 | serge | 67 | |
521 | diamond | 68 | fs_execute_from_sysdir: |
3240 | johnfound | 69 | xor ebx, ebx ; command line arguments. |
2382 | hidnplayr | 70 | fs_execute_from_sysdir_param: |
3240 | johnfound | 71 | xor eax, eax ; no STDIO |
72 | xor ecx, ecx ; no STDERR |
||
73 | |||
74 | xor edx, edx ; flags (currently only debug flag). |
||
2382 | hidnplayr | 75 | mov esi, sysdir_path |
363 | serge | 76 | |
164 | serge | 77 | align 4 |
363 | serge | 78 | proc fs_execute |
3240 | johnfound | 79 | ; eax - STDIO handle |
80 | ; ecx - STDERR handle |
||
363 | serge | 81 | |
82 | ; ebx - cmdline |
||
83 | ; edx - flags |
||
84 | ; ebp - full filename |
||
85 | |||
1074 | Galkov | 86 | locals |
87 | cmdline rd 64 ;256/4 |
||
88 | filename rd 256 ;1024/4 |
||
89 | flags dd ? |
||
363 | serge | 90 | |
1074 | Galkov | 91 | save_cr3 dd ? |
92 | slot dd ? |
||
93 | slot_base dd ? |
||
94 | file_base dd ? |
||
95 | file_size dd ? |
||
2540 | hidnplayr | 96 | handle dd ? ;temp. for default cursor handle for curr. thread |
1074 | Galkov | 97 | ;app header data |
98 | hdr_cmdline dd ? ;0x00 |
||
99 | hdr_path dd ? ;0x04 |
||
100 | hdr_eip dd ? ;0x08 |
||
101 | hdr_esp dd ? ;0x0C |
||
102 | hdr_mem dd ? ;0x10 |
||
103 | hdr_i_end dd ? ;0x14 |
||
3240 | johnfound | 104 | |
105 | hdr_stdio dd ? |
||
106 | hdr_stderr dd ? |
||
1074 | Galkov | 107 | endl |
164 | serge | 108 | |
3240 | johnfound | 109 | pushad |
110 | |||
111 | mov [hdr_stdio], eax |
||
112 | mov [hdr_stderr], ecx |
||
113 | |||
114 | cmp [SCR_MODE], word 0x13 |
||
115 | jbe @f |
||
116 | |||
117 | pushad |
||
118 | stdcall set_cursor, [def_cursor_clock] |
||
119 | mov [handle], eax |
||
120 | mov [redrawmouse_unconditional], 1 |
||
121 | call __sys_draw_pointer |
||
122 | popad |
||
123 | |||
124 | @@: |
||
125 | mov [flags], edx |
||
126 | |||
127 | ; [ebp] pointer to filename |
||
128 | |||
2382 | hidnplayr | 129 | lea edi, [filename] |
130 | lea ecx, [edi+1024] |
||
131 | mov al, '/' |
||
132 | stosb |
||
521 | diamond | 133 | @@: |
2382 | hidnplayr | 134 | cmp edi, ecx |
135 | jae .bigfilename |
||
136 | lodsb |
||
137 | stosb |
||
138 | test al, al |
||
139 | jnz @b |
||
140 | mov esi, [ebp] |
||
141 | test esi, esi |
||
142 | jz .namecopied |
||
143 | mov byte [edi-1], '/' |
||
521 | diamond | 144 | @@: |
2382 | hidnplayr | 145 | cmp edi, ecx |
146 | jae .bigfilename |
||
147 | lodsb |
||
148 | stosb |
||
149 | test al, al |
||
150 | jnz @b |
||
151 | jmp .namecopied |
||
521 | diamond | 152 | .bigfilename: |
2382 | hidnplayr | 153 | popad |
154 | mov eax, -ERROR_FILE_NOT_FOUND |
||
1220 | serge | 155 | |
2540 | hidnplayr | 156 | jmp .final |
157 | |||
521 | diamond | 158 | .namecopied: |
363 | serge | 159 | |
2382 | hidnplayr | 160 | mov [cmdline], ebx |
161 | test ebx, ebx |
||
162 | jz @F |
||
519 | serge | 163 | |
2382 | hidnplayr | 164 | lea eax, [cmdline] |
165 | mov dword [eax+252], 0 |
||
166 | stdcall strncpy, eax, ebx, 255 |
||
519 | serge | 167 | @@: |
2382 | hidnplayr | 168 | lea eax, [filename] |
169 | stdcall load_file, eax |
||
2540 | hidnplayr | 170 | |
2382 | hidnplayr | 171 | mov esi, -ERROR_FILE_NOT_FOUND |
172 | test eax, eax |
||
173 | jz .err_file |
||
237 | serge | 174 | |
2382 | hidnplayr | 175 | mov [file_base], eax |
176 | mov [file_size], ebx |
||
237 | serge | 177 | |
2382 | hidnplayr | 178 | lea ebx, [hdr_cmdline] |
179 | call test_app_header |
||
3240 | johnfound | 180 | mov esi, -ERROR_INVALID_HEADER |
2382 | hidnplayr | 181 | test eax, eax |
182 | jz .err_hdr |
||
237 | serge | 183 | |
3240 | johnfound | 184 | ; The header is OK, so check for the version and if == hdrVersionConsole, patch the header with |
185 | ; the handles of the console IO socket handlers. |
||
186 | mov edx, [hdr_stdio] |
||
187 | mov ecx, [hdr_stderr] |
||
188 | |||
189 | cmp [eax+APP_HEADER_02_.version], hdrVersionConsole |
||
190 | jae .patch_header |
||
191 | |||
192 | or edx, ecx |
||
193 | jz .wait_lock |
||
194 | |||
195 | mov esi, -ERROR_WRONG_HEADER_VERSION |
||
196 | jmp .err_hdr |
||
197 | |||
198 | .patch_header: |
||
199 | mov [eax+APP_HEADER_02_.stdio], edx |
||
200 | mov [eax+APP_HEADER_02_.stderr], ecx |
||
201 | |||
237 | serge | 202 | .wait_lock: |
2382 | hidnplayr | 203 | cmp [application_table_status], 0 |
204 | je .get_lock |
||
205 | call change_task |
||
206 | jmp .wait_lock |
||
237 | serge | 207 | |
208 | .get_lock: |
||
2382 | hidnplayr | 209 | mov eax, 1 |
210 | xchg eax, [application_table_status] |
||
211 | test eax, eax |
||
212 | jnz .wait_lock |
||
237 | serge | 213 | |
2382 | hidnplayr | 214 | call set_application_table_status |
237 | serge | 215 | |
2382 | hidnplayr | 216 | call get_new_process_place |
217 | test eax, eax |
||
3240 | johnfound | 218 | mov esi, -ERROR_TOO_MANY_PROCESSES |
2382 | hidnplayr | 219 | jz .err |
237 | serge | 220 | |
2382 | hidnplayr | 221 | mov [slot], eax |
222 | shl eax, 8 |
||
223 | add eax, SLOT_BASE |
||
224 | mov [slot_base], eax |
||
225 | mov edi, eax |
||
237 | serge | 226 | |
3240 | johnfound | 227 | ;_clear_ 256 ;clean extended information about process |
228 | mov ecx, 256/4 |
||
229 | xor eax, eax |
||
230 | cld |
||
231 | rep stosd |
||
232 | |||
237 | serge | 233 | ; write application name |
2382 | hidnplayr | 234 | lea eax, [filename] |
235 | stdcall strrchr, eax, '/' ; now eax points to name without path |
||
237 | serge | 236 | |
2382 | hidnplayr | 237 | lea esi, [eax+1] |
238 | test eax, eax |
||
3240 | johnfound | 239 | jnz @F |
240 | lea esi, [filename] |
||
241 | @@: |
||
242 | mov ecx, 11 ; 11 chars for name! 8 - is old value! |
||
243 | mov edi, [slot_base] |
||
244 | .copy_process_name_loop: |
||
245 | lodsb |
||
2382 | hidnplayr | 246 | cmp al, '.' |
247 | jz .copy_process_name_done |
||
248 | test al, al |
||
249 | jz .copy_process_name_done |
||
250 | stosb |
||
251 | loop .copy_process_name_loop |
||
237 | serge | 252 | .copy_process_name_done: |
253 | |||
2382 | hidnplayr | 254 | mov ebx, cr3 |
255 | mov [save_cr3], ebx |
||
269 | serge | 256 | |
2382 | hidnplayr | 257 | stdcall create_app_space, [hdr_mem], [file_base], [file_size] |
3240 | johnfound | 258 | mov esi, -ERROR_MEMORY_NOT_ENOUGH ; no memory |
2382 | hidnplayr | 259 | test eax, eax |
260 | jz .failed |
||
237 | serge | 261 | |
2382 | hidnplayr | 262 | mov ebx, [slot_base] |
263 | mov [ebx+APPDATA.dir_table], eax |
||
264 | mov eax, [hdr_mem] |
||
265 | mov [ebx+APPDATA.mem_size], eax |
||
237 | serge | 266 | |
2382 | hidnplayr | 267 | xor edx, edx |
268 | cmp word [6], '02' |
||
269 | jne @f |
||
1220 | serge | 270 | |
2382 | hidnplayr | 271 | not edx |
1220 | serge | 272 | @@: |
2382 | hidnplayr | 273 | mov [ebx+APPDATA.tls_base], edx |
1220 | serge | 274 | |
357 | serge | 275 | if GREEDY_KERNEL |
276 | else |
||
2382 | hidnplayr | 277 | mov ecx, [hdr_mem] |
278 | mov edi, [file_size] |
||
279 | add edi, 4095 |
||
280 | and edi, not 4095 |
||
281 | sub ecx, edi |
||
282 | jna @F |
||
269 | serge | 283 | |
2382 | hidnplayr | 284 | xor eax, eax |
285 | cld |
||
286 | rep stosb |
||
247 | serge | 287 | @@: |
269 | serge | 288 | end if |
289 | |||
290 | ; release only virtual space, not phisical memory |
||
291 | |||
2382 | hidnplayr | 292 | stdcall free_kernel_space, [file_base] |
293 | lea eax, [hdr_cmdline] |
||
294 | lea ebx, [cmdline] |
||
295 | lea ecx, [filename] |
||
296 | stdcall set_app_params , [slot], eax, ebx, ecx, [flags] |
||
237 | serge | 297 | |
2382 | hidnplayr | 298 | mov eax, [save_cr3] |
299 | call set_cr3 |
||
237 | serge | 300 | |
2382 | hidnplayr | 301 | xor ebx, ebx |
302 | mov [application_table_status], ebx;unlock application_table_status mutex |
||
303 | mov eax, [process_number];set result |
||
2540 | hidnplayr | 304 | |
305 | jmp .final |
||
306 | |||
237 | serge | 307 | .failed: |
2382 | hidnplayr | 308 | mov eax, [save_cr3] |
309 | call set_cr3 |
||
269 | serge | 310 | .err: |
247 | serge | 311 | .err_hdr: |
2382 | hidnplayr | 312 | stdcall kernel_free, [file_base] |
247 | serge | 313 | .err_file: |
2382 | hidnplayr | 314 | xor eax, eax |
3240 | johnfound | 315 | mov [application_table_status], eax |
316 | mov eax, esi |
||
317 | .final: |
||
318 | cmp [SCR_MODE], word 0x13 |
||
319 | jbe @f |
||
320 | pushad |
||
321 | stdcall set_cursor, [handle] |
||
322 | mov [redrawmouse_unconditional], 1 |
||
323 | call __sys_draw_pointer |
||
324 | popad |
||
325 | @@: |
||
326 | ret |
||
327 | endp |
||
328 | |||
2540 | hidnplayr | 329 | align 4 |
330 | test_app_header: |
||
331 | virtual at eax |
||
332 | APP_HEADER_00 APP_HEADER_00_ |
||
333 | end virtual |
||
334 | virtual at eax |
||
335 | APP_HEADER_01 APP_HEADER_01_ |
||
336 | end virtual |
||
337 | |||
338 | cmp dword [eax], 'MENU' |
||
2382 | hidnplayr | 339 | jne .fail |
340 | cmp word [eax+4], 'ET' |
||
341 | jne .fail |
||
164 | serge | 342 | |
2382 | hidnplayr | 343 | cmp [eax+6], word '00' |
344 | jne .check_01_header |
||
164 | serge | 345 | |
2382 | hidnplayr | 346 | mov ecx, [APP_HEADER_00.start] |
347 | mov [ebx+0x08], ecx ;app_eip |
||
348 | mov edx, [APP_HEADER_00.mem_size] |
||
349 | mov [ebx+0x10], edx ;app_mem |
||
350 | shr edx, 1 |
||
351 | sub edx, 0x10 |
||
352 | mov [ebx+0x0C], edx ;app_esp |
||
353 | mov ecx, [APP_HEADER_00.i_param] |
||
354 | mov [ebx], ecx ;app_cmdline |
||
355 | mov [ebx+4], dword 0 ;app_path |
||
356 | mov edx, [APP_HEADER_00.i_end] |
||
357 | mov [ebx+0x14], edx |
||
358 | ret |
||
164 | serge | 359 | |
237 | serge | 360 | .check_01_header: |
164 | serge | 361 | |
2382 | hidnplayr | 362 | cmp [eax+6], word '01' |
363 | je @f |
||
364 | cmp [eax+6], word '02' |
||
365 | jne .fail |
||
1220 | serge | 366 | @@: |
2382 | hidnplayr | 367 | mov ecx, [APP_HEADER_01.start] |
368 | mov [ebx+0x08], ecx ;app_eip |
||
369 | mov edx, [APP_HEADER_01.mem_size] |
||
381 | serge | 370 | |
371 | ; \begin{diamond}[20.08.2006] |
||
372 | ; sanity check (functions 19,58 load app_i_end bytes and that must |
||
373 | ; fit in allocated memory to prevent kernel faults) |
||
2382 | hidnplayr | 374 | cmp edx, [APP_HEADER_01.i_end] |
375 | jb .fail |
||
381 | serge | 376 | ; \end{diamond}[20.08.2006] |
377 | |||
2382 | hidnplayr | 378 | mov [ebx+0x10], edx ;app_mem |
379 | mov ecx, [APP_HEADER_01.stack_top] |
||
380 | mov [ebx+0x0C], ecx ;app_esp |
||
381 | mov edx, [APP_HEADER_01.i_param] |
||
382 | mov [ebx], edx ;app_cmdline |
||
383 | mov ecx, [APP_HEADER_01.i_icon] |
||
384 | mov [ebx+4], ecx ;app_path |
||
385 | mov edx, [APP_HEADER_01.i_end] |
||
386 | mov [ebx+0x14], edx |
||
387 | ret |
||
237 | serge | 388 | .fail: |
2382 | hidnplayr | 389 | xor eax, eax |
390 | ret |
||
164 | serge | 391 | |
392 | align 4 |
||
393 | proc get_new_process_place |
||
394 | ;input: |
||
395 | ; none |
||
396 | ;result: |
||
397 | ; eax=[new_process_place]<>0 - ok |
||
398 | ; 0 - failed. |
||
399 | ;This function find least empty slot. |
||
400 | ;It doesn't increase [TASK_COUNT]! |
||
2382 | hidnplayr | 401 | mov eax, CURRENT_TASK |
402 | mov ebx, [TASK_COUNT] |
||
403 | inc ebx |
||
404 | shl ebx, 5 |
||
405 | add ebx, eax ;ebx - address of process information for (last+1) slot |
||
164 | serge | 406 | .newprocessplace: |
407 | ;eax = address of process information for current slot |
||
2382 | hidnplayr | 408 | cmp eax, ebx |
409 | jz .endnewprocessplace ;empty slot after high boundary |
||
410 | add eax, 0x20 |
||
411 | cmp word [eax+0xa], 9;check process state, 9 means that process slot is empty |
||
412 | jnz .newprocessplace |
||
164 | serge | 413 | .endnewprocessplace: |
2382 | hidnplayr | 414 | mov ebx, eax |
415 | sub eax, CURRENT_TASK |
||
416 | shr eax, 5 ;calculate slot index |
||
417 | cmp eax, 256 |
||
418 | jge .failed ;it should be <256 |
||
419 | mov word [ebx+0xa], 9;set process state to 9 (for slot after hight boundary) |
||
420 | ret |
||
164 | serge | 421 | .failed: |
2382 | hidnplayr | 422 | xor eax, eax |
423 | ret |
||
164 | serge | 424 | endp |
425 | |||
426 | align 4 |
||
269 | serge | 427 | proc create_app_space stdcall, app_size:dword,img_base:dword,img_size:dword |
1074 | Galkov | 428 | locals |
429 | app_pages dd ? |
||
430 | img_pages dd ? |
||
431 | dir_addr dd ? |
||
432 | app_tabs dd ? |
||
433 | endl |
||
164 | serge | 434 | |
2382 | hidnplayr | 435 | mov ecx, pg_data.mutex |
436 | call mutex_lock |
||
164 | serge | 437 | |
2382 | hidnplayr | 438 | xor eax, eax |
439 | mov [dir_addr], eax |
||
164 | serge | 440 | |
2382 | hidnplayr | 441 | mov eax, [app_size] |
442 | add eax, 4095 |
||
443 | and eax, NOT(4095) |
||
444 | mov [app_size], eax |
||
445 | mov ebx, eax |
||
446 | shr eax, 12 |
||
447 | mov [app_pages], eax |
||
170 | serge | 448 | |
2382 | hidnplayr | 449 | add ebx, 0x3FFFFF |
450 | and ebx, NOT(0x3FFFFF) |
||
451 | shr ebx, 22 |
||
452 | mov [app_tabs], ebx |
||
164 | serge | 453 | |
2382 | hidnplayr | 454 | mov ecx, [img_size] |
455 | add ecx, 4095 |
||
456 | and ecx, NOT(4095) |
||
164 | serge | 457 | |
2382 | hidnplayr | 458 | mov [img_size], ecx |
459 | shr ecx, 12 |
||
460 | mov [img_pages], ecx |
||
164 | serge | 461 | |
2382 | hidnplayr | 462 | if GREEDY_KERNEL |
463 | lea eax, [ecx+ebx+2];only image size |
||
464 | else |
||
465 | lea eax, [eax+ebx+2];all requested memory |
||
466 | end if |
||
467 | cmp eax, [pg_data.pages_free] |
||
468 | ja .fail |
||
170 | serge | 469 | |
2382 | hidnplayr | 470 | call alloc_page |
471 | test eax, eax |
||
472 | jz .fail |
||
473 | mov [dir_addr], eax |
||
474 | stdcall map_page, [tmp_task_pdir], eax, dword PG_SW |
||
164 | serge | 475 | |
2382 | hidnplayr | 476 | mov edi, [tmp_task_pdir] |
477 | mov ecx, (OS_BASE shr 20)/4 |
||
478 | xor eax, eax |
||
479 | cld |
||
480 | rep stosd |
||
465 | serge | 481 | |
2382 | hidnplayr | 482 | mov ecx, (OS_BASE shr 20)/4 |
483 | mov esi, sys_pgdir+(OS_BASE shr 20) |
||
484 | rep movsd |
||
164 | serge | 485 | |
2382 | hidnplayr | 486 | mov eax, [dir_addr] |
487 | or eax, PG_SW |
||
488 | mov [edi-4096+(page_tabs shr 20)], eax |
||
378 | serge | 489 | |
2382 | hidnplayr | 490 | and eax, -4096 |
491 | call set_cr3 |
||
164 | serge | 492 | |
2382 | hidnplayr | 493 | mov edx, [app_tabs] |
494 | mov edi, new_app_base |
||
164 | serge | 495 | @@: |
2382 | hidnplayr | 496 | call alloc_page |
497 | test eax, eax |
||
498 | jz .fail |
||
164 | serge | 499 | |
2382 | hidnplayr | 500 | stdcall map_page_table, edi, eax |
501 | add edi, 0x00400000 |
||
502 | dec edx |
||
503 | jnz @B |
||
164 | serge | 504 | |
2382 | hidnplayr | 505 | mov edi, new_app_base |
506 | shr edi, 10 |
||
507 | add edi, page_tabs |
||
269 | serge | 508 | |
2382 | hidnplayr | 509 | mov ecx, [app_tabs] |
510 | shl ecx, 10 |
||
511 | xor eax, eax |
||
512 | rep stosd |
||
164 | serge | 513 | |
2382 | hidnplayr | 514 | mov ecx, [img_pages] |
515 | mov ebx, PG_UW |
||
516 | mov edx, new_app_base |
||
517 | mov esi, [img_base] |
||
518 | mov edi, new_app_base |
||
519 | shr esi, 10 |
||
520 | shr edi, 10 |
||
521 | add esi, page_tabs |
||
522 | add edi, page_tabs |
||
269 | serge | 523 | .remap: |
2382 | hidnplayr | 524 | lodsd |
525 | or eax, ebx; force user level r/w access |
||
526 | stosd |
||
527 | add edx, 0x1000 |
||
528 | dec [app_pages] |
||
529 | dec ecx |
||
530 | jnz .remap |
||
269 | serge | 531 | |
2382 | hidnplayr | 532 | mov ecx, [app_pages] |
533 | test ecx, ecx |
||
534 | jz .done |
||
269 | serge | 535 | |
536 | if GREEDY_KERNEL |
||
2382 | hidnplayr | 537 | mov eax, 0x02 |
538 | rep stosd |
||
269 | serge | 539 | else |
540 | |||
164 | serge | 541 | .alloc: |
2382 | hidnplayr | 542 | call alloc_page |
543 | test eax, eax |
||
544 | jz .fail |
||
164 | serge | 545 | |
2382 | hidnplayr | 546 | stdcall map_page, edx, eax, dword PG_UW |
547 | add edx, 0x1000 |
||
548 | dec [app_pages] |
||
549 | jnz .alloc |
||
269 | serge | 550 | end if |
164 | serge | 551 | |
269 | serge | 552 | .done: |
2382 | hidnplayr | 553 | stdcall map_page, [tmp_task_pdir], dword 0, dword PG_UNMAP |
164 | serge | 554 | |
2382 | hidnplayr | 555 | mov ecx, pg_data.mutex |
556 | call mutex_unlock |
||
557 | mov eax, [dir_addr] |
||
558 | ret |
||
164 | serge | 559 | .fail: |
2382 | hidnplayr | 560 | mov ecx, pg_data.mutex |
561 | call mutex_unlock |
||
562 | cmp [dir_addr], 0 |
||
563 | je @f |
||
564 | stdcall destroy_app_space, [dir_addr], 0 |
||
164 | serge | 565 | @@: |
2382 | hidnplayr | 566 | xor eax, eax |
567 | ret |
||
164 | serge | 568 | endp |
569 | |||
570 | align 4 |
||
571 | set_cr3: |
||
465 | serge | 572 | |
2382 | hidnplayr | 573 | mov ebx, [current_slot] |
574 | mov [ebx+APPDATA.dir_table], eax |
||
575 | mov cr3, eax |
||
576 | ret |
||
164 | serge | 577 | |
578 | align 4 |
||
579 | proc destroy_page_table stdcall, pg_tab:dword |
||
580 | |||
2382 | hidnplayr | 581 | push esi |
164 | serge | 582 | |
2382 | hidnplayr | 583 | mov esi, [pg_tab] |
584 | mov ecx, 1024 |
||
164 | serge | 585 | .free: |
2382 | hidnplayr | 586 | mov eax, [esi] |
587 | test eax, 1 |
||
588 | jz .next |
||
589 | test eax, 1 shl 9 |
||
590 | jnz .next ;skip shared pages |
||
591 | call free_page |
||
164 | serge | 592 | .next: |
2382 | hidnplayr | 593 | add esi, 4 |
594 | dec ecx |
||
595 | jnz .free |
||
596 | pop esi |
||
597 | ret |
||
164 | serge | 598 | endp |
599 | |||
600 | align 4 |
||
1311 | diamond | 601 | proc destroy_app_space stdcall, pg_dir:dword, dlls_list:dword |
164 | serge | 602 | |
2382 | hidnplayr | 603 | xor edx, edx |
604 | push edx |
||
605 | mov eax, 0x2 |
||
606 | mov ebx, [pg_dir] |
||
164 | serge | 607 | .loop: |
608 | ;eax = current slot of process |
||
2382 | hidnplayr | 609 | mov ecx, eax |
610 | shl ecx, 5 |
||
611 | cmp byte [CURRENT_TASK+ecx+0xa], 9;if process running? |
||
612 | jz @f ;skip empty slots |
||
613 | shl ecx, 3 |
||
614 | add ecx, SLOT_BASE |
||
615 | cmp [ecx+APPDATA.dir_table], ebx;compare page directory addresses |
||
616 | jnz @f |
||
617 | mov [ebp-4], ecx |
||
618 | inc edx ;thread found |
||
164 | serge | 619 | @@: |
2382 | hidnplayr | 620 | inc eax |
621 | cmp eax, [TASK_COUNT] ;exit loop if we look through all processes |
||
622 | jle .loop |
||
164 | serge | 623 | |
624 | ;edx = number of threads |
||
625 | ;our process is zombi so it isn't counted |
||
2382 | hidnplayr | 626 | pop ecx |
627 | cmp edx, 1 |
||
628 | jg .ret |
||
164 | serge | 629 | ;if there isn't threads then clear memory. |
2382 | hidnplayr | 630 | mov esi, [dlls_list] |
631 | call destroy_all_hdlls;ecx=APPDATA |
||
164 | serge | 632 | |
2382 | hidnplayr | 633 | mov ecx, pg_data.mutex |
634 | call mutex_lock |
||
1311 | diamond | 635 | |
2382 | hidnplayr | 636 | mov eax, [pg_dir] |
637 | and eax, not 0xFFF |
||
638 | stdcall map_page, [tmp_task_pdir], eax, PG_SW |
||
639 | mov esi, [tmp_task_pdir] |
||
640 | mov edi, (OS_BASE shr 20)/4 |
||
164 | serge | 641 | .destroy: |
2382 | hidnplayr | 642 | mov eax, [esi] |
643 | test eax, 1 |
||
644 | jz .next |
||
645 | and eax, not 0xFFF |
||
646 | stdcall map_page, [tmp_task_ptab], eax, PG_SW |
||
647 | stdcall destroy_page_table, [tmp_task_ptab] |
||
648 | mov eax, [esi] |
||
649 | call free_page |
||
164 | serge | 650 | .next: |
2382 | hidnplayr | 651 | add esi, 4 |
652 | dec edi |
||
653 | jnz .destroy |
||
164 | serge | 654 | |
2382 | hidnplayr | 655 | mov eax, [pg_dir] |
656 | call free_page |
||
164 | serge | 657 | .exit: |
2382 | hidnplayr | 658 | stdcall map_page, [tmp_task_ptab], 0, PG_UNMAP |
659 | stdcall map_page, [tmp_task_pdir], 0, PG_UNMAP |
||
660 | mov ecx, pg_data.mutex |
||
661 | call mutex_unlock |
||
1311 | diamond | 662 | .ret: |
2382 | hidnplayr | 663 | ret |
164 | serge | 664 | endp |
665 | |||
520 | serge | 666 | align 4 |
667 | get_pid: |
||
2382 | hidnplayr | 668 | mov eax, [TASK_BASE] |
669 | mov eax, [eax+TASKDATA.pid] |
||
670 | ret |
||
520 | serge | 671 | |
164 | serge | 672 | pid_to_slot: |
673 | ;Input: |
||
674 | ; eax - pid of process |
||
675 | ;Output: |
||
676 | ; eax - slot of process or 0 if process don't exists |
||
677 | ;Search process by PID. |
||
2382 | hidnplayr | 678 | push ebx |
679 | push ecx |
||
680 | mov ebx, [TASK_COUNT] |
||
681 | shl ebx, 5 |
||
682 | mov ecx, 2*32 |
||
164 | serge | 683 | |
684 | .loop: |
||
685 | ;ecx=offset of current process info entry |
||
686 | ;ebx=maximum permitted offset |
||
2382 | hidnplayr | 687 | cmp byte [CURRENT_TASK+ecx+0xa], 9 |
688 | jz .endloop ;skip empty slots |
||
689 | cmp [CURRENT_TASK+ecx+0x4], eax;check PID |
||
690 | jz .pid_found |
||
164 | serge | 691 | .endloop: |
2382 | hidnplayr | 692 | add ecx, 32 |
693 | cmp ecx, ebx |
||
694 | jle .loop |
||
164 | serge | 695 | |
2382 | hidnplayr | 696 | pop ecx |
697 | pop ebx |
||
698 | xor eax, eax |
||
699 | ret |
||
164 | serge | 700 | |
701 | .pid_found: |
||
2382 | hidnplayr | 702 | shr ecx, 5 |
703 | mov eax, ecx ;convert offset to index of slot |
||
704 | pop ecx |
||
705 | pop ebx |
||
706 | ret |
||
164 | serge | 707 | |
708 | check_region: |
||
709 | ;input: |
||
1329 | Lrz | 710 | ; esi - start of buffer |
711 | ; edx - size of buffer |
||
164 | serge | 712 | ;result: |
713 | ; eax = 1 region lays in app memory |
||
714 | ; eax = 0 region don't lays in app memory |
||
2382 | hidnplayr | 715 | mov eax, [CURRENT_TASK] |
1329 | Lrz | 716 | ; jmp check_process_region |
164 | serge | 717 | ;----------------------------------------------------------------------------- |
1329 | Lrz | 718 | ;check_process_region: |
164 | serge | 719 | ;input: |
720 | ; eax - slot |
||
1329 | Lrz | 721 | ; esi - start of buffer |
722 | ; edx - size of buffer |
||
164 | serge | 723 | ;result: |
724 | ; eax = 1 region lays in app memory |
||
725 | ; eax = 0 region don't lays in app memory |
||
726 | |||
2382 | hidnplayr | 727 | test edx, edx |
728 | jle .ok |
||
729 | shl eax, 5 |
||
730 | cmp word [CURRENT_TASK+eax+0xa], 0 |
||
731 | jnz .failed |
||
732 | shl eax, 3 |
||
733 | mov eax, [SLOT_BASE+eax+0xb8] |
||
734 | test eax, eax |
||
735 | jz .failed |
||
164 | serge | 736 | |
2382 | hidnplayr | 737 | mov eax, 1 |
738 | ret |
||
164 | serge | 739 | |
740 | |||
741 | ; call MEM_Get_Linear_Address |
||
742 | ; push ebx |
||
743 | ; push ecx |
||
744 | ; push edx |
||
745 | ; mov edx,ebx |
||
746 | ; and edx,not (4096-1) |
||
747 | ; sub ebx,edx |
||
748 | ; add ecx,ebx |
||
749 | ; mov ebx,edx |
||
750 | ; add ecx,(4096-1) |
||
751 | ; and ecx,not (4096-1) |
||
752 | ;.loop: |
||
753 | ;;eax - linear address of page directory |
||
754 | ;;ebx - current page |
||
755 | ;;ecx - current size |
||
756 | ; mov edx,ebx |
||
757 | ; shr edx,22 |
||
758 | ; mov edx,[eax+4*edx] |
||
759 | ; and edx,not (4096-1) |
||
760 | ; test edx,edx |
||
761 | ; jz .failed1 |
||
762 | ; push eax |
||
763 | ; mov eax,edx |
||
764 | ; call MEM_Get_Linear_Address |
||
765 | ; mov edx,ebx |
||
766 | ; shr edx,12 |
||
767 | ; and edx,(1024-1) |
||
768 | ; mov eax,[eax+4*edx] |
||
769 | ; and eax,not (4096-1) |
||
770 | ; test eax,eax |
||
771 | ; pop eax |
||
772 | ; jz .failed1 |
||
773 | ; add ebx,4096 |
||
774 | ; sub ecx,4096 |
||
775 | ; jg .loop |
||
776 | ; pop edx |
||
777 | ; pop ecx |
||
778 | ; pop ebx |
||
779 | .ok: |
||
2382 | hidnplayr | 780 | mov eax, 1 |
781 | ret |
||
164 | serge | 782 | ; |
783 | ;.failed1: |
||
784 | ; pop edx |
||
785 | ; pop ecx |
||
786 | ; pop ebx |
||
787 | .failed: |
||
2382 | hidnplayr | 788 | xor eax, eax |
789 | ret |
||
164 | serge | 790 | |
791 | align 4 |
||
792 | proc read_process_memory |
||
793 | ;Input: |
||
794 | ; eax - process slot |
||
1329 | Lrz | 795 | ; ecx - buffer address |
796 | ; edx - buffer size |
||
797 | ; esi - start address in other process |
||
164 | serge | 798 | ;Output: |
799 | ; eax - number of bytes read. |
||
1074 | Galkov | 800 | locals |
801 | slot dd ? |
||
802 | buff dd ? |
||
803 | r_count dd ? |
||
804 | offset dd ? |
||
805 | tmp_r_cnt dd ? |
||
806 | endl |
||
164 | serge | 807 | |
2382 | hidnplayr | 808 | mov [slot], eax |
809 | mov [buff], ecx |
||
810 | and [r_count], 0 |
||
811 | mov [tmp_r_cnt], edx |
||
812 | mov [offset], esi |
||
164 | serge | 813 | |
2382 | hidnplayr | 814 | pushad |
164 | serge | 815 | .read_mem: |
2382 | hidnplayr | 816 | mov edx, [offset] |
817 | mov ebx, [tmp_r_cnt] |
||
164 | serge | 818 | |
2382 | hidnplayr | 819 | mov ecx, 0x400000 |
820 | and edx, 0x3FFFFF |
||
821 | sub ecx, edx |
||
822 | cmp ecx, ebx |
||
823 | jbe @f |
||
824 | mov ecx, ebx |
||
164 | serge | 825 | @@: |
2382 | hidnplayr | 826 | cmp ecx, 0x8000 |
827 | jna @F |
||
828 | mov ecx, 0x8000 |
||
164 | serge | 829 | @@: |
2382 | hidnplayr | 830 | mov ebx, [offset] |
1220 | serge | 831 | |
2382 | hidnplayr | 832 | push ecx |
833 | stdcall map_memEx, [proc_mem_map], \ |
||
834 | [slot], ebx, ecx, PG_MAP |
||
835 | pop ecx |
||
164 | serge | 836 | |
2382 | hidnplayr | 837 | mov esi, [offset] |
838 | and esi, 0xfff |
||
839 | sub eax, esi |
||
840 | jbe .ret |
||
841 | cmp ecx, eax |
||
842 | jbe @f |
||
843 | mov ecx, eax |
||
844 | mov [tmp_r_cnt], eax |
||
1314 | diamond | 845 | @@: |
2382 | hidnplayr | 846 | add esi, [proc_mem_map] |
847 | mov edi, [buff] |
||
848 | mov edx, ecx |
||
849 | rep movsb |
||
850 | add [r_count], edx |
||
164 | serge | 851 | |
2382 | hidnplayr | 852 | add [offset], edx |
853 | sub [tmp_r_cnt], edx |
||
854 | jnz .read_mem |
||
1314 | diamond | 855 | .ret: |
2382 | hidnplayr | 856 | popad |
857 | mov eax, [r_count] |
||
858 | ret |
||
164 | serge | 859 | endp |
860 | |||
861 | align 4 |
||
862 | proc write_process_memory |
||
863 | ;Input: |
||
864 | ; eax - process slot |
||
1329 | Lrz | 865 | ; ecx - buffer address |
866 | ; edx - buffer size |
||
867 | ; esi - start address in other process |
||
164 | serge | 868 | ;Output: |
869 | ; eax - number of bytes written |
||
870 | |||
1074 | Galkov | 871 | locals |
872 | slot dd ? |
||
873 | buff dd ? |
||
874 | w_count dd ? |
||
875 | offset dd ? |
||
876 | tmp_w_cnt dd ? |
||
877 | endl |
||
164 | serge | 878 | |
2382 | hidnplayr | 879 | mov [slot], eax |
880 | mov [buff], ecx |
||
881 | and [w_count], 0 |
||
882 | mov [tmp_w_cnt], edx |
||
883 | mov [offset], esi |
||
164 | serge | 884 | |
2382 | hidnplayr | 885 | pushad |
164 | serge | 886 | .read_mem: |
2382 | hidnplayr | 887 | mov edx, [offset] |
888 | mov ebx, [tmp_w_cnt] |
||
164 | serge | 889 | |
2382 | hidnplayr | 890 | mov ecx, 0x400000 |
891 | and edx, 0x3FFFFF |
||
892 | sub ecx, edx |
||
893 | cmp ecx, ebx |
||
894 | jbe @f |
||
895 | mov ecx, ebx |
||
164 | serge | 896 | @@: |
2382 | hidnplayr | 897 | cmp ecx, 0x8000 |
898 | jna @F |
||
899 | mov ecx, 0x8000 |
||
164 | serge | 900 | @@: |
2382 | hidnplayr | 901 | mov ebx, [offset] |
465 | serge | 902 | ; add ebx, new_app_base |
2382 | hidnplayr | 903 | push ecx |
904 | stdcall map_memEx, [proc_mem_map], \ |
||
905 | [slot], ebx, ecx, PG_SW |
||
906 | pop ecx |
||
164 | serge | 907 | |
2382 | hidnplayr | 908 | mov edi, [offset] |
909 | and edi, 0xfff |
||
910 | sub eax, edi |
||
911 | jbe .ret |
||
912 | cmp ecx, eax |
||
913 | jbe @f |
||
914 | mov ecx, eax |
||
915 | mov [tmp_w_cnt], eax |
||
1314 | diamond | 916 | @@: |
2382 | hidnplayr | 917 | add edi, [proc_mem_map] |
918 | mov esi, [buff] |
||
919 | mov edx, ecx |
||
920 | rep movsb |
||
164 | serge | 921 | |
2382 | hidnplayr | 922 | add [w_count], edx |
923 | add [offset], edx |
||
924 | sub [tmp_w_cnt], edx |
||
925 | jnz .read_mem |
||
1314 | diamond | 926 | .ret: |
2382 | hidnplayr | 927 | popad |
928 | mov eax, [w_count] |
||
929 | ret |
||
164 | serge | 930 | endp |
931 | |||
932 | align 4 |
||
933 | proc new_sys_threads |
||
1074 | Galkov | 934 | locals |
935 | slot dd ? |
||
936 | app_cmdline dd ? ;0x00 |
||
937 | app_path dd ? ;0x04 |
||
938 | app_eip dd ? ;0x08 |
||
939 | app_esp dd ? ;0x0C |
||
940 | app_mem dd ? ;0x10 |
||
941 | endl |
||
164 | serge | 942 | |
2382 | hidnplayr | 943 | cmp ebx, 1 |
944 | jne .failed ;other subfunctions |
||
164 | serge | 945 | |
2382 | hidnplayr | 946 | xor eax, eax |
947 | mov [app_eip], ecx |
||
948 | mov [app_cmdline], eax |
||
949 | mov [app_esp], edx |
||
950 | mov [app_path], eax |
||
1074 | Galkov | 951 | ;mov esi,new_process_loading |
952 | ;call sys_msg_board_str |
||
164 | serge | 953 | .wait_lock: |
2382 | hidnplayr | 954 | cmp [application_table_status], 0 |
955 | je .get_lock |
||
956 | call change_task |
||
957 | jmp .wait_lock |
||
164 | serge | 958 | |
959 | .get_lock: |
||
2382 | hidnplayr | 960 | mov eax, 1 |
961 | xchg eax, [application_table_status] |
||
962 | test eax, eax |
||
963 | jnz .wait_lock |
||
164 | serge | 964 | |
2382 | hidnplayr | 965 | call set_application_table_status |
164 | serge | 966 | |
2382 | hidnplayr | 967 | call get_new_process_place |
968 | test eax, eax |
||
969 | jz .failed |
||
164 | serge | 970 | |
2382 | hidnplayr | 971 | mov [slot], eax |
164 | serge | 972 | |
2382 | hidnplayr | 973 | mov esi, [current_slot] |
974 | mov ebx, esi ;ebx=esi - pointer to extended information about current thread |
||
164 | serge | 975 | |
2382 | hidnplayr | 976 | mov edi, eax |
977 | shl edi, 8 |
||
978 | add edi, SLOT_BASE |
||
979 | mov edx, edi ;edx=edi - pointer to extended infomation about new thread |
||
980 | mov ecx, 256/4 |
||
981 | xor eax, eax |
||
982 | cld |
||
983 | rep stosd ;clean extended information about new thread |
||
984 | mov esi, ebx |
||
985 | mov edi, edx |
||
986 | mov ecx, 11 |
||
987 | rep movsb ;copy process name |
||
164 | serge | 988 | |
2382 | hidnplayr | 989 | mov eax, [ebx+APPDATA.heap_base] |
990 | mov [edx+APPDATA.heap_base], eax |
||
164 | serge | 991 | |
2382 | hidnplayr | 992 | mov ecx, [ebx+APPDATA.heap_top] |
993 | mov [edx+APPDATA.heap_top], ecx |
||
237 | serge | 994 | |
2382 | hidnplayr | 995 | mov eax, [ebx+APPDATA.mem_size] |
996 | mov [edx+APPDATA.mem_size], eax |
||
237 | serge | 997 | |
2382 | hidnplayr | 998 | mov ecx, [ebx+APPDATA.dir_table] |
999 | mov [edx+APPDATA.dir_table], ecx;copy page directory |
||
237 | serge | 1000 | |
2382 | hidnplayr | 1001 | mov eax, [ebx+APPDATA.dlls_list_ptr] |
1002 | mov [edx+APPDATA.dlls_list_ptr], eax |
||
1311 | diamond | 1003 | |
2382 | hidnplayr | 1004 | mov eax, [ebx+APPDATA.tls_base] |
1005 | test eax, eax |
||
1006 | jz @F |
||
1220 | serge | 1007 | |
2382 | hidnplayr | 1008 | push edx |
1009 | stdcall user_alloc, 4096 |
||
1010 | pop edx |
||
1011 | test eax, eax |
||
1012 | jz .failed1;eax=0 |
||
1220 | serge | 1013 | @@: |
2382 | hidnplayr | 1014 | mov [edx+APPDATA.tls_base], eax |
1220 | serge | 1015 | |
2382 | hidnplayr | 1016 | lea eax, [app_cmdline] |
1017 | stdcall set_app_params , [slot], eax, dword 0, \ |
||
1018 | dword 0,dword 0 |
||
237 | serge | 1019 | |
1074 | Galkov | 1020 | ;mov esi,new_process_running |
2382 | hidnplayr | 1021 | ;call sys_msg_board_str ;output information about succefull startup |
1022 | xor eax, eax |
||
1023 | mov [application_table_status], eax ;unlock application_table_status mutex |
||
1024 | mov eax, [process_number] ;set result |
||
1025 | ret |
||
164 | serge | 1026 | .failed: |
2382 | hidnplayr | 1027 | xor eax, eax |
1322 | Lrz | 1028 | .failed1: |
2382 | hidnplayr | 1029 | mov [application_table_status], eax |
1030 | dec eax ;-1 |
||
1031 | ret |
||
164 | serge | 1032 | endp |
1033 | |||
1034 | align 4 |
||
1220 | serge | 1035 | tls_app_entry: |
1036 | |||
2382 | hidnplayr | 1037 | call init_heap |
1220 | serge | 1038 | stdcall user_alloc, 4096 |
1039 | |||
2382 | hidnplayr | 1040 | mov edx, [current_slot] |
1041 | mov [edx+APPDATA.tls_base], eax |
||
1042 | mov [tls_data_l+2], ax |
||
1043 | shr eax, 16 |
||
1044 | mov [tls_data_l+4], al |
||
1045 | mov [tls_data_l+7], ah |
||
1046 | mov dx, app_tls |
||
1047 | mov fs, dx |
||
1220 | serge | 1048 | popad |
1049 | iretd |
||
1050 | |||
1051 | |||
1074 | Galkov | 1052 | EFL_IF equ 0x0200 |
465 | serge | 1053 | EFL_IOPL1 equ 0x1000 |
1054 | EFL_IOPL2 equ 0x2000 |
||
1055 | EFL_IOPL3 equ 0x3000 |
||
1056 | |||
1057 | |||
237 | serge | 1058 | align 4 |
1059 | proc set_app_params stdcall,slot:dword, params:dword,\ |
||
1074 | Galkov | 1060 | cmd_line:dword, app_path:dword, flags:dword |
164 | serge | 1061 | |
1074 | Galkov | 1062 | locals |
1063 | pl0_stack dd ? |
||
1064 | endl |
||
237 | serge | 1065 | |
2382 | hidnplayr | 1066 | stdcall kernel_alloc, RING0_STACK_SIZE+512 |
1067 | mov [pl0_stack], eax |
||
357 | serge | 1068 | |
2382 | hidnplayr | 1069 | lea edi, [eax+RING0_STACK_SIZE] |
357 | serge | 1070 | |
2382 | hidnplayr | 1071 | mov eax, [slot] |
1072 | mov ebx, eax |
||
357 | serge | 1073 | |
2382 | hidnplayr | 1074 | shl eax, 8 |
1075 | mov [eax+SLOT_BASE+APPDATA.fpu_state], edi |
||
1076 | mov [eax+SLOT_BASE+APPDATA.exc_handler], 0 |
||
1077 | mov [eax+SLOT_BASE+APPDATA.except_mask], 0 |
||
3359 | hidnplayr | 1078 | mov [eax+SLOT_BASE+APPDATA.terminate_protection], 80000001h |
357 | serge | 1079 | |
465 | serge | 1080 | ;set default io permission map |
2382 | hidnplayr | 1081 | mov ecx, [SLOT_BASE+256+APPDATA.io_map] |
1082 | mov [eax+SLOT_BASE+APPDATA.io_map], ecx |
||
1083 | mov ecx, [SLOT_BASE+256+APPDATA.io_map+4] |
||
1084 | mov [eax+SLOT_BASE+APPDATA.io_map+4], ecx |
||
465 | serge | 1085 | |
2382 | hidnplayr | 1086 | mov esi, fpu_data |
1087 | mov ecx, 512/4 |
||
1088 | rep movsd |
||
237 | serge | 1089 | |
2382 | hidnplayr | 1090 | cmp ebx, [TASK_COUNT] |
1091 | jle .noinc |
||
1092 | inc dword [TASK_COUNT] ;update number of processes |
||
237 | serge | 1093 | .noinc: |
2382 | hidnplayr | 1094 | shl ebx, 8 |
1095 | lea edx, [ebx+SLOT_BASE+APP_EV_OFFSET] |
||
1096 | mov [SLOT_BASE+APPDATA.fd_ev+ebx], edx |
||
1097 | mov [SLOT_BASE+APPDATA.bk_ev+ebx], edx |
||
354 | serge | 1098 | |
2382 | hidnplayr | 1099 | add edx, APP_OBJ_OFFSET-APP_EV_OFFSET |
1100 | mov [SLOT_BASE+APPDATA.fd_obj+ebx], edx |
||
1101 | mov [SLOT_BASE+APPDATA.bk_obj+ebx], edx |
||
237 | serge | 1102 | |
2382 | hidnplayr | 1103 | mov ecx, [def_cursor] |
1104 | mov [SLOT_BASE+APPDATA.cursor+ebx], ecx |
||
1105 | mov eax, [pl0_stack] |
||
1106 | mov [SLOT_BASE+APPDATA.pl0_stack+ebx], eax |
||
1107 | add eax, RING0_STACK_SIZE |
||
1108 | mov [SLOT_BASE+APPDATA.saved_esp0+ebx], eax |
||
281 | serge | 1109 | |
2382 | hidnplayr | 1110 | push ebx |
1111 | stdcall kernel_alloc, 0x1000 |
||
1112 | pop ebx |
||
1113 | mov esi, [current_slot] |
||
1114 | mov esi, [esi+APPDATA.cur_dir] |
||
1115 | mov ecx, 0x1000/4 |
||
1116 | mov edi, eax |
||
1117 | mov [ebx+SLOT_BASE+APPDATA.cur_dir], eax |
||
1118 | rep movsd |
||
521 | diamond | 1119 | |
2382 | hidnplayr | 1120 | shr ebx, 3 |
1121 | mov eax, new_app_base |
||
1122 | mov dword [CURRENT_TASK+ebx+0x10], eax |
||
237 | serge | 1123 | |
1124 | .add_command_line: |
||
2382 | hidnplayr | 1125 | mov edx, [params] |
1126 | mov edx, [edx] ;app_cmdline |
||
1127 | test edx, edx |
||
1128 | jz @f ;application doesn't need parameters |
||
281 | serge | 1129 | |
2382 | hidnplayr | 1130 | mov eax, edx |
1131 | add eax, 256 |
||
1132 | jc @f |
||
281 | serge | 1133 | |
2382 | hidnplayr | 1134 | cmp eax, [SLOT_BASE+APPDATA.mem_size+ebx*8] |
1135 | ja @f |
||
281 | serge | 1136 | |
2382 | hidnplayr | 1137 | mov byte [edx], 0 ;force empty string if no cmdline given |
1138 | mov eax, [cmd_line] |
||
1139 | test eax, eax |
||
1140 | jz @f |
||
1141 | stdcall strncpy, edx, eax, 256 |
||
237 | serge | 1142 | @@: |
2382 | hidnplayr | 1143 | mov edx, [params] |
1144 | mov edx, [edx+4];app_path |
||
1145 | test edx, edx |
||
1146 | jz @F ;application don't need path of file |
||
1147 | mov eax, edx |
||
1148 | add eax, 1024 |
||
1149 | jc @f |
||
1150 | cmp eax, [SLOT_BASE+APPDATA.mem_size+ebx*8] |
||
1151 | ja @f |
||
1152 | stdcall strncpy, edx, [app_path], 1024 |
||
237 | serge | 1153 | @@: |
2382 | hidnplayr | 1154 | mov ebx, [slot] |
1155 | mov eax, ebx |
||
1156 | shl ebx, 5 |
||
1157 | lea ecx, [draw_data+ebx];ecx - pointer to draw data |
||
465 | serge | 1158 | |
2382 | hidnplayr | 1159 | mov edx, irq0.return |
1160 | cmp [ebx*8+SLOT_BASE+APPDATA.tls_base], -1 |
||
1161 | jne @F |
||
1162 | mov edx, tls_app_entry |
||
1220 | serge | 1163 | @@: |
237 | serge | 1164 | ; set window state to 'normal' (non-minimized/maximized/rolled-up) state |
2382 | hidnplayr | 1165 | mov [ebx+window_data+WDATA.fl_wstate], WSTATE_NORMAL |
1166 | mov [ebx+window_data+WDATA.fl_redraw], 1 |
||
1167 | add ebx, CURRENT_TASK ;ebx - pointer to information about process |
||
1168 | mov [ebx+TASKDATA.wnd_number], al;set window number on screen = process slot |
||
237 | serge | 1169 | |
2382 | hidnplayr | 1170 | mov [ebx+TASKDATA.event_mask], dword 1+2+4;set default event flags (see 40 function) |
237 | serge | 1171 | |
2382 | hidnplayr | 1172 | inc dword [process_number] |
1173 | mov eax, [process_number] |
||
1174 | mov [ebx+4], eax ;set PID |
||
237 | serge | 1175 | |
1176 | ;set draw data to full screen |
||
2382 | hidnplayr | 1177 | xor eax, eax |
1178 | mov [ecx+0], dword eax |
||
1179 | mov [ecx+4], dword eax |
||
1180 | mov eax, [Screen_Max_X] |
||
1181 | mov [ecx+8], eax |
||
1182 | mov eax, [Screen_Max_Y] |
||
1183 | mov [ecx+12], eax |
||
237 | serge | 1184 | |
2382 | hidnplayr | 1185 | mov ebx, [pl0_stack] |
1186 | mov esi, [params] |
||
1187 | lea ecx, [ebx+REG_EIP] |
||
1188 | xor eax, eax |
||
237 | serge | 1189 | |
2382 | hidnplayr | 1190 | mov [ebx+REG_RET], edx |
1191 | mov [ebx+REG_EDI], eax |
||
1192 | mov [ebx+REG_ESI], eax |
||
1193 | mov [ebx+REG_EBP], eax |
||
1194 | mov [ebx+REG_ESP], ecx;ebx+REG_EIP |
||
1195 | mov [ebx+REG_EBX], eax |
||
1196 | mov [ebx+REG_EDX], eax |
||
1197 | mov [ebx+REG_ECX], eax |
||
1198 | mov [ebx+REG_EAX], eax |
||
237 | serge | 1199 | |
2382 | hidnplayr | 1200 | mov eax, [esi+0x08] ;app_eip |
1201 | mov [ebx+REG_EIP], eax;app_entry |
||
1202 | mov [ebx+REG_CS], dword app_code |
||
3359 | hidnplayr | 1203 | mov eax, [CURRENT_TASK] |
1204 | shl eax, 8 ; created by kernel? |
||
1205 | cmp [SLOT_BASE+eax+APPDATA.dir_table], sys_pgdir - OS_BASE |
||
1206 | jnz @f |
||
1207 | cmp [app_path], 0 ; it is a thread? |
||
1208 | jnz @f |
||
1209 | mov [ebx+REG_CS], dword os_code ; kernel thread |
||
1210 | @@: |
||
2382 | hidnplayr | 1211 | mov [ebx+REG_EFLAGS], dword EFL_IOPL1+EFL_IF |
465 | serge | 1212 | |
2382 | hidnplayr | 1213 | mov eax, [esi+0x0C] ;app_esp |
1214 | mov [ebx+REG_APP_ESP], eax;app_stack |
||
1215 | mov [ebx+REG_SS], dword app_data |
||
237 | serge | 1216 | |
2382 | hidnplayr | 1217 | lea ecx, [ebx+REG_RET] |
1218 | mov ebx, [slot] |
||
1219 | shl ebx, 5 |
||
1220 | mov [ebx*8+SLOT_BASE+APPDATA.saved_esp], ecx |
||
237 | serge | 1221 | |
2382 | hidnplayr | 1222 | xor ecx, ecx; process state - running |
237 | serge | 1223 | ; set if debuggee |
2382 | hidnplayr | 1224 | test byte [flags], 1 |
1225 | jz .no_debug |
||
1226 | inc ecx ; process state - suspended |
||
1227 | mov eax, [CURRENT_TASK] |
||
1228 | mov [SLOT_BASE+ebx*8+APPDATA.debugger_slot], eax |
||
237 | serge | 1229 | .no_debug: |
2382 | hidnplayr | 1230 | mov [CURRENT_TASK+ebx+TASKDATA.state], cl |
1074 | Galkov | 1231 | ;mov esi,new_process_running |
1232 | ;call sys_msg_board_str ;output information about succefull startup |
||
2382 | hidnplayr | 1233 | ret |
237 | serge | 1234 | endp |
1235 | |||
2382 | hidnplayr | 1236 | |
1237 | align 4 |
||
1238 | |||
1239 | get_stack_base: |
||
1240 | mov eax, [current_slot] |
||
1241 | mov eax, [eax+APPDATA.pl0_stack] |
||
1242 | ret |
||
1243 | |||
1244 | |||
164 | serge | 1245 | include "debug.inc"256 |