blob: 84dc890d2bf380cf248d8d9bd90acd02fdc91c56 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * linux/arch/arm/lib/backtrace.S
3 *
4 * Copyright (C) 1995, 1996 Russell King
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 * 27/03/03 Ian Molton Clean up CONFIG_CPU
11 *
12 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070013#include <linux/linkage.h>
14#include <asm/assembler.h>
15 .text
16
17@ fp is 0 or stack frame
18
19#define frame r4
Russell King7ab3f8d2007-03-02 15:01:36 +000020#define sv_fp r5
21#define sv_pc r6
Linus Torvalds1da177e2005-04-16 15:20:36 -070022#define mask r7
23#define offset r8
24
25ENTRY(__backtrace)
26 mov r1, #0x10
27 mov r0, fp
28
29ENTRY(c_backtrace)
30
Malcolm Parsons3ee357f2006-03-25 21:58:03 +000031#if !defined(CONFIG_FRAME_POINTER) || !defined(CONFIG_PRINTK)
Linus Torvalds1da177e2005-04-16 15:20:36 -070032 mov pc, lr
33#else
Linus Torvalds1da177e2005-04-16 15:20:36 -070034 stmfd sp!, {r4 - r8, lr} @ Save an extra register so we have a location...
Russell King7ab3f8d2007-03-02 15:01:36 +000035 movs frame, r0 @ if frame pointer is zero
36 beq no_frame @ we have no stack frames
Linus Torvalds1da177e2005-04-16 15:20:36 -070037
Russell King7ab3f8d2007-03-02 15:01:36 +000038 tst r1, #0x10 @ 26 or 32-bit mode?
39 moveq mask, #0xfc000003 @ mask for 26-bit
40 movne mask, #0 @ mask for 32-bit
41
421: stmfd sp!, {pc} @ calculate offset of PC stored
43 ldr r0, [sp], #4 @ by stmfd for this CPU
44 adr r1, 1b
Linus Torvalds1da177e2005-04-16 15:20:36 -070045 sub offset, r0, r1
46
Russell King7ab3f8d2007-03-02 15:01:36 +000047/*
48 * Stack frame layout:
49 * optionally saved caller registers (r4 - r10)
50 * saved fp
51 * saved sp
52 * saved lr
53 * frame => saved pc
54 * optionally saved arguments (r0 - r3)
55 * saved sp => <next word>
56 *
57 * Functions start with the following code sequence:
58 * mov ip, sp
59 * stmfd sp!, {r0 - r3} (optional)
60 * corrected pc => stmfd sp!, {..., fp, ip, lr, pc}
61 */
62for_each_frame: tst frame, mask @ Check for address exceptions
63 bne no_frame
Linus Torvalds1da177e2005-04-16 15:20:36 -070064
Russell King7ab3f8d2007-03-02 15:01:36 +0000651001: ldr sv_pc, [frame, #0] @ get saved pc
661002: ldr sv_fp, [frame, #-12] @ get saved fp
67
68 sub sv_pc, sv_pc, offset @ Correct PC for prefetching
69 bic sv_pc, sv_pc, mask @ mask PC/LR for the mode
70
711003: ldr r2, [sv_pc, #-4] @ if stmfd sp!, {args} exists,
72 ldr r3, .Ldsi+4 @ adjust saved 'pc' back one
73 teq r3, r2, lsr #10 @ instruction
74 subne r0, sv_pc, #4 @ allow for mov
75 subeq r0, sv_pc, #8 @ allow for mov + stmia
76
77 ldr r1, [frame, #-4] @ get saved lr
78 mov r2, frame
79 bic r1, r1, mask @ mask PC/LR for the mode
Linus Torvalds1da177e2005-04-16 15:20:36 -070080 bl dump_backtrace_entry
81
Russell King7ab3f8d2007-03-02 15:01:36 +000082 ldr r1, [sv_pc, #-4] @ if stmfd sp!, {args} exists,
83 ldr r3, .Ldsi+4
84 teq r3, r1, lsr #10
85 ldreq r0, [frame, #-8] @ get sp
86 subeq r0, r0, #4 @ point at the last arg
87 bleq .Ldumpstm @ dump saved registers
Linus Torvalds1da177e2005-04-16 15:20:36 -070088
Russell King7ab3f8d2007-03-02 15:01:36 +0000891004: ldr r1, [sv_pc, #0] @ if stmfd sp!, {..., fp, ip, lr, pc}
90 ldr r3, .Ldsi @ instruction exists,
91 teq r3, r1, lsr #10
92 subeq r0, frame, #16
93 bleq .Ldumpstm @ dump saved registers
Linus Torvalds1da177e2005-04-16 15:20:36 -070094
Russell King7ab3f8d2007-03-02 15:01:36 +000095 teq sv_fp, #0 @ zero saved fp means
96 beq no_frame @ no further frames
Linus Torvalds1da177e2005-04-16 15:20:36 -070097
Russell King7ab3f8d2007-03-02 15:01:36 +000098 cmp sv_fp, frame @ next frame must be
99 mov frame, sv_fp @ above the current frame
100 bhi for_each_frame
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101
Russell King7ab3f8d2007-03-02 15:01:36 +00001021006: adr r0, .Lbad
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103 mov r1, frame
104 bl printk
Russell King7ab3f8d2007-03-02 15:01:36 +0000105no_frame: ldmfd sp!, {r4 - r8, pc}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106
107 .section __ex_table,"a"
108 .align 3
Russell King7ab3f8d2007-03-02 15:01:36 +0000109 .long 1001b, 1006b
110 .long 1002b, 1006b
111 .long 1003b, 1006b
112 .long 1004b, 1006b
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113 .previous
114
115#define instr r4
116#define reg r5
117#define stack r6
118
Russell King7ab3f8d2007-03-02 15:01:36 +0000119.Ldumpstm: stmfd sp!, {instr, reg, stack, r7, lr}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120 mov stack, r0
121 mov instr, r1
Russell King7ab3f8d2007-03-02 15:01:36 +0000122 mov reg, #10
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123 mov r7, #0
1241: mov r3, #1
125 tst instr, r3, lsl reg
126 beq 2f
127 add r7, r7, #1
Russell King7ab3f8d2007-03-02 15:01:36 +0000128 teq r7, #6
129 moveq r7, #1
130 moveq r1, #'\n'
131 movne r1, #' '
132 ldr r3, [stack], #-4
133 mov r2, reg
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134 adr r0, .Lfp
135 bl printk
1362: subs reg, reg, #1
137 bpl 1b
138 teq r7, #0
139 adrne r0, .Lcr
140 blne printk
Russell King7ab3f8d2007-03-02 15:01:36 +0000141 ldmfd sp!, {instr, reg, stack, r7, pc}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142
Russell King7ab3f8d2007-03-02 15:01:36 +0000143.Lfp: .asciz "%cr%d:%08x"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144.Lcr: .asciz "\n"
145.Lbad: .asciz "Backtrace aborted due to bad frame pointer <%p>\n"
146 .align
Russell King7ab3f8d2007-03-02 15:01:36 +0000147.Ldsi: .word 0xe92dd800 >> 10 @ stmfd sp!, {... fp, ip, lr, pc}
148 .word 0xe92d0000 >> 10 @ stmfd sp!, {}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149
150#endif