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