Merge branch 'for-linus' of git://one.firstfloor.org/home/andi/git/linux-2.6
[linux-2.6] / arch / um / sys-i386 / sysrq.c
1 /*
2  * Copyright (C) 2001 - 2003 Jeff Dike (jdike@addtoit.com)
3  * Licensed under the GPL
4  */
5
6 #include "linux/config.h"
7 #include "linux/kernel.h"
8 #include "linux/smp.h"
9 #include "linux/sched.h"
10 #include "linux/kallsyms.h"
11 #include "asm/ptrace.h"
12 #include "sysrq.h"
13
14 /* This is declared by <linux/sched.h> */
15 void show_regs(struct pt_regs *regs)
16 {
17         printk("\n");
18         printk("EIP: %04lx:[<%08lx>] CPU: %d %s", 
19                0xffff & PT_REGS_CS(regs), PT_REGS_IP(regs),
20                smp_processor_id(), print_tainted());
21         if (PT_REGS_CS(regs) & 3)
22                 printk(" ESP: %04lx:%08lx", 0xffff & PT_REGS_SS(regs),
23                        PT_REGS_SP(regs));
24         printk(" EFLAGS: %08lx\n    %s\n", PT_REGS_EFLAGS(regs),
25                print_tainted());
26         printk("EAX: %08lx EBX: %08lx ECX: %08lx EDX: %08lx\n",
27                 PT_REGS_EAX(regs), PT_REGS_EBX(regs), 
28                PT_REGS_ECX(regs), 
29                PT_REGS_EDX(regs));
30         printk("ESI: %08lx EDI: %08lx EBP: %08lx",
31                PT_REGS_ESI(regs), PT_REGS_EDI(regs), 
32                PT_REGS_EBP(regs));
33         printk(" DS: %04lx ES: %04lx\n",
34                0xffff & PT_REGS_DS(regs), 
35                0xffff & PT_REGS_ES(regs));
36
37         show_trace(NULL, (unsigned long *) &regs);
38 }
39
40 /* Copied from i386. */
41 static inline int valid_stack_ptr(struct thread_info *tinfo, void *p)
42 {
43         return  p > (void *)tinfo &&
44                 p < (void *)tinfo + THREAD_SIZE - 3;
45 }
46
47 /* Adapted from i386 (we also print the address we read from). */
48 static inline unsigned long print_context_stack(struct thread_info *tinfo,
49                                 unsigned long *stack, unsigned long ebp)
50 {
51         unsigned long addr;
52
53 #ifdef CONFIG_FRAME_POINTER
54         while (valid_stack_ptr(tinfo, (void *)ebp)) {
55                 addr = *(unsigned long *)(ebp + 4);
56                 printk("%08lx:  [<%08lx>]", ebp + 4, addr);
57                 print_symbol(" %s", addr);
58                 printk("\n");
59                 ebp = *(unsigned long *)ebp;
60         }
61 #else
62         while (valid_stack_ptr(tinfo, stack)) {
63                 addr = *stack;
64                 if (__kernel_text_address(addr)) {
65                         printk("%08lx:  [<%08lx>]", (unsigned long) stack, addr);
66                         print_symbol(" %s", addr);
67                         printk("\n");
68                 }
69                 stack++;
70         }
71 #endif
72         return ebp;
73 }
74
75 void show_trace(struct task_struct* task, unsigned long * stack)
76 {
77         unsigned long ebp;
78         struct thread_info *context;
79
80         /* Turn this into BUG_ON if possible. */
81         if (!stack) {
82                 stack = (unsigned long*) &stack;
83                 printk("show_trace: got NULL stack, implicit assumption task == current");
84                 WARN_ON(1);
85         }
86
87         if (!task)
88                 task = current;
89
90         if (task != current) {
91                 ebp = (unsigned long) KSTK_EBP(task);
92         } else {
93                 asm ("movl %%ebp, %0" : "=r" (ebp) : );
94         }
95
96         context = (struct thread_info *)
97                 ((unsigned long)stack & (~(THREAD_SIZE - 1)));
98         print_context_stack(context, stack, ebp);
99
100         printk("\n");
101 }
102