Rev 3500 | Rev 3626 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
431 | serge | 1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;; ;; |
||
2465 | Serge | 3 | ;; Copyright (C) KolibriOS team 2004-2011. All rights reserved. ;; |
431 | serge | 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 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
||
1 | ha | 13 | |
593 | mikedld | 14 | $Revision: 3555 $ |
15 | |||
1056 | Galkov | 16 | align 4 ;3A08 |
1 | ha | 17 | build_interrupt_table: |
1056 | Galkov | 18 | mov edi, idts |
19 | mov esi, sys_int |
||
20 | mov ecx, 0x40 |
||
21 | mov eax, (10001110b shl 24) + os_code |
||
2434 | Serge | 22 | @@: |
23 | movsw ;low word of code-entry |
||
1056 | Galkov | 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 |
||
1 | ha | 31 | |
1056 | Galkov | 32 | iglobal |
33 | align 4 |
||
34 | sys_int: |
||
35 | ;exception handlers addresses (for interrupt gate construction) |
||
1076 | Galkov | 36 | dd e0,e1,e2,e3,e4,e5,e6,except_7 ; SEE: core/fpu.inc |
1056 | Galkov | 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 |
||
164 | serge | 40 | |
1056 | Galkov | 41 | ;interrupt handlers addresses (for interrupt gate construction) |
2434 | Serge | 42 | ; 0x20 .. 0x2F - IRQ handlers |
1056 | Galkov | 43 | dd irq0, irq_serv.irq_1, irq_serv.irq_2 |
44 | dd irq_serv.irq_3, irq_serv.irq_4 |
||
2010 | serge | 45 | dd irq_serv.irq_5, irq_serv.irq_6, irq_serv.irq_7 |
1056 | Galkov | 46 | dd irq_serv.irq_8, irq_serv.irq_9, irq_serv.irq_10 |
2010 | serge | 47 | dd irq_serv.irq_11, irq_serv.irq_12, irqD, irq_serv.irq_14, irq_serv.irq_15 |
2434 | Serge | 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 |
||
1 | ha | 56 | |
2130 | serge | 57 | times 32 - IRQ_RESERVED dd unknown_interrupt |
1056 | Galkov | 58 | ;int_0x40 gate trap (for directly copied) |
59 | dw i40 and 0xFFFF, os_code, 11101111b shl 8, i40 shr 16 |
||
656 | mikedld | 60 | |
1076 | Galkov | 61 | idtreg: ; data for LIDT instruction (!!! must be immediately below sys_int data) |
1056 | Galkov | 62 | dw 2*($-sys_int-4)-1 |
63 | dd idts ;0x8000B100 |
||
3555 | Serge | 64 | dw 0 ;просто выравнивание |
656 | mikedld | 65 | |
1056 | Galkov | 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 |
||
164 | serge | 68 | |
1056 | Galkov | 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 |
||
1 | ha | 76 | |
3500 | Serge | 77 | if lang eq sp |
78 | include 'core/sys32-sp.inc' |
||
79 | else |
||
1056 | Galkov | 80 | msg_sel_ker db "kernel", 0 |
81 | msg_sel_app db "application", 0 |
||
3500 | Serge | 82 | end if |
1 | ha | 83 | |
84 | endg |
||
85 | |||
1056 | Galkov | 86 | macro save_ring3_context { |
87 | pushad |
||
40 | halyavin | 88 | } |
1056 | Galkov | 89 | macro restore_ring3_context { |
90 | popad |
||
40 | halyavin | 91 | } |
1056 | Galkov | 92 | macro exc_wo_code [num] { |
8 | poddubny | 93 | e#num : |
1056 | Galkov | 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 |
||
1 | ha | 98 | |
1056 | Galkov | 99 | macro exc_w_code [num] { |
22 | poddubny | 100 | e#num : |
1056 | Galkov | 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 |
||
22 | poddubny | 106 | |
107 | |||
1056 | Galkov | 108 | uglobal |
109 | pf_err_code dd ? |
||
110 | endg |
||
1 | ha | 111 | |
3555 | Serge | 112 | page_fault_exc: ; дуракоусточивость: селекторы испорчены... |
113 | pop [ss:pf_err_code]; действительно до следующего #PF |
||
1056 | Galkov | 114 | save_ring3_context |
2434 | Serge | 115 | mov bl, 14 |
1086 | Galkov | 116 | |
3555 | Serge | 117 | exc_c: ; исключения (все, кроме 7-го - #NM) |
118 | ; Фрэйм стека при исключении/прерывании из 3-го кольца + pushad (т.е., именно здесь) |
||
1056 | Galkov | 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 |
||
3555 | Serge | 124 | ; это фрэйм от pushad |
1056 | Galkov | 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 | |||
3555 | Serge | 134 | mov ax, app_data ;исключение |
135 | mov ds, ax ;загрузим правильные значения |
||
136 | mov es, ax ;в регистры |
||
137 | cld ; и приводим DF к стандарту |
||
2434 | Serge | 138 | movzx ebx, bl |
709 | diamond | 139 | ; redirect to V86 manager? (EFLAGS & 0x20000) != 0? |
2434 | Serge | 140 | test byte[reg_eflags+2], 2 |
1056 | Galkov | 141 | jnz v86_exc_c |
2434 | Serge | 142 | cmp bl, 14 ; #PF |
1074 | Galkov | 143 | jne @f |
1076 | Galkov | 144 | call page_fault_handler ; SEE: core/memory.inc |
2434 | Serge | 145 | @@: |
146 | mov esi, [current_slot] |
||
1074 | Galkov | 147 | btr [esi+APPDATA.except_mask], ebx |
148 | jnc @f |
||
2434 | Serge | 149 | mov eax, [esi+APPDATA.exc_handler] |
1074 | Galkov | 150 | test eax, eax |
1056 | Galkov | 151 | jnz IRetToUserHook |
2434 | Serge | 152 | @@: |
153 | cli |
||
1056 | Galkov | 154 | mov eax, [esi+APPDATA.debugger_slot] |
155 | test eax, eax |
||
156 | jnz .debug |
||
157 | sti |
||
40 | halyavin | 158 | ; not debuggee => say error and terminate |
1056 | Galkov | 159 | call show_error_parameters ;; only ONE using, inline ??? |
160 | ;mov edx, [TASK_BASE] |
||
161 | mov [edx + TASKDATA.state], byte 4 ; terminate |
||
3555 | Serge | 162 | call wakeup_osloop |
1076 | Galkov | 163 | jmp change_task ; stack - here it does not matter at all, SEE: core/shed.inc |
40 | halyavin | 164 | .debug: |
165 | ; we are debugged process, notify debugger and suspend ourself |
||
166 | ; eax=debugger PID |
||
2434 | Serge | 167 | mov ecx, 1 ; debug_message code=other_exception |
168 | cmp bl, 1 ; #DB |
||
1076 | Galkov | 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 |
||
2434 | Serge | 175 | .l1: |
176 | shl dl, 2 |
||
1076 | Galkov | 177 | jc @f |
178 | and bl, cl |
||
2434 | Serge | 179 | @@: |
180 | sar cl, 1 |
||
1076 | Galkov | 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 |
||
2434 | Serge | 190 | add esp, 12 |
1076 | Galkov | 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 |
||
1 | ha | 196 | |
1056 | Galkov | 197 | IRetToUserHook: |
198 | xchg eax, [reg_eip] |
||
1074 | Galkov | 199 | sub dword[reg_esp3], 8 |
1056 | Galkov | 200 | mov edi, [reg_esp3] |
201 | stosd |
||
1074 | Galkov | 202 | mov [edi], ebx |
1056 | Galkov | 203 | restore_ring3_context |
1638 | serge | 204 | ; simply return control to interrupted process |
1056 | Galkov | 205 | unknown_interrupt: |
206 | iretd |
||
1 | ha | 207 | |
658 | Ghost | 208 | ;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= |
1638 | serge | 209 | ; bl - error vector |
1 | ha | 210 | show_error_parameters: |
2010 | serge | 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: |
||
2434 | Serge | 219 | mov edx, [TASK_BASE];not scratched below |
3500 | Serge | 220 | if lang eq sp |
221 | DEBUGF 1, "K : Proceso - terminado forzado PID: %x [%s]\n", [edx+TASKDATA.pid], [current_slot] |
||
222 | else |
||
223 | DEBUGF 1, "K : Process - forced terminate PID: %x [%s]\n", [edx+TASKDATA.pid], [current_slot] |
||
224 | end if |
||
1056 | Galkov | 225 | cmp bl, 0x08 |
226 | jb .l0 |
||
227 | cmp bl, 0x0e |
||
228 | jbe .l1 |
||
2434 | Serge | 229 | .l0: |
230 | mov bl, 0x09 |
||
231 | .l1: |
||
232 | mov eax, [msg_fault_sel+ebx*4 - 0x08*4] |
||
1056 | Galkov | 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] |
||
2434 | Serge | 241 | @@: |
242 | DEBUGF 1, "K : EAX : %x EBX : %x ECX : %x\n", [reg_eax+4], [reg_ebx+4], [reg_ecx+4] |
||
1056 | Galkov | 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 |
||
658 | Ghost | 247 | ;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= |
164 | serge | 248 | |
1056 | Galkov | 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 |
||
16 | poddubny | 262 | |
1638 | serge | 263 | |
2106 | serge | 264 | align 4 |
3555 | Serge | 265 | lock_application_table: |
266 | push eax ecx edx |
||
267 | mov ecx, application_table_mutex |
||
268 | call mutex_lock |
||
1 | ha | 269 | |
2434 | Serge | 270 | mov eax, [CURRENT_TASK] |
271 | shl eax, 5 |
||
272 | add eax, CURRENT_TASK+TASKDATA.pid |
||
273 | mov eax, [eax] |
||
1 | ha | 274 | |
3555 | Serge | 275 | mov [application_table_owner], eax |
1 | ha | 276 | |
3555 | Serge | 277 | pop edx ecx eax |
1 | ha | 278 | |
1056 | Galkov | 279 | ret |
1 | ha | 280 | |
2106 | serge | 281 | align 4 |
3555 | Serge | 282 | unlock_application_table: |
283 | push eax ecx edx |
||
1 | ha | 284 | |
3555 | Serge | 285 | mov [application_table_owner], 0 |
286 | mov ecx, application_table_mutex |
||
287 | call mutex_unlock |
||
1 | ha | 288 | |
3555 | Serge | 289 | pop edx ecx eax |
1 | ha | 290 | |
1056 | Galkov | 291 | ret |
1 | ha | 292 | |
3555 | Serge | 293 | ; * eax = 64 - номер функции |
294 | ; * ebx = 1 - единственная подфункция |
||
295 | ; * ecx = новый размер памяти |
||
296 | ;Возвращаемое значение: |
||
297 | ; * eax = 0 - успешно |
||
298 | ; * eax = 1 - недостаточно памяти |
||
1306 | Lrz | 299 | |
2106 | serge | 300 | align 4 |
1 | ha | 301 | sys_resize_app_memory: |
1306 | Lrz | 302 | ; ebx = 1 - resize |
303 | ; ecx = new amount of memory |
||
1 | ha | 304 | |
1306 | Lrz | 305 | ; cmp eax,1 |
2434 | Serge | 306 | dec ebx |
307 | jnz .no_application_mem_resize |
||
1307 | Lrz | 308 | stdcall new_mem_resize, ecx |
2434 | Serge | 309 | mov [esp+32], eax |
164 | serge | 310 | .no_application_mem_resize: |
1056 | Galkov | 311 | ret |
1 | ha | 312 | |
313 | iglobal |
||
1056 | Galkov | 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 |
||
1 | ha | 317 | endg |
318 | |||
329 | serge | 319 | ; param |
320 | ; esi= slot |
||
1 | ha | 321 | |
2106 | serge | 322 | align 4 |
1 | ha | 323 | terminate: ; terminate application |
324 | |||
1056 | Galkov | 325 | .slot equ esp ;locals |
329 | serge | 326 | |
2434 | Serge | 327 | push esi ;save .slot |
334 | serge | 328 | |
2434 | Serge | 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 |
||
334 | serge | 336 | @@: |
3555 | Serge | 337 | lea edx, [SLOT_BASE+esi] |
338 | call scheduler_remove_thread |
||
1056 | Galkov | 339 | ;mov esi,process_terminating |
340 | ;call sys_msg_board_str |
||
3555 | Serge | 341 | call lock_application_table |
1 | ha | 342 | |
709 | diamond | 343 | ; if the process is in V86 mode... |
1056 | Galkov | 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 |
||
709 | diamond | 350 | ; ...it has page directory for V86 mode |
1056 | Galkov | 351 | mov esi, [eax+SLOT_BASE+APPDATA.saved_esp0] |
352 | mov ecx, [esi+4] |
||
353 | mov [eax+SLOT_BASE+APPDATA.dir_table], ecx |
||
709 | diamond | 354 | ; ...and I/O permission map for V86 mode |
1056 | Galkov | 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 |
||
709 | diamond | 359 | .nov86: |
360 | |||
2434 | Serge | 361 | mov esi, [.slot] |
362 | shl esi, 8 |
||
363 | add esi, SLOT_BASE+APP_OBJ_OFFSET |
||
329 | serge | 364 | @@: |
2434 | Serge | 365 | mov eax, [esi+APPOBJ.fd] |
366 | test eax, eax |
||
367 | jz @F |
||
334 | serge | 368 | |
2434 | Serge | 369 | cmp eax, esi |
370 | je @F |
||
164 | serge | 371 | |
2434 | Serge | 372 | push esi |
373 | call [eax+APPOBJ.destroy] |
||
1056 | Galkov | 374 | DEBUGF 1,"%s",msg_obj_destroy |
2434 | Serge | 375 | pop esi |
376 | jmp @B |
||
329 | serge | 377 | @@: |
1311 | diamond | 378 | |
2434 | Serge | 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] |
||
1 | ha | 382 | |
2434 | Serge | 383 | mov esi, [.slot] |
3555 | Serge | 384 | cmp [fpu_owner], esi ; if user fpu last -> fpu user = 2 |
2434 | Serge | 385 | jne @F |
164 | serge | 386 | |
3555 | Serge | 387 | mov [fpu_owner], 2 |
388 | mov eax, [256*2+SLOT_BASE+APPDATA.fpu_state] |
||
2434 | Serge | 389 | clts |
390 | bt [cpu_caps], CAPS_SSE |
||
391 | jnc .no_SSE |
||
392 | fxrstor [eax] |
||
393 | jmp @F |
||
203 | serge | 394 | .no_SSE: |
2434 | Serge | 395 | fnclex |
396 | frstor [eax] |
||
357 | serge | 397 | @@: |
203 | serge | 398 | |
2434 | Serge | 399 | mov [KEY_COUNT], byte 0 ; empty keyboard buffer |
400 | mov [BTN_COUNT], byte 0 ; empty button buffer |
||
1 | ha | 401 | |
402 | |||
92 | diamond | 403 | ; remove defined hotkeys |
1056 | Galkov | 404 | mov eax, hotkey_list |
92 | diamond | 405 | .loop: |
1056 | Galkov | 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] |
||
92 | diamond | 412 | @@: |
1056 | Galkov | 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 |
||
92 | diamond | 421 | .cont: |
1056 | Galkov | 422 | add eax, 16 |
423 | cmp eax, hotkey_list+256*16 |
||
424 | jb .loop |
||
2987 | Serge | 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 | @@: |
||
92 | diamond | 436 | ; remove hotkeys in buffer |
1056 | Galkov | 437 | mov eax, hotkey_buffer |
92 | diamond | 438 | .loop2: |
1056 | Galkov | 439 | cmp [eax], esi |
440 | jnz .cont2 |
||
441 | and dword [eax+4], 0 |
||
442 | and dword [eax], 0 |
||
92 | diamond | 443 | .cont2: |
1056 | Galkov | 444 | add eax, 8 |
445 | cmp eax, hotkey_buffer+120*8 |
||
446 | jb .loop2 |
||
92 | diamond | 447 | |
2434 | Serge | 448 | mov ecx, esi ; remove buttons |
1 | ha | 449 | bnewba2: |
2434 | Serge | 450 | mov edi, [BTN_ADDR] |
451 | mov eax, edi |
||
452 | cld |
||
453 | movzx ebx, word [edi] |
||
454 | inc bx |
||
1 | ha | 455 | bnewba: |
2434 | Serge | 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 |
||
1 | ha | 471 | bnmba: |
472 | |||
2434 | Serge | 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 |
||
1 | ha | 485 | |
2434 | Serge | 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 |
||
1 | ha | 499 | |
40 | halyavin | 500 | ; debuggee test |
2434 | Serge | 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 |
||
40 | halyavin | 514 | .nodebug: |
2434 | Serge | 515 | popad |
40 | halyavin | 516 | |
2434 | Serge | 517 | mov ebx, [.slot] |
518 | shl ebx, 8 |
||
519 | push ebx |
||
520 | mov ebx, [SLOT_BASE+ebx+APPDATA.pl0_stack] |
||
1 | ha | 521 | |
2434 | Serge | 522 | stdcall kernel_free, ebx |
1 | ha | 523 | |
2434 | Serge | 524 | pop ebx |
525 | mov ebx, [SLOT_BASE+ebx+APPDATA.cur_dir] |
||
526 | stdcall kernel_free, ebx |
||
521 | diamond | 527 | |
2434 | Serge | 528 | mov edi, [.slot] |
529 | shl edi, 8 |
||
530 | add edi, SLOT_BASE |
||
465 | serge | 531 | |
2434 | Serge | 532 | mov eax, [edi+APPDATA.io_map] |
533 | cmp eax, [SLOT_BASE+256+APPDATA.io_map] |
||
534 | je @F |
||
535 | call free_page |
||
465 | serge | 536 | @@: |
2434 | Serge | 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 |
||
465 | serge | 541 | @@: |
2434 | Serge | 542 | mov eax, 0x20202020 |
543 | stosd |
||
544 | stosd |
||
545 | stosd |
||
546 | mov ecx, 244/4 |
||
547 | xor eax, eax |
||
548 | rep stosd |
||
1 | ha | 549 | |
102 | poddubny | 550 | ; activate window |
2434 | Serge | 551 | movzx eax, word [WIN_STACK + esi*2] |
552 | cmp eax, [TASK_COUNT] |
||
553 | jne .dont_activate |
||
1056 | Galkov | 554 | pushad |
102 | poddubny | 555 | .check_next_window: |
2434 | Serge | 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 |
||
154 | diamond | 565 | ; \begin{diamond}[19.09.2006] |
566 | ; skip minimized windows |
||
2434 | Serge | 567 | test [edi + WDATA.fl_wstate], WSTATE_MINIMIZED |
568 | jnz .check_next_window |
||
154 | diamond | 569 | ; \end{diamond} |
2434 | Serge | 570 | call waredraw |
102 | poddubny | 571 | .nothing_to_activate: |
1056 | Galkov | 572 | popad |
102 | poddubny | 573 | .dont_activate: |
574 | |||
1056 | Galkov | 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 |
||
1306 | Lrz | 581 | and [hd1_status], 0 |
92 | diamond | 582 | @@: |
1056 | Galkov | 583 | cmp [cd_status], esi |
584 | jnz @f |
||
585 | call free_cd_channel |
||
1306 | Lrz | 586 | and [cd_status], 0 |
92 | diamond | 587 | @@: |
1056 | Galkov | 588 | cmp [flp_status], esi |
589 | jnz @f |
||
1306 | Lrz | 590 | and [flp_status], 0 |
92 | diamond | 591 | @@: |
1056 | Galkov | 592 | pop esi |
593 | cmp [bgrlockpid], esi |
||
594 | jnz @f |
||
595 | and [bgrlockpid], 0 |
||
1306 | Lrz | 596 | and [bgrlock], 0 |
546 | diamond | 597 | @@: |
1 | ha | 598 | |
2434 | Serge | 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] |
||
1 | ha | 604 | |
605 | rmpr0: |
||
606 | |||
2434 | Serge | 607 | mov esi, [RESERVED_PORTS] |
1 | ha | 608 | |
2434 | Serge | 609 | test esi, esi |
610 | jz rmpr9 |
||
1 | ha | 611 | |
612 | rmpr3: |
||
613 | |||
2434 | Serge | 614 | mov edi, esi |
615 | shl edi, 4 |
||
616 | add edi, RESERVED_PORTS |
||
1 | ha | 617 | |
2434 | Serge | 618 | cmp edx, [edi] |
619 | je rmpr4 |
||
1 | ha | 620 | |
2434 | Serge | 621 | dec esi |
622 | jnz rmpr3 |
||
1 | ha | 623 | |
2434 | Serge | 624 | jmp rmpr9 |
1 | ha | 625 | |
626 | rmpr4: |
||
627 | |||
2434 | Serge | 628 | mov ecx, 256 |
629 | sub ecx, esi |
||
630 | shl ecx, 4 |
||
1 | ha | 631 | |
2434 | Serge | 632 | mov esi, edi |
633 | add esi, 16 |
||
634 | cld |
||
635 | rep movsb |
||
1 | ha | 636 | |
2434 | Serge | 637 | dec dword [RESERVED_PORTS] |
1 | ha | 638 | |
2434 | Serge | 639 | jmp rmpr0 |
1 | ha | 640 | |
641 | rmpr9: |
||
642 | |||
2434 | Serge | 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 |
||
40 | halyavin | 647 | ; debugger test - terminate all debuggees |
2434 | Serge | 648 | mov eax, 2 |
649 | mov ecx, SLOT_BASE+2*0x100+APPDATA.debugger_slot |
||
40 | halyavin | 650 | .xd0: |
2434 | Serge | 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 |
||
40 | halyavin | 661 | @@: |
2434 | Serge | 662 | inc eax |
663 | add ecx, 0x100 |
||
664 | jmp .xd0 |
||
40 | halyavin | 665 | .xd1: |
1 | ha | 666 | ; call systest |
2434 | Serge | 667 | sti ; .. and life goes on |
1 | ha | 668 | |
2434 | Serge | 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 |
||
1 | ha | 677 | |
3555 | Serge | 678 | call unlock_application_table |
506 | mikedld | 679 | ;mov esi,process_terminated |
680 | ;call sys_msg_board_str |
||
2434 | Serge | 681 | add esp, 4 |
682 | ret |
||
345 | serge | 683 | restore .slot |
1 | ha | 684 | |
2987 | Serge | 685 | ;build_scheduler: |
686 | ; mov esi, boot_sched_1 |
||
687 | ; call boot_log |
||
688 | ; call build_process_gdt_tss_pointer |
||
1 | ha | 689 | |
2987 | Serge | 690 | ; mov esi,boot_sched_2 |
691 | ; call boot_log |
||
692 | ; ret |
||
3500 | Serge | 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 |