2 * linux/arch/unicore32/lib/backtrace.S
4 * Code specific to PKUnity SoC and UniCore ISA
6 * Copyright (C) 2001-2010 GUAN Xue-tao
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
12 #include <linux/linkage.h>
13 #include <asm/assembler.h>
16 @ fp is 0 or stack frame
28 #if !defined(CONFIG_FRAME_POINTER) || !defined(CONFIG_PRINTK)
33 stm.w (v4 - v8, lr), [sp-] @ Save an extra register
34 @ so we have a location...
35 mov.a frame, r0 @ if frame pointer is zero
36 beq no_frame @ we have no stack frames
38 1: stm.w (pc), [sp-] @ calculate offset of PC stored
39 ldw.w r0, [sp]+, #4 @ by stmfd for this CPU
45 * optionally saved caller registers (r4 - r10)
50 * optionally saved arguments (r0 - r3)
51 * saved sp => <next word>
53 * Functions start with the following code sequence:
55 * stm.w (r0 - r3), [sp-] (optional)
56 * corrected pc => stm.w sp, (..., fp, ip, lr, pc)
60 1001: ldw sv_pc, [frame+], #0 @ get saved pc
61 1002: ldw sv_fp, [frame+], #-12 @ get saved fp
63 sub sv_pc, sv_pc, offset @ Correct PC for prefetching
65 1003: ldw r2, [sv_pc+], #-4 @ if stmfd sp, {args} exists,
66 ldw r3, .Ldsi+4 @ adjust saved 'pc' back one
67 cxor.a r3, r2 >> #14 @ instruction
69 sub r0, sv_pc, #4 @ allow for mov
72 sub r0, sv_pc, #8 @ allow for mov + stmia
74 ldw r1, [frame+], #-4 @ get saved lr
76 b.l dump_backtrace_entry
78 ldw r1, [sv_pc+], #-4 @ if stmfd sp, {args} exists,
82 ldw r0, [frame+], #-8 @ get sp
83 sub r0, r0, #4 @ point at the last arg
84 b.l .Ldumpstm @ dump saved registers
86 1004: ldw r1, [sv_pc+], #0 @ if stmfd {, fp, ip, lr, pc}
87 ldw r3, .Ldsi @ instruction exists,
91 b.l .Ldumpstm @ dump saved registers
93 cxor.a sv_fp, #0 @ zero saved fp means
94 beq no_frame @ no further frames
96 csub.a sv_fp, frame @ next frame must be
97 mov frame, sv_fp @ above the current frame
103 no_frame: ldm.w (v4 - v8, pc), [sp]+
107 .pushsection __ex_table,"a"
119 .Ldumpstm: stm.w (instr, reg, stack, v7, lr), [sp-]
129 cand.a instr, r3 << reg
136 ldw.w r3, [stack]+, #-4
142 cand.a instr, #0x40 @ if H is 1, high 16 regs
144 add r2, r2, #0x10 @ so r2 need add 16
148 2: sub.a reg, reg, #1
154 201: ldm.w (instr, reg, stack, v7, pc), [sp]+
156 .Lfp: .asciz "%cr%d:%08x"
158 .Lbad: .asciz "Backtrace aborted due to bad frame pointer <%p>\n"
160 .Ldsi: .word 0x92eec000 >> 14 @ stm.w sp, (... fp, ip, lr, pc)
161 .word 0x92e10000 >> 14 @ stm.w sp, ()