BXE: min->MIN, plus an spatch
[akaros.git] / kern / arch / x86 / trap32.c
1 /* Copyright (c) 2009-13 The Regents of the University of California
2  * Barret Rhoden <brho@cs.berkeley.edu>
3  * See LICENSE for details.
4  *
5  * x86 trap.c bit-specific functions. */
6
7 #include <arch/mmu.h>
8 #include <arch/x86.h>
9 #include <arch/arch.h>
10 #include <arch/console.h>
11 #include <arch/apic.h>
12 #include <ros/common.h>
13 #include <smp.h>
14 #include <assert.h>
15 #include <pmap.h>
16 #include <trap.h>
17 #include <monitor.h>
18 #include <process.h>
19 #include <mm.h>
20 #include <stdio.h>
21 #include <slab.h>
22 #include <syscall.h>
23 #include <kdebug.h>
24 #include <kmalloc.h>
25
26 static void print_regs(push_regs_t *regs)
27 {
28         printk("  edi  0x%08x\n", regs->reg_edi);
29         printk("  esi  0x%08x\n", regs->reg_esi);
30         printk("  ebp  0x%08x\n", regs->reg_ebp);
31         printk("  oesp 0x%08x\n", regs->reg_oesp);
32         printk("  ebx  0x%08x\n", regs->reg_ebx);
33         printk("  edx  0x%08x\n", regs->reg_edx);
34         printk("  ecx  0x%08x\n", regs->reg_ecx);
35         printk("  eax  0x%08x\n", regs->reg_eax);
36 }
37
38 void print_trapframe(struct hw_trapframe *hw_tf)
39 {
40         static spinlock_t ptf_lock = SPINLOCK_INITIALIZER_IRQSAVE;
41
42         struct per_cpu_info *pcpui = &per_cpu_info[core_id()];
43         /* This is only called in debug scenarios, and often when the kernel trapped
44          * and needs to tell us about it.  Disable the lock checker so it doesn't go
45          * nuts when we print/panic */
46         pcpui->__lock_checking_enabled--;
47         spin_lock_irqsave(&ptf_lock);
48         printk("TRAP frame at %p on core %d\n", hw_tf, core_id());
49         print_regs(&hw_tf->tf_regs);
50         printk("  gs   0x----%04x\n", hw_tf->tf_gs);
51         printk("  fs   0x----%04x\n", hw_tf->tf_fs);
52         printk("  es   0x----%04x\n", hw_tf->tf_es);
53         printk("  ds   0x----%04x\n", hw_tf->tf_ds);
54         printk("  trap 0x%08x %s\n",  hw_tf->tf_trapno,
55                                       x86_trapname(hw_tf->tf_trapno));
56         printk("  err  0x%08x\n",     hw_tf->tf_err);
57         printk("  eip  0x%08x\n",     hw_tf->tf_eip);
58         printk("  cs   0x----%04x\n", hw_tf->tf_cs);
59         printk("  flag 0x%08x\n",     hw_tf->tf_eflags);
60         /* Prevents us from thinking these mean something for nested interrupts. */
61         if (hw_tf->tf_cs != GD_KT) {
62                 printk("  esp  0x%08x\n",     hw_tf->tf_esp);
63                 printk("  ss   0x----%04x\n", hw_tf->tf_ss);
64         }
65         spin_unlock_irqsave(&ptf_lock);
66         pcpui->__lock_checking_enabled++;
67 }
68
69 void __arch_reflect_trap_hwtf(struct hw_trapframe *hw_tf, unsigned int trap_nr,
70                               unsigned int err, unsigned long aux)
71 {
72         hw_tf->tf_trapno = trap_nr;
73         /* this can be necessary, since hw_tf is the pcpui one, and the err that
74          * came in probably came from the kernel stack's hw_tf. */
75         hw_tf->tf_err = err;
76         hw_tf->tf_regs.reg_oesp = aux;
77         hw_tf->tf_padding3 = ROS_ARCH_REFL_ID;
78 }