Rev 139 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 139 | Rev 147 | ||
---|---|---|---|
Line 54... | Line 54... | ||
54 | cmp byte [0xe000], 1 |
54 | cmp byte [0xe000], 1 |
55 | jne @f |
55 | jne @f |
56 | sti |
56 | sti |
57 | @@:ret |
57 | @@:ret |
Line 58... | Line -... | ||
58 | - | ||
59 | new_start_application_floppy: |
- | |
60 | ;input: |
- | |
61 | ; eax - pointer to filename |
- | |
62 | ; ebx - parameters to pass |
- | |
63 | ; edx - flags |
- | |
64 | ;result: |
- | |
65 | ; eax - pid of new process |
- | |
66 | ; or 0 if call fails. |
- | |
67 | mov [appl_path],edi |
- | |
68 | pushad |
- | |
69 | mov esi,new_process_loading |
- | |
70 | call sys_msg_board_str ;write to debug board |
- | |
71 | - | ||
72 | ;wait application_table_status mutex |
- | |
73 | .table_status: |
- | |
74 | cli |
- | |
75 | cmp [application_table_status],0 |
- | |
76 | jz .stf |
- | |
77 | sti |
- | |
78 | call change_task |
- | |
79 | jmp .table_status |
- | |
80 | .stf: |
- | |
81 | call set_application_table_status |
- | |
82 | ;we can change system tables now |
- | |
83 | push edi |
- | |
84 | push ebx |
- | |
85 | push eax |
- | |
86 | call find_new_process_place ;find empty process slot |
- | |
87 | sti |
- | |
88 | test eax,eax |
- | |
89 | mov ecx, -0x20 ; too many processes |
- | |
90 | jz .failed |
- | |
91 | - | ||
92 | mov edi,eax |
- | |
93 | shl edi,8 |
- | |
94 | add edi,0x80000 |
- | |
95 | mov ecx,256/4 |
- | |
96 | xor eax,eax |
- | |
97 | cld |
- | |
98 | rep stosd ;clean extended information about process |
- | |
99 | - | ||
100 | ;set new process name |
- | |
101 | mov [appl_path_size],eax |
- | |
102 | pop eax |
- | |
103 | push eax |
- | |
104 | .find_last_byte: |
- | |
105 | cmp byte [eax],0 |
- | |
106 | jz .find_last_byte_end |
- | |
107 | inc eax |
- | |
108 | inc [appl_path_size] |
- | |
109 | jmp .find_last_byte |
- | |
110 | .find_last_byte_end: |
- | |
111 | add [appl_path_size],24 |
- | |
112 | sub eax,11 ;last 11 bytes = application name |
- | |
113 | ; mov eax,[esp] ;eax - pointer to file name |
- | |
114 | mov ebx,[new_process_place] |
- | |
115 | shl ebx,8 |
- | |
116 | add ebx,0x80000 + APPDATA.app_name |
- | |
117 | mov ecx,11 |
- | |
118 | call memmove |
- | |
119 | - | ||
120 | ;read header of file |
- | |
121 | mov eax,[esp] |
- | |
122 | mov ebx,1 ;index of first block |
- | |
123 | mov ecx,2 ;number of blocks |
- | |
124 | mov edx,0x90000 ;temp area |
- | |
125 | mov esi,12 ;file name length |
- | |
126 | mov edi,[esp+8] |
- | |
127 | ; cli |
- | |
128 | call floppy_fileread ;read file from FD |
- | |
129 | ; sti |
- | |
130 | mov ecx, eax |
- | |
131 | neg ecx |
- | |
132 | jnz .cleanfailed |
- | |
133 | ;check MENUET signature |
- | |
134 | mov ecx, -0x1F ; not Menuet/Kolibri executable |
- | |
135 | cmp [0x90000],dword 'MENU' |
- | |
136 | jnz .cleanfailed |
- | |
137 | cmp [0x90004],word 'ET' |
- | |
138 | jnz .cleanfailed |
- | |
139 | - | ||
140 | call get_app_params ;parse header fields |
- | |
141 | jc .cleanfailed |
- | |
142 | - | ||
143 | mov eax,[new_process_place] |
- | |
144 | inc ecx ; -0x1E = no memory |
- | |
145 | call create_app_cr3_table ;create page directory for new process |
- | |
146 | test eax,eax |
- | |
147 | jz .cleanfailed_mem |
- | |
148 | - | ||
149 | call MEM_Get_Linear_Address ;calculate linear address of it |
- | |
150 | - | ||
151 | mov ebx,std_application_base_address |
- | |
152 | mov ecx,[app_mem] |
- | |
153 | add ecx,4095 |
- | |
154 | shr ecx,12 |
- | |
155 | mov edx,eax |
- | |
156 | call mem_alloc_specified_region ;allocate memory for application |
- | |
157 | test eax,eax |
- | |
158 | mov ecx, -0x1E |
- | |
159 | jz .cleanfailed_mem1 |
- | |
160 | - | ||
161 | mov eax,[edx+(std_application_base_address shr 20)] |
- | |
162 | and eax,not (4096-1) ;eax - physical address of first (for application memory) page table |
- | |
163 | call MEM_Get_Linear_Address |
- | |
164 | mov edx,eax |
- | |
165 | - | ||
166 | ;read file |
- | |
167 | mov ebx,1 |
- | |
168 | mov esi,12 ;length of file name |
- | |
169 | .loop1: |
- | |
170 | ;edx = linear address of current page table entry |
- | |
171 | ;ebx = index of current block in file |
- | |
172 | push edx |
- | |
173 | mov eax,[edx] |
- | |
174 | and eax,not (4096-1) |
- | |
175 | call MEM_Get_Linear_Address |
- | |
176 | mov edx,eax ;read file block to current page |
- | |
177 | mov eax,[esp+4] ;restore pointer to file name |
- | |
178 | mov ecx,8 ;number of blocks read |
- | |
179 | mov ebp,edx ;save buffer address for .endofimage |
- | |
180 | push ebx |
- | |
181 | mov edi,[esp+16] |
- | |
182 | ; cli |
- | |
183 | call floppy_fileread |
- | |
184 | ;ebx=file size |
- | |
185 | ; sti |
- | |
186 | pop ecx |
- | |
187 | add ecx,8 |
- | |
188 | test eax,eax |
- | |
189 | jnz .endloop1 ;check io errors |
- | |
190 | mov eax,[app_i_end] |
- | |
191 | add eax,511 |
- | |
192 | shr eax,9 |
- | |
193 | cmp ecx,eax |
- | |
194 | jg .endofimage ;we have loaded whole program |
- | |
195 | add ebx,511 |
- | |
196 | shr ebx,9 |
- | |
197 | cmp ecx,ebx |
- | |
198 | jg .endloop1 ;if end of file? |
- | |
199 | mov ebx,ecx |
- | |
200 | pop edx |
- | |
201 | add edx,4 |
- | |
202 | jmp .loop1 |
- | |
203 | - | ||
204 | .endofimage: ;set to zero memory at end of page |
- | |
205 | mov ecx,[app_i_end] |
- | |
206 | and ecx,4096-1 |
- | |
207 | jz .endloop1 |
- | |
208 | lea edi,[ebp+ecx] |
- | |
209 | neg ecx |
- | |
210 | add ecx,4096 |
- | |
211 | xor eax,eax |
- | |
212 | cld |
- | |
213 | rep stosb |
- | |
214 | .endloop1: |
- | |
215 | add esp,8+4 ;pop linear address of page table entry and pointer to file name |
- | |
216 | call new_start_application_fl.add_app_parameters |
- | |
217 | mov [esp+28],eax |
- | |
218 | popad |
- | |
219 | ret |
- | |
220 | - | ||
221 | .cleanfailed_mem1: |
- | |
222 | ;there is mem for directory entry, but there is no mem for pages |
- | |
223 | ;so free directory entry |
- | |
224 | mov eax,[new_process_place] |
- | |
225 | shl eax,8 |
- | |
226 | mov eax,[0x80000+eax+APPDATA.dir_table] |
- | |
227 | call MEM_Free_Page |
- | |
228 | .cleanfailed_mem: |
- | |
229 | ;there is no mem for directory entry, display message. |
- | |
230 | mov esi,start_not_enough_memory |
- | |
231 | call sys_msg_board_str |
- | |
232 | .cleanfailed: ;clean process name |
- | |
233 | push ecx ; save error code |
- | |
234 | ;can't read file, clean process name. |
- | |
235 | ;this avoid problems with panel application. |
- | |
236 | mov edi,[new_process_place] |
- | |
237 | shl edi,8 |
- | |
238 | add edi,0x80000 + APPDATA.app_name |
- | |
239 | mov ecx,11 |
- | |
240 | mov eax,' ' |
- | |
241 | cld |
- | |
242 | rep stosb |
- | |
243 | pop eax |
- | |
244 | .failed: |
- | |
245 | ;no more slots |
- | |
246 | add esp,8+4 |
- | |
247 | mov [application_table_status],0 |
- | |
248 | mov [esp+1Ch], eax |
- | |
249 | popad |
- | |
250 | sti |
- | |
251 | ret |
- | |
252 | - | ||
253 | ;----------------------------------------------------------------------------- |
- | |
254 | new_start_application_fl: |
- | |
255 | ;input: |
- | |
256 | ; eax - pointer to filename |
- | |
257 | ; ebx - parameters to pass |
- | |
258 | ; edx - flags |
- | |
259 | ;result: |
- | |
260 | ; eax - pid of new process |
- | |
261 | ; or 0 if call fails. |
- | |
262 | mov [appl_path],edi |
- | |
263 | mov [appl_path_size],36 |
- | |
264 | pushad |
- | |
265 | mov esi,new_process_loading |
- | |
266 | call sys_msg_board_str ;write to debug board |
- | |
267 | - | ||
268 | ;wait application_table_status mutex |
- | |
269 | .table_status: |
- | |
270 | cli |
- | |
271 | cmp [application_table_status],0 |
- | |
272 | jz .stf |
- | |
273 | sti |
- | |
274 | call change_task |
- | |
275 | jmp .table_status |
- | |
276 | .stf: |
- | |
277 | call set_application_table_status |
- | |
278 | ;we can change system tables now |
- | |
279 | push ebx |
- | |
280 | push eax |
- | |
281 | call find_new_process_place ;find empty process slot |
- | |
282 | call safe_sti |
- | |
283 | test eax,eax |
- | |
284 | mov ecx, -0x20 ; too many processes |
- | |
285 | jz .failed |
- | |
286 | - | ||
287 | mov edi,eax |
- | |
288 | shl edi,8 |
- | |
289 | add edi,0x80000 |
- | |
290 | mov ecx,256/4 |
- | |
291 | xor eax,eax |
- | |
292 | cld |
- | |
293 | rep stosd ;clean extended information about process |
- | |
294 | - | ||
295 | ;set new process name |
- | |
296 | mov eax,[esp] ;eax - pointer to file name |
- | |
297 | mov ebx,[new_process_place] |
- | |
298 | shl ebx,8 |
- | |
299 | add ebx,0x80000 + APPDATA.app_name |
- | |
300 | mov ecx,11 |
- | |
301 | call memmove |
- | |
302 | - | ||
303 | ;read header of file |
- | |
304 | mov ebx,1 ;index of first block |
- | |
305 | mov ecx,2 ;number of blocks |
- | |
306 | mov edx,0x90000 ;temp area |
- | |
307 | mov esi,12 ;file name length |
- | |
308 | cli |
- | |
309 | call fileread ;read file from RD |
- | |
310 | call safe_sti |
- | |
311 | mov ecx, eax |
- | |
312 | neg ecx |
- | |
313 | jnz .cleanfailed |
- | |
314 | ;check MENUET signature |
- | |
315 | mov ecx, -0x1F ; not Menuet/Kolibri executable |
- | |
316 | cmp [0x90000],dword 'MENU' |
- | |
317 | jnz .cleanfailed |
- | |
318 | cmp [0x90004],word 'ET' |
- | |
319 | jnz .cleanfailed |
- | |
320 | - | ||
321 | call get_app_params ;parse header fields |
- | |
322 | jc .cleanfailed |
- | |
323 | - | ||
324 | mov eax,[new_process_place] |
- | |
325 | inc ecx ; -0x1E = no memory |
- | |
326 | call create_app_cr3_table ;create page directory for new process |
- | |
327 | test eax,eax |
- | |
328 | jz .cleanfailed_mem |
- | |
329 | - | ||
330 | call MEM_Get_Linear_Address ;calculate linear address of it |
- | |
331 | - | ||
332 | mov ebx,std_application_base_address |
- | |
333 | mov ecx,[app_mem] |
- | |
334 | add ecx,4095 |
- | |
335 | shr ecx,12 |
- | |
336 | mov edx,eax |
- | |
337 | call mem_alloc_specified_region ;allocate memory for application |
- | |
338 | test eax,eax |
- | |
339 | mov ecx, -0x1E |
- | |
340 | jz .cleanfailed_mem1 |
- | |
341 | - | ||
342 | mov eax,[edx+(std_application_base_address shr 20)] |
- | |
343 | and eax,not (4096-1) ;eax - physical address of first (for application memory) page table |
- | |
344 | call MEM_Get_Linear_Address |
- | |
345 | mov edx,eax |
- | |
346 | - | ||
347 | ;read file |
- | |
348 | mov ebx,1 |
- | |
349 | mov esi,12 ;length of file name |
- | |
350 | .loop1: |
- | |
351 | ;edx = linear address of current page table entry |
- | |
352 | ;ebx = index of current block in file |
- | |
353 | push edx |
- | |
354 | mov eax,[edx] |
- | |
355 | and eax,not (4096-1) |
- | |
356 | call MEM_Get_Linear_Address |
- | |
357 | mov edx,eax ;read file block to current page |
- | |
358 | mov eax,[esp+4] ;restore pointer to file name |
- | |
359 | mov ecx,8 ;number of blocks read |
- | |
360 | mov ebp,edx ;save buffer address for .endofimage |
- | |
361 | push ebx |
- | |
362 | cli |
- | |
363 | call fileread |
- | |
364 | ;ebx=file size |
- | |
365 | call safe_sti |
- | |
366 | pop ecx |
- | |
367 | add ecx,8 |
- | |
368 | test eax,eax |
- | |
369 | jnz .endloop1 ;check io errors |
- | |
370 | mov eax,[app_i_end] |
- | |
371 | add eax,511 |
- | |
372 | shr eax,9 |
- | |
373 | cmp ecx,eax |
- | |
374 | jg .endofimage ;we have loaded whole program |
- | |
375 | add ebx,511 |
- | |
376 | shr ebx,9 |
- | |
377 | cmp ecx,ebx |
- | |
378 | jg .endloop1 ;if end of file? |
- | |
379 | mov ebx,ecx |
- | |
380 | pop edx |
- | |
381 | add edx,4 |
- | |
382 | jmp .loop1 |
- | |
383 | - | ||
384 | .endofimage: ;set to zero memory at end of page |
- | |
385 | mov ecx,[app_i_end] |
- | |
386 | and ecx,4096-1 |
- | |
387 | jz .endloop1 |
- | |
388 | lea edi,[ebp+ecx] |
- | |
389 | neg ecx |
- | |
390 | add ecx,4096 |
- | |
391 | xor eax,eax |
- | |
392 | cld |
- | |
393 | rep stosb |
- | |
394 | .endloop1: |
- | |
395 | add esp,8 ;pop linear address of page table entry and pointer to file name |
- | |
396 | call .add_app_parameters |
- | |
397 | mov [esp+28],eax |
- | |
398 | popad |
- | |
399 | ret |
- | |
400 | - | ||
401 | .cleanfailed_mem1: |
- | |
402 | ;there is mem for directory entry, but there is no mem for pages |
- | |
403 | ;so free directory entry |
- | |
404 | mov eax,[new_process_place] |
- | |
405 | shl eax,8 |
- | |
406 | mov eax,[0x80000+eax+APPDATA.dir_table] |
- | |
407 | call MEM_Free_Page |
- | |
408 | .cleanfailed_mem: |
- | |
409 | ;there is no mem for directory entry, display message. |
- | |
410 | mov esi,start_not_enough_memory |
- | |
411 | call sys_msg_board_str |
- | |
412 | .cleanfailed: ;clean process name |
- | |
413 | push ecx ; save error code |
- | |
414 | ;can't read file, clean process name. |
- | |
415 | ;this avoid problems with panel application. |
- | |
416 | mov edi,[new_process_place] |
- | |
417 | shl edi,8 |
- | |
418 | add edi,0x80000+APPDATA.app_name |
- | |
419 | mov ecx,11 |
- | |
420 | mov eax,' ' |
- | |
421 | cld |
- | |
422 | rep stosb |
- | |
423 | pop eax |
- | |
424 | .failed: |
- | |
425 | ;no more slots |
- | |
426 | add esp,8 |
- | |
427 | mov [application_table_status],0 |
- | |
428 | mov [esp+1Ch], eax |
- | |
429 | popad |
- | |
430 | call safe_sti |
- | |
431 | ret |
- | |
432 | - | ||
433 | .add_app_parameters: |
- | |
434 | ;input: |
- | |
435 | ; [esp] - pointer to parameters |
- | |
436 | ; [esp+4]-[esp+36] pushad registers. |
- | |
437 | ;result |
- | |
438 | ; eax - pid of new process |
- | |
439 | ; or zero if failed |
- | |
440 | cli |
- | |
441 | mov ebx,[new_process_place] |
- | |
442 | cmp ebx,[0x3004] |
- | |
443 | jle .noinc |
- | |
444 | inc dword [0x3004] ;update number of processes |
- | |
445 | .noinc: |
- | |
446 | - | ||
447 | ; mov ebx,[new_process_place] |
- | |
448 | ;set 0x8c field of extended information about process |
- | |
449 | ;(size of application memory) |
- | |
450 | shl ebx,8 |
- | |
451 | mov eax,[app_mem] |
- | |
452 | mov [second_base_address+0x80000+APPDATA.mem_size+ebx],eax |
- | |
453 | ;set 0x10 field of information about process |
- | |
454 | ;(application base address) |
- | |
455 | ; mov ebx,[new_process_place] |
- | |
456 | ; shl ebx,5 |
- | |
457 | shr ebx,3 |
- | |
458 | mov dword [second_base_address+0x3000+ebx+TASKDATA.mem_start],std_application_base_address |
- | |
459 | - | ||
460 | ;add command line parameters |
- | |
461 | .add_command_line: |
- | |
462 | mov edx,[app_i_param] |
- | |
463 | test edx,edx |
- | |
464 | jz .no_command_line ;application don't need parameters |
- | |
465 | mov eax,[esp+4] |
- | |
466 | test eax,eax |
- | |
467 | jz .no_command_line ;no parameters specified |
- | |
468 | ;calculate parameter length |
- | |
469 | mov esi,eax |
- | |
470 | xor ecx,ecx |
- | |
471 | inc ecx ; include terminating null |
- | |
472 | .command_line_len: |
- | |
473 | cmp byte [esi],0 |
- | |
474 | jz .command_line_len_end |
- | |
475 | inc esi |
- | |
476 | inc ecx |
- | |
477 | cmp ecx,256 |
- | |
478 | jl .command_line_len |
- | |
479 | - | ||
480 | .command_line_len_end: |
- | |
481 | ;ecx - parameter length |
- | |
482 | ;edx - address of parameters in new process address space |
- | |
483 | mov ebx,eax ;ebx - address of parameters in our address space |
- | |
484 | mov eax,[new_process_place] |
- | |
485 | call write_process_memory ;copy parameters to new process address space |
- | |
486 | - | ||
487 | .no_command_line: |
- | |
488 | ;****************************************************************** |
- | |
489 | mov edx,[app_i_icon] |
- | |
490 | test edx,edx |
- | |
491 | jz .no_command_line_1 ;application don't need path of file |
- | |
492 | mov ebx,[appl_path] |
- | |
493 | mov ecx,[appl_path_size] |
- | |
494 | mov eax,[new_process_place] |
- | |
495 | call write_process_memory ;copy path of file to new process address space |
- | |
496 | .no_command_line_1: |
- | |
497 | ;****************************************************************** |
- | |
498 | mov ebx,[new_process_place] |
- | |
499 | mov eax,ebx |
- | |
500 | shl ebx,5 |
- | |
501 | add ebx,0x3000 ;ebx - pointer to information about process |
- | |
502 | mov [ebx+TASKDATA.wnd_number],al ;set window number on screen = process slot |
- | |
503 | - | ||
504 | mov [ebx+TASKDATA.event_mask],dword 1+2+4 ;set default event flags (see 40 function) |
- | |
505 | - | ||
506 | inc dword [process_number] |
- | |
507 | mov eax,[process_number] |
- | |
508 | mov [ebx+TASKDATA.pid],eax ;set PID |
- | |
509 | - | ||
510 | mov ecx,ebx |
- | |
511 | add ecx,draw_data-0x3000 ;ecx - pointer to draw data |
- | |
512 | ;set draw data to full screen |
- | |
513 | mov [ecx+RECT.left],dword 0 |
- | |
514 | mov [ecx+RECT.top],dword 0 |
- | |
515 | mov eax,[0xfe00] |
- | |
516 | mov [ecx+RECT.right],eax |
- | |
517 | mov eax,[0xfe04] |
- | |
518 | mov [ecx+RECT.bottom],eax |
- | |
519 | ;set window state to 'normal' (non-minimized/maximized/rolled-up) state |
- | |
520 | mov [ecx+WDATA.fl_wstate],WSTATE_NORMAL |
- | |
521 | ;set cr3 register in TSS of application |
- | |
522 | mov ecx,[new_process_place] |
- | |
523 | shl ecx,8 |
- | |
524 | mov eax,[0x80000+APPDATA.dir_table+ecx] |
- | |
525 | add eax,8+16 ;add flags |
- | |
526 | mov [l.cr3],eax |
- | |
527 | - | ||
528 | mov eax,[app_start] |
- | |
529 | mov [l.eip],eax ;set eip in TSS |
- | |
530 | mov eax,[app_esp] |
- | |
531 | mov [l.esp],eax ;set stack in TSS |
- | |
532 | - | ||
533 | ;gdt |
- | |
534 | ;mov ebx,[new_process_place] |
- | |
535 | ;shl ebx,3 |
- | |
536 | mov ax,app_code ;ax - selector of code segment |
- | |
537 | ;add ax,bx |
- | |
538 | mov [l.cs],ax |
- | |
539 | mov ax,app_data |
- | |
540 | ;add ax,bx ;ax - selector of data segment |
- | |
541 | mov [l.ss],ax |
- | |
542 | mov [l.ds],ax |
- | |
543 | mov [l.es],ax |
- | |
544 | mov [l.fs],ax |
- | |
545 | mov ax,graph_data ;ax - selector of graphic segment |
- | |
546 | mov [l.gs],ax |
- | |
547 | mov [l.io],word 128 |
- | |
548 | mov [l.eflags],dword 0x11202 |
- | |
549 | mov [l.ss0],os_data |
- | |
550 | mov ebx,[new_process_place] |
- | |
551 | shl ebx,12 |
- | |
552 | add ebx,sysint_stack_data+4096 |
- | |
553 | mov [l.esp0],ebx |
- | |
554 | - | ||
555 | ;copy tss to it place |
- | |
556 | mov eax,tss_sceleton |
- | |
557 | mov ebx,[new_process_place] |
- | |
558 | imul ebx,tss_step |
- | |
559 | add ebx,tss_data ;ebx - address of application TSS |
- | |
560 | mov ecx,120 |
- | |
561 | call memmove |
- | |
562 | - | ||
563 | ;Add IO access table - bit array of permitted ports |
- | |
564 | or eax,-1 |
- | |
565 | mov edi,[new_process_place] |
- | |
566 | imul edi,tss_step |
- | |
567 | add edi,tss_data+128 |
- | |
568 | mov ecx,2048 |
- | |
569 | cld |
- | |
570 | rep stosd ;full access to 2048*8=16384 ports |
- | |
571 | - | ||
572 | mov ecx,ebx ;ecx - address of application TSS |
- | |
573 | mov edi,[new_process_place] |
- | |
574 | shl edi,3 |
- | |
575 | ;set TSS descriptor |
- | |
576 | mov [edi+gdts+tss0+0],word tss_step ;limit (size) |
- | |
577 | mov [edi+gdts+tss0+2],cx ;part of offset |
- | |
578 | mov eax,ecx |
- | |
579 | shr eax,16 |
- | |
580 | mov [edi+gdts+tss0+4],al ;part of offset |
- | |
581 | mov [edi+gdts+tss0+7],ah ;part of offset |
- | |
582 | mov [edi+gdts+tss0+5],word 01010000b*256+11101001b ;system flags |
- | |
583 | - | ||
584 | - | ||
585 | ;flush keyboard and buttons queue |
- | |
586 | mov [0xf400],byte 0 |
- | |
587 | mov [0xf500],byte 0 |
- | |
588 | - | ||
589 | mov edi,[new_process_place] |
- | |
590 | shl edi,5 |
- | |
591 | add edi,window_data |
- | |
592 | mov ebx,[new_process_place] |
- | |
593 | movzx esi,word [0xC000+ebx*2] |
- | |
594 | lea esi,[0xC400+esi*2] |
- | |
595 | call windowactivate ;gui initialization |
- | |
596 | - | ||
597 | mov ebx,[new_process_place] |
- | |
598 | shl ebx,5 |
- | |
599 | ; set if debuggee |
- | |
600 | test byte [esp+28], 1 |
- | |
601 | jz .no_debug |
- | |
602 | mov [0x3000+ebx+TASKDATA.state], 1 ; set process state - suspended |
- | |
603 | mov eax, [0x3000] |
- | |
604 | mov [0x80000+ebx*8+APPDATA.debugger_slot], eax ;set debugger PID - current |
- | |
605 | jmp .debug |
- | |
606 | .no_debug: |
- | |
607 | mov [0x3000+ebx+TASKDATA.state], 0 ; set process state - running |
- | |
608 | .debug: |
- | |
609 | - | ||
610 | mov esi,new_process_running |
- | |
611 | call sys_msg_board_str ;output information about succefull startup |
- | |
612 | - | ||
613 | ; add esp,4 ;pop pointer to parameters |
- | |
614 | ; popad |
- | |
615 | mov eax,[process_number] ;set result |
- | |
616 | mov [application_table_status],0 ;unlock application_table_status mutex |
- | |
617 | call safe_sti |
- | |
618 | ret 4 |
58 | |
619 | ;----------------------------------------------------------------------------- |
59 | ;----------------------------------------------------------------------------- |
620 | new_sys_threads: |
60 | new_sys_threads: |
621 | ;eax=1 - create thread |
61 | ;eax=1 - create thread |
622 | ; ebx=thread start |
62 | ; ebx=thread start |
Line 674... | Line 114... | ||
674 | ; mov eax,[new_process_place] |
114 | ; mov eax,[new_process_place] |
675 | ; mov ebx,[0x3000] |
115 | ; mov ebx,[0x3000] |
676 | ; call addreference_app_cr3_table |
116 | ; call addreference_app_cr3_table |
Line 677... | Line 117... | ||
677 | 117 | ||
678 | push 0 ;no parameters |
118 | push 0 ;no parameters |
679 | call new_start_application_fl.add_app_parameters ;start thread |
119 | call fs_execute.add_app_parameters ;start thread |
680 | mov [esp+28],eax |
120 | mov [esp+28],eax |
681 | popad |
121 | popad |
Line 682... | Line 122... | ||
682 | ret |
122 | ret |
Line 1220... | Line 660... | ||
1220 | ;Output |
660 | ;Output |
1221 | ; eax - linear address for kernel |
661 | ; eax - linear address for kernel |
1222 | add eax,std_application_base_address |
662 | add eax,std_application_base_address |
1223 | ret |
663 | ret |
1224 | ;----------------------------------------------------------------------------- |
664 | ;----------------------------------------------------------------------------- |
1225 | new_start_application_hd: |
- | |
1226 | ;eax - file name (kernel address) |
- | |
1227 | ;ebx - file name length |
- | |
1228 | ;ecx - work area (kernel address) |
- | |
1229 | ;edx - flags |
- | |
1230 | ;ebp - parameters |
- | |
1231 | mov [appl_path],edi |
- | |
1232 | pushad |
- | |
1233 | - | ||
1234 | mov esi,new_process_loading |
- | |
1235 | call sys_msg_board_str ;write message to message board |
- | |
1236 | - | ||
1237 | ;lock application_table_status mutex |
- | |
1238 | .table_status: |
- | |
1239 | cli |
- | |
1240 | cmp [application_table_status],0 |
- | |
1241 | jz .stf |
- | |
1242 | sti |
- | |
1243 | call change_task |
- | |
1244 | jmp .table_status |
- | |
1245 | .stf: |
- | |
1246 | call set_application_table_status |
- | |
1247 | - | ||
1248 | push ebp |
- | |
1249 | push ebx |
- | |
1250 | push eax |
- | |
1251 | push ecx |
- | |
1252 | call find_new_process_place ;find new process slot |
- | |
1253 | sti |
- | |
1254 | test eax,eax |
- | |
1255 | mov ecx, -0x20 ; too many processes |
- | |
1256 | jz .failed |
- | |
1257 | - | ||
1258 | ;write application name |
- | |
1259 | xor eax,eax |
- | |
1260 | mov [appl_path_size],eax |
- | |
1261 | mov eax,[esp+4] |
- | |
1262 | .find_last_byte: |
- | |
1263 | cmp byte [eax],0 |
- | |
1264 | jz .find_last_byte_end |
- | |
1265 | inc eax |
- | |
1266 | inc [appl_path_size] |
- | |
1267 | jmp .find_last_byte |
- | |
1268 | .find_last_byte_end: |
- | |
1269 | add [appl_path_size],24 |
- | |
1270 | lea esi,[eax-11] ;last 11 bytes = application name |
- | |
1271 | mov edi,[new_process_place] |
- | |
1272 | shl edi,8 |
- | |
1273 | add edi,0x80000+APPDATA.app_name |
- | |
1274 | mov ecx,11 |
- | |
1275 | cld |
- | |
1276 | rep movsb ;copy name to extended information about process |
- | |
1277 | - | ||
1278 | ;read header |
- | |
1279 | mov eax,[esp+4] ;file name |
- | |
1280 | mov esi,[esp] ;work area |
- | |
1281 | mov ecx,1 ;read from first block |
- | |
1282 | mov edx,1 ;read 1 block |
- | |
1283 | call read_hd_file |
- | |
1284 | mov ecx, eax |
- | |
1285 | neg ecx |
- | |
1286 | jnz .cleanfailed |
- | |
1287 | - | ||
1288 | pop esi |
- | |
1289 | push esi |
- | |
1290 | ;check menuet signature |
- | |
1291 | mov ecx, -0x1F ; not Menuet/Kolibri executable |
- | |
1292 | cmp [esi+1024+0],dword 'MENU' ;read_hd_file function write file to +1024 offset |
- | |
1293 | jnz .cleanfailed |
- | |
1294 | cmp [esi+1024+4],word 'ET' |
- | |
1295 | jnz .cleanfailed |
- | |
1296 | add esi,1024 |
- | |
1297 | mov edi,0x90000 |
- | |
1298 | mov ecx,512/4 |
- | |
1299 | cld |
- | |
1300 | rep movsd ;copy first block to 0x90000 address for get_app_params function |
- | |
1301 | call get_app_params |
- | |
1302 | mov ecx, -0x1F ; not Menuet/Kolibri executable |
- | |
1303 | jc .cleanfailed |
- | |
1304 | - | ||
1305 | mov eax,[new_process_place] |
- | |
1306 | inc ecx ; -0x1E = no memory |
- | |
1307 | call create_app_cr3_table ;create page directory |
- | |
1308 | test eax,eax |
- | |
1309 | jz .cleanfailed_mem |
- | |
1310 | - | ||
1311 | call MEM_Get_Linear_Address |
- | |
1312 | - | ||
1313 | mov ebx,std_application_base_address |
- | |
1314 | mov ecx,[app_mem] |
- | |
1315 | add ecx,4096-1 |
- | |
1316 | shr ecx,12 |
- | |
1317 | mov edx,eax ;edx - linear address of page directory |
- | |
1318 | call mem_alloc_specified_region ;allocate memory for application |
- | |
1319 | mov ecx, -0x1E ; no memory |
- | |
1320 | test eax,eax |
- | |
1321 | jz .cleanfailed_mem1 |
- | |
1322 | - | ||
1323 | add edx,(std_application_base_address shr 20) |
- | |
1324 | mov eax,[edx] |
- | |
1325 | and eax,not (4096-1) |
- | |
1326 | call MEM_Get_Linear_Address |
- | |
1327 | push edx ;save pointer to first page table |
- | |
1328 | mov edx,eax |
- | |
1329 | ;read file |
- | |
1330 | mov ecx,1 |
- | |
1331 | xor ebp,ebp |
- | |
1332 | .loop1: |
- | |
1333 | ;[esp] - pointer to current page directory entry |
- | |
1334 | ;edx - pointer to current page table |
- | |
1335 | ;ebp - offset in page |
- | |
1336 | ;ecx - current cluster |
- | |
1337 | push edx |
- | |
1338 | mov eax,[esp+12] ;file name |
- | |
1339 | mov ebx,[esp+16] ;file name length |
- | |
1340 | mov esi,[esp+8] ;work area |
- | |
1341 | mov edx,1 ;number of blocks to read |
- | |
1342 | push ecx |
- | |
1343 | push ebp |
- | |
1344 | cli |
- | |
1345 | call read_hd_file |
- | |
1346 | sti |
- | |
1347 | pop ebp |
- | |
1348 | test eax,eax |
- | |
1349 | jnz .endloop1 ;check io errors |
- | |
1350 | - | ||
1351 | mov esi,[esp+8+4] ;work area |
- | |
1352 | add esi,1024 |
- | |
1353 | mov eax,[esp+4] ;current page table |
- | |
1354 | mov eax,[eax] |
- | |
1355 | and eax,not (4096-1) |
- | |
1356 | call MEM_Get_Linear_Address;calculate linear page address |
- | |
1357 | lea edi,[eax+ebp] ;add page offset |
- | |
1358 | mov ecx,512/4 |
- | |
1359 | cld |
- | |
1360 | rep movsd ;copy data |
- | |
1361 | - | ||
1362 | pop ecx |
- | |
1363 | inc ecx ;next block |
- | |
1364 | mov eax,[app_i_end] ;todo: precalculate ([app_i_end]+4095)/4096 |
- | |
1365 | add eax,512-1 |
- | |
1366 | shr eax,9 ;calculate application image size |
- | |
1367 | cmp ecx,eax |
- | |
1368 | jg .endloop11 |
- | |
1369 | pop edx |
- | |
1370 | add ebp,512 ;new offset |
- | |
1371 | test ebp,4096 |
- | |
1372 | jz .loop1 |
- | |
1373 | xor ebp,ebp |
- | |
1374 | add edx,4 ;go to next page |
- | |
1375 | test edx,(4096-1) |
- | |
1376 | jnz .loop1 |
- | |
1377 | add dword [esp],4 ;go to next directory entry |
- | |
1378 | mov eax,[esp] |
- | |
1379 | mov eax,[eax] |
- | |
1380 | and eax,not (4096-1) |
- | |
1381 | call MEM_Get_Linear_Address |
- | |
1382 | mov edx,eax |
- | |
1383 | jmp .loop1 |
- | |
1384 | .endloop1: |
- | |
1385 | add esp,4 ;pop ecx |
- | |
1386 | .endloop11: |
- | |
1387 | add esp,4+4 ;pop edx, pop edx |
- | |
1388 | - | ||
1389 | ;add_app_parameters |
- | |
1390 | add esp,12 ;now pointer to parameters is on the top of the stack |
- | |
1391 | call new_start_application_fl.add_app_parameters ;start process |
- | |
1392 | mov [esp+28],eax |
- | |
1393 | popad |
- | |
1394 | ret |
- | |
1395 | - | ||
1396 | .cleanfailed_mem1: |
- | |
1397 | ;there is mem for directory entry, but there is no mem for pages |
- | |
1398 | ;so free directory entry |
- | |
1399 | mov eax,[new_process_place] |
- | |
1400 | shl eax,8 |
- | |
1401 | mov eax,[0x80000+eax+APPDATA.dir_table] |
- | |
1402 | call MEM_Free_Page |
- | |
1403 | .cleanfailed_mem: |
- | |
1404 | ;there is no mem for directory entry, display message. |
- | |
1405 | mov esi,start_not_enough_memory |
- | |
1406 | call sys_msg_board_str |
- | |
1407 | .cleanfailed: ;clean process name |
- | |
1408 | push ecx |
- | |
1409 | ;can't read file, clean process name. |
- | |
1410 | ;this avoid problems with panel application. |
- | |
1411 | mov edi,[new_process_place] |
- | |
1412 | shl edi,8 |
- | |
1413 | add edi,0x80000+APPDATA.app_name |
- | |
1414 | mov ecx,11 |
- | |
1415 | mov eax,' ' |
- | |
1416 | cld |
- | |
1417 | rep stosb |
- | |
1418 | pop eax |
- | |
1419 | .failed: |
- | |
1420 | ;no more slots |
- | |
1421 | add esp,16 |
- | |
1422 | mov [esp+1Ch], eax |
- | |
1423 | popad |
- | |
1424 | mov [application_table_status],0 |
- | |
1425 | sti |
- | |
1426 | ret |
- | |
1427 | end if |
- | |
Line 1428... | Line 665... | ||
1428 | 665 | ||
1429 | ; \begin{diamond} |
666 | ; \begin{diamond} |
Line 1430... | Line 667... | ||
1430 | include 'debug.inc' |
667 | include 'debug.inc' |
Line 1606... | Line 843... | ||
1606 | jmp .loop1 |
843 | jmp .loop1 |
1607 | .endloop1: |
844 | .endloop1: |
1608 | pop edx |
845 | pop edx |
1609 | cmp eax, 6 |
846 | cmp eax, 6 |
1610 | jnz .cleanfailed_mem2 |
847 | jnz .cleanfailed_mem2 |
1611 | call new_start_application_fl.add_app_parameters |
848 | call .add_app_parameters |
1612 | mov [esp+28], eax |
849 | mov [esp+28], eax |
1613 | popad |
850 | popad |
1614 | ret |
851 | ret |
Line 1615... | Line 852... | ||
1615 | 852 | ||
Line 1647... | Line 884... | ||
1647 | popad |
884 | popad |
1648 | mov [application_table_status], 0 |
885 | mov [application_table_status], 0 |
1649 | call safe_sti |
886 | call safe_sti |
1650 | ret |
887 | ret |
1651 | ; \end{diamond}0>>-->-->-->-->256 |
888 | ; \end{diamond} |
- | 889 | .add_app_parameters: |
|
- | 890 | ;input: |
|
- | 891 | ; [esp] - pointer to parameters |
|
- | 892 | ; [esp+4]-[esp+36] pushad registers. |
|
- | 893 | ;result |
|
- | 894 | ; eax - pid of new process |
|
- | 895 | ; or zero if failed |
|
- | 896 | cli |
|
- | 897 | mov ebx,[new_process_place] |
|
- | 898 | cmp ebx,[0x3004] |
|
- | 899 | jle .noinc |
|
- | 900 | inc dword [0x3004] ;update number of processes |
|
- | 901 | .noinc: |
|
- | 902 | ||
- | 903 | ; mov ebx,[new_process_place] |
|
- | 904 | ;set 0x8c field of extended information about process |
|
- | 905 | ;(size of application memory) |
|
- | 906 | shl ebx,8 |
|
- | 907 | mov eax,[app_mem] |
|
- | 908 | mov [second_base_address+0x80000+APPDATA.mem_size+ebx],eax |
|
- | 909 | ;set 0x10 field of information about process |
|
- | 910 | ;(application base address) |
|
- | 911 | ; mov ebx,[new_process_place] |
|
- | 912 | ; shl ebx,5 |
|
- | 913 | shr ebx,3 |
|
- | 914 | mov dword [second_base_address+0x3000+ebx+TASKDATA.mem_start],std_application_base_address |
|
- | 915 | ||
- | 916 | ;add command line parameters |
|
- | 917 | .add_command_line: |
|
- | 918 | mov edx,[app_i_param] |
|
- | 919 | test edx,edx |
|
- | 920 | jz .no_command_line ;application don't need parameters |
|
- | 921 | mov eax,[esp+4] |
|
- | 922 | test eax,eax |
|
- | 923 | jz .no_command_line ;no parameters specified |
|
- | 924 | ;calculate parameter length |
|
- | 925 | mov esi,eax |
|
- | 926 | xor ecx,ecx |
|
- | 927 | inc ecx ; include terminating null |
|
- | 928 | .command_line_len: |
|
- | 929 | cmp byte [esi],0 |
|
- | 930 | jz .command_line_len_end |
|
- | 931 | inc esi |
|
- | 932 | inc ecx |
|
- | 933 | cmp ecx,256 |
|
- | 934 | jl .command_line_len |
|
- | 935 | ||
- | 936 | .command_line_len_end: |
|
- | 937 | ;ecx - parameter length |
|
- | 938 | ;edx - address of parameters in new process address space |
|
- | 939 | mov ebx,eax ;ebx - address of parameters in our address space |
|
- | 940 | mov eax,[new_process_place] |
|
- | 941 | call write_process_memory ;copy parameters to new process address space |
|
- | 942 | ||
- | 943 | .no_command_line: |
|
- | 944 | ;****************************************************************** |
|
- | 945 | mov edx,[app_i_icon] |
|
- | 946 | test edx,edx |
|
- | 947 | jz .no_command_line_1 ;application don't need path of file |
|
- | 948 | mov ebx,[appl_path] |
|
- | 949 | mov ecx,[appl_path_size] |
|
- | 950 | mov eax,[new_process_place] |
|
- | 951 | call write_process_memory ;copy path of file to new process address space |
|
- | 952 | .no_command_line_1: |
|
- | 953 | ;****************************************************************** |
|
- | 954 | mov ebx,[new_process_place] |
|
- | 955 | mov eax,ebx |
|
- | 956 | shl ebx,5 |
|
- | 957 | mov [ebx+window_data+WDATA.fl_wstate],WSTATE_NORMAL |
|
- | 958 | mov [ebx+window_data+WDATA.fl_redraw],1 |
|
- | 959 | add ebx,0x3000 ;ebx - pointer to information about process |
|
- | 960 | mov [ebx+TASKDATA.wnd_number],al ;set window number on screen = process slot |
|
- | 961 | ||
- | 962 | mov [ebx+TASKDATA.event_mask],dword 1+2+4 ;set default event flags (see 40 function) |
|
- | 963 | ||
- | 964 | inc dword [process_number] |
|
- | 965 | mov eax,[process_number] |
|
- | 966 | mov [ebx+TASKDATA.pid],eax ;set PID |
|
- | 967 | ||
- | 968 | mov ecx,ebx |
|
- | 969 | add ecx,draw_data-0x3000 ;ecx - pointer to draw data |
|
- | 970 | ;set draw data to full screen |
|
- | 971 | mov [ecx+RECT.left],dword 0 |
|
- | 972 | mov [ecx+RECT.top],dword 0 |
|
- | 973 | mov eax,[0xfe00] |
|
- | 974 | mov [ecx+RECT.right],eax |
|
- | 975 | mov eax,[0xfe04] |
|
- | 976 | mov [ecx+RECT.bottom],eax |
|
- | 977 | ;set cr3 register in TSS of application |
|
- | 978 | mov ecx,[new_process_place] |
|
- | 979 | shl ecx,8 |
|
- | 980 | mov eax,[0x80000+APPDATA.dir_table+ecx] |
|
- | 981 | add eax,8+16 ;add flags |
|
- | 982 | mov [l.cr3],eax |
|
- | 983 | ||
- | 984 | mov eax,[app_start] |
|
- | 985 | mov [l.eip],eax ;set eip in TSS |
|
- | 986 | mov eax,[app_esp] |
|
- | 987 | mov [l.esp],eax ;set stack in TSS |
|
- | 988 | ||
- | 989 | ;gdt |
|
- | 990 | ;mov ebx,[new_process_place] |
|
- | 991 | ;shl ebx,3 |
|
- | 992 | mov ax,app_code ;ax - selector of code segment |
|
- | 993 | ;add ax,bx |
|
- | 994 | mov [l.cs],ax |
|
- | 995 | mov ax,app_data |
|
- | 996 | ;add ax,bx ;ax - selector of data segment |
|
- | 997 | mov [l.ss],ax |
|
- | 998 | mov [l.ds],ax |
|
- | 999 | mov [l.es],ax |
|
- | 1000 | mov [l.fs],ax |
|
- | 1001 | mov ax,graph_data ;ax - selector of graphic segment |
|
- | 1002 | mov [l.gs],ax |
|
- | 1003 | mov [l.io],word 128 |
|
- | 1004 | mov [l.eflags],dword 0x11202 |
|
- | 1005 | mov [l.ss0],os_data |
|
- | 1006 | mov ebx,[new_process_place] |
|
- | 1007 | shl ebx,12 |
|
- | 1008 | add ebx,sysint_stack_data+4096 |
|
- | 1009 | mov [l.esp0],ebx |
|
- | 1010 | ||
- | 1011 | ;copy tss to it place |
|
- | 1012 | mov eax,tss_sceleton |
|
- | 1013 | mov ebx,[new_process_place] |
|
- | 1014 | imul ebx,tss_step |
|
- | 1015 | add ebx,tss_data ;ebx - address of application TSS |
|
- | 1016 | mov ecx,120 |
|
- | 1017 | call memmove |
|
- | 1018 | ||
- | 1019 | ;Add IO access table - bit array of permitted ports |
|
- | 1020 | or eax,-1 |
|
- | 1021 | mov edi,[new_process_place] |
|
- | 1022 | imul edi,tss_step |
|
- | 1023 | add edi,tss_data+128 |
|
- | 1024 | mov ecx,2048 |
|
- | 1025 | cld |
|
- | 1026 | rep stosd ;full access to 2048*8=16384 ports |
|
- | 1027 | ||
- | 1028 | mov ecx,ebx ;ecx - address of application TSS |
|
- | 1029 | mov edi,[new_process_place] |
|
- | 1030 | shl edi,3 |
|
- | 1031 | ;set TSS descriptor |
|
- | 1032 | mov [edi+gdts+tss0+0],word tss_step ;limit (size) |
|
- | 1033 | mov [edi+gdts+tss0+2],cx ;part of offset |
|
- | 1034 | mov eax,ecx |
|
- | 1035 | shr eax,16 |
|
- | 1036 | mov [edi+gdts+tss0+4],al ;part of offset |
|
- | 1037 | mov [edi+gdts+tss0+7],ah ;part of offset |
|
- | 1038 | mov [edi+gdts+tss0+5],word 01010000b*256+11101001b ;system flags |
|
- | 1039 | ||
- | 1040 | ||
- | 1041 | ;flush keyboard and buttons queue |
|
- | 1042 | mov [0xf400],byte 0 |
|
- | 1043 | mov [0xf500],byte 0 |
|
- | 1044 | ||
- | 1045 | mov edi,[new_process_place] |
|
- | 1046 | shl edi,5 |
|
- | 1047 | add edi,window_data |
|
- | 1048 | mov ebx,[new_process_place] |
|
- | 1049 | movzx esi,word [0xC000+ebx*2] |
|
- | 1050 | lea esi,[0xC400+esi*2] |
|
- | 1051 | call windowactivate ;gui initialization |
|
- | 1052 | ||
- | 1053 | mov ebx,[new_process_place] |
|
- | 1054 | shl ebx,5 |
|
- | 1055 | ; set if debuggee |
|
- | 1056 | test byte [esp+28], 1 |
|
- | 1057 | jz .no_debug |
|
- | 1058 | mov [0x3000+ebx+TASKDATA.state], 1 ; set process state - suspended |
|
- | 1059 | mov eax, [0x3000] |
|
- | 1060 | mov [0x80000+ebx*8+APPDATA.debugger_slot], eax ;set debugger PID - current |
|
- | 1061 | jmp .debug |
|
- | 1062 | .no_debug: |
|
- | 1063 | mov [0x3000+ebx+TASKDATA.state], 0 ; set process state - running |
|
- | 1064 | .debug: |
|
- | 1065 | ||
- | 1066 | mov esi,new_process_running |
|
- | 1067 | call sys_msg_board_str ;output information about succefull startup |
|
- | 1068 | ||
- | 1069 | ; add esp,4 ;pop pointer to parameters |
|
- | 1070 | ; popad |
|
- | 1071 | mov eax,[process_number] ;set result |
|
- | 1072 | mov [application_table_status],0 ;unlock application_table_status mutex |
|
- | 1073 | call safe_sti |
|
- | 1074 | ret 4 |
|
- | 1075 | ||
- | 1076 | end if0>>-->-->-->-->256 |