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