2019-06-04 11:11:33 +03:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-only */
|
2005-04-17 02:20:36 +04:00
|
|
|
/*
|
|
|
|
* linux/arch/arm/lib/backtrace.S
|
|
|
|
*
|
|
|
|
* Copyright (C) 1995, 1996 Russell King
|
|
|
|
*
|
|
|
|
* 27/03/03 Ian Molton Clean up CONFIG_CPU
|
|
|
|
*/
|
2016-11-15 16:55:59 +03:00
|
|
|
#include <linux/kern_levels.h>
|
2005-04-17 02:20:36 +04:00
|
|
|
#include <linux/linkage.h>
|
|
|
|
#include <asm/assembler.h>
|
|
|
|
.text
|
|
|
|
|
|
|
|
@ fp is 0 or stack frame
|
|
|
|
|
|
|
|
#define frame r4
|
2007-03-02 18:01:36 +03:00
|
|
|
#define sv_fp r5
|
|
|
|
#define sv_pc r6
|
2005-04-17 02:20:36 +04:00
|
|
|
#define mask r7
|
|
|
|
#define offset r8
|
2020-06-09 07:30:07 +03:00
|
|
|
#define loglvl r9
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
ENTRY(c_backtrace)
|
|
|
|
|
2006-03-26 00:58:03 +03:00
|
|
|
#if !defined(CONFIG_FRAME_POINTER) || !defined(CONFIG_PRINTK)
|
2014-06-30 19:29:12 +04:00
|
|
|
ret lr
|
2008-08-28 14:22:32 +04:00
|
|
|
ENDPROC(c_backtrace)
|
2005-04-17 02:20:36 +04:00
|
|
|
#else
|
2020-06-09 07:30:07 +03:00
|
|
|
stmfd sp!, {r4 - r9, lr} @ Save an extra register so we have a location...
|
2007-03-02 18:01:36 +03:00
|
|
|
movs frame, r0 @ if frame pointer is zero
|
|
|
|
beq no_frame @ we have no stack frames
|
2020-06-09 07:30:07 +03:00
|
|
|
mov loglvl, r2
|
2007-03-02 18:01:36 +03:00
|
|
|
|
|
|
|
tst r1, #0x10 @ 26 or 32-bit mode?
|
2009-07-24 15:32:57 +04:00
|
|
|
ARM( moveq mask, #0xfc000003 )
|
|
|
|
THUMB( moveq mask, #0xfc000000 )
|
|
|
|
THUMB( orreq mask, #0x03 )
|
2007-03-02 18:01:36 +03:00
|
|
|
movne mask, #0 @ mask for 32-bit
|
|
|
|
|
|
|
|
1: stmfd sp!, {pc} @ calculate offset of PC stored
|
|
|
|
ldr r0, [sp], #4 @ by stmfd for this CPU
|
|
|
|
adr r1, 1b
|
2005-04-17 02:20:36 +04:00
|
|
|
sub offset, r0, r1
|
|
|
|
|
2007-03-02 18:01:36 +03:00
|
|
|
/*
|
|
|
|
* Stack frame layout:
|
|
|
|
* optionally saved caller registers (r4 - r10)
|
|
|
|
* saved fp
|
|
|
|
* saved sp
|
|
|
|
* saved lr
|
|
|
|
* frame => saved pc
|
|
|
|
* optionally saved arguments (r0 - r3)
|
|
|
|
* saved sp => <next word>
|
|
|
|
*
|
|
|
|
* Functions start with the following code sequence:
|
|
|
|
* mov ip, sp
|
|
|
|
* stmfd sp!, {r0 - r3} (optional)
|
|
|
|
* corrected pc => stmfd sp!, {..., fp, ip, lr, pc}
|
|
|
|
*/
|
|
|
|
for_each_frame: tst frame, mask @ Check for address exceptions
|
|
|
|
bne no_frame
|
|
|
|
|
|
|
|
1001: ldr sv_pc, [frame, #0] @ get saved pc
|
|
|
|
1002: ldr sv_fp, [frame, #-12] @ get saved fp
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2007-03-02 18:01:36 +03:00
|
|
|
sub sv_pc, sv_pc, offset @ Correct PC for prefetching
|
|
|
|
bic sv_pc, sv_pc, mask @ mask PC/LR for the mode
|
|
|
|
|
|
|
|
1003: ldr r2, [sv_pc, #-4] @ if stmfd sp!, {args} exists,
|
|
|
|
ldr r3, .Ldsi+4 @ adjust saved 'pc' back one
|
2019-08-01 10:15:23 +03:00
|
|
|
teq r3, r2, lsr #11 @ instruction
|
2007-03-02 18:01:36 +03:00
|
|
|
subne r0, sv_pc, #4 @ allow for mov
|
|
|
|
subeq r0, sv_pc, #8 @ allow for mov + stmia
|
|
|
|
|
|
|
|
ldr r1, [frame, #-4] @ get saved lr
|
|
|
|
mov r2, frame
|
|
|
|
bic r1, r1, mask @ mask PC/LR for the mode
|
2020-06-09 07:30:07 +03:00
|
|
|
mov r3, loglvl
|
2005-04-17 02:20:36 +04:00
|
|
|
bl dump_backtrace_entry
|
|
|
|
|
2007-03-02 18:01:36 +03:00
|
|
|
ldr r1, [sv_pc, #-4] @ if stmfd sp!, {args} exists,
|
|
|
|
ldr r3, .Ldsi+4
|
2013-10-20 18:34:10 +04:00
|
|
|
teq r3, r1, lsr #11
|
2007-03-02 18:01:36 +03:00
|
|
|
ldreq r0, [frame, #-8] @ get sp
|
|
|
|
subeq r0, r0, #4 @ point at the last arg
|
2020-06-09 07:30:07 +03:00
|
|
|
mov r2, loglvl
|
2016-11-15 16:55:59 +03:00
|
|
|
bleq dump_backtrace_stm @ dump saved registers
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2007-03-02 18:01:36 +03:00
|
|
|
1004: ldr r1, [sv_pc, #0] @ if stmfd sp!, {..., fp, ip, lr, pc}
|
|
|
|
ldr r3, .Ldsi @ instruction exists,
|
2013-10-20 18:34:10 +04:00
|
|
|
teq r3, r1, lsr #11
|
2007-03-02 18:01:36 +03:00
|
|
|
subeq r0, frame, #16
|
2020-06-09 07:30:07 +03:00
|
|
|
mov r2, loglvl
|
2016-11-15 16:55:59 +03:00
|
|
|
bleq dump_backtrace_stm @ dump saved registers
|
2007-03-02 18:01:36 +03:00
|
|
|
|
|
|
|
teq sv_fp, #0 @ zero saved fp means
|
|
|
|
beq no_frame @ no further frames
|
|
|
|
|
|
|
|
cmp sv_fp, frame @ next frame must be
|
|
|
|
mov frame, sv_fp @ above the current frame
|
|
|
|
bhi for_each_frame
|
|
|
|
|
|
|
|
1006: adr r0, .Lbad
|
2020-06-09 07:30:07 +03:00
|
|
|
mov r1, loglvl
|
|
|
|
mov r2, frame
|
2005-04-17 02:20:36 +04:00
|
|
|
bl printk
|
2020-06-09 07:30:07 +03:00
|
|
|
no_frame: ldmfd sp!, {r4 - r9, pc}
|
2008-08-28 14:22:32 +04:00
|
|
|
ENDPROC(c_backtrace)
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2010-04-19 13:15:03 +04:00
|
|
|
.pushsection __ex_table,"a"
|
2005-04-17 02:20:36 +04:00
|
|
|
.align 3
|
2007-03-02 18:01:36 +03:00
|
|
|
.long 1001b, 1006b
|
|
|
|
.long 1002b, 1006b
|
|
|
|
.long 1003b, 1006b
|
|
|
|
.long 1004b, 1006b
|
2010-04-19 13:15:03 +04:00
|
|
|
.popsection
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2020-06-09 07:30:07 +03:00
|
|
|
.Lbad: .asciz "%sBacktrace aborted due to bad frame pointer <%p>\n"
|
2005-04-17 02:20:36 +04:00
|
|
|
.align
|
2013-10-20 18:34:10 +04:00
|
|
|
.Ldsi: .word 0xe92dd800 >> 11 @ stmfd sp!, {... fp, ip, lr, pc}
|
|
|
|
.word 0xe92d0000 >> 11 @ stmfd sp!, {}
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
#endif
|