ia64/xen-unstable

view extras/mini-os/traps.c @ 6685:549f4256ab3c

Remove control interface in kernels and domain builder.
Signed-off-by: Christian Limpach <Christian.Limpach@cl.cam.ac.uk>
author cl349@firebug.cl.cam.ac.uk
date Wed Sep 07 17:43:56 2005 +0000 (2005-09-07)
parents a83ac0806d6b
children df1348e72390 cdfa7dd00c44 b2f4823b6ff0
line source
2 #include <os.h>
3 #include <traps.h>
4 #include <hypervisor.h>
5 #include <mm.h>
6 #include <lib.h>
8 /*
9 * These are assembler stubs in entry.S.
10 * They are the actual entry points for virtual exceptions.
11 */
12 void divide_error(void);
13 void debug(void);
14 void int3(void);
15 void overflow(void);
16 void bounds(void);
17 void invalid_op(void);
18 void device_not_available(void);
19 void coprocessor_segment_overrun(void);
20 void invalid_TSS(void);
21 void segment_not_present(void);
22 void stack_segment(void);
23 void general_protection(void);
24 void page_fault(void);
25 void coprocessor_error(void);
26 void simd_coprocessor_error(void);
27 void alignment_check(void);
28 void spurious_interrupt_bug(void);
29 void machine_check(void);
32 extern void do_exit(void);
34 void dump_regs(struct pt_regs *regs)
35 {
36 unsigned long esp;
37 unsigned short ss;
39 #ifdef __x86_64__
40 esp = regs->rsp;
41 ss = regs->xss;
42 #else
43 esp = (unsigned long) (&regs->esp);
44 ss = __KERNEL_DS;
45 if (regs->xcs & 2) {
46 printk("CS is true, esp is %x\n", regs->esp);
47 esp = regs->esp;
48 ss = regs->xss & 0xffff;
49 }
50 #endif
51 printf("EIP: %04x:[<%p>]\n",
52 0xffff & regs->xcs , regs->eip);
53 printf("EFLAGS: %p\n",regs->eflags);
54 printf("eax: %08lx ebx: %08lx ecx: %08lx edx: %08lx\n",
55 regs->eax, regs->ebx, regs->ecx, regs->edx);
56 printf("esi: %08lx edi: %08lx ebp: %08lx esp: %08lx\n",
57 regs->esi, regs->edi, regs->ebp, esp);
58 #ifdef __x86_64__
59 printf("r8 : %p r9 : %p r10: %p r11: %p\n",
60 regs->r8, regs->r9, regs->r10, regs->r11);
61 printf("r12: %p r13: %p r14: %p r15: %p\n",
62 regs->r12, regs->r13, regs->r14, regs->r15);
63 #endif
64 printf("ds: %04x es: %04x ss: %04x\n",
65 regs->xds & 0xffff, regs->xes & 0xffff, ss);
66 }
69 static void do_trap(int trapnr, char *str, struct pt_regs * regs, unsigned long error_code)
70 {
71 printk("FATAL: Unhandled Trap %d (%s), error code=0x%lx\n", trapnr, str, error_code);
72 printk("Regs address %p\n", regs);
73 dump_regs(regs);
74 do_exit();
75 }
77 #define DO_ERROR(trapnr, str, name) \
78 void do_##name(struct pt_regs * regs, unsigned long error_code) \
79 { \
80 do_trap(trapnr, str, regs, error_code); \
81 }
83 #define DO_ERROR_INFO(trapnr, str, name, sicode, siaddr) \
84 void do_##name(struct pt_regs * regs, unsigned long error_code) \
85 { \
86 do_trap(trapnr, str, regs, error_code); \
87 }
89 DO_ERROR_INFO( 0, "divide error", divide_error, FPE_INTDIV, regs->eip)
90 DO_ERROR( 3, "int3", int3)
91 DO_ERROR( 4, "overflow", overflow)
92 DO_ERROR( 5, "bounds", bounds)
93 DO_ERROR_INFO( 6, "invalid operand", invalid_op, ILL_ILLOPN, regs->eip)
94 DO_ERROR( 7, "device not available", device_not_available)
95 DO_ERROR( 9, "coprocessor segment overrun", coprocessor_segment_overrun)
96 DO_ERROR(10, "invalid TSS", invalid_TSS)
97 DO_ERROR(11, "segment not present", segment_not_present)
98 DO_ERROR(12, "stack segment", stack_segment)
99 DO_ERROR_INFO(17, "alignment check", alignment_check, BUS_ADRALN, 0)
100 DO_ERROR(18, "machine check", machine_check)
102 void do_page_fault(struct pt_regs *regs, unsigned long error_code,
103 unsigned long addr)
104 {
105 printk("Page fault at linear address %p\n", addr);
106 dump_regs(regs);
107 #ifdef __x86_64__
108 {
109 unsigned long *tab = (unsigned long *)start_info.pt_base;
110 unsigned long page;
112 printk("Pagetable walk from %p:\n", tab);
114 page = tab[l4_table_offset(addr)];
115 tab = __va(mfn_to_pfn(pte_to_mfn(page)) << PAGE_SHIFT);
116 printk(" L4 = %p (%p)\n", page, tab);
117 if ( !(page & AGERESENT) )
118 goto out;
120 page = tab[l3_table_offset(addr)];
121 tab = __va(mfn_to_pfn(pte_to_mfn(page)) << PAGE_SHIFT);
122 printk(" L3 = %p (%p)\n", page, tab);
123 if ( !(page & AGERESENT) )
124 goto out;
126 page = tab[l2_table_offset(addr)];
127 tab = __va(mfn_to_pfn(pte_to_mfn(page)) << PAGE_SHIFT);
128 printk(" L2 = %p (%p) %s\n", page, tab,
129 (page & AGESE) ? "(2MB)" : "");
130 if ( !(page & AGERESENT) || (page & AGESE) )
131 goto out;
133 page = tab[l1_table_offset(addr)];
134 printk(" L1 = %p\n", page);
135 }
136 #endif
137 do_exit();
138 }
140 void do_general_protection(struct pt_regs *regs, long error_code)
141 {
142 printk("GPF %p, error_code=%lx\n", regs, error_code);
143 dump_regs(regs);
144 do_exit();
145 }
148 void do_debug(struct pt_regs * regs)
149 {
150 printk("Debug exception\n");
151 #define TF_MASK 0x100
152 regs->eflags &= ~TF_MASK;
153 dump_regs(regs);
154 do_exit();
155 }
157 void do_coprocessor_error(struct pt_regs * regs)
158 {
159 printk("Copro error\n");
160 dump_regs(regs);
161 do_exit();
162 }
164 void simd_math_error(void *eip)
165 {
166 printk("SIMD error\n");
167 }
169 void do_simd_coprocessor_error(struct pt_regs * regs)
170 {
171 printk("SIMD copro error\n");
172 }
174 void do_spurious_interrupt_bug(struct pt_regs * regs)
175 {
176 }
178 /*
179 * Submit a virtual IDT to teh hypervisor. This consists of tuples
180 * (interrupt vector, privilege ring, CS:EIP of handler).
181 * The 'privilege ring' field specifies the least-privileged ring that
182 * can trap to that vector using a software-interrupt instruction (INT).
183 */
184 static trap_info_t trap_table[] = {
185 { 0, 0, __KERNEL_CS, (unsigned long)divide_error },
186 { 1, 0, __KERNEL_CS, (unsigned long)debug },
187 { 3, 3, __KERNEL_CS, (unsigned long)int3 },
188 { 4, 3, __KERNEL_CS, (unsigned long)overflow },
189 { 5, 3, __KERNEL_CS, (unsigned long)bounds },
190 { 6, 0, __KERNEL_CS, (unsigned long)invalid_op },
191 { 7, 0, __KERNEL_CS, (unsigned long)device_not_available },
192 { 9, 0, __KERNEL_CS, (unsigned long)coprocessor_segment_overrun },
193 { 10, 0, __KERNEL_CS, (unsigned long)invalid_TSS },
194 { 11, 0, __KERNEL_CS, (unsigned long)segment_not_present },
195 { 12, 0, __KERNEL_CS, (unsigned long)stack_segment },
196 { 13, 0, __KERNEL_CS, (unsigned long)general_protection },
197 { 14, 0, __KERNEL_CS, (unsigned long)page_fault },
198 { 15, 0, __KERNEL_CS, (unsigned long)spurious_interrupt_bug },
199 { 16, 0, __KERNEL_CS, (unsigned long)coprocessor_error },
200 { 17, 0, __KERNEL_CS, (unsigned long)alignment_check },
201 { 18, 0, __KERNEL_CS, (unsigned long)machine_check },
202 { 19, 0, __KERNEL_CS, (unsigned long)simd_coprocessor_error },
203 { 0, 0, 0, 0 }
204 };
208 void trap_init(void)
209 {
210 HYPERVISOR_set_trap_table(trap_table);
211 }