/*1* AVR32 specific backtracing code for oprofile2*3* Copyright 2008 Weinmann GmbH4*5* Author: Nikolaus Voss <[email protected]>6*7* Based on i386 oprofile backtrace code by John Levon and David Smith8*9* This program is free software; you can redistribute it and/or modify10* it under the terms of the GNU General Public License version 2 as11* published by the Free Software Foundation.12*13*/1415#include <linux/oprofile.h>16#include <linux/sched.h>17#include <linux/uaccess.h>1819/* The first two words of each frame on the stack look like this if we have20* frame pointers */21struct frame_head {22unsigned long lr;23struct frame_head *fp;24};2526/* copied from arch/avr32/kernel/process.c */27static inline int valid_stack_ptr(struct thread_info *tinfo, unsigned long p)28{29return (p > (unsigned long)tinfo)30&& (p < (unsigned long)tinfo + THREAD_SIZE - 3);31}3233/* copied from arch/x86/oprofile/backtrace.c */34static struct frame_head *dump_user_backtrace(struct frame_head *head)35{36struct frame_head bufhead[2];3738/* Also check accessibility of one struct frame_head beyond */39if (!access_ok(VERIFY_READ, head, sizeof(bufhead)))40return NULL;41if (__copy_from_user_inatomic(bufhead, head, sizeof(bufhead)))42return NULL;4344oprofile_add_trace(bufhead[0].lr);4546/* frame pointers should strictly progress back up the stack47* (towards higher addresses) */48if (bufhead[0].fp <= head)49return NULL;5051return bufhead[0].fp;52}5354void avr32_backtrace(struct pt_regs * const regs, unsigned int depth)55{56/* Get first frame pointer */57struct frame_head *head = (struct frame_head *)(regs->r7);5859if (!user_mode(regs)) {60#ifdef CONFIG_FRAME_POINTER61/*62* Traverse the kernel stack from frame to frame up to63* "depth" steps.64*/65while (depth-- && valid_stack_ptr(task_thread_info(current),66(unsigned long)head)) {67oprofile_add_trace(head->lr);68if (head->fp <= head)69break;70head = head->fp;71}72#endif73} else {74/* Assume we have frame pointers in user mode process */75while (depth-- && head)76head = dump_user_backtrace(head);77}78}7980818283