xref: /linux/arch/x86/um/sysrq_32.c (revision 382d95fdfa7ff5c54f6495c597c7cf6d124e404b)
15c48b108SAl Viro /*
25c48b108SAl Viro  * Copyright (C) 2001 - 2003 Jeff Dike (jdike@addtoit.com)
35c48b108SAl Viro  * Licensed under the GPL
45c48b108SAl Viro  */
55c48b108SAl Viro 
6*382d95fdSAl Viro #include <linux/kernel.h>
7*382d95fdSAl Viro #include <linux/smp.h>
8*382d95fdSAl Viro #include <linux/sched.h>
9*382d95fdSAl Viro #include <linux/kallsyms.h>
10*382d95fdSAl Viro #include <asm/ptrace.h>
11*382d95fdSAl Viro #include <asm/sysrq.h>
125c48b108SAl Viro 
135c48b108SAl Viro /* This is declared by <linux/sched.h> */
145c48b108SAl Viro void show_regs(struct pt_regs *regs)
155c48b108SAl Viro {
165c48b108SAl Viro         printk("\n");
175c48b108SAl Viro         printk("EIP: %04lx:[<%08lx>] CPU: %d %s",
185c48b108SAl Viro 	       0xffff & PT_REGS_CS(regs), PT_REGS_IP(regs),
195c48b108SAl Viro 	       smp_processor_id(), print_tainted());
205c48b108SAl Viro         if (PT_REGS_CS(regs) & 3)
215c48b108SAl Viro                 printk(" ESP: %04lx:%08lx", 0xffff & PT_REGS_SS(regs),
225c48b108SAl Viro 		       PT_REGS_SP(regs));
235c48b108SAl Viro         printk(" EFLAGS: %08lx\n    %s\n", PT_REGS_EFLAGS(regs),
245c48b108SAl Viro 	       print_tainted());
255c48b108SAl Viro         printk("EAX: %08lx EBX: %08lx ECX: %08lx EDX: %08lx\n",
26243412beSAl Viro                PT_REGS_AX(regs), PT_REGS_BX(regs),
27243412beSAl Viro 	       PT_REGS_CX(regs), PT_REGS_DX(regs));
285c48b108SAl Viro         printk("ESI: %08lx EDI: %08lx EBP: %08lx",
29243412beSAl Viro 	       PT_REGS_SI(regs), PT_REGS_DI(regs), PT_REGS_BP(regs));
305c48b108SAl Viro         printk(" DS: %04lx ES: %04lx\n",
315c48b108SAl Viro 	       0xffff & PT_REGS_DS(regs),
325c48b108SAl Viro 	       0xffff & PT_REGS_ES(regs));
335c48b108SAl Viro 
345c48b108SAl Viro         show_trace(NULL, (unsigned long *) &regs);
355c48b108SAl Viro }
365c48b108SAl Viro 
375c48b108SAl Viro /* Copied from i386. */
385c48b108SAl Viro static inline int valid_stack_ptr(struct thread_info *tinfo, void *p)
395c48b108SAl Viro {
405c48b108SAl Viro 	return	p > (void *)tinfo &&
415c48b108SAl Viro 		p < (void *)tinfo + THREAD_SIZE - 3;
425c48b108SAl Viro }
435c48b108SAl Viro 
445c48b108SAl Viro /* Adapted from i386 (we also print the address we read from). */
455c48b108SAl Viro static inline unsigned long print_context_stack(struct thread_info *tinfo,
465c48b108SAl Viro 				unsigned long *stack, unsigned long ebp)
475c48b108SAl Viro {
485c48b108SAl Viro 	unsigned long addr;
495c48b108SAl Viro 
505c48b108SAl Viro #ifdef CONFIG_FRAME_POINTER
515c48b108SAl Viro 	while (valid_stack_ptr(tinfo, (void *)ebp)) {
525c48b108SAl Viro 		addr = *(unsigned long *)(ebp + 4);
535c48b108SAl Viro 		printk("%08lx:  [<%08lx>]", ebp + 4, addr);
545c48b108SAl Viro 		print_symbol(" %s", addr);
555c48b108SAl Viro 		printk("\n");
565c48b108SAl Viro 		ebp = *(unsigned long *)ebp;
575c48b108SAl Viro 	}
585c48b108SAl Viro #else
595c48b108SAl Viro 	while (valid_stack_ptr(tinfo, stack)) {
605c48b108SAl Viro 		addr = *stack;
615c48b108SAl Viro 		if (__kernel_text_address(addr)) {
625c48b108SAl Viro 			printk("%08lx:  [<%08lx>]", (unsigned long) stack, addr);
635c48b108SAl Viro 			print_symbol(" %s", addr);
645c48b108SAl Viro 			printk("\n");
655c48b108SAl Viro 		}
665c48b108SAl Viro 		stack++;
675c48b108SAl Viro 	}
685c48b108SAl Viro #endif
695c48b108SAl Viro 	return ebp;
705c48b108SAl Viro }
715c48b108SAl Viro 
725c48b108SAl Viro void show_trace(struct task_struct* task, unsigned long * stack)
735c48b108SAl Viro {
745c48b108SAl Viro 	unsigned long ebp;
755c48b108SAl Viro 	struct thread_info *context;
765c48b108SAl Viro 
775c48b108SAl Viro 	/* Turn this into BUG_ON if possible. */
785c48b108SAl Viro 	if (!stack) {
795c48b108SAl Viro 		stack = (unsigned long*) &stack;
805c48b108SAl Viro 		printk("show_trace: got NULL stack, implicit assumption task == current");
815c48b108SAl Viro 		WARN_ON(1);
825c48b108SAl Viro 	}
835c48b108SAl Viro 
845c48b108SAl Viro 	if (!task)
855c48b108SAl Viro 		task = current;
865c48b108SAl Viro 
875c48b108SAl Viro 	if (task != current) {
885c48b108SAl Viro 		ebp = (unsigned long) KSTK_EBP(task);
895c48b108SAl Viro 	} else {
905c48b108SAl Viro 		asm ("movl %%ebp, %0" : "=r" (ebp) : );
915c48b108SAl Viro 	}
925c48b108SAl Viro 
935c48b108SAl Viro 	context = (struct thread_info *)
945c48b108SAl Viro 		((unsigned long)stack & (~(THREAD_SIZE - 1)));
955c48b108SAl Viro 	print_context_stack(context, stack, ebp);
965c48b108SAl Viro 
975c48b108SAl Viro 	printk("\n");
985c48b108SAl Viro }
995c48b108SAl Viro 
100