akaros/kern/arch/x86/trap64.c
<<
>>
Prefs
   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
  26static spinlock_t ptf_lock = SPINLOCK_INITIALIZER_IRQSAVE;
  27
  28void print_trapframe(struct hw_trapframe *hw_tf)
  29{
  30        struct per_cpu_info *pcpui = &per_cpu_info[core_id()];
  31
  32        /* This is only called in debug scenarios, and often when the kernel
  33         * trapped and needs to tell us about it.  Disable the lock checker so
  34         * it doesn't go nuts when we print/panic */
  35        pcpui->__lock_checking_enabled--;
  36        spin_lock_irqsave(&ptf_lock);
  37        printk("HW TRAP frame %sat %p on core %d\n",
  38               x86_hwtf_is_partial(hw_tf) ? "(partial) " : "",
  39               hw_tf, core_id());
  40        printk("  rax  0x%016lx\n",           hw_tf->tf_rax);
  41        printk("  rbx  0x%016lx\n",           hw_tf->tf_rbx);
  42        printk("  rcx  0x%016lx\n",           hw_tf->tf_rcx);
  43        printk("  rdx  0x%016lx\n",           hw_tf->tf_rdx);
  44        printk("  rbp  0x%016lx\n",           hw_tf->tf_rbp);
  45        printk("  rsi  0x%016lx\n",           hw_tf->tf_rsi);
  46        printk("  rdi  0x%016lx\n",           hw_tf->tf_rdi);
  47        printk("  r8   0x%016lx\n",           hw_tf->tf_r8);
  48        printk("  r9   0x%016lx\n",           hw_tf->tf_r9);
  49        printk("  r10  0x%016lx\n",           hw_tf->tf_r10);
  50        printk("  r11  0x%016lx\n",           hw_tf->tf_r11);
  51        printk("  r12  0x%016lx\n",           hw_tf->tf_r12);
  52        printk("  r13  0x%016lx\n",           hw_tf->tf_r13);
  53        printk("  r14  0x%016lx\n",           hw_tf->tf_r14);
  54        printk("  r15  0x%016lx\n",           hw_tf->tf_r15);
  55        printk("  trap 0x%08x %s\n",          hw_tf->tf_trapno,
  56                                              x86_trapname(hw_tf->tf_trapno));
  57        /* FYI: these aren't physically adjacent to trap and err */
  58        if (hw_tf->tf_cs == GD_KT)
  59                printk("  gsbs 0x%016lx\n",       read_gsbase());
  60        else
  61                printk("  gsbs 0x%016lx\n",       hw_tf->tf_gsbase);
  62        printk("  fsbs 0x%016lx\n",           hw_tf->tf_fsbase);
  63        printk("  err  0x--------%08x\n",     hw_tf->tf_err);
  64        printk("  rip  0x%016lx\n",           hw_tf->tf_rip);
  65        printk("  cs   0x------------%04x\n", hw_tf->tf_cs);
  66        printk("  flag 0x%016lx\n",           hw_tf->tf_rflags);
  67        printk("  rsp  0x%016lx\n",           hw_tf->tf_rsp);
  68        printk("  ss   0x------------%04x\n", hw_tf->tf_ss);
  69        spin_unlock_irqsave(&ptf_lock);
  70        pcpui->__lock_checking_enabled++;
  71
  72        /* Used in trapentry64.S */
  73        static_assert(offsetof(struct hw_trapframe, tf_cs) -
  74                      offsetof(struct hw_trapframe, tf_rax) == 0x90);
  75        static_assert(offsetof(struct hw_trapframe, tf_padding0) -
  76                      offsetof(struct hw_trapframe, tf_rax) == 0xac);
  77        /* Used in trap64.h */
  78        static_assert(offsetof(struct per_cpu_info, stacktop) == 0);
  79}
  80
  81void print_swtrapframe(struct sw_trapframe *sw_tf)
  82{
  83        struct per_cpu_info *pcpui = &per_cpu_info[core_id()];
  84
  85        pcpui->__lock_checking_enabled--;
  86        spin_lock_irqsave(&ptf_lock);
  87        printk("SW TRAP frame %sat %p on core %d\n",
  88               x86_swtf_is_partial(sw_tf) ? "(partial) " : "",
  89               sw_tf, core_id());
  90        printk("  rbx  0x%016lx\n",           sw_tf->tf_rbx);
  91        printk("  rbp  0x%016lx\n",           sw_tf->tf_rbp);
  92        printk("  r12  0x%016lx\n",           sw_tf->tf_r12);
  93        printk("  r13  0x%016lx\n",           sw_tf->tf_r13);
  94        printk("  r14  0x%016lx\n",           sw_tf->tf_r14);
  95        printk("  r15  0x%016lx\n",           sw_tf->tf_r15);
  96        printk("  gsbs 0x%016lx\n",           sw_tf->tf_gsbase);
  97        printk("  fsbs 0x%016lx\n",           sw_tf->tf_fsbase);
  98        printk("  rip  0x%016lx\n",           sw_tf->tf_rip);
  99        printk("  rsp  0x%016lx\n",           sw_tf->tf_rsp);
 100        printk(" mxcsr 0x%08x\n",             sw_tf->tf_mxcsr);
 101        printk(" fpucw 0x%04x\n",             sw_tf->tf_fpucw);
 102        spin_unlock_irqsave(&ptf_lock);
 103        pcpui->__lock_checking_enabled++;
 104}
 105
 106void print_vmtrapframe(struct vm_trapframe *vm_tf)
 107{
 108        struct per_cpu_info *pcpui = &per_cpu_info[core_id()];
 109
 110        pcpui->__lock_checking_enabled--;
 111        spin_lock_irqsave(&ptf_lock);
 112        printk("VM Trapframe %sat %p on core %d\n",
 113               x86_vmtf_is_partial(vm_tf) ? "(partial) " : "",
 114               vm_tf, core_id());
 115        printk("  rax  0x%016lx\n",           vm_tf->tf_rax);
 116        printk("  rbx  0x%016lx\n",           vm_tf->tf_rbx);
 117        printk("  rcx  0x%016lx\n",           vm_tf->tf_rcx);
 118        printk("  rdx  0x%016lx\n",           vm_tf->tf_rdx);
 119        printk("  rbp  0x%016lx\n",           vm_tf->tf_rbp);
 120        printk("  rsi  0x%016lx\n",           vm_tf->tf_rsi);
 121        printk("  rdi  0x%016lx\n",           vm_tf->tf_rdi);
 122        printk("  r8   0x%016lx\n",           vm_tf->tf_r8);
 123        printk("  r9   0x%016lx\n",           vm_tf->tf_r9);
 124        printk("  r10  0x%016lx\n",           vm_tf->tf_r10);
 125        printk("  r11  0x%016lx\n",           vm_tf->tf_r11);
 126        printk("  r12  0x%016lx\n",           vm_tf->tf_r12);
 127        printk("  r13  0x%016lx\n",           vm_tf->tf_r13);
 128        printk("  r14  0x%016lx\n",           vm_tf->tf_r14);
 129        printk("  r15  0x%016lx\n",           vm_tf->tf_r15);
 130        printk("  rip  0x%016lx\n",           vm_tf->tf_rip);
 131        printk("  rflg 0x%016lx\n",           vm_tf->tf_rflags);
 132        printk("  rsp  0x%016lx\n",           vm_tf->tf_rsp);
 133        printk("  cr2  0x%016lx\n",           vm_tf->tf_cr2);
 134        printk("  cr3  0x%016lx\n",           vm_tf->tf_cr3);
 135        printk("Gpcore 0x%08x\n",             vm_tf->tf_guest_pcoreid);
 136        printk("Flags  0x%08x\n",             vm_tf->tf_flags);
 137        printk("Inject 0x%08x\n",             vm_tf->tf_trap_inject);
 138        printk("ExitRs 0x%08x\n",             vm_tf->tf_exit_reason);
 139        printk("ExitQl 0x%08x\n",             vm_tf->tf_exit_qual);
 140        printk("Intr1  0x%016lx\n",           vm_tf->tf_intrinfo1);
 141        printk("Intr2  0x%016lx\n",           vm_tf->tf_intrinfo2);
 142        printk("GIntr  0x----%04x\n",         vm_tf->tf_guest_intr_status);
 143        printk("GVA    0x%016lx\n",           vm_tf->tf_guest_va);
 144        printk("GPA    0x%016lx\n",           vm_tf->tf_guest_pa);
 145        spin_unlock_irqsave(&ptf_lock);
 146        pcpui->__lock_checking_enabled++;
 147}
 148
 149void __arch_reflect_trap_hwtf(struct hw_trapframe *hw_tf, unsigned int trap_nr,
 150                              unsigned int err, unsigned long aux)
 151{
 152        hw_tf->tf_trapno = trap_nr;
 153        /* this can be necessary, since hw_tf is the pcpui one, and the err that
 154         * came in probably came from the kernel stack's hw_tf. */
 155        hw_tf->tf_err = err;
 156        hw_tf->tf_padding4 = (uint32_t)(aux);
 157        hw_tf->tf_padding5 = (uint32_t)(aux >> 32);
 158        hw_tf->tf_padding3 = ROS_ARCH_REFL_ID;
 159}
 160