Palacios Public Git Repository

To checkout Palacios execute

  git clone http://v3vee.org/palacios/palacios.web/palacios.git
This will give you the master branch. You probably want the devel branch or one of the release branches. To switch to the devel branch, simply execute
  cd palacios
  git checkout --track -b devel origin/devel
The other branches are similar.


5e785a663d7e8196cd6d29f312e90a3fa6a4b916
[palacios-OLD.git] / kitten / arch / x86_64 / kernel / show.c
1 #include <lwk/kernel.h>
2 #include <lwk/task.h>
3 #include <lwk/ptrace.h>
4 #include <lwk/version.h>
5 #include <lwk/kallsyms.h>
6 #include <arch/msr.h>
7
8 /**
9  * Prints a nicely formatted address to the console.
10  * This attempts to look up the symbolic name of the address.
11  */
12 void
13 printk_address(unsigned long address)
14 {
15         unsigned long offset = 0, symsize;
16         const char *symname;
17         char namebuf[128];
18
19         symname = kallsyms_lookup(address, &symsize, &offset, namebuf);
20         if (!symname) {
21                 printk(" [<%016lx>]\n", address);
22                 return;
23         }
24         printk(" [<%016lx>] %s+0x%lx/0x%lx\n",
25                 address, symname, offset, symsize);
26 }
27
28
29 /**
30  * Print a stack trace of the context.
31  */
32 void
33 kstack_trace(
34         void *                  rbp_v
35 )
36 {
37 #ifndef CONFIG_FRAME_POINTER
38         printk( "Unable to generate stack trace "
39                 "(recompile with CONFIG_FRAME_POINTER)\n" );
40         return;
41 #endif
42
43         uint64_t * rbp = rbp_v;
44         if( rbp == 0 )
45                 asm( "mov %%rbp, %0" : "=r"(rbp) );
46
47         int max_depth = 16;
48         printk( "Stack trace from RBP %p\n", rbp );
49
50         while( rbp && max_depth-- )
51         {
52                 printk_address( rbp[1] );
53                 rbp = (uint64_t*) *rbp;
54         }
55 }
56
57
58 /**
59  * Prints x86_64 general purpose registers and friends to the console.
60  * NOTE: This prints the CPU register values contained in the passed in
61  *       'struct pt_regs *'.  It DOES NOT print the current values in
62  *       the CPU's registers.
63  */
64 void
65 show_registers(struct pt_regs * regs)
66 {
67         unsigned long cr0 = 0L, cr2 = 0L, cr3 = 0L, cr4 = 0L, fs, gs, shadowgs;
68         unsigned int fsindex, gsindex;
69         unsigned int ds, cs, es;
70         bool user_fault = (regs->rip < PAGE_OFFSET);
71         char namebuf[128];
72
73         printk("Task ID: %d   Task Name: %s   UTS_RELEASE: %s\n",
74                 current->id, current->name, UTS_RELEASE);
75         printk("RIP: %04lx:%016lx (%s)\n", regs->cs & 0xffff, regs->rip,
76                (user_fault) ? "user-context"
77                             : kallsyms_lookup(regs->rip, NULL, NULL, namebuf));
78         printk("RSP: %04lx:%016lx EFLAGS: %08lx ERR: %08lx\n",
79                 regs->ss, regs->rsp, regs->eflags, regs->orig_rax);
80         printk("RAX: %016lx RBX: %016lx RCX: %016lx\n",
81                regs->rax, regs->rbx, regs->rcx);
82         printk("RDX: %016lx RSI: %016lx RDI: %016lx\n",
83                regs->rdx, regs->rsi, regs->rdi);
84         printk("RBP: %016lx R08: %016lx R09: %016lx\n",
85                regs->rbp, regs->r8, regs->r9);
86         printk("R10: %016lx R11: %016lx R12: %016lx\n",
87                regs->r10, regs->r11, regs->r12);
88         printk("R13: %016lx R14: %016lx R15: %016lx\n",
89                regs->r13, regs->r14, regs->r15);
90
91         asm("movl %%ds,%0" : "=r" (ds));
92         asm("movl %%cs,%0" : "=r" (cs));
93         asm("movl %%es,%0" : "=r" (es));
94         asm("movl %%fs,%0" : "=r" (fsindex));
95         asm("movl %%gs,%0" : "=r" (gsindex));
96
97         rdmsrl(MSR_FS_BASE, fs);
98         rdmsrl(MSR_GS_BASE, gs);
99         rdmsrl(MSR_KERNEL_GS_BASE, shadowgs);
100
101         asm("movq %%cr0, %0": "=r" (cr0));
102         asm("movq %%cr2, %0": "=r" (cr2));
103         asm("movq %%cr3, %0": "=r" (cr3));
104         asm("movq %%cr4, %0": "=r" (cr4));
105
106         printk("FS:  %016lx(%04x) GS:%016lx(%04x) knlGS:%016lx\n",
107                fs, fsindex, gs, gsindex, shadowgs);
108         printk("CS:  %04x DS: %04x ES: %04x CR0: %016lx\n", cs, ds, es, cr0);
109         printk("CR2: %016lx CR3: %016lx CR4: %016lx\n", cr2, cr3, cr4);
110
111         if (!user_fault)
112                 kstack_trace( (void *) regs->rbp );
113 }
114