Rev 1038 | Rev 1074 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1038 | Rev 1056 | ||
---|---|---|---|
Line 9... | Line 9... | ||
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 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
Line 13... | Line 13... | ||
13 | 13 | ||
Line 14... | Line 14... | ||
14 | $Revision: 1038 $ |
14 | $Revision: 1056 $ |
15 | - | ||
16 | - | ||
17 | align 4 |
- | |
18 | idtreg: |
- | |
19 | dw 8*0x41-1 |
15 | |
20 | dd idts+8 |
- | |
21 | 16 | ||
22 | build_interrupt_table: |
17 | align 4 ;3A08 |
23 | 18 | build_interrupt_table: |
|
24 | mov edi, idts+8 |
- | |
25 | mov esi, sys_int |
- | |
26 | mov ecx, 0x40 |
19 | mov edi, idts |
27 | @@: |
20 | mov esi, sys_int |
28 | lodsd |
21 | mov ecx, 0x40 |
29 | mov [edi], ax ; lower part of offset |
22 | mov eax, (10001110b shl 24) + os_code |
30 | mov [edi+2], word os_code ; segment selector |
- | |
31 | mov ax, word 10001110b shl 8 ; type: interrupt gate |
23 | @@: movsw ;low word of code-entry |
32 | mov [edi+4], eax |
- | |
33 | add edi, 8 |
- | |
34 | loop @b |
24 | stosd ;interrupt gate type : os_code selector |
35 | 25 | movsw ;high word of code-entry |
|
36 | ;mov edi,8*0x40+idts+8 |
26 | loop @b |
37 | mov dword [edi], (i40 and 0xFFFF) or (os_code shl 16) |
27 | movsd ;copy low dword of trap gate for int 0x40 |
Line 38... | Line 28... | ||
38 | mov dword [edi+4], (11101111b shl 8) or (i40 and 0xFFFF0000) |
28 | movsd ;copy high dword of trap gate for int 0x40 |
39 | ; type: trap gate |
- | |
40 | ret |
29 | lidt [esi] |
41 | - | ||
42 | iglobal |
- | |
43 | 30 | ret |
|
44 | msg_sel_ker db "kernel", 0 |
31 | |
45 | msg_sel_app db "application", 0 |
32 | iglobal |
46 | - | ||
47 | sys_int: |
33 | align 4 |
48 | dd e0,debug_exc,e2,e3 |
- | |
49 | dd e4,e5,e6,e7 |
34 | sys_int: |
50 | dd e8,e9,e10,e11 |
35 | ;exception handlers addresses (for interrupt gate construction) |
Line -... | Line 36... | ||
- | 36 | dd e0,e1,e2,e3,e4,e5,e6,except_7 |
|
51 | dd e12,e13,page_fault_handler,e15 |
37 | dd e8,e9,e10,e11,e12,e13,page_fault_exc,e15 |
52 | 38 | dd e16, e17,e18, e19 |
|
53 | dd except_16, e17,e18, except_19 |
39 | times 12 dd unknown_interrupt ;int_20..int_31 |
54 | times 12 dd unknown_interrupt |
40 | |
55 | 41 | ;interrupt handlers addresses (for interrupt gate construction) |
|
56 | dd irq0, irq_serv.irq_1, irq_serv.irq_2 |
42 | dd irq0, irq_serv.irq_1, irq_serv.irq_2 |
57 | if USE_COM_IRQ |
43 | if USE_COM_IRQ |
58 | dd irq_serv.irq_3, irq_serv.irq_4 |
44 | dd irq_serv.irq_3, irq_serv.irq_4 |
59 | else |
45 | else |
- | 46 | dd p_irq3, p_irq4 ;??? íåñòûêîâêà |
|
- | 47 | end if |
|
- | 48 | dd irq_serv.irq_5, p_irq6, irq_serv.irq_7 |
|
- | 49 | dd irq_serv.irq_8, irq_serv.irq_9, irq_serv.irq_10 |
|
Line -... | Line 50... | ||
- | 50 | dd irq_serv.irq_11, irq_serv.irq_12, irqD,p_irq14,p_irq15 |
|
60 | dd p_irq3, p_irq4 |
51 | times 16 dd unknown_interrupt ;int_0x30..int_0x3F |
- | 52 | ||
- | 53 | ;int_0x40 gate trap (for directly copied) |
|
- | 54 | dw i40 and 0xFFFF, os_code, 11101111b shl 8, i40 shr 16 |
|
- | 55 | ||
- | 56 | idtreg: ; data for LIDT instruction (must be immediately below sys_int data) |
|
- | 57 | dw 2*($-sys_int-4)-1 |
|
- | 58 | dd idts ;0x8000B100 |
|
- | 59 | dw 0 ;ïðîñòî âûðàâíèâàíèå |
|
- | 60 | ||
- | 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 |
|
- | 63 | ||
- | 64 | msg_exc_8 db "Double fault", 0 |
|
- | 65 | msg_exc_u db "Undefined Exception", 0 |
|
- | 66 | msg_exc_a db "Invalid TSS", 0 |
|
- | 67 | msg_exc_b db "Segment not present", 0 |
|
Line 61... | Line -... | ||
61 | end if |
- | |
62 | dd irq_serv.irq_5, p_irq6, irq_serv.irq_7 |
68 | msg_exc_c db "Stack fault", 0 |
Line 63... | Line 69... | ||
63 | dd irq_serv.irq_8, irq_serv.irq_9, irq_serv.irq_10 |
69 | msg_exc_d db "General protection fault", 0 |
64 | dd irq_serv.irq_11, irq_serv.irq_12,irqD ,p_irq14,p_irq15 |
- | |
65 | 70 | msg_exc_e db "Page fault", 0 |
|
66 | times 16 dd unknown_interrupt |
71 | |
67 | 72 | msg_sel_ker db "kernel", 0 |
|
68 | dd i40 |
- | |
69 | endg |
73 | msg_sel_app db "application", 0 |
70 | 74 | ||
71 | macro save_ring3_context |
- | |
72 | { |
- | |
73 | pushad |
- | |
74 | } |
- | |
75 | macro restore_ring3_context |
- | |
76 | { |
75 | endg |
77 | popad |
- | |
78 | } |
- | |
79 | 76 | ||
80 | ; simply return control to interrupted process |
77 | macro save_ring3_context { |
81 | unknown_interrupt: |
78 | pushad |
82 | iret |
79 | } |
83 | - | ||
- | 80 | macro restore_ring3_context { |
|
Line 84... | Line 81... | ||
84 | macro exc_wo_code [num] |
81 | popad |
85 | { |
- | |
86 | forward |
- | |
87 | e#num : |
82 | } |
88 | save_ring3_context |
83 | macro exc_wo_code [num] { |
89 | mov bl, num |
84 | e#num : |
90 | jmp exc_c |
85 | save_ring3_context |
91 | } |
86 | mov bl, num |
92 | - | ||
- | 87 | jmp exc_c |
|
Line 93... | Line -... | ||
93 | macro exc_w_code [num] |
- | |
94 | { |
- | |
Line 95... | Line 88... | ||
95 | forward |
88 | } exc_wo_code 0,1,2,3,4,5,6,15,16,19 |
96 | e#num : |
- | |
97 | add esp, 4 |
- | |
98 | save_ring3_context |
89 | |
- | 90 | macro exc_w_code [num] { |
|
Line -... | Line 91... | ||
- | 91 | e#num : |
|
- | 92 | add esp, 4 |
|
- | 93 | save_ring3_context |
|
- | 94 | mov bl, num |
|
- | 95 | jmp exc_c |
|
- | 96 | } exc_w_code 8,9,10,11,12,13,17,18 |
|
- | 97 | ||
- | 98 | ||
- | 99 | uglobal |
|
- | 100 | pf_err_code dd ? |
|
- | 101 | endg |
|
- | 102 | ||
- | 103 | page_fault_exc: |
|
- | 104 | pop [pf_err_code] ;äåéñòâèòåëüíî äî ñëåäóþùåãî #PF |
|
- | 105 | save_ring3_context |
|
- | 106 | mov bl,14 |
|
- | 107 | exc_c: ;èñêëþ÷åíèå |
|
- | 108 | ; Ôðýéì ñòåêà ïðè èñêëþ÷åíèè/ïðåðûâàíèè èç 3-ãî êîëüöà + pushad (ò.å., èìåííî çäåñü) |
|
- | 109 | reg_ss equ esp+0x30 |
|
- | 110 | reg_esp3 equ esp+0x2C |
|
- | 111 | reg_eflags equ esp+0x28 |
|
- | 112 | reg_cs3 equ esp+0x24 |
|
- | 113 | reg_eip equ esp+0x20 |
|
- | 114 | ; ýòî ôðýéì îò pushad |
|
99 | mov bl, num |
115 | reg_eax equ esp+0x1C |
100 | jmp exc_c |
116 | reg_ecx equ esp+0x18 |
101 | } |
117 | reg_edx equ esp+0x14 |
102 | - | ||
- | 118 | reg_ebx equ esp+0x10 |
|
103 | exc_wo_code 0, 2, 3, 4, 5, 6, 9, 15, 18 |
119 | reg_esp0 equ esp+0x0C |
104 | exc_w_code 8, 10, 11, 12, 13, 14, 17 |
120 | reg_ebp equ esp+0x08 |
105 | 121 | reg_esi equ esp+0x04 |
|
- | 122 | reg_edi equ esp+0x00 |
|
- | 123 | ||
- | 124 | Mov ds,ax,app_data ; çàãðóçèì ïðàâèëüíûå çíà÷åíèÿ |
|
- | 125 | mov es,ax ; â ñåãìåíòíûå ðåãèñòðû |
|
- | 126 | cld ; è ïðèâîäèì DF ê ñòàíäàðòó |
|
- | 127 | ; redirect to V86 manager? (EFLAGS & 0x20000) != 0? |
|
- | 128 | test byte[reg_eflags+2],2 |
|
- | 129 | jnz v86_exc_c |
|
- | 130 | cmp bl,14 ; #PF |
|
106 | exc_c: |
131 | jne .l0 |
107 | mov ax, app_data ;èñêëþ÷åíèå |
132 | call page_fault_handler |
108 | mov ds, ax ;çàãðóçèì ïðàâèëüíûå çíà÷åíè |
133 | .l0: mov esi, [current_slot] |
109 | mov es, ax ;â ðåãèñòðû |
134 | mov eax,[esi+APPDATA.fpu_handler] |
110 | 135 | cmp bl,16 ; #MF |
|
111 | ; redirect to V86 manager? (EFLAGS & 0x20000) != 0? |
- | |
112 | test byte [esp+20h+8+2], 2 |
- | |
113 | jnz v86_exc_c |
136 | je .l1 |
114 | - | ||
115 | ; test if debugging |
137 | cmp bl,19 ; #XF |
116 | cli |
138 | jne .l2 |
117 | mov eax, [current_slot] |
- | |
118 | mov eax, [eax+APPDATA.debugger_slot] |
139 | mov eax,[esi+APPDATA.sse_handler] |
119 | test eax, eax |
- | |
120 | jnz .debug |
140 | .l1: test eax, eax |
121 | sti |
141 | jnz IRetToUserHook |
122 | ; not debuggee => say error and terminate |
142 | .l2: cli |
123 | movzx eax, bl |
- | |
124 | mov [error_interrupt], eax |
143 | mov eax, [esi+APPDATA.debugger_slot] |
125 | call show_error_parameters |
- | |
126 | add esp, 0x20 |
144 | test eax, eax |
127 | mov edx, [TASK_BASE] |
145 | jnz .debug |
128 | mov [edx + TASKDATA.state], byte 4 |
- | |
129 | - | ||
130 | jmp change_task |
146 | sti |
131 | 147 | ; not debuggee => say error and terminate |
|
132 | .debug: |
148 | call show_error_parameters ;; only ONE using, inline ??? |
133 | ; we are debugged process, notify debugger and suspend ourself |
149 | ;mov edx, [TASK_BASE] |
134 | ; eax=debugger PID |
150 | mov [edx + TASKDATA.state], byte 4 ; terminate |
135 | cld |
151 | jmp change_task ; stack - here it does not matter at all |
136 | movzx ecx, bl |
152 | .debug: |
137 | push ecx |
153 | ; we are debugged process, notify debugger and suspend ourself |
138 | mov ecx, [TASK_BASE] |
154 | ; eax=debugger PID |
- | 155 | cmp bl,1 ; #DB |
|
139 | push dword [ecx+TASKDATA.pid] ; PID of current process |
156 | je debug_ex |
Line 140... | Line -... | ||
140 | push 12 |
- | |
141 | pop ecx |
- | |
142 | push 1 ; 1=exception |
- | |
143 | call debugger_notify |
- | |
144 | pop ecx |
- | |
145 | pop ecx |
157 | movzx edx, bl ; debug_message data=Number_Of_Exception |
146 | pop ecx |
158 | mov ecx,1 ; debug_message code=other_exception |
147 | mov edx, [TASK_BASE] |
159 | jmp debug_ex.notify ; notify debugger and suspend ourself |
148 | mov byte [edx+TASKDATA.state], 1 ; suspended |
- | |
149 | call change_task |
160 | |
150 | restore_ring3_context |
- | |
151 | iretd |
161 | IRetToUserHook: |
152 | - | ||
153 | iglobal |
- | |
154 | hexletters db '0123456789ABCDEF' |
- | |
155 | error_interrupt dd -1 |
- | |
156 | endg |
162 | xchg eax, [reg_eip] |
157 | - | ||
158 | ;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= |
- | |
159 | show_error_parameters: |
- | |
160 | mov eax,[CURRENT_TASK] |
- | |
161 | shl eax, 5 |
163 | sub dword[reg_esp3], 4 |
162 | DEBUGF 1, "K : Process - forced terminate PID: %x\n", [CURRENT_TASK + TASKDATA.pid + eax] |
- | |
163 | mov eax, [error_interrupt] |
- | |
164 | cmp al, 0x08 |
164 | mov edi, [reg_esp3] |
165 | jne @f |
- | |
166 | DEBUGF 1, "K : Double fault\n" |
165 | stosd |
167 | jmp defined_error |
- | |
168 | @@: |
- | |
169 | cmp al, 0x0a |
- | |
170 | jne @f |
- | |
171 | DEBUGF 1, "K : Invalid TSS\n" |
166 | restore_ring3_context |
172 | jmp defined_error |
- | |
173 | @@: |
167 | unknown_interrupt: |
174 | cmp al, 0x0b |
- | |
175 | jne @f |
- | |
176 | DEBUGF 1, "K : Segment not present\n" |
- | |
177 | jmp defined_error |
- | |
178 | @@: |
168 | iretd |
179 | cmp al, 0x0c |
- | |
180 | jne @f |
- | |
181 | DEBUGF 1, "K : Stack fault\n" |
- | |
182 | jmp defined_error |
- | |
183 | @@: |
- | |
184 | cmp al, 0x0d |
- | |
185 | jne @f |
- | |
186 | DEBUGF 1, "K : General protection fault\n" |
- | |
187 | jmp defined_error |
169 | |
188 | @@: |
170 | ;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= |
189 | cmp al, 0x0e |
171 | show_error_parameters: |
190 | jne @f |
172 | mov edx,[TASK_BASE] ;not scratched below |
191 | DEBUGF 1, "K : Page fault\n" |
173 | DEBUGF 1, "K : Process - forced terminate PID: %x\n", [edx+TASKDATA.pid] |
192 | jmp defined_error |
174 | cmp bl, 0x08 |
193 | @@: |
175 | jb .l0 |
194 | DEBUGF 1, "K : Undefined Exception\n" |
- | |
- | 176 | cmp bl, 0x0e |
|
- | 177 | jbe .l1 |
|
- | 178 | .l0: mov bl, 0x09 |
|
195 | defined_error: |
179 | .l1: movzx eax,bl |
196 | DEBUGF 1, "K : EAX : %x EBX : %x ECX : %x\n", [esp + 0x20], [esp - 12 + 0x20], [esp - 4 + 0x20] |
180 | mov eax,[msg_fault_sel+eax*4 - 0x08*4] |
197 | DEBUGF 1, "K : EDX : %x ESI : %x EDI : %x\n", [esp - 8 + 0x20], [esp - 24 + 0x20], [esp - 28 + 0x20] |
181 | DEBUGF 1, "K : %s\n", eax |
Line -... | Line 182... | ||
- | 182 | mov eax, [reg_cs3+4] |
|
- | 183 | mov edi, msg_sel_app |
|
- | 184 | mov ebx, [reg_esp3+4] |
|
- | 185 | cmp eax, app_code |
|
- | 186 | je @f |
|
- | 187 | mov edi, msg_sel_ker |
|
- | 188 | mov ebx, [reg_esp0+4] |
|
- | 189 | @@: DEBUGF 1, "K : EAX : %x EBX : %x ECX : %x\n", [reg_eax+4], [reg_ebx+4], [reg_ecx+4] |
|
- | 190 | DEBUGF 1, "K : EDX : %x ESI : %x EDI : %x\n", [reg_edx+4], [reg_esi+4], [reg_edi+4] |
|
- | 191 | DEBUGF 1, "K : EBP : %x EIP : %x ESP : %x\n", [reg_ebp+4], [reg_eip+4], ebx |
|
- | 192 | DEBUGF 1, "K : Flags : %x CS : %x (%s)\n", [reg_eflags+4], eax, edi |
|
- | 193 | ret |
|
- | 194 | ;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= |
|
Line 198... | Line 195... | ||
198 | DEBUGF 1, "K : EBP : %x EIP : %x ", [esp - 20 + 0x20], [esp + 4 + 0x20] |
195 | |
199 | 196 | restore reg_ss |
|
200 | mov eax, [esp + 8 + 0x20] |
- | |
201 | mov edi, msg_sel_app |
- | |
202 | mov ebx, [esp + 16 + 0x20] |
197 | restore reg_esp3 |
203 | cmp eax, app_code |
198 | restore reg_eflags |
204 | je @f |
199 | restore reg_cs |
205 | mov edi, msg_sel_ker |
200 | restore reg_eip |
Line 206... | Line -... | ||
206 | mov ebx, [esp - 16 + 0x20] |
- | |
Line 207... | Line 201... | ||
207 | @@: |
201 | restore reg_eax |
208 | DEBUGF 1, "ESP : %x\nK : Flags : %x CS : %x (%s)\n", ebx, [esp + 12 + 0x20], eax, edi |
202 | restore reg_ecx |
209 | ret |
203 | restore reg_edx |
Line 275... | Line 269... | ||
275 | out 0xa0,al |
269 | out 0xa0,al |
276 | out 0x20, al |
270 | out 0x20, al |
277 | ret |
271 | ret |
Line 278... | Line 272... | ||
278 | 272 | ||
279 | irqD: |
- | |
280 | save_ring3_context |
- | |
281 | mov ax, app_data ;os_data |
- | |
282 | mov ds, ax |
273 | irqD: |
283 | mov es, ax |
- | |
284 | - | ||
285 | mov dx,0xf0 |
274 | push eax |
286 | mov al,0 |
275 | mov al,0 |
287 | out dx,al |
- | |
288 | - | ||
289 | mov dx,0xa0 |
276 | out 0xf0,al |
290 | mov al,0x20 |
277 | mov al,0x20 |
291 | out dx,al |
278 | out 0xa0,al |
292 | mov dx,0x20 |
279 | out 0x20,al |
293 | out dx,al |
- | |
294 | - | ||
295 | restore_ring3_context |
- | |
296 | 280 | pop eax |
|
Line -... | Line 281... | ||
- | 281 | iret |
|
- | 282 | ||
297 | iret |
283 | |
Line 298... | Line 284... | ||
298 | 284 | irqh 2,3,4,5,7,8,9,10,11 |
|
299 | 285 | ||
300 | irqhandler: |
286 | irqhandler: |