aboutsummaryrefslogtreecommitdiffstats
path: root/arch/alpha/lib/stacktrace.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
commit1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch)
tree0bba044c4ce775e45a88a51686b5d9f90697ea9d /arch/alpha/lib/stacktrace.c
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history, even though we have it. We can create a separate "historical" git archive of that later if we want to, and in the meantime it's about 3.2GB when imported into git - space that would just make the early git days unnecessarily complicated, when we don't have a lot of good infrastructure for it. Let it rip!
Diffstat (limited to 'arch/alpha/lib/stacktrace.c')
-rw-r--r--arch/alpha/lib/stacktrace.c103
1 files changed, 103 insertions, 0 deletions
diff --git a/arch/alpha/lib/stacktrace.c b/arch/alpha/lib/stacktrace.c
new file mode 100644
index 000000000000..6d432e42aedc
--- /dev/null
+++ b/arch/alpha/lib/stacktrace.c
@@ -0,0 +1,103 @@
1#include <linux/kernel.h>
2#include <asm/system.h>
3
4typedef unsigned int instr;
5
6#define MAJOR_OP 0xfc000000
7#define LDA_OP 0x20000000
8#define STQ_OP 0xb4000000
9#define BR_OP 0xc0000000
10
11#define STK_ALLOC_1 0x23de8000 /* lda $30,-X($30) */
12#define STK_ALLOC_1M 0xffff8000
13#define STK_ALLOC_2 0x43c0153e /* subq $30,X,$30 */
14#define STK_ALLOC_2M 0xffe01fff
15
16#define MEM_REG 0x03e00000
17#define MEM_BASE 0x001f0000
18#define MEM_OFF 0x0000ffff
19#define MEM_OFF_SIGN 0x00008000
20#define BASE_SP 0x001e0000
21
22#define STK_ALLOC_MATCH(INSTR) \
23 (((INSTR) & STK_ALLOC_1M) == STK_ALLOC_1 \
24 || ((INSTR) & STK_ALLOC_2M) == STK_ALLOC_2)
25#define STK_PUSH_MATCH(INSTR) \
26 (((INSTR) & (MAJOR_OP | MEM_BASE | MEM_OFF_SIGN)) == (STQ_OP | BASE_SP))
27#define MEM_OP_OFFSET(INSTR) \
28 (((long)((INSTR) & MEM_OFF) << 48) >> 48)
29#define MEM_OP_REG(INSTR) \
30 (((INSTR) & MEM_REG) >> 22)
31
32/* Branches, jumps, PAL calls, and illegal opcodes end a basic block. */
33#define BB_END(INSTR) \
34 (((instr)(INSTR) >= BR_OP) | ((instr)(INSTR) < LDA_OP) | \
35 ((((instr)(INSTR) ^ 0x60000000) < 0x20000000) & \
36 (((instr)(INSTR) & 0x0c000000) != 0)))
37
38#define IS_KERNEL_TEXT(PC) ((unsigned long)(PC) > START_ADDR)
39
40static char reg_name[][4] = {
41 "v0 ", "t0 ", "t1 ", "t2 ", "t3 ", "t4 ", "t5 ", "t6 ", "t7 ",
42 "s0 ", "s1 ", "s2 ", "s3 ", "s4 ", "s5 ", "s6 ", "a0 ", "a1 ",
43 "a2 ", "a3 ", "a4 ", "a5 ", "t8 ", "t9 ", "t10", "t11", "ra ",
44 "pv ", "at ", "gp ", "sp ", "0"
45};
46
47
48static instr *
49display_stored_regs(instr * pro_pc, unsigned char * sp)
50{
51 instr * ret_pc = 0;
52 int reg;
53 unsigned long value;
54
55 printk("Prologue [<%p>], Frame %p:\n", pro_pc, sp);
56 while (!BB_END(*pro_pc))
57 if (STK_PUSH_MATCH(*pro_pc)) {
58 reg = (*pro_pc & MEM_REG) >> 21;
59 value = *(unsigned long *)(sp + (*pro_pc & MEM_OFF));
60 if (reg == 26)
61 ret_pc = (instr *)value;
62 printk("\t\t%s / 0x%016lx\n", reg_name[reg], value);
63 }
64 return ret_pc;
65}
66
67static instr *
68seek_prologue(instr * pc)
69{
70 while (!STK_ALLOC_MATCH(*pc))
71 --pc;
72 while (!BB_END(*(pc - 1)))
73 --pc;
74 return pc;
75}
76
77static long
78stack_increment(instr * prologue_pc)
79{
80 while (!STK_ALLOC_MATCH(*prologue_pc))
81 ++prologue_pc;
82
83 /* Count the bytes allocated. */
84 if ((*prologue_pc & STK_ALLOC_1M) == STK_ALLOC_1M)
85 return -(((long)(*prologue_pc) << 48) >> 48);
86 else
87 return (*prologue_pc >> 13) & 0xff;
88}
89
90void
91stacktrace(void)
92{
93 instr * ret_pc;
94 instr * prologue = (instr *)stacktrace;
95 register unsigned char * sp __asm__ ("$30");
96
97 printk("\tstack trace:\n");
98 do {
99 ret_pc = display_stored_regs(prologue, sp);
100 sp += stack_increment(prologue);
101 prologue = seek_prologue(ret_pc);
102 } while (IS_KERNEL_TEXT(ret_pc));
103}