ia64/xen-unstable

view extras/mini-os/traps.c @ 9788:bdcc838b9a72

Add small memory warning message to domain configuration examples.

Signed-off-by: Daniel Stekloff <dsteklof@us.ibm.com>
author stekloff@dyn9047022152.beaverton.ibm.com
date Wed Apr 19 22:58:24 2006 +0100 (2006-04-19)
parents 920b448b5485
children 62c8e97d56cf
line source
2 #include <os.h>
3 #include <traps.h>
4 #include <hypervisor.h>
5 #include <mm.h>
6 #include <lib.h>
7 #include <sched.h>
9 /*
10 * These are assembler stubs in entry.S.
11 * They are the actual entry points for virtual exceptions.
12 */
13 void divide_error(void);
14 void debug(void);
15 void int3(void);
16 void overflow(void);
17 void bounds(void);
18 void invalid_op(void);
19 void device_not_available(void);
20 void coprocessor_segment_overrun(void);
21 void invalid_TSS(void);
22 void segment_not_present(void);
23 void stack_segment(void);
24 void general_protection(void);
25 void page_fault(void);
26 void coprocessor_error(void);
27 void simd_coprocessor_error(void);
28 void alignment_check(void);
29 void spurious_interrupt_bug(void);
30 void machine_check(void);
33 void dump_regs(struct pt_regs *regs)
34 {
35 printk("Thread: %s\n", current->name);
36 #ifdef __i386__
37 printk("EIP: %x, EFLAGS %x.\n", regs->eip, regs->eflags);
38 printk("EBX: %08x ECX: %08x EDX: %08x\n",
39 regs->ebx, regs->ecx, regs->edx);
40 printk("ESI: %08x EDI: %08x EBP: %08x EAX: %08x\n",
41 regs->esi, regs->edi, regs->ebp, regs->eax);
42 printk("DS: %04x ES: %04x orig_eax: %08x, eip: %08x\n",
43 regs->xds, regs->xes, regs->orig_eax, regs->eip);
44 printk("CS: %04x EFLAGS: %08x esp: %08x ss: %04x\n",
45 regs->xcs, regs->eflags, regs->esp, regs->xss);
46 #else
47 printk("RIP: %04lx:[<%016lx>] ", regs->cs & 0xffff, regs->rip);
48 printk("\nRSP: %04lx:%016lx EFLAGS: %08lx\n",
49 regs->ss, regs->rsp, regs->eflags);
50 printk("RAX: %016lx RBX: %016lx RCX: %016lx\n",
51 regs->rax, regs->rbx, regs->rcx);
52 printk("RDX: %016lx RSI: %016lx RDI: %016lx\n",
53 regs->rdx, regs->rsi, regs->rdi);
54 printk("RBP: %016lx R08: %016lx R09: %016lx\n",
55 regs->rbp, regs->r8, regs->r9);
56 printk("R10: %016lx R11: %016lx R12: %016lx\n",
57 regs->r10, regs->r11, regs->r12);
58 printk("R13: %016lx R14: %016lx R15: %016lx\n",
59 regs->r13, regs->r14, regs->r15);
60 #endif
61 }
63 static void do_trap(int trapnr, char *str, struct pt_regs * regs, unsigned long error_code)
64 {
65 printk("FATAL: Unhandled Trap %d (%s), error code=0x%lx\n", trapnr, str, error_code);
66 printk("Regs address %p\n", regs);
67 dump_regs(regs);
68 do_exit();
69 }
71 #define DO_ERROR(trapnr, str, name) \
72 void do_##name(struct pt_regs * regs, unsigned long error_code) \
73 { \
74 do_trap(trapnr, str, regs, error_code); \
75 }
77 #define DO_ERROR_INFO(trapnr, str, name, sicode, siaddr) \
78 void do_##name(struct pt_regs * regs, unsigned long error_code) \
79 { \
80 do_trap(trapnr, str, regs, error_code); \
81 }
83 DO_ERROR_INFO( 0, "divide error", divide_error, FPE_INTDIV, regs->eip)
84 DO_ERROR( 3, "int3", int3)
85 DO_ERROR( 4, "overflow", overflow)
86 DO_ERROR( 5, "bounds", bounds)
87 DO_ERROR_INFO( 6, "invalid operand", invalid_op, ILL_ILLOPN, regs->eip)
88 DO_ERROR( 7, "device not available", device_not_available)
89 DO_ERROR( 9, "coprocessor segment overrun", coprocessor_segment_overrun)
90 DO_ERROR(10, "invalid TSS", invalid_TSS)
91 DO_ERROR(11, "segment not present", segment_not_present)
92 DO_ERROR(12, "stack segment", stack_segment)
93 DO_ERROR_INFO(17, "alignment check", alignment_check, BUS_ADRALN, 0)
94 DO_ERROR(18, "machine check", machine_check)
96 void page_walk(unsigned long virt_address)
97 {
98 unsigned long *tab = (unsigned long *)start_info.pt_base;
99 unsigned long addr = virt_address, page;
100 printk("Pagetable walk from virt %lx, base %lx:\n", virt_address, start_info.pt_base);
102 #if defined(__x86_64__)
103 page = tab[l4_table_offset(addr)];
104 tab = to_virt(mfn_to_pfn(pte_to_mfn(page)) << PAGE_SHIFT);
105 printk(" L4 = %p (%p) [offset = %lx]\n", page, tab, l4_table_offset(addr));
107 page = tab[l3_table_offset(addr)];
108 tab = to_virt(mfn_to_pfn(pte_to_mfn(page)) << PAGE_SHIFT);
109 printk(" L3 = %p (%p) [offset = %lx]\n", page, tab, l3_table_offset(addr));
110 #endif
111 page = tab[l2_table_offset(addr)];
112 tab = to_virt(mfn_to_pfn(pte_to_mfn(page)) << PAGE_SHIFT);
113 printk(" L2 = %p (%p) [offset = %lx]\n", page, tab, l2_table_offset(addr));
115 page = tab[l1_table_offset(addr)];
116 printk(" L1 = %p (%p) [offset = %lx]\n", page, tab, l1_table_offset(addr));
118 }
120 #define read_cr2() \
121 (HYPERVISOR_shared_info->vcpu_info[smp_processor_id()].arch.cr2)
123 void do_page_fault(struct pt_regs *regs, unsigned long error_code)
124 {
125 unsigned long addr = read_cr2();
126 printk("Page fault at linear address %p, regs %p, code %lx\n", addr, regs,
127 error_code);
128 dump_regs(regs);
129 page_walk(addr);
130 do_exit();
131 }
133 void do_general_protection(struct pt_regs *regs, long error_code)
134 {
135 #ifdef __i386__
136 printk("GPF eip: %p, error_code=%lx\n", regs->eip, error_code);
137 #else
138 printk("GPF rip: %p, error_code=%lx\n", regs->rip, error_code);
139 #endif
140 dump_regs(regs);
141 do_exit();
142 }
145 void do_debug(struct pt_regs * regs)
146 {
147 printk("Debug exception\n");
148 #define TF_MASK 0x100
149 regs->eflags &= ~TF_MASK;
150 dump_regs(regs);
151 do_exit();
152 }
154 void do_coprocessor_error(struct pt_regs * regs)
155 {
156 printk("Copro error\n");
157 dump_regs(regs);
158 do_exit();
159 }
161 void simd_math_error(void *eip)
162 {
163 printk("SIMD error\n");
164 }
166 void do_simd_coprocessor_error(struct pt_regs * regs)
167 {
168 printk("SIMD copro error\n");
169 }
171 void do_spurious_interrupt_bug(struct pt_regs * regs)
172 {
173 }
175 /*
176 * Submit a virtual IDT to teh hypervisor. This consists of tuples
177 * (interrupt vector, privilege ring, CS:EIP of handler).
178 * The 'privilege ring' field specifies the least-privileged ring that
179 * can trap to that vector using a software-interrupt instruction (INT).
180 */
181 static trap_info_t trap_table[] = {
182 { 0, 0, __KERNEL_CS, (unsigned long)divide_error },
183 { 1, 0, __KERNEL_CS, (unsigned long)debug },
184 { 3, 3, __KERNEL_CS, (unsigned long)int3 },
185 { 4, 3, __KERNEL_CS, (unsigned long)overflow },
186 { 5, 3, __KERNEL_CS, (unsigned long)bounds },
187 { 6, 0, __KERNEL_CS, (unsigned long)invalid_op },
188 { 7, 0, __KERNEL_CS, (unsigned long)device_not_available },
189 { 9, 0, __KERNEL_CS, (unsigned long)coprocessor_segment_overrun },
190 { 10, 0, __KERNEL_CS, (unsigned long)invalid_TSS },
191 { 11, 0, __KERNEL_CS, (unsigned long)segment_not_present },
192 { 12, 0, __KERNEL_CS, (unsigned long)stack_segment },
193 { 13, 0, __KERNEL_CS, (unsigned long)general_protection },
194 { 14, 0, __KERNEL_CS, (unsigned long)page_fault },
195 { 15, 0, __KERNEL_CS, (unsigned long)spurious_interrupt_bug },
196 { 16, 0, __KERNEL_CS, (unsigned long)coprocessor_error },
197 { 17, 0, __KERNEL_CS, (unsigned long)alignment_check },
198 { 18, 0, __KERNEL_CS, (unsigned long)machine_check },
199 { 19, 0, __KERNEL_CS, (unsigned long)simd_coprocessor_error },
200 { 0, 0, 0, 0 }
201 };
205 void trap_init(void)
206 {
207 HYPERVISOR_set_trap_table(trap_table);
208 }