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