···11+/*22+ * Stack trace management functions33+ *44+ * Copyright (C) 2007 Atmel Corporation55+ *66+ * This program is free software; you can redistribute it and/or modify77+ * it under the terms of the GNU General Public License version 2 as88+ * published by the Free Software Foundation.99+ */1010+#include <linux/sched.h>1111+#include <linux/stacktrace.h>1212+#include <linux/thread_info.h>1313+1414+register unsigned long current_frame_pointer asm("r7");1515+1616+struct stackframe {1717+ unsigned long lr;1818+ unsigned long fp;1919+};2020+2121+/*2222+ * Save stack-backtrace addresses into a stack_trace buffer.2323+ */2424+void save_stack_trace(struct stack_trace *trace)2525+{2626+ unsigned long low, high;2727+ unsigned long fp;2828+ struct stackframe *frame;2929+ int skip = trace->skip;3030+3131+ low = (unsigned long)task_stack_page(current);3232+ high = low + THREAD_SIZE;3333+ fp = current_frame_pointer;3434+3535+ while (fp >= low && fp <= (high - 8)) {3636+ frame = (struct stackframe *)fp;3737+3838+ if (skip) {3939+ skip--;4040+ } else {4141+ trace->entries[trace->nr_entries++] = frame->lr;4242+ if (trace->nr_entries >= trace->max_entries)4343+ break;4444+ }4545+4646+ /*4747+ * The next frame must be at a higher address than the4848+ * current frame.4949+ */5050+ low = fp + 8;5151+ fp = frame->fp;5252+ }5353+}