2 * Copyright (C) 2010-2013 Imagination Technologies Ltd.
4 * This file is subject to the terms and conditions of the GNU General Public
5 * License. See the file "COPYING" in the main directory of this archive
9 #include <linux/oprofile.h>
10 #include <linux/uaccess.h>
11 #include <asm/processor.h>
12 #include <asm/stacktrace.h>
14 #include "backtrace.h"
16 static void user_backtrace_fp(unsigned long __user
*fp
, unsigned int depth
)
18 while (depth
-- && access_ok(VERIFY_READ
, fp
, 8)) {
20 unsigned long __user
*fpnew
;
21 if (__copy_from_user_inatomic(&addr
, fp
+ 1, sizeof(addr
)))
25 oprofile_add_trace(addr
);
27 /* stack grows up, so frame pointers must decrease */
28 if (__copy_from_user_inatomic(&fpnew
, fp
+ 0, sizeof(fpnew
)))
36 static int kernel_backtrace_frame(struct stackframe
*frame
, void *data
)
38 unsigned int *depth
= data
;
40 oprofile_add_trace(frame
->pc
);
42 /* decrement depth and stop if we reach 0 */
46 /* otherwise onto the next frame */
50 void metag_backtrace(struct pt_regs
* const regs
, unsigned int depth
)
52 if (user_mode(regs
)) {
53 unsigned long *fp
= (unsigned long *)regs
->ctx
.AX
[1].U0
;
54 user_backtrace_fp((unsigned long __user __force
*)fp
, depth
);
56 struct stackframe frame
;
57 frame
.fp
= regs
->ctx
.AX
[1].U0
; /* A0FrP */
58 frame
.sp
= user_stack_pointer(regs
); /* A0StP */
59 frame
.lr
= 0; /* from stack */
60 frame
.pc
= regs
->ctx
.CurrPC
; /* PC */
61 walk_stackframe(&frame
, &kernel_backtrace_frame
, &depth
);