Rev 3539 | Rev 3598 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2288 | clevermous | 1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;; ;; |
||
2455 | mario79 | 3 | ;; Copyright (C) KolibriOS team 2004-2011. All rights reserved. ;; |
2288 | clevermous | 4 | ;; Distributed under terms of the GNU General Public License ;; |
5 | ;; ;; |
||
6 | ;; ;; |
||
7 | ;; MenuetOS process management, protected ring3 ;; |
||
8 | ;; ;; |
||
9 | ;; Distributed under GPL. See file COPYING for details. ;; |
||
10 | ;; Copyright 2003 Ville Turjanmaa ;; |
||
11 | ;; ;; |
||
12 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
||
13 | |||
14 | $Revision: 3558 $ |
||
15 | |||
16 | align 4 ;3A08 |
||
17 | build_interrupt_table: |
||
18 | mov edi, idts |
||
19 | mov esi, sys_int |
||
20 | mov ecx, 0x40 |
||
21 | mov eax, (10001110b shl 24) + os_code |
||
22 | @@: |
||
23 | movsw ;low word of code-entry |
||
24 | stosd ;interrupt gate type : os_code selector |
||
25 | movsw ;high word of code-entry |
||
26 | loop @b |
||
27 | movsd ;copy low dword of trap gate for int 0x40 |
||
28 | movsd ;copy high dword of trap gate for int 0x40 |
||
29 | lidt [esi] |
||
30 | ret |
||
31 | |||
32 | iglobal |
||
33 | align 4 |
||
34 | sys_int: |
||
35 | ;exception handlers addresses (for interrupt gate construction) |
||
36 | dd e0,e1,e2,e3,e4,e5,e6,except_7 ; SEE: core/fpu.inc |
||
37 | dd e8,e9,e10,e11,e12,e13,page_fault_exc,e15 |
||
38 | dd e16, e17,e18, e19 |
||
39 | times 12 dd unknown_interrupt ;int_20..int_31 |
||
40 | |||
41 | ;interrupt handlers addresses (for interrupt gate construction) |
||
42 | ; 0x20 .. 0x2F - IRQ handlers |
||
43 | dd irq0, irq_serv.irq_1, irq_serv.irq_2 |
||
44 | dd irq_serv.irq_3, irq_serv.irq_4 |
||
45 | dd irq_serv.irq_5, irq_serv.irq_6, irq_serv.irq_7 |
||
46 | dd irq_serv.irq_8, irq_serv.irq_9, irq_serv.irq_10 |
||
47 | dd irq_serv.irq_11, irq_serv.irq_12, irqD, irq_serv.irq_14, irq_serv.irq_15 |
||
48 | dd irq_serv.irq_16 |
||
49 | dd irq_serv.irq_17 |
||
50 | dd irq_serv.irq_18 |
||
51 | dd irq_serv.irq_19 |
||
52 | dd irq_serv.irq_20 |
||
53 | dd irq_serv.irq_21 |
||
54 | dd irq_serv.irq_22 |
||
55 | dd irq_serv.irq_23 |
||
56 | |||
57 | times 32 - IRQ_RESERVED dd unknown_interrupt |
||
58 | ;int_0x40 gate trap (for directly copied) |
||
59 | dw i40 and 0xFFFF, os_code, 11101111b shl 8, i40 shr 16 |
||
60 | |||
61 | idtreg: ; data for LIDT instruction (!!! must be immediately below sys_int data) |
||
62 | dw 2*($-sys_int-4)-1 |
||
63 | dd idts ;0x8000B100 |
||
3539 | clevermous | 64 | dw 0 ;просто выравнивание |
2288 | clevermous | 65 | |
66 | msg_fault_sel dd msg_exc_8,msg_exc_u,msg_exc_a,msg_exc_b |
||
67 | dd msg_exc_c,msg_exc_d,msg_exc_e |
||
68 | |||
69 | msg_exc_8 db "Double fault", 0 |
||
70 | msg_exc_u db "Undefined Exception", 0 |
||
71 | msg_exc_a db "Invalid TSS", 0 |
||
72 | msg_exc_b db "Segment not present", 0 |
||
73 | msg_exc_c db "Stack fault", 0 |
||
74 | msg_exc_d db "General protection fault", 0 |
||
75 | msg_exc_e db "Page fault", 0 |
||
76 | |||
3342 | yogev_ezra | 77 | if lang eq sp |
3344 | yogev_ezra | 78 | include 'core/sys32-sp.inc' |
3342 | yogev_ezra | 79 | else |
80 | msg_sel_ker db "kernel", 0 |
||
81 | msg_sel_app db "application", 0 |
||
3309 | esevece | 82 | end if |
2288 | clevermous | 83 | |
84 | endg |
||
85 | |||
86 | macro save_ring3_context { |
||
87 | pushad |
||
88 | } |
||
89 | macro restore_ring3_context { |
||
90 | popad |
||
91 | } |
||
92 | macro exc_wo_code [num] { |
||
93 | e#num : |
||
94 | save_ring3_context |
||
95 | mov bl, num |
||
96 | jmp exc_c |
||
97 | } exc_wo_code 0,1,2,3,4,5,6,15,16,19 |
||
98 | |||
99 | macro exc_w_code [num] { |
||
100 | e#num : |
||
101 | add esp, 4 |
||
102 | save_ring3_context |
||
103 | mov bl, num |
||
104 | jmp exc_c |
||
105 | } exc_w_code 8,9,10,11,12,13,17,18 |
||
106 | |||
107 | |||
108 | uglobal |
||
109 | pf_err_code dd ? |
||
110 | endg |
||
111 | |||
3539 | clevermous | 112 | page_fault_exc: ; дуракоусточивость: селекторы испорчены... |
113 | pop [ss:pf_err_code]; действительно до следующего #PF |
||
2288 | clevermous | 114 | save_ring3_context |
115 | mov bl, 14 |
||
116 | |||
3539 | clevermous | 117 | exc_c: ; исключения (все, кроме 7-го - #NM) |
118 | ; Фрэйм стека при исключении/прерывании из 3-го кольца + pushad (т.е., именно здесь) |
||
2288 | clevermous | 119 | reg_ss equ esp+0x30 |
120 | reg_esp3 equ esp+0x2C |
||
121 | reg_eflags equ esp+0x28 |
||
122 | reg_cs3 equ esp+0x24 |
||
123 | reg_eip equ esp+0x20 |
||
3539 | clevermous | 124 | ; это фрэйм от pushad |
2288 | clevermous | 125 | reg_eax equ esp+0x1C |
126 | reg_ecx equ esp+0x18 |
||
127 | reg_edx equ esp+0x14 |
||
128 | reg_ebx equ esp+0x10 |
||
129 | reg_esp0 equ esp+0x0C |
||
130 | reg_ebp equ esp+0x08 |
||
131 | reg_esi equ esp+0x04 |
||
132 | reg_edi equ esp+0x00 |
||
133 | |||
3539 | clevermous | 134 | mov ax, app_data ;исключение |
135 | mov ds, ax ;загрузим правильные значения |
||
136 | mov es, ax ;в регистры |
||
137 | cld ; и приводим DF к стандарту |
||
2288 | clevermous | 138 | movzx ebx, bl |
139 | ; redirect to V86 manager? (EFLAGS & 0x20000) != 0? |
||
140 | test byte[reg_eflags+2], 2 |
||
141 | jnz v86_exc_c |
||
142 | cmp bl, 14 ; #PF |
||
143 | jne @f |
||
144 | call page_fault_handler ; SEE: core/memory.inc |
||
145 | @@: |
||
146 | mov esi, [current_slot] |
||
147 | btr [esi+APPDATA.except_mask], ebx |
||
148 | jnc @f |
||
149 | mov eax, [esi+APPDATA.exc_handler] |
||
150 | test eax, eax |
||
151 | jnz IRetToUserHook |
||
152 | @@: |
||
153 | cli |
||
154 | mov eax, [esi+APPDATA.debugger_slot] |
||
155 | test eax, eax |
||
156 | jnz .debug |
||
157 | sti |
||
158 | ; not debuggee => say error and terminate |
||
159 | call show_error_parameters ;; only ONE using, inline ??? |
||
160 | ;mov edx, [TASK_BASE] |
||
161 | mov [edx + TASKDATA.state], byte 4 ; terminate |
||
3534 | clevermous | 162 | call wakeup_osloop |
2288 | clevermous | 163 | jmp change_task ; stack - here it does not matter at all, SEE: core/shed.inc |
164 | .debug: |
||
165 | ; we are debugged process, notify debugger and suspend ourself |
||
166 | ; eax=debugger PID |
||
167 | mov ecx, 1 ; debug_message code=other_exception |
||
168 | cmp bl, 1 ; #DB |
||
169 | jne .notify ; notify debugger and suspend ourself |
||
170 | mov ebx, dr6 ; debug_message data=DR6_image |
||
171 | xor edx, edx |
||
172 | mov dr6, edx |
||
173 | mov edx, dr7 |
||
174 | mov cl, not 8 |
||
175 | .l1: |
||
176 | shl dl, 2 |
||
177 | jc @f |
||
178 | and bl, cl |
||
179 | @@: |
||
180 | sar cl, 1 |
||
181 | jc .l1 |
||
182 | mov cl, 3 ; debug_message code=debug_exception |
||
183 | .notify: |
||
184 | push ebx ; debug_message data |
||
185 | mov ebx, [TASK_BASE] |
||
186 | push [ebx+TASKDATA.pid] ; PID |
||
187 | push ecx ; debug_message code ((here: ecx==1/3)) |
||
188 | mov cl, 12 ; debug_message size |
||
189 | call debugger_notify ;; only ONE using, inline ??? SEE: core/debug.inc |
||
190 | add esp, 12 |
||
191 | mov edx, [TASK_BASE] |
||
192 | mov byte [edx+TASKDATA.state], 1 ; suspended |
||
193 | call change_task ; SEE: core/shed.inc |
||
194 | restore_ring3_context |
||
195 | iretd |
||
196 | |||
197 | IRetToUserHook: |
||
198 | xchg eax, [reg_eip] |
||
199 | sub dword[reg_esp3], 8 |
||
200 | mov edi, [reg_esp3] |
||
201 | stosd |
||
202 | mov [edi], ebx |
||
203 | restore_ring3_context |
||
204 | ; simply return control to interrupted process |
||
205 | unknown_interrupt: |
||
206 | iretd |
||
207 | |||
208 | ;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= |
||
209 | ; bl - error vector |
||
210 | show_error_parameters: |
||
211 | cmp bl, 0x06 |
||
212 | jnz .no_ud |
||
213 | push ebx |
||
214 | mov ebx, ud_user_message |
||
215 | mov ebp, notifyapp |
||
216 | call fs_execute_from_sysdir_param |
||
217 | pop ebx |
||
218 | .no_ud: |
||
219 | mov edx, [TASK_BASE];not scratched below |
||
3309 | esevece | 220 | if lang eq sp |
221 | DEBUGF 1, "K : Proceso - terminado forzado PID: %x [%s]\n", [edx+TASKDATA.pid], [current_slot] |
||
222 | else |
||
3294 | clevermous | 223 | DEBUGF 1, "K : Process - forced terminate PID: %x [%s]\n", [edx+TASKDATA.pid], [current_slot] |
3309 | esevece | 224 | end if |
2288 | clevermous | 225 | cmp bl, 0x08 |
226 | jb .l0 |
||
227 | cmp bl, 0x0e |
||
228 | jbe .l1 |
||
229 | .l0: |
||
230 | mov bl, 0x09 |
||
231 | .l1: |
||
232 | mov eax, [msg_fault_sel+ebx*4 - 0x08*4] |
||
233 | DEBUGF 1, "K : %s\n", eax |
||
234 | mov eax, [reg_cs3+4] |
||
235 | mov edi, msg_sel_app |
||
236 | mov ebx, [reg_esp3+4] |
||
237 | cmp eax, app_code |
||
238 | je @f |
||
239 | mov edi, msg_sel_ker |
||
240 | mov ebx, [reg_esp0+4] |
||
241 | @@: |
||
242 | DEBUGF 1, "K : EAX : %x EBX : %x ECX : %x\n", [reg_eax+4], [reg_ebx+4], [reg_ecx+4] |
||
243 | DEBUGF 1, "K : EDX : %x ESI : %x EDI : %x\n", [reg_edx+4], [reg_esi+4], [reg_edi+4] |
||
244 | DEBUGF 1, "K : EBP : %x EIP : %x ESP : %x\n", [reg_ebp+4], [reg_eip+4], ebx |
||
245 | DEBUGF 1, "K : Flags : %x CS : %x (%s)\n", [reg_eflags+4], eax, edi |
||
246 | ret |
||
247 | ;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= |
||
248 | |||
249 | restore reg_ss |
||
250 | restore reg_esp3 |
||
251 | restore reg_eflags |
||
252 | restore reg_cs |
||
253 | restore reg_eip |
||
254 | restore reg_eax |
||
255 | restore reg_ecx |
||
256 | restore reg_edx |
||
257 | restore reg_ebx |
||
258 | restore reg_esp0 |
||
259 | restore reg_ebp |
||
260 | restore reg_esi |
||
261 | restore reg_edi |
||
262 | |||
263 | |||
264 | align 4 |
||
3534 | clevermous | 265 | lock_application_table: |
266 | push eax ecx edx |
||
267 | mov ecx, application_table_mutex |
||
268 | call mutex_lock |
||
2288 | clevermous | 269 | |
270 | mov eax, [CURRENT_TASK] |
||
271 | shl eax, 5 |
||
272 | add eax, CURRENT_TASK+TASKDATA.pid |
||
273 | mov eax, [eax] |
||
274 | |||
3534 | clevermous | 275 | mov [application_table_owner], eax |
2288 | clevermous | 276 | |
3534 | clevermous | 277 | pop edx ecx eax |
2288 | clevermous | 278 | |
279 | ret |
||
280 | |||
281 | align 4 |
||
3534 | clevermous | 282 | unlock_application_table: |
283 | push eax ecx edx |
||
2288 | clevermous | 284 | |
3534 | clevermous | 285 | mov [application_table_owner], 0 |
286 | mov ecx, application_table_mutex |
||
287 | call mutex_unlock |
||
2288 | clevermous | 288 | |
3534 | clevermous | 289 | pop edx ecx eax |
2288 | clevermous | 290 | |
291 | ret |
||
292 | |||
3539 | clevermous | 293 | ; * eax = 64 - номер функции |
294 | ; * ebx = 1 - единственная подфункция |
||
295 | ; * ecx = новый размер памяти |
||
296 | ;Возвращаемое значение: |
||
297 | ; * eax = 0 - успешно |
||
298 | ; * eax = 1 - недостаточно памяти |
||
2288 | clevermous | 299 | |
300 | align 4 |
||
301 | sys_resize_app_memory: |
||
302 | ; ebx = 1 - resize |
||
303 | ; ecx = new amount of memory |
||
304 | |||
305 | ; cmp eax,1 |
||
306 | dec ebx |
||
307 | jnz .no_application_mem_resize |
||
308 | stdcall new_mem_resize, ecx |
||
309 | mov [esp+32], eax |
||
310 | .no_application_mem_resize: |
||
311 | ret |
||
312 | |||
313 | iglobal |
||
314 | ; process_terminating db 'K : Process - terminating',13,10,0 |
||
315 | ; process_terminated db 'K : Process - done',13,10,0 |
||
316 | msg_obj_destroy db 'K : destroy app object',13,10,0 |
||
317 | endg |
||
318 | |||
319 | ; param |
||
320 | ; esi= slot |
||
321 | |||
322 | align 4 |
||
323 | terminate: ; terminate application |
||
324 | |||
325 | .slot equ esp ;locals |
||
326 | |||
327 | push esi ;save .slot |
||
328 | |||
329 | shl esi, 8 |
||
330 | cmp [SLOT_BASE+esi+APPDATA.dir_table], 0 |
||
331 | jne @F |
||
332 | pop esi |
||
333 | shl esi, 5 |
||
334 | mov [CURRENT_TASK+esi+TASKDATA.state], 9 |
||
335 | ret |
||
336 | @@: |
||
3534 | clevermous | 337 | lea edx, [SLOT_BASE+esi] |
338 | call scheduler_remove_thread |
||
2288 | clevermous | 339 | ;mov esi,process_terminating |
340 | ;call sys_msg_board_str |
||
3534 | clevermous | 341 | call lock_application_table |
2288 | clevermous | 342 | |
343 | ; if the process is in V86 mode... |
||
344 | mov eax, [.slot] |
||
345 | shl eax, 8 |
||
346 | mov esi, [eax+SLOT_BASE+APPDATA.pl0_stack] |
||
347 | add esi, RING0_STACK_SIZE |
||
348 | cmp [eax+SLOT_BASE+APPDATA.saved_esp0], esi |
||
349 | jz .nov86 |
||
350 | ; ...it has page directory for V86 mode |
||
351 | mov esi, [eax+SLOT_BASE+APPDATA.saved_esp0] |
||
352 | mov ecx, [esi+4] |
||
353 | mov [eax+SLOT_BASE+APPDATA.dir_table], ecx |
||
354 | ; ...and I/O permission map for V86 mode |
||
355 | mov ecx, [esi+12] |
||
356 | mov [eax+SLOT_BASE+APPDATA.io_map], ecx |
||
357 | mov ecx, [esi+8] |
||
358 | mov [eax+SLOT_BASE+APPDATA.io_map+4], ecx |
||
359 | .nov86: |
||
360 | |||
361 | mov esi, [.slot] |
||
362 | shl esi, 8 |
||
363 | add esi, SLOT_BASE+APP_OBJ_OFFSET |
||
364 | @@: |
||
365 | mov eax, [esi+APPOBJ.fd] |
||
366 | test eax, eax |
||
367 | jz @F |
||
368 | |||
369 | cmp eax, esi |
||
370 | je @F |
||
371 | |||
372 | push esi |
||
373 | call [eax+APPOBJ.destroy] |
||
374 | DEBUGF 1,"%s",msg_obj_destroy |
||
375 | pop esi |
||
376 | jmp @B |
||
377 | @@: |
||
378 | |||
379 | mov eax, [.slot] |
||
380 | shl eax, 8 |
||
381 | stdcall destroy_app_space, [SLOT_BASE+eax+APPDATA.dir_table], [SLOT_BASE+eax+APPDATA.dlls_list_ptr] |
||
382 | |||
383 | mov esi, [.slot] |
||
3534 | clevermous | 384 | cmp [fpu_owner], esi ; if user fpu last -> fpu user = 2 |
2288 | clevermous | 385 | jne @F |
386 | |||
3534 | clevermous | 387 | mov [fpu_owner], 2 |
388 | mov eax, [256*2+SLOT_BASE+APPDATA.fpu_state] |
||
2288 | clevermous | 389 | clts |
390 | bt [cpu_caps], CAPS_SSE |
||
391 | jnc .no_SSE |
||
392 | fxrstor [eax] |
||
393 | jmp @F |
||
394 | .no_SSE: |
||
395 | fnclex |
||
396 | frstor [eax] |
||
397 | @@: |
||
398 | |||
399 | mov [KEY_COUNT], byte 0 ; empty keyboard buffer |
||
400 | mov [BTN_COUNT], byte 0 ; empty button buffer |
||
401 | |||
402 | |||
403 | ; remove defined hotkeys |
||
404 | mov eax, hotkey_list |
||
405 | .loop: |
||
406 | cmp [eax+8], esi |
||
407 | jnz .cont |
||
408 | mov ecx, [eax] |
||
409 | jecxz @f |
||
410 | push dword [eax+12] |
||
411 | pop dword [ecx+12] |
||
412 | @@: |
||
413 | mov ecx, [eax+12] |
||
414 | push dword [eax] |
||
415 | pop dword [ecx] |
||
416 | xor ecx, ecx |
||
417 | mov [eax], ecx |
||
418 | mov [eax+4], ecx |
||
419 | mov [eax+8], ecx |
||
420 | mov [eax+12], ecx |
||
421 | .cont: |
||
422 | add eax, 16 |
||
423 | cmp eax, hotkey_list+256*16 |
||
424 | jb .loop |
||
2709 | mario79 | 425 | ; get process PID |
426 | mov eax, esi |
||
427 | shl eax, 5 |
||
428 | mov eax, [eax+CURRENT_TASK+TASKDATA.pid] |
||
429 | ; compare current lock input with process PID |
||
430 | cmp eax, [PID_lock_input] |
||
431 | jne @f |
||
432 | |||
433 | xor eax, eax |
||
434 | mov [PID_lock_input], eax |
||
435 | @@: |
||
2288 | clevermous | 436 | ; remove hotkeys in buffer |
437 | mov eax, hotkey_buffer |
||
438 | .loop2: |
||
439 | cmp [eax], esi |
||
440 | jnz .cont2 |
||
441 | and dword [eax+4], 0 |
||
442 | and dword [eax], 0 |
||
443 | .cont2: |
||
444 | add eax, 8 |
||
445 | cmp eax, hotkey_buffer+120*8 |
||
446 | jb .loop2 |
||
447 | |||
448 | mov ecx, esi ; remove buttons |
||
449 | bnewba2: |
||
450 | mov edi, [BTN_ADDR] |
||
451 | mov eax, edi |
||
452 | cld |
||
453 | movzx ebx, word [edi] |
||
454 | inc bx |
||
455 | bnewba: |
||
456 | dec bx |
||
457 | jz bnmba |
||
458 | add eax, 0x10 |
||
459 | cmp cx, [eax] |
||
460 | jnz bnewba |
||
461 | pusha |
||
462 | mov ecx, ebx |
||
463 | inc ecx |
||
464 | shl ecx, 4 |
||
465 | mov ebx, eax |
||
466 | add eax, 0x10 |
||
467 | call memmove |
||
468 | dec dword [edi] |
||
469 | popa |
||
470 | jmp bnewba2 |
||
471 | bnmba: |
||
472 | |||
473 | pusha ; save window coordinates for window restoring |
||
474 | cld |
||
475 | shl esi, 5 |
||
476 | add esi, window_data |
||
477 | mov eax, [esi+WDATA.box.left] |
||
478 | mov [draw_limits.left], eax |
||
479 | add eax, [esi+WDATA.box.width] |
||
480 | mov [draw_limits.right], eax |
||
481 | mov eax, [esi+WDATA.box.top] |
||
482 | mov [draw_limits.top], eax |
||
483 | add eax, [esi+WDATA.box.height] |
||
484 | mov [draw_limits.bottom], eax |
||
485 | |||
486 | xor eax, eax |
||
487 | mov [esi+WDATA.box.left], eax |
||
488 | mov [esi+WDATA.box.width], eax |
||
489 | mov [esi+WDATA.box.top], eax |
||
490 | mov [esi+WDATA.box.height], eax |
||
491 | mov [esi+WDATA.cl_workarea], eax |
||
492 | mov [esi+WDATA.cl_titlebar], eax |
||
493 | mov [esi+WDATA.cl_frames], eax |
||
494 | mov dword [esi+WDATA.reserved], eax; clear all flags: wstate, redraw, wdrawn |
||
495 | lea edi, [esi-window_data+draw_data] |
||
496 | mov ecx, 32/4 |
||
497 | rep stosd |
||
498 | popa |
||
499 | |||
500 | ; debuggee test |
||
501 | pushad |
||
502 | mov edi, esi |
||
503 | shl edi, 5 |
||
504 | mov eax, [SLOT_BASE+edi*8+APPDATA.debugger_slot] |
||
505 | test eax, eax |
||
506 | jz .nodebug |
||
507 | push 8 |
||
508 | pop ecx |
||
509 | push dword [CURRENT_TASK+edi+TASKDATA.pid]; PID |
||
510 | push 2 |
||
511 | call debugger_notify |
||
512 | pop ecx |
||
513 | pop ecx |
||
514 | .nodebug: |
||
515 | popad |
||
516 | |||
517 | mov ebx, [.slot] |
||
518 | shl ebx, 8 |
||
519 | push ebx |
||
520 | mov ebx, [SLOT_BASE+ebx+APPDATA.pl0_stack] |
||
521 | |||
522 | stdcall kernel_free, ebx |
||
523 | |||
524 | pop ebx |
||
525 | mov ebx, [SLOT_BASE+ebx+APPDATA.cur_dir] |
||
526 | stdcall kernel_free, ebx |
||
527 | |||
528 | mov edi, [.slot] |
||
529 | shl edi, 8 |
||
530 | add edi, SLOT_BASE |
||
531 | |||
532 | mov eax, [edi+APPDATA.io_map] |
||
533 | cmp eax, [SLOT_BASE+256+APPDATA.io_map] |
||
534 | je @F |
||
535 | call free_page |
||
536 | @@: |
||
537 | mov eax, [edi+APPDATA.io_map+4] |
||
538 | cmp eax, [SLOT_BASE+256+APPDATA.io_map+4] |
||
539 | je @F |
||
540 | call free_page |
||
541 | @@: |
||
542 | mov eax, 0x20202020 |
||
543 | stosd |
||
544 | stosd |
||
545 | stosd |
||
546 | mov ecx, 244/4 |
||
547 | xor eax, eax |
||
548 | rep stosd |
||
549 | |||
550 | ; activate window |
||
551 | movzx eax, word [WIN_STACK + esi*2] |
||
552 | cmp eax, [TASK_COUNT] |
||
553 | jne .dont_activate |
||
554 | pushad |
||
555 | .check_next_window: |
||
556 | dec eax |
||
557 | cmp eax, 1 |
||
558 | jbe .nothing_to_activate |
||
559 | lea esi, [WIN_POS+eax*2] |
||
560 | movzx edi, word [esi] ; edi = process |
||
561 | shl edi, 5 |
||
562 | cmp [CURRENT_TASK + edi + TASKDATA.state], byte 9 ; skip dead slots |
||
563 | je .check_next_window |
||
564 | add edi, window_data |
||
565 | ; \begin{diamond}[19.09.2006] |
||
566 | ; skip minimized windows |
||
567 | test [edi + WDATA.fl_wstate], WSTATE_MINIMIZED |
||
568 | jnz .check_next_window |
||
569 | ; \end{diamond} |
||
570 | call waredraw |
||
571 | .nothing_to_activate: |
||
572 | popad |
||
573 | .dont_activate: |
||
574 | |||
575 | push esi ; remove hd1 & cd & flp reservation |
||
576 | shl esi, 5 |
||
577 | mov esi, [esi+CURRENT_TASK+TASKDATA.pid] |
||
578 | cmp [hd1_status], esi |
||
579 | jnz @f |
||
580 | call free_hd_channel |
||
581 | and [hd1_status], 0 |
||
582 | @@: |
||
583 | cmp [cd_status], esi |
||
584 | jnz @f |
||
585 | call free_cd_channel |
||
586 | and [cd_status], 0 |
||
587 | @@: |
||
588 | cmp [flp_status], esi |
||
589 | jnz @f |
||
590 | and [flp_status], 0 |
||
591 | @@: |
||
592 | pop esi |
||
593 | cmp [bgrlockpid], esi |
||
594 | jnz @f |
||
595 | and [bgrlockpid], 0 |
||
596 | and [bgrlock], 0 |
||
597 | @@: |
||
598 | |||
599 | pusha ; remove all port reservations |
||
600 | mov edx, esi |
||
601 | shl edx, 5 |
||
602 | add edx, CURRENT_TASK |
||
603 | mov edx, [edx+TASKDATA.pid] |
||
604 | |||
605 | rmpr0: |
||
606 | |||
607 | mov esi, [RESERVED_PORTS] |
||
608 | |||
609 | test esi, esi |
||
610 | jz rmpr9 |
||
611 | |||
612 | rmpr3: |
||
613 | |||
614 | mov edi, esi |
||
615 | shl edi, 4 |
||
616 | add edi, RESERVED_PORTS |
||
617 | |||
618 | cmp edx, [edi] |
||
619 | je rmpr4 |
||
620 | |||
621 | dec esi |
||
622 | jnz rmpr3 |
||
623 | |||
624 | jmp rmpr9 |
||
625 | |||
626 | rmpr4: |
||
627 | |||
628 | mov ecx, 256 |
||
629 | sub ecx, esi |
||
630 | shl ecx, 4 |
||
631 | |||
632 | mov esi, edi |
||
633 | add esi, 16 |
||
634 | cld |
||
635 | rep movsb |
||
636 | |||
637 | dec dword [RESERVED_PORTS] |
||
638 | |||
639 | jmp rmpr0 |
||
640 | |||
641 | rmpr9: |
||
642 | |||
643 | popa |
||
644 | mov edi, esi ; do not run this process slot |
||
645 | shl edi, 5 |
||
646 | mov [edi+CURRENT_TASK + TASKDATA.state], byte 9 |
||
647 | ; debugger test - terminate all debuggees |
||
648 | mov eax, 2 |
||
649 | mov ecx, SLOT_BASE+2*0x100+APPDATA.debugger_slot |
||
650 | .xd0: |
||
651 | cmp eax, [TASK_COUNT] |
||
652 | ja .xd1 |
||
653 | cmp dword [ecx], esi |
||
654 | jnz @f |
||
655 | and dword [ecx], 0 |
||
656 | pushad |
||
657 | xchg eax, ecx |
||
658 | mov ebx, 2 |
||
659 | call sys_system |
||
660 | popad |
||
661 | @@: |
||
662 | inc eax |
||
663 | add ecx, 0x100 |
||
664 | jmp .xd0 |
||
665 | .xd1: |
||
666 | ; call systest |
||
667 | sti ; .. and life goes on |
||
668 | |||
669 | mov eax, [draw_limits.left] |
||
670 | mov ebx, [draw_limits.top] |
||
671 | mov ecx, [draw_limits.right] |
||
672 | mov edx, [draw_limits.bottom] |
||
673 | call calculatescreen |
||
674 | xor eax, eax |
||
675 | xor esi, esi |
||
676 | call redrawscreen |
||
677 | |||
3534 | clevermous | 678 | call unlock_application_table |
2288 | clevermous | 679 | ;mov esi,process_terminated |
680 | ;call sys_msg_board_str |
||
681 | add esp, 4 |
||
682 | ret |
||
683 | restore .slot |
||
684 | |||
2642 | mario79 | 685 | ;build_scheduler: |
686 | ; mov esi, boot_sched_1 |
||
687 | ; call boot_log |
||
688 | ; call build_process_gdt_tss_pointer |
||
2288 | clevermous | 689 | |
2642 | mario79 | 690 | ; mov esi,boot_sched_2 |
691 | ; call boot_log |
||
692 | ; ret |
||
3296 | clevermous | 693 | |
694 | ; Three following procedures are used to guarantee that |
||
695 | ; some part of kernel code will not be terminated from outside |
||
696 | ; while it is running. |
||
697 | ; Note: they do not protect a thread from terminating due to errors inside |
||
698 | ; the thread; accessing a nonexisting memory would still terminate it. |
||
699 | |||
700 | ; First two procedures must be used in pair by thread-to-be-protected |
||
701 | ; to signal the beginning and the end of an important part. |
||
702 | ; It is OK to have nested areas. |
||
703 | |||
704 | ; The last procedure must be used by outside wanna-be-terminators; |
||
705 | ; if it is safe to terminate the given thread immediately, it returns eax=1; |
||
706 | ; otherwise, it returns eax=0 and notifies the target thread that it should |
||
707 | ; terminate itself when leaving a critical area (the last critical area if |
||
708 | ; they are nested). |
||
709 | |||
710 | ; Implementation. Those procedures use one dword in APPDATA for the thread, |
||
711 | ; APPDATA.terminate_protection. |
||
712 | ; * The upper bit is 1 during normal operations and 0 when terminate is requested. |
||
713 | ; * Other bits form a number = depth of critical regions, |
||
714 | ; plus 1 if the upper bit is 1. |
||
715 | ; * When this dword goes to zero, the thread should be destructed, |
||
716 | ; and the procedure in which it happened becomes responsible for destruction. |
||
717 | |||
718 | ; Enter critical area. Called by thread which wants to be protected. |
||
719 | proc protect_from_terminate |
||
720 | mov edx, [current_slot] |
||
721 | ; Atomically increment depth of critical areas and get the old value. |
||
722 | mov eax, 1 |
||
723 | lock xadd [edx+APPDATA.terminate_protection], eax |
||
724 | ; If the old value was zero, somebody has started to terminate us, |
||
725 | ; so we are destructing and cannot do anything protected. |
||
726 | ; Otherwise, return to the caller. |
||
727 | test eax, eax |
||
728 | jz @f |
||
729 | ret |
||
730 | @@: |
||
731 | ; Wait for somebody to finish us. |
||
732 | call change_task |
||
733 | jmp @b |
||
734 | endp |
||
735 | |||
736 | ; Leave critical area. Called by thread which wants to be protected. |
||
737 | proc unprotect_from_terminate |
||
738 | mov edx, [current_slot] |
||
739 | ; Atomically decrement depth of critical areas. |
||
740 | lock dec [edx+APPDATA.terminate_protection] |
||
741 | ; If the result of decrement is zero, somebody has requested termination, |
||
742 | ; but at that moment we were inside a critical area; terminate now. |
||
743 | jz sys_end |
||
744 | ; Otherwise, return to the caller. |
||
745 | ret |
||
746 | endp |
||
747 | |||
748 | ; Request termination of thread identified by edx = SLOT_BASE + slot*256. |
||
749 | ; Called by anyone. |
||
750 | proc request_terminate |
||
751 | xor eax, eax ; set return value |
||
752 | ; Atomically clear the upper bit. If it was already zero, then |
||
753 | ; somebody has requested termination before us, so just exit. |
||
754 | lock btr [edx+APPDATA.terminate_protection], 31 |
||
755 | jnc .unsafe |
||
756 | ; Atomically decrement depth of critical areas. |
||
757 | lock dec [edx+APPDATA.terminate_protection] |
||
758 | ; If the result of decrement is nonzero, the target thread is inside a |
||
759 | ; critical area; leave termination to leaving that area. |
||
760 | jnz .unsafe |
||
761 | ; Otherwise, it is safe to kill the target now and the caller is responsible |
||
762 | ; for this. Return eax=1. |
||
763 | inc eax |
||
764 | .unsafe: |
||
765 | ret |
||
766 | endp |
||
767 |