[MIPS] Use common definitions from asm-generic/signal.h
[linux-2.6/linux-mips/linux-dm7025.git] / arch / powerpc / oprofile / backtrace.c
blob75f57bc96b404416480d410a537eccfcdbcfe4b6
1 /**
2 * Copyright (C) 2005 Brian Rogan <bcr6@cornell.edu>, IBM
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version
7 * 2 of the License, or (at your option) any later version.
8 **/
10 #include <linux/oprofile.h>
11 #include <linux/sched.h>
12 #include <asm/processor.h>
13 #include <asm/uaccess.h>
15 #define STACK_SP(STACK) *(STACK)
17 #define STACK_LR64(STACK) *((unsigned long *)(STACK) + 2)
18 #define STACK_LR32(STACK) *((unsigned int *)(STACK) + 1)
20 #ifdef CONFIG_PPC64
21 #define STACK_LR(STACK) STACK_LR64(STACK)
22 #else
23 #define STACK_LR(STACK) STACK_LR32(STACK)
24 #endif
26 static unsigned int user_getsp32(unsigned int sp, int is_first)
28 unsigned int stack_frame[2];
30 if (!access_ok(VERIFY_READ, sp, sizeof(stack_frame)))
31 return 0;
34 * The most likely reason for this is that we returned -EFAULT,
35 * which means that we've done all that we can do from
36 * interrupt context.
38 if (__copy_from_user_inatomic(stack_frame, (void *)(long)sp,
39 sizeof(stack_frame)))
40 return 0;
42 if (!is_first)
43 oprofile_add_trace(STACK_LR32(stack_frame));
46 * We do not enforce increasing stack addresses here because
47 * we may transition to a different stack, eg a signal handler.
49 return STACK_SP(stack_frame);
52 #ifdef CONFIG_PPC64
53 static unsigned long user_getsp64(unsigned long sp, int is_first)
55 unsigned long stack_frame[3];
57 if (!access_ok(VERIFY_READ, sp, sizeof(stack_frame)))
58 return 0;
60 if (__copy_from_user_inatomic(stack_frame, (void *)sp,
61 sizeof(stack_frame)))
62 return 0;
64 if (!is_first)
65 oprofile_add_trace(STACK_LR64(stack_frame));
67 return STACK_SP(stack_frame);
69 #endif
71 static unsigned long kernel_getsp(unsigned long sp, int is_first)
73 unsigned long *stack_frame = (unsigned long *)sp;
75 if (!validate_sp(sp, current, STACK_FRAME_OVERHEAD))
76 return 0;
78 if (!is_first)
79 oprofile_add_trace(STACK_LR(stack_frame));
82 * We do not enforce increasing stack addresses here because
83 * we might be transitioning from an interrupt stack to a kernel
84 * stack. validate_sp() is designed to understand this, so just
85 * use it.
87 return STACK_SP(stack_frame);
90 void op_powerpc_backtrace(struct pt_regs * const regs, unsigned int depth)
92 unsigned long sp = regs->gpr[1];
93 int first_frame = 1;
95 /* We ditch the top stackframe so need to loop through an extra time */
96 depth += 1;
98 if (!user_mode(regs)) {
99 while (depth--) {
100 sp = kernel_getsp(sp, first_frame);
101 if (!sp)
102 break;
103 first_frame = 0;
105 } else {
106 #ifdef CONFIG_PPC64
107 if (!test_thread_flag(TIF_32BIT)) {
108 while (depth--) {
109 sp = user_getsp64(sp, first_frame);
110 if (!sp)
111 break;
112 first_frame = 0;
115 return;
117 #endif
119 while (depth--) {
120 sp = user_getsp32(sp, first_frame);
121 if (!sp)
122 break;
123 first_frame = 0;