blob: b0951d0e8b2ca61e68b9ff976a5bc96b5eca696c [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
Catalin Marinas93ed3972008-08-28 11:22:32 +010033ENDPROC(__backtrace)
34ENDPROC(c_backtrace)
Linus Torvalds1da177e2005-04-16 15:20:36 -070035#else
Linus Torvalds1da177e2005-04-16 15:20:36 -070036 stmfd sp!, {r4 - r8, lr} @ Save an extra register so we have a location...
Russell King7ab3f8d2007-03-02 15:01:36 +000037 movs frame, r0 @ if frame pointer is zero
38 beq no_frame @ we have no stack frames
Linus Torvalds1da177e2005-04-16 15:20:36 -070039
Russell King7ab3f8d2007-03-02 15:01:36 +000040 tst r1, #0x10 @ 26 or 32-bit mode?
41 moveq mask, #0xfc000003 @ mask for 26-bit
42 movne mask, #0 @ mask for 32-bit
43
441: stmfd sp!, {pc} @ calculate offset of PC stored
45 ldr r0, [sp], #4 @ by stmfd for this CPU
46 adr r1, 1b
Linus Torvalds1da177e2005-04-16 15:20:36 -070047 sub offset, r0, r1
48
Russell King7ab3f8d2007-03-02 15:01:36 +000049/*
50 * Stack frame layout:
51 * optionally saved caller registers (r4 - r10)
52 * saved fp
53 * saved sp
54 * saved lr
55 * frame => saved pc
56 * optionally saved arguments (r0 - r3)
57 * saved sp => <next word>
58 *
59 * Functions start with the following code sequence:
60 * mov ip, sp
61 * stmfd sp!, {r0 - r3} (optional)
62 * corrected pc => stmfd sp!, {..., fp, ip, lr, pc}
63 */
64for_each_frame: tst frame, mask @ Check for address exceptions
65 bne no_frame
Linus Torvalds1da177e2005-04-16 15:20:36 -070066
Russell King7ab3f8d2007-03-02 15:01:36 +0000671001: ldr sv_pc, [frame, #0] @ get saved pc
681002: ldr sv_fp, [frame, #-12] @ get saved fp
69
70 sub sv_pc, sv_pc, offset @ Correct PC for prefetching
71 bic sv_pc, sv_pc, mask @ mask PC/LR for the mode
72
731003: ldr r2, [sv_pc, #-4] @ if stmfd sp!, {args} exists,
74 ldr r3, .Ldsi+4 @ adjust saved 'pc' back one
75 teq r3, r2, lsr #10 @ instruction
76 subne r0, sv_pc, #4 @ allow for mov
77 subeq r0, sv_pc, #8 @ allow for mov + stmia
78
79 ldr r1, [frame, #-4] @ get saved lr
80 mov r2, frame
81 bic r1, r1, mask @ mask PC/LR for the mode
Linus Torvalds1da177e2005-04-16 15:20:36 -070082 bl dump_backtrace_entry
83
Russell King7ab3f8d2007-03-02 15:01:36 +000084 ldr r1, [sv_pc, #-4] @ if stmfd sp!, {args} exists,
85 ldr r3, .Ldsi+4
86 teq r3, r1, lsr #10
87 ldreq r0, [frame, #-8] @ get sp
88 subeq r0, r0, #4 @ point at the last arg
89 bleq .Ldumpstm @ dump saved registers
Linus Torvalds1da177e2005-04-16 15:20:36 -070090
Russell King7ab3f8d2007-03-02 15:01:36 +0000911004: ldr r1, [sv_pc, #0] @ if stmfd sp!, {..., fp, ip, lr, pc}
92 ldr r3, .Ldsi @ instruction exists,
93 teq r3, r1, lsr #10
94 subeq r0, frame, #16
95 bleq .Ldumpstm @ dump saved registers
Linus Torvalds1da177e2005-04-16 15:20:36 -070096
Russell King7ab3f8d2007-03-02 15:01:36 +000097 teq sv_fp, #0 @ zero saved fp means
98 beq no_frame @ no further frames
Linus Torvalds1da177e2005-04-16 15:20:36 -070099
Russell King7ab3f8d2007-03-02 15:01:36 +0000100 cmp sv_fp, frame @ next frame must be
101 mov frame, sv_fp @ above the current frame
102 bhi for_each_frame
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103
Russell King7ab3f8d2007-03-02 15:01:36 +00001041006: adr r0, .Lbad
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105 mov r1, frame
106 bl printk
Russell King7ab3f8d2007-03-02 15:01:36 +0000107no_frame: ldmfd sp!, {r4 - r8, pc}
Catalin Marinas93ed3972008-08-28 11:22:32 +0100108ENDPROC(__backtrace)
109ENDPROC(c_backtrace)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110
111 .section __ex_table,"a"
112 .align 3
Russell King7ab3f8d2007-03-02 15:01:36 +0000113 .long 1001b, 1006b
114 .long 1002b, 1006b
115 .long 1003b, 1006b
116 .long 1004b, 1006b
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117 .previous
118
119#define instr r4
120#define reg r5
121#define stack r6
122
Russell King7ab3f8d2007-03-02 15:01:36 +0000123.Ldumpstm: stmfd sp!, {instr, reg, stack, r7, lr}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 mov stack, r0
125 mov instr, r1
Russell King7ab3f8d2007-03-02 15:01:36 +0000126 mov reg, #10
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 mov r7, #0
1281: mov r3, #1
129 tst instr, r3, lsl reg
130 beq 2f
131 add r7, r7, #1
Russell King7ab3f8d2007-03-02 15:01:36 +0000132 teq r7, #6
133 moveq r7, #1
134 moveq r1, #'\n'
135 movne r1, #' '
136 ldr r3, [stack], #-4
137 mov r2, reg
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138 adr r0, .Lfp
139 bl printk
1402: subs reg, reg, #1
141 bpl 1b
142 teq r7, #0
143 adrne r0, .Lcr
144 blne printk
Russell King7ab3f8d2007-03-02 15:01:36 +0000145 ldmfd sp!, {instr, reg, stack, r7, pc}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146
Russell King7ab3f8d2007-03-02 15:01:36 +0000147.Lfp: .asciz "%cr%d:%08x"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148.Lcr: .asciz "\n"
149.Lbad: .asciz "Backtrace aborted due to bad frame pointer <%p>\n"
150 .align
Russell King7ab3f8d2007-03-02 15:01:36 +0000151.Ldsi: .word 0xe92dd800 >> 10 @ stmfd sp!, {... fp, ip, lr, pc}
152 .word 0xe92d0000 >> 10 @ stmfd sp!, {}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153
154#endif