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.


Merge branch 'devel'
[palacios.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 /*
74         printk("Task ID: %d   Task Name: %s   UTS_RELEASE: %s\n",
75                 current ? current->id : -1,
76                 current ? current->name : "BAD CURRENT",
77                 UTS_RELEASE
78         );
79 */
80         printk("RIP: %04lx:%016lx (%s)\n", regs->cs & 0xffff, regs->rip,
81                (user_fault) ? "user-context"
82                             : kallsyms_lookup(regs->rip, NULL, NULL, namebuf));
83         printk("RSP: %04lx:%016lx EFLAGS: %08lx ERR: %08lx\n",
84                 regs->ss, regs->rsp, regs->eflags, regs->orig_rax);
85         printk("RAX: %016lx RBX: %016lx RCX: %016lx\n",
86                regs->rax, regs->rbx, regs->rcx);
87         printk("RDX: %016lx RSI: %016lx RDI: %016lx\n",
88                regs->rdx, regs->rsi, regs->rdi);
89         printk("RBP: %016lx R08: %016lx R09: %016lx\n",
90                regs->rbp, regs->r8, regs->r9);
91         printk("R10: %016lx R11: %016lx R12: %016lx\n",
92                regs->r10, regs->r11, regs->r12);
93         printk("R13: %016lx R14: %016lx R15: %016lx\n",
94                regs->r13, regs->r14, regs->r15);
95
96         asm("movl %%ds,%0" : "=r" (ds));
97         asm("movl %%cs,%0" : "=r" (cs));
98         asm("movl %%es,%0" : "=r" (es));
99         asm("movl %%fs,%0" : "=r" (fsindex));
100         asm("movl %%gs,%0" : "=r" (gsindex));
101
102         rdmsrl(MSR_FS_BASE, fs);
103         rdmsrl(MSR_GS_BASE, gs);
104         rdmsrl(MSR_KERNEL_GS_BASE, shadowgs);
105
106         asm("movq %%cr0, %0": "=r" (cr0));
107         asm("movq %%cr2, %0": "=r" (cr2));
108         asm("movq %%cr3, %0": "=r" (cr3));
109         asm("movq %%cr4, %0": "=r" (cr4));
110
111         printk("FS:  %016lx(%04x) GS:%016lx(%04x) knlGS:%016lx\n",
112                fs, fsindex, gs, gsindex, shadowgs);
113         printk("CS:  %04x DS: %04x ES: %04x CR0: %016lx\n", cs, ds, es, cr0);
114         printk("CR2: %016lx CR3: %016lx CR4: %016lx\n", cr2, cr3, cr4);
115
116         if (!user_fault)
117                 kstack_trace( (void *) regs->rbp );
118 }
119