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