Rev 1638 | Rev 2106 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
431 | serge | 1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;; ;; |
||
709 | diamond | 3 | ;; Copyright (C) KolibriOS team 2004-2008. 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: 2010 $ |
15 | |||
16 | |||
1056 | Galkov | 17 | align 4 ;3A08 |
1 | ha | 18 | build_interrupt_table: |
1056 | Galkov | 19 | mov edi, idts |
20 | mov esi, sys_int |
||
21 | mov ecx, 0x40 |
||
22 | mov eax, (10001110b shl 24) + os_code |
||
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 |
||
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) |
1638 | serge | 42 | ; 0x20 .. 0x2F - IRQ handlers |
1056 | Galkov | 43 | dd irq0, irq_serv.irq_1, irq_serv.irq_2 |
44 | if USE_COM_IRQ |
||
45 | dd irq_serv.irq_3, irq_serv.irq_4 |
||
46 | else |
||
47 | dd p_irq3, p_irq4 ;??? нестыковка |
||
48 | end if |
||
2010 | serge | 49 | dd irq_serv.irq_5, irq_serv.irq_6, irq_serv.irq_7 |
1056 | Galkov | 50 | dd irq_serv.irq_8, irq_serv.irq_9, irq_serv.irq_10 |
2010 | serge | 51 | dd irq_serv.irq_11, irq_serv.irq_12, irqD, irq_serv.irq_14, irq_serv.irq_15 |
1638 | serge | 52 | ; I don`t known how to use IRQ_RESERVE |
53 | if IRQ_RESERVE > 16 |
||
54 | dd irq_serv.irq_16 |
||
55 | dd irq_serv.irq_17 |
||
56 | dd irq_serv.irq_18 |
||
57 | dd irq_serv.irq_19 |
||
58 | dd irq_serv.irq_20 |
||
59 | dd irq_serv.irq_21 |
||
60 | dd irq_serv.irq_22 |
||
61 | dd irq_serv.irq_23 |
||
62 | end if |
||
1 | ha | 63 | |
1638 | serge | 64 | times 32 - IRQ_RESERVE dd unknown_interrupt |
1056 | Galkov | 65 | ;int_0x40 gate trap (for directly copied) |
66 | dw i40 and 0xFFFF, os_code, 11101111b shl 8, i40 shr 16 |
||
656 | mikedld | 67 | |
1076 | Galkov | 68 | idtreg: ; data for LIDT instruction (!!! must be immediately below sys_int data) |
1056 | Galkov | 69 | dw 2*($-sys_int-4)-1 |
70 | dd idts ;0x8000B100 |
||
71 | dw 0 ;просто выравнивание |
||
656 | mikedld | 72 | |
1056 | Galkov | 73 | msg_fault_sel dd msg_exc_8,msg_exc_u,msg_exc_a,msg_exc_b |
74 | dd msg_exc_c,msg_exc_d,msg_exc_e |
||
164 | serge | 75 | |
1056 | Galkov | 76 | msg_exc_8 db "Double fault", 0 |
77 | msg_exc_u db "Undefined Exception", 0 |
||
78 | msg_exc_a db "Invalid TSS", 0 |
||
79 | msg_exc_b db "Segment not present", 0 |
||
80 | msg_exc_c db "Stack fault", 0 |
||
81 | msg_exc_d db "General protection fault", 0 |
||
82 | msg_exc_e db "Page fault", 0 |
||
1 | ha | 83 | |
1056 | Galkov | 84 | msg_sel_ker db "kernel", 0 |
85 | msg_sel_app db "application", 0 |
||
1 | ha | 86 | |
87 | endg |
||
88 | |||
1056 | Galkov | 89 | macro save_ring3_context { |
90 | pushad |
||
40 | halyavin | 91 | } |
1056 | Galkov | 92 | macro restore_ring3_context { |
93 | popad |
||
40 | halyavin | 94 | } |
1056 | Galkov | 95 | macro exc_wo_code [num] { |
8 | poddubny | 96 | e#num : |
1056 | Galkov | 97 | save_ring3_context |
98 | mov bl, num |
||
99 | jmp exc_c |
||
100 | } exc_wo_code 0,1,2,3,4,5,6,15,16,19 |
||
1 | ha | 101 | |
1056 | Galkov | 102 | macro exc_w_code [num] { |
22 | poddubny | 103 | e#num : |
1056 | Galkov | 104 | add esp, 4 |
105 | save_ring3_context |
||
106 | mov bl, num |
||
107 | jmp exc_c |
||
108 | } exc_w_code 8,9,10,11,12,13,17,18 |
||
22 | poddubny | 109 | |
110 | |||
1056 | Galkov | 111 | uglobal |
112 | pf_err_code dd ? |
||
113 | endg |
||
1 | ha | 114 | |
1086 | Galkov | 115 | page_fault_exc: ; дуракоусточивость: селекторы испорчены... |
116 | pop [ss:pf_err_code]; действительно до следующего #PF |
||
1056 | Galkov | 117 | save_ring3_context |
118 | mov bl,14 |
||
1086 | Galkov | 119 | |
120 | exc_c: ; исключения (все, кроме 7-го - #NM) |
||
1056 | Galkov | 121 | ; Фрэйм стека при исключении/прерывании из 3-го кольца + pushad (т.е., именно здесь) |
122 | reg_ss equ esp+0x30 |
||
123 | reg_esp3 equ esp+0x2C |
||
124 | reg_eflags equ esp+0x28 |
||
125 | reg_cs3 equ esp+0x24 |
||
126 | reg_eip equ esp+0x20 |
||
127 | ; это фрэйм от pushad |
||
128 | reg_eax equ esp+0x1C |
||
129 | reg_ecx equ esp+0x18 |
||
130 | reg_edx equ esp+0x14 |
||
131 | reg_ebx equ esp+0x10 |
||
132 | reg_esp0 equ esp+0x0C |
||
133 | reg_ebp equ esp+0x08 |
||
134 | reg_esi equ esp+0x04 |
||
135 | reg_edi equ esp+0x00 |
||
136 | |||
1638 | serge | 137 | mov ax, app_data ;исключение |
138 | mov ds, ax ;загрузим правильные значени |
||
139 | mov es, ax ;в регистры |
||
1056 | Galkov | 140 | cld ; и приводим DF к стандарту |
1074 | Galkov | 141 | movzx ebx,bl |
709 | diamond | 142 | ; redirect to V86 manager? (EFLAGS & 0x20000) != 0? |
1056 | Galkov | 143 | test byte[reg_eflags+2],2 |
144 | jnz v86_exc_c |
||
145 | cmp bl,14 ; #PF |
||
1074 | Galkov | 146 | jne @f |
1076 | Galkov | 147 | call page_fault_handler ; SEE: core/memory.inc |
1074 | Galkov | 148 | @@: mov esi, [current_slot] |
149 | btr [esi+APPDATA.except_mask], ebx |
||
150 | jnc @f |
||
151 | mov eax,[esi+APPDATA.exc_handler] |
||
152 | test eax, eax |
||
1056 | Galkov | 153 | jnz IRetToUserHook |
1074 | Galkov | 154 | @@: cli |
1056 | Galkov | 155 | mov eax, [esi+APPDATA.debugger_slot] |
156 | test eax, eax |
||
157 | jnz .debug |
||
158 | sti |
||
40 | halyavin | 159 | ; not debuggee => say error and terminate |
1056 | Galkov | 160 | call show_error_parameters ;; only ONE using, inline ??? |
161 | ;mov edx, [TASK_BASE] |
||
162 | mov [edx + TASKDATA.state], byte 4 ; terminate |
||
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 |
||
1076 | Galkov | 167 | mov ecx,1 ; debug_message code=other_exception |
1056 | Galkov | 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 |
||
175 | .l1: shl dl,2 |
||
176 | jc @f |
||
177 | and bl, cl |
||
178 | @@: sar cl,1 |
||
179 | jc .l1 |
||
180 | mov cl, 3 ; debug_message code=debug_exception |
||
181 | .notify: |
||
182 | push ebx ; debug_message data |
||
183 | mov ebx, [TASK_BASE] |
||
184 | push [ebx+TASKDATA.pid] ; PID |
||
185 | push ecx ; debug_message code ((here: ecx==1/3)) |
||
186 | mov cl, 12 ; debug_message size |
||
187 | call debugger_notify ;; only ONE using, inline ??? SEE: core/debug.inc |
||
188 | add esp,12 |
||
189 | mov edx, [TASK_BASE] |
||
190 | mov byte [edx+TASKDATA.state], 1 ; suspended |
||
191 | call change_task ; SEE: core/shed.inc |
||
192 | restore_ring3_context |
||
193 | iretd |
||
1 | ha | 194 | |
1056 | Galkov | 195 | IRetToUserHook: |
196 | xchg eax, [reg_eip] |
||
1074 | Galkov | 197 | sub dword[reg_esp3], 8 |
1056 | Galkov | 198 | mov edi, [reg_esp3] |
199 | stosd |
||
1074 | Galkov | 200 | mov [edi], ebx |
1056 | Galkov | 201 | restore_ring3_context |
1638 | serge | 202 | ; simply return control to interrupted process |
1056 | Galkov | 203 | unknown_interrupt: |
204 | iretd |
||
1 | ha | 205 | |
658 | Ghost | 206 | ;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= |
1638 | serge | 207 | ; bl - error vector |
1 | ha | 208 | show_error_parameters: |
2010 | serge | 209 | cmp bl, 0x06 |
210 | jnz .no_ud |
||
211 | push ebx |
||
212 | mov ebx, ud_user_message |
||
213 | mov ebp, notifyapp |
||
214 | call fs_execute_from_sysdir_param |
||
215 | pop ebx |
||
216 | .no_ud: |
||
1056 | Galkov | 217 | mov edx,[TASK_BASE] ;not scratched below |
218 | DEBUGF 1, "K : Process - forced terminate PID: %x\n", [edx+TASKDATA.pid] |
||
219 | cmp bl, 0x08 |
||
220 | jb .l0 |
||
221 | cmp bl, 0x0e |
||
222 | jbe .l1 |
||
223 | .l0: mov bl, 0x09 |
||
1074 | Galkov | 224 | .l1: mov eax,[msg_fault_sel+ebx*4 - 0x08*4] |
1056 | Galkov | 225 | DEBUGF 1, "K : %s\n", eax |
226 | mov eax, [reg_cs3+4] |
||
227 | mov edi, msg_sel_app |
||
228 | mov ebx, [reg_esp3+4] |
||
229 | cmp eax, app_code |
||
230 | je @f |
||
231 | mov edi, msg_sel_ker |
||
232 | mov ebx, [reg_esp0+4] |
||
233 | @@: DEBUGF 1, "K : EAX : %x EBX : %x ECX : %x\n", [reg_eax+4], [reg_ebx+4], [reg_ecx+4] |
||
234 | DEBUGF 1, "K : EDX : %x ESI : %x EDI : %x\n", [reg_edx+4], [reg_esi+4], [reg_edi+4] |
||
235 | DEBUGF 1, "K : EBP : %x EIP : %x ESP : %x\n", [reg_ebp+4], [reg_eip+4], ebx |
||
236 | DEBUGF 1, "K : Flags : %x CS : %x (%s)\n", [reg_eflags+4], eax, edi |
||
237 | ret |
||
658 | Ghost | 238 | ;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= |
164 | serge | 239 | |
1056 | Galkov | 240 | restore reg_ss |
241 | restore reg_esp3 |
||
242 | restore reg_eflags |
||
243 | restore reg_cs |
||
244 | restore reg_eip |
||
245 | restore reg_eax |
||
246 | restore reg_ecx |
||
247 | restore reg_edx |
||
248 | restore reg_ebx |
||
249 | restore reg_esp0 |
||
250 | restore reg_ebp |
||
251 | restore reg_esi |
||
252 | restore reg_edi |
||
16 | poddubny | 253 | |
1638 | serge | 254 | ; IRQ runtime |
255 | |||
6 | poddubny | 256 | ; irq1 -> hid/keyboard.inc |
1056 | Galkov | 257 | macro irqh [num] { |
8 | poddubny | 258 | p_irq#num : |
1056 | Galkov | 259 | mov edi, num |
260 | jmp irqhandler |
||
8 | poddubny | 261 | } |
1 | ha | 262 | |
1638 | serge | 263 | irqh 2,3,4,5,7,8,9,10,11 |
264 | ; I don`t known how to use IRQ_RESERVE |
||
265 | if IRQ_RESERVE > 16 |
||
266 | irqh 16, 17, 18, 19, 20, 21, 22, 23 |
||
267 | end if |
||
1 | ha | 268 | |
1638 | serge | 269 | p_irq6: ; FDC |
980 | diamond | 270 | save_ring3_context |
271 | mov ax, app_data ;os_data |
||
272 | mov ds, ax |
||
273 | mov es, ax |
||
982 | diamond | 274 | mov edi, 6 |
980 | diamond | 275 | cmp [v86_irqhooks+edi*8], 0 |
276 | jnz v86_irq2 |
||
277 | call fdc_irq |
||
1638 | serge | 278 | mov [check_idle_semaphore], 5 |
279 | mov al, 6 |
||
280 | call IRQ_EOI |
||
980 | diamond | 281 | restore_ring3_context |
282 | iret |
||
15 | poddubny | 283 | |
1638 | serge | 284 | irq13: ; Math coprocessor |
285 | save_ring3_context |
||
286 | mov ax, app_data ;os_data |
||
287 | mov ds, ax |
||
288 | mov es, ax |
||
15 | poddubny | 289 | |
1638 | serge | 290 | mov dx, 0xf0 |
291 | mov al, 0 |
||
292 | out dx, al |
||
293 | |||
294 | mov al, 13 |
||
295 | call IRQ_EOI |
||
296 | restore_ring3_context |
||
297 | iret |
||
298 | |||
299 | p_irq14: ; HDD |
||
1056 | Galkov | 300 | save_ring3_context |
301 | mov ax, app_data ;os_data |
||
302 | mov ds, ax |
||
303 | mov es, ax |
||
304 | mov edi, 14 |
||
305 | cmp [v86_irqhooks+edi*8], 0 |
||
306 | jnz v86_irq2 |
||
307 | ; mov byte [BOOT_VAR + 0x48E], 0xFF |
||
308 | call [irq14_func] |
||
1638 | serge | 309 | mov [check_idle_semaphore], 5 |
310 | mov al, 14 |
||
311 | call IRQ_EOI |
||
1056 | Galkov | 312 | restore_ring3_context |
313 | iret |
||
1638 | serge | 314 | |
315 | p_irq15: ; HDD2 |
||
1056 | Galkov | 316 | save_ring3_context |
317 | mov ax, app_data ;os_data |
||
318 | mov ds, ax |
||
319 | mov es, ax |
||
320 | mov edi, 15 |
||
321 | cmp [v86_irqhooks+edi*8], 0 |
||
322 | jnz v86_irq2 |
||
323 | ; mov byte [BOOT_VAR + 0x48E], 0xFF |
||
324 | call [irq15_func] |
||
1638 | serge | 325 | mov [check_idle_semaphore], 5 |
326 | mov al, 15 |
||
327 | call IRQ_EOI |
||
1056 | Galkov | 328 | restore_ring3_context |
329 | iret |
||
160 | diamond | 330 | |
33 | mario79 | 331 | ready_for_next_irq: |
1306 | Lrz | 332 | mov eax,5 |
333 | mov [check_idle_semaphore],eax |
||
334 | ; mov al, 0x20 |
||
335 | add eax,(0x20-0x5) |
||
336 | |||
1056 | Galkov | 337 | out 0x20, al |
338 | ret |
||
1306 | Lrz | 339 | ;destroy eax |
33 | mario79 | 340 | ready_for_next_irq_1: |
1306 | Lrz | 341 | mov eax,5 |
342 | mov [check_idle_semaphore],eax |
||
343 | ; mov al, 0x20 |
||
344 | add eax,(0x20-0x5) |
||
1056 | Galkov | 345 | out 0xa0,al |
346 | out 0x20, al |
||
347 | ret |
||
33 | mario79 | 348 | |
6 | poddubny | 349 | irqD: |
1056 | Galkov | 350 | push eax |
1306 | Lrz | 351 | xor eax,eax |
1056 | Galkov | 352 | out 0xf0,al |
353 | mov al,0x20 |
||
354 | out 0xa0,al |
||
355 | out 0x20,al |
||
356 | pop eax |
||
357 | iret |
||
164 | serge | 358 | |
1 | ha | 359 | |
1638 | serge | 360 | align 4 |
40 | halyavin | 361 | |
1 | ha | 362 | irqhandler: |
363 | |||
1056 | Galkov | 364 | mov esi,edi ; 1 |
365 | shl esi,6 ; 1 |
||
1 | ha | 366 | add esi,irq00read ; 1 |
1056 | Galkov | 367 | shl edi,12 ; 1 |
381 | serge | 368 | add edi,IRQ_SAVE |
75 | diamond | 369 | mov ecx,16 |
1 | ha | 370 | |
371 | irqnewread: |
||
75 | diamond | 372 | dec ecx |
373 | js irqover |
||
1 | ha | 374 | |
1056 | Galkov | 375 | movzx edx, word [esi] ; 2+ |
1 | ha | 376 | |
1056 | Galkov | 377 | test edx, edx ; 1 |
1 | ha | 378 | jz irqover |
379 | |||
380 | |||
1056 | Galkov | 381 | mov ebx, [edi] ; address of begin of buffer in edi ; + 0x0 dword - data size |
382 | mov eax, 4000 ; + 0x4 dword - data begin offset |
||
759 | Rus | 383 | cmp ebx, eax |
1 | ha | 384 | je irqfull |
1056 | Galkov | 385 | add ebx, [edi + 0x4] ; add data size to data begin offset |
386 | cmp ebx, eax ; if end of buffer, begin cycle again |
||
759 | Rus | 387 | jb @f |
1 | ha | 388 | |
759 | Rus | 389 | xor ebx, ebx |
1 | ha | 390 | |
759 | Rus | 391 | @@: |
392 | add ebx, edi |
||
1056 | Galkov | 393 | movzx eax, byte[esi + 3] ; get type of data being received 1 - byte, 2 - word |
759 | Rus | 394 | dec eax |
395 | jz irqbyte |
||
396 | dec eax |
||
397 | jnz noirqword |
||
1 | ha | 398 | |
759 | Rus | 399 | in ax,dx |
1056 | Galkov | 400 | cmp ebx, 3999 ; check for address odd in the end of buffer |
759 | Rus | 401 | jne .odd |
402 | mov [ebx + 0x10], ax |
||
403 | jmp .add_size |
||
404 | .odd: |
||
1056 | Galkov | 405 | mov [ebx + 0x10], al ; I could make mistake here :) |
759 | Rus | 406 | mov [edi + 0x10], ah |
407 | .add_size: |
||
408 | add dword [edi], 2 |
||
409 | jmp nextport |
||
1 | ha | 410 | |
411 | |||
759 | Rus | 412 | irqbyte: |
413 | in al,dx |
||
414 | mov [ebx + 0x10],al |
||
415 | inc dword [edi] |
||
416 | nextport: |
||
1 | ha | 417 | add esi,4 |
418 | jmp irqnewread |
||
419 | |||
759 | Rus | 420 | |
1 | ha | 421 | noirqword: |
422 | irqfull: |
||
423 | irqover: |
||
424 | |||
425 | ret |
||
426 | |||
427 | |||
428 | |||
429 | set_application_table_status: |
||
1056 | Galkov | 430 | push eax |
1 | ha | 431 | |
1056 | Galkov | 432 | mov eax,[CURRENT_TASK] |
433 | shl eax, 5 |
||
434 | add eax,CURRENT_TASK+TASKDATA.pid |
||
435 | mov eax,[eax] |
||
1 | ha | 436 | |
1056 | Galkov | 437 | mov [application_table_status],eax |
1 | ha | 438 | |
1056 | Galkov | 439 | pop eax |
1 | ha | 440 | |
1056 | Galkov | 441 | ret |
1 | ha | 442 | |
443 | |||
444 | clear_application_table_status: |
||
1056 | Galkov | 445 | push eax |
1 | ha | 446 | |
1056 | Galkov | 447 | mov eax,[CURRENT_TASK] |
448 | shl eax, 5 |
||
449 | add eax,CURRENT_TASK+TASKDATA.pid |
||
450 | mov eax,[eax] |
||
1 | ha | 451 | |
1056 | Galkov | 452 | cmp eax,[application_table_status] |
453 | jne apptsl1 |
||
1306 | Lrz | 454 | xor eax,eax |
455 | mov [application_table_status],eax |
||
1 | ha | 456 | apptsl1: |
457 | |||
1056 | Galkov | 458 | pop eax |
1 | ha | 459 | |
1056 | Galkov | 460 | ret |
1 | ha | 461 | |
1306 | Lrz | 462 | ; * eax = 64 - номер функции |
463 | ; * ebx = 1 - единственная подфункция |
||
464 | ; * ecx = новый размер памяти |
||
465 | ;Возвращаемое значение: |
||
466 | ; * eax = 0 - успешно |
||
467 | ; * eax = 1 - недостаточно памяти |
||
468 | |||
1 | ha | 469 | sys_resize_app_memory: |
1306 | Lrz | 470 | ; ebx = 1 - resize |
471 | ; ecx = new amount of memory |
||
1 | ha | 472 | |
1306 | Lrz | 473 | ; cmp eax,1 |
474 | dec ebx |
||
475 | jnz .no_application_mem_resize |
||
1307 | Lrz | 476 | stdcall new_mem_resize, ecx |
1306 | Lrz | 477 | mov [esp+32], eax |
164 | serge | 478 | .no_application_mem_resize: |
1056 | Galkov | 479 | ret |
1 | ha | 480 | |
481 | iglobal |
||
1056 | Galkov | 482 | ; process_terminating db 'K : Process - terminating',13,10,0 |
483 | ; process_terminated db 'K : Process - done',13,10,0 |
||
484 | msg_obj_destroy db 'K : destroy app object',13,10,0 |
||
1 | ha | 485 | endg |
486 | |||
329 | serge | 487 | ; param |
488 | ; esi= slot |
||
1 | ha | 489 | |
490 | terminate: ; terminate application |
||
491 | |||
1056 | Galkov | 492 | .slot equ esp ;locals |
329 | serge | 493 | |
1056 | Galkov | 494 | push esi ;save .slot |
334 | serge | 495 | |
1056 | Galkov | 496 | shl esi, 8 |
497 | cmp [SLOT_BASE+esi+APPDATA.dir_table], 0 |
||
498 | jne @F |
||
499 | pop esi |
||
500 | shl esi, 5 |
||
501 | mov [CURRENT_TASK+esi+TASKDATA.state], 9 |
||
502 | ret |
||
334 | serge | 503 | @@: |
1056 | Galkov | 504 | ;mov esi,process_terminating |
505 | ;call sys_msg_board_str |
||
40 | halyavin | 506 | @@: |
1056 | Galkov | 507 | cli |
508 | cmp [application_table_status],0 |
||
509 | je term9 |
||
510 | sti |
||
511 | call change_task |
||
512 | jmp @b |
||
329 | serge | 513 | term9: |
1056 | Galkov | 514 | call set_application_table_status |
1 | ha | 515 | |
709 | diamond | 516 | ; if the process is in V86 mode... |
1056 | Galkov | 517 | mov eax, [.slot] |
518 | shl eax, 8 |
||
519 | mov esi, [eax+SLOT_BASE+APPDATA.pl0_stack] |
||
520 | add esi, RING0_STACK_SIZE |
||
521 | cmp [eax+SLOT_BASE+APPDATA.saved_esp0], esi |
||
522 | jz .nov86 |
||
709 | diamond | 523 | ; ...it has page directory for V86 mode |
1056 | Galkov | 524 | mov esi, [eax+SLOT_BASE+APPDATA.saved_esp0] |
525 | mov ecx, [esi+4] |
||
526 | mov [eax+SLOT_BASE+APPDATA.dir_table], ecx |
||
709 | diamond | 527 | ; ...and I/O permission map for V86 mode |
1056 | Galkov | 528 | mov ecx, [esi+12] |
529 | mov [eax+SLOT_BASE+APPDATA.io_map], ecx |
||
530 | mov ecx, [esi+8] |
||
531 | mov [eax+SLOT_BASE+APPDATA.io_map+4], ecx |
||
709 | diamond | 532 | .nov86: |
533 | |||
1056 | Galkov | 534 | mov esi, [.slot] |
535 | shl esi,8 |
||
536 | add esi, SLOT_BASE+APP_OBJ_OFFSET |
||
329 | serge | 537 | @@: |
1056 | Galkov | 538 | mov eax, [esi+APPOBJ.fd] |
539 | test eax, eax |
||
540 | jz @F |
||
334 | serge | 541 | |
1056 | Galkov | 542 | cmp eax, esi |
543 | je @F |
||
164 | serge | 544 | |
1056 | Galkov | 545 | push esi |
546 | call [eax+APPOBJ.destroy] |
||
547 | DEBUGF 1,"%s",msg_obj_destroy |
||
548 | pop esi |
||
549 | jmp @B |
||
329 | serge | 550 | @@: |
1311 | diamond | 551 | |
1056 | Galkov | 552 | mov eax, [.slot] |
553 | shl eax, 8 |
||
1311 | diamond | 554 | stdcall destroy_app_space, [SLOT_BASE+eax+APPDATA.dir_table], [SLOT_BASE+eax+APPDATA.dlls_list_ptr] |
1 | ha | 555 | |
1056 | Galkov | 556 | mov esi, [.slot] |
557 | cmp [fpu_owner],esi ; if user fpu last -> fpu user = 1 |
||
558 | jne @F |
||
164 | serge | 559 | |
1056 | Galkov | 560 | mov [fpu_owner],1 |
561 | mov eax, [256+SLOT_BASE+APPDATA.fpu_state] |
||
562 | clts |
||
563 | bt [cpu_caps], CAPS_SSE |
||
564 | jnc .no_SSE |
||
565 | fxrstor [eax] |
||
566 | jmp @F |
||
203 | serge | 567 | .no_SSE: |
1056 | Galkov | 568 | fnclex |
569 | frstor [eax] |
||
357 | serge | 570 | @@: |
203 | serge | 571 | |
1056 | Galkov | 572 | mov [KEY_COUNT],byte 0 ; empty keyboard buffer |
573 | mov [BTN_COUNT],byte 0 ; empty button buffer |
||
1 | ha | 574 | |
575 | |||
92 | diamond | 576 | ; remove defined hotkeys |
1056 | Galkov | 577 | mov eax, hotkey_list |
92 | diamond | 578 | .loop: |
1056 | Galkov | 579 | cmp [eax+8], esi |
580 | jnz .cont |
||
581 | mov ecx, [eax] |
||
582 | jecxz @f |
||
583 | push dword [eax+12] |
||
584 | pop dword [ecx+12] |
||
92 | diamond | 585 | @@: |
1056 | Galkov | 586 | mov ecx, [eax+12] |
587 | push dword [eax] |
||
588 | pop dword [ecx] |
||
589 | xor ecx, ecx |
||
590 | mov [eax], ecx |
||
591 | mov [eax+4], ecx |
||
592 | mov [eax+8], ecx |
||
593 | mov [eax+12], ecx |
||
92 | diamond | 594 | .cont: |
1056 | Galkov | 595 | add eax, 16 |
596 | cmp eax, hotkey_list+256*16 |
||
597 | jb .loop |
||
92 | diamond | 598 | ; remove hotkeys in buffer |
1056 | Galkov | 599 | mov eax, hotkey_buffer |
92 | diamond | 600 | .loop2: |
1056 | Galkov | 601 | cmp [eax], esi |
602 | jnz .cont2 |
||
603 | and dword [eax+4], 0 |
||
604 | and dword [eax], 0 |
||
92 | diamond | 605 | .cont2: |
1056 | Galkov | 606 | add eax, 8 |
607 | cmp eax, hotkey_buffer+120*8 |
||
608 | jb .loop2 |
||
92 | diamond | 609 | |
1056 | Galkov | 610 | mov ecx,esi ; remove buttons |
1 | ha | 611 | bnewba2: |
381 | serge | 612 | mov edi,[BTN_ADDR] |
1 | ha | 613 | mov eax,edi |
614 | cld |
||
615 | movzx ebx,word [edi] |
||
616 | inc bx |
||
617 | bnewba: |
||
618 | dec bx |
||
1056 | Galkov | 619 | jz bnmba |
1 | ha | 620 | add eax,0x10 |
621 | cmp cx,[eax] |
||
622 | jnz bnewba |
||
623 | pusha |
||
624 | mov ecx,ebx |
||
625 | inc ecx |
||
626 | shl ecx,4 |
||
627 | mov ebx,eax |
||
628 | add eax,0x10 |
||
629 | call memmove |
||
630 | dec dword [edi] |
||
631 | popa |
||
632 | jmp bnewba2 |
||
633 | bnmba: |
||
634 | |||
635 | pusha ; save window coordinates for window restoring |
||
636 | cld |
||
637 | shl esi,5 |
||
638 | add esi,window_data |
||
114 | mikedld | 639 | mov eax,[esi+WDATA.box.left] |
1362 | mikedld | 640 | mov [draw_limits.left],eax |
114 | mikedld | 641 | add eax,[esi+WDATA.box.width] |
1362 | mikedld | 642 | mov [draw_limits.right],eax |
114 | mikedld | 643 | mov eax,[esi+WDATA.box.top] |
1362 | mikedld | 644 | mov [draw_limits.top],eax |
114 | mikedld | 645 | add eax,[esi+WDATA.box.height] |
1362 | mikedld | 646 | mov [draw_limits.bottom],eax |
1 | ha | 647 | |
142 | diamond | 648 | xor eax, eax |
649 | mov [esi+WDATA.box.left],eax |
||
650 | mov [esi+WDATA.box.width],eax |
||
114 | mikedld | 651 | mov [esi+WDATA.box.top],eax |
142 | diamond | 652 | mov [esi+WDATA.box.height],eax |
115 | poddubny | 653 | mov [esi+WDATA.cl_workarea],eax |
654 | mov [esi+WDATA.cl_titlebar],eax |
||
655 | mov [esi+WDATA.cl_frames],eax |
||
656 | mov dword [esi+WDATA.reserved],eax ; clear all flags: wstate, redraw, wdrawn |
||
102 | poddubny | 657 | lea edi, [esi-window_data+draw_data] |
1 | ha | 658 | mov ecx,32/4 |
659 | rep stosd |
||
660 | popa |
||
661 | |||
40 | halyavin | 662 | ; debuggee test |
663 | pushad |
||
664 | mov edi, esi |
||
665 | shl edi, 5 |
||
380 | serge | 666 | mov eax, [SLOT_BASE+edi*8+APPDATA.debugger_slot] |
40 | halyavin | 667 | test eax, eax |
1056 | Galkov | 668 | jz .nodebug |
40 | halyavin | 669 | push 8 |
670 | pop ecx |
||
1056 | Galkov | 671 | push dword [CURRENT_TASK+edi+TASKDATA.pid] ; PID |
40 | halyavin | 672 | push 2 |
673 | call debugger_notify |
||
674 | pop ecx |
||
675 | pop ecx |
||
676 | .nodebug: |
||
677 | popad |
||
678 | |||
1056 | Galkov | 679 | mov ebx, [.slot] |
680 | shl ebx, 8 |
||
681 | push ebx |
||
682 | mov ebx,[SLOT_BASE+ebx+APPDATA.pl0_stack] |
||
1 | ha | 683 | |
1056 | Galkov | 684 | stdcall kernel_free, ebx |
1 | ha | 685 | |
1056 | Galkov | 686 | pop ebx |
687 | mov ebx,[SLOT_BASE+ebx+APPDATA.cur_dir] |
||
688 | stdcall kernel_free, ebx |
||
521 | diamond | 689 | |
1056 | Galkov | 690 | mov edi, [.slot] |
691 | shl edi,8 |
||
692 | add edi,SLOT_BASE |
||
465 | serge | 693 | |
1056 | Galkov | 694 | mov eax, [edi+APPDATA.io_map] |
1310 | diamond | 695 | cmp eax, [SLOT_BASE+256+APPDATA.io_map] |
1056 | Galkov | 696 | je @F |
697 | call free_page |
||
465 | serge | 698 | @@: |
1056 | Galkov | 699 | mov eax, [edi+APPDATA.io_map+4] |
1310 | diamond | 700 | cmp eax, [SLOT_BASE+256+APPDATA.io_map+4] |
1056 | Galkov | 701 | je @F |
702 | call free_page |
||
465 | serge | 703 | @@: |
1056 | Galkov | 704 | mov eax, 0x20202020 |
705 | stosd |
||
706 | stosd |
||
707 | stosd |
||
708 | mov ecx,244/4 |
||
709 | xor eax, eax |
||
710 | rep stosd |
||
1 | ha | 711 | |
102 | poddubny | 712 | ; activate window |
1056 | Galkov | 713 | movzx eax, word [WIN_STACK + esi*2] |
714 | cmp eax, [TASK_COUNT] |
||
715 | jne .dont_activate |
||
716 | pushad |
||
102 | poddubny | 717 | .check_next_window: |
1056 | Galkov | 718 | dec eax |
719 | cmp eax, 1 |
||
720 | jbe .nothing_to_activate |
||
721 | lea esi, [WIN_POS+eax*2] |
||
722 | movzx edi, word [esi] ; edi = process |
||
723 | shl edi, 5 |
||
724 | cmp [CURRENT_TASK + edi + TASKDATA.state], byte 9 ; skip dead slots |
||
725 | je .check_next_window |
||
726 | add edi, window_data |
||
154 | diamond | 727 | ; \begin{diamond}[19.09.2006] |
728 | ; skip minimized windows |
||
1056 | Galkov | 729 | test [edi + WDATA.fl_wstate], WSTATE_MINIMIZED |
730 | jnz .check_next_window |
||
154 | diamond | 731 | ; \end{diamond} |
1056 | Galkov | 732 | call waredraw |
102 | poddubny | 733 | .nothing_to_activate: |
1056 | Galkov | 734 | popad |
102 | poddubny | 735 | .dont_activate: |
736 | |||
1056 | Galkov | 737 | push esi ; remove hd1 & cd & flp reservation |
738 | shl esi, 5 |
||
739 | mov esi, [esi+CURRENT_TASK+TASKDATA.pid] |
||
740 | cmp [hd1_status], esi |
||
741 | jnz @f |
||
742 | call free_hd_channel |
||
1306 | Lrz | 743 | and [hd1_status], 0 |
92 | diamond | 744 | @@: |
1056 | Galkov | 745 | cmp [cd_status], esi |
746 | jnz @f |
||
747 | call free_cd_channel |
||
1306 | Lrz | 748 | and [cd_status], 0 |
92 | diamond | 749 | @@: |
1056 | Galkov | 750 | cmp [flp_status], esi |
751 | jnz @f |
||
1306 | Lrz | 752 | and [flp_status], 0 |
92 | diamond | 753 | @@: |
1056 | Galkov | 754 | pop esi |
755 | cmp [bgrlockpid], esi |
||
756 | jnz @f |
||
757 | and [bgrlockpid], 0 |
||
1306 | Lrz | 758 | and [bgrlock], 0 |
546 | diamond | 759 | @@: |
1 | ha | 760 | |
761 | pusha ; remove all irq reservations |
||
92 | diamond | 762 | mov eax,esi |
115 | poddubny | 763 | shl eax, 5 |
379 | serge | 764 | mov eax,[eax+CURRENT_TASK+TASKDATA.pid] |
1 | ha | 765 | mov edi,irq_owner |
774 | Rus | 766 | xor ebx, ebx |
767 | xor edx, edx |
||
1 | ha | 768 | newirqfree: |
774 | Rus | 769 | cmp [edi + 4 * ebx], eax |
1 | ha | 770 | jne nofreeirq |
1056 | Galkov | 771 | mov [edi + 4 * ebx], edx ; remove irq reservation |
772 | mov [irq_tab + 4 * ebx], edx ; remove irq handler |
||
773 | mov [irq_rights + 4 * ebx], edx ; set access rights to full access |
||
1 | ha | 774 | nofreeirq: |
774 | Rus | 775 | inc ebx |
776 | cmp ebx, 16 |
||
1056 | Galkov | 777 | jb newirqfree |
1 | ha | 778 | popa |
779 | |||
1056 | Galkov | 780 | pusha ; remove all port reservations |
1 | ha | 781 | mov edx,esi |
115 | poddubny | 782 | shl edx, 5 |
379 | serge | 783 | add edx,CURRENT_TASK |
115 | poddubny | 784 | mov edx,[edx+TASKDATA.pid] |
1 | ha | 785 | |
786 | rmpr0: |
||
787 | |||
381 | serge | 788 | mov esi,[RESERVED_PORTS] |
1 | ha | 789 | |
1306 | Lrz | 790 | test esi,esi |
791 | jz rmpr9 |
||
1 | ha | 792 | |
793 | rmpr3: |
||
794 | |||
795 | mov edi,esi |
||
796 | shl edi,4 |
||
381 | serge | 797 | add edi,RESERVED_PORTS |
1 | ha | 798 | |
799 | cmp edx,[edi] |
||
1056 | Galkov | 800 | je rmpr4 |
1 | ha | 801 | |
802 | dec esi |
||
803 | jnz rmpr3 |
||
804 | |||
805 | jmp rmpr9 |
||
806 | |||
807 | rmpr4: |
||
808 | |||
809 | mov ecx,256 |
||
810 | sub ecx,esi |
||
811 | shl ecx,4 |
||
812 | |||
813 | mov esi,edi |
||
814 | add esi,16 |
||
815 | cld |
||
816 | rep movsb |
||
817 | |||
381 | serge | 818 | dec dword [RESERVED_PORTS] |
1 | ha | 819 | |
820 | jmp rmpr0 |
||
821 | |||
822 | rmpr9: |
||
823 | |||
824 | popa |
||
1056 | Galkov | 825 | mov edi,esi ; do not run this process slot |
6 | poddubny | 826 | shl edi, 5 |
379 | serge | 827 | mov [edi+CURRENT_TASK + TASKDATA.state],byte 9 |
40 | halyavin | 828 | ; debugger test - terminate all debuggees |
829 | mov eax, 2 |
||
380 | serge | 830 | mov ecx, SLOT_BASE+2*0x100+APPDATA.debugger_slot |
40 | halyavin | 831 | .xd0: |
379 | serge | 832 | cmp eax, [TASK_COUNT] |
1056 | Galkov | 833 | ja .xd1 |
40 | halyavin | 834 | cmp dword [ecx], esi |
835 | jnz @f |
||
836 | and dword [ecx], 0 |
||
837 | pushad |
||
684 | diamond | 838 | xchg eax, ecx |
839 | mov ebx, 2 |
||
40 | halyavin | 840 | call sys_system |
841 | popad |
||
842 | @@: |
||
843 | inc eax |
||
844 | add ecx, 0x100 |
||
845 | jmp .xd0 |
||
846 | .xd1: |
||
1 | ha | 847 | ; call systest |
848 | sti ; .. and life goes on |
||
849 | |||
1362 | mikedld | 850 | mov eax, [draw_limits.left] |
851 | mov ebx, [draw_limits.top] |
||
852 | mov ecx, [draw_limits.right] |
||
853 | mov edx, [draw_limits.bottom] |
||
1 | ha | 854 | call calculatescreen |
855 | xor eax, eax |
||
856 | xor esi, esi |
||
857 | call redrawscreen |
||
858 | |||
381 | serge | 859 | mov [MOUSE_BACKGROUND],byte 0 ; no mouse background |
860 | mov [DONT_DRAW_MOUSE],byte 0 ; draw mouse |
||
1 | ha | 861 | |
1306 | Lrz | 862 | and [application_table_status],0 |
506 | mikedld | 863 | ;mov esi,process_terminated |
864 | ;call sys_msg_board_str |
||
357 | serge | 865 | add esp, 4 |
1 | ha | 866 | ret |
345 | serge | 867 | restore .slot |
1 | ha | 868 | |
869 | iglobal |
||
1056 | Galkov | 870 | boot_sched_1 db 'Building gdt tss pointer',0 |
871 | boot_sched_2 db 'Building IDT table',0 |
||
1 | ha | 872 | endg |
873 | |||
874 | |||
875 | build_scheduler: |
||
876 | |||
1056 | Galkov | 877 | mov esi,boot_sched_1 |
878 | call boot_log |
||
465 | serge | 879 | ; call build_process_gdt_tss_pointer |
1 | ha | 880 | |
465 | serge | 881 | ; mov esi,boot_sched_2 |
882 | ; call boot_log |
||
1 | ha | 883 | |
1056 | Galkov | 884 | ret |