2 * linux/arch/arm/lib/backtrace.S
4 * Copyright (C) 1995, 1996 Russell King
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.
10 * 27/03/03 Ian Molton Clean up CONFIG_CPU
13 #include <linux/linkage.h>
14 #include <asm/assembler.h>
17 @ fp is 0 or stack frame
31 #if !defined(CONFIG_FRAME_POINTER) || !defined(CONFIG_PRINTK)
36 stmfd sp!, {r4 - r8, lr} @ Save an extra register so we have a location...
37 movs frame, r0 @ if frame pointer is zero
38 beq no_frame @ we have no stack frames
40 tst r1, #0x10 @ 26 or 32-bit mode?
41 moveq mask, #0xfc000003 @ mask for 26-bit
42 movne mask, #0 @ mask for 32-bit
44 1: stmfd sp!, {pc} @ calculate offset of PC stored
45 ldr r0, [sp], #4 @ by stmfd for this CPU
51 * optionally saved caller registers (r4 - r10)
56 * optionally saved arguments (r0 - r3)
57 * saved sp => <next word>
59 * Functions start with the following code sequence:
61 * stmfd sp!, {r0 - r3} (optional)
62 * corrected pc => stmfd sp!, {..., fp, ip, lr, pc}
64 for_each_frame: tst frame, mask @ Check for address exceptions
67 1001: ldr sv_pc, [frame, #0] @ get saved pc
68 1002: ldr sv_fp, [frame, #-12] @ get saved fp
70 sub sv_pc, sv_pc, offset @ Correct PC for prefetching
71 bic sv_pc, sv_pc, mask @ mask PC/LR for the mode
73 1003: 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
79 ldr r1, [frame, #-4] @ get saved lr
81 bic r1, r1, mask @ mask PC/LR for the mode
82 bl dump_backtrace_entry
84 ldr r1, [sv_pc, #-4] @ if stmfd sp!, {args} exists,
87 ldreq r0, [frame, #-8] @ get sp
88 subeq r0, r0, #4 @ point at the last arg
89 bleq .Ldumpstm @ dump saved registers
91 1004: ldr r1, [sv_pc, #0] @ if stmfd sp!, {..., fp, ip, lr, pc}
92 ldr r3, .Ldsi @ instruction exists,
95 bleq .Ldumpstm @ dump saved registers
97 teq sv_fp, #0 @ zero saved fp means
98 beq no_frame @ no further frames
100 cmp sv_fp, frame @ next frame must be
101 mov frame, sv_fp @ above the current frame
107 no_frame: ldmfd sp!, {r4 - r8, pc}
111 .section __ex_table,"a"
123 .Ldumpstm: stmfd sp!, {instr, reg, stack, r7, lr}
129 tst instr, r3, lsl reg
145 ldmfd sp!, {instr, reg, stack, r7, pc}
147 .Lfp: .asciz "%cr%d:%08x"
149 .Lbad: .asciz "Backtrace aborted due to bad frame pointer <%p>\n"
151 .Ldsi: .word 0xe92dd800 >> 10 @ stmfd sp!, {... fp, ip, lr, pc}
152 .word 0xe92d0000 >> 10 @ stmfd sp!, {}