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