1 /* Provide basic stack dumping functions
3 * Copyright 2004-2009 Analog Devices Inc.
5 * Licensed under the GPL-2 or later
8 #include <linux/kernel.h>
9 #include <linux/thread_info.h>
11 #include <linux/uaccess.h>
12 #include <linux/module.h>
13 #include <linux/sched/debug.h>
15 #include <asm/trace.h>
18 * Checks to see if the address pointed to is either a
19 * 16-bit CALL instruction, or a 32-bit CALL instruction
21 static bool is_bfin_call(unsigned short *addr
)
25 if (!get_instruction(&opcode
, addr
))
28 if ((opcode
>= 0x0060 && opcode
<= 0x0067) ||
29 (opcode
>= 0x0070 && opcode
<= 0x0077) ||
30 (opcode
>= 0xE3000000 && opcode
<= 0xE3FFFFFF))
37 void show_stack(struct task_struct
*task
, unsigned long *stack
)
40 unsigned int *addr
, *endstack
, *fp
= 0, *frame
;
41 unsigned short *ins_addr
;
43 unsigned int i
, j
, ret_addr
, frame_no
= 0;
46 * If we have been passed a specific stack, use that one otherwise
47 * if we have been passed a task structure, use that, otherwise
48 * use the stack of where the variable "stack" exists
53 /* We know this is a kernel stack, so this is the start/end */
54 stack
= (unsigned long *)task
->thread
.ksp
;
55 endstack
= (unsigned int *)(((unsigned int)(stack
) & ~(THREAD_SIZE
- 1)) + THREAD_SIZE
);
57 /* print out the existing stack info */
58 stack
= (unsigned long *)&stack
;
59 endstack
= (unsigned int *)PAGE_ALIGN((unsigned int)stack
);
62 endstack
= (unsigned int *)PAGE_ALIGN((unsigned int)stack
);
64 printk(KERN_NOTICE
"Stack info:\n");
65 decode_address(buf
, (unsigned int)stack
);
66 printk(KERN_NOTICE
" SP: [0x%p] %s\n", stack
, buf
);
68 if (!access_ok(VERIFY_READ
, stack
, (unsigned int)endstack
- (unsigned int)stack
)) {
69 printk(KERN_NOTICE
"Invalid stack pointer\n");
73 /* First thing is to look for a frame pointer */
74 for (addr
= (unsigned int *)((unsigned int)stack
& ~0xF); addr
< endstack
; addr
++) {
77 ins_addr
= (unsigned short *)*addr
;
79 if (is_bfin_call(ins_addr
))
83 /* Let's check to see if it is a frame pointer */
84 while (fp
>= (addr
- 1) && fp
< endstack
85 && fp
&& ((unsigned int) fp
& 0x3) == 0)
86 fp
= (unsigned int *)*fp
;
87 if (fp
== 0 || fp
== endstack
) {
96 printk(KERN_NOTICE
" FP: (0x%p)\n", fp
);
101 * Now that we think we know where things are, we
102 * walk the stack again, this time printing things out
103 * incase there is no frame pointer, we still look for
104 * valid return addresses
107 /* First time print out data, next time, print out symbols */
108 for (j
= 0; j
<= 1; j
++) {
110 printk(KERN_NOTICE
"Return addresses in stack:\n");
112 printk(KERN_NOTICE
" Memory from 0x%08lx to %p", ((long unsigned int)stack
& ~0xF), endstack
);
117 for (addr
= (unsigned int *)((unsigned int)stack
& ~0xF), i
= 0;
118 addr
< endstack
; addr
++, i
++) {
121 if (!j
&& i
% 8 == 0)
122 printk(KERN_NOTICE
"%p:", addr
);
124 /* if it is an odd address, or zero, just skip it */
125 if (*addr
& 0x1 || !*addr
)
128 ins_addr
= (unsigned short *)*addr
;
130 /* Go back one instruction, and see if it is a CALL */
132 ret_addr
= is_bfin_call(ins_addr
);
134 if (!j
&& stack
== (unsigned long *)addr
)
135 printk("[%08x]", *addr
);
138 decode_address(buf
, (unsigned int)*addr
);
140 printk(KERN_NOTICE
" frame %2i : %s\n", frame_no
, buf
);
143 printk(KERN_NOTICE
" address : %s\n", buf
);
145 printk("<%08x>", *addr
);
146 else if (fp
== addr
) {
150 printk("(%08x)", *addr
);
152 fp
= (unsigned int *)*addr
;
156 printk(" %08x ", *addr
);
163 EXPORT_SYMBOL(show_stack
);
165 void dump_stack(void)
168 #ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
171 trace_buffer_save(tflags
);
172 dump_bfin_trace_buffer();
173 dump_stack_print_info(KERN_DEFAULT
);
174 show_stack(current
, &stack
);
175 trace_buffer_restore(tflags
);
177 EXPORT_SYMBOL(dump_stack
);