@@ -11,9 +11,6 @@ ifeq ($(CONFIG_EFI),y)
$(error Cannot build arm32 tests as EFI apps)
endif
-# stack.o relies on frame pointers.
-KEEP_FRAME_POINTER := y
-
CFLAGS += $(machine)
CFLAGS += -mcpu=$(PROCESSOR)
CFLAGS += -mno-unaligned-access
@@ -22,6 +22,7 @@ define arch_elf_check =
endef
cstart.o = $(TEST_DIR)/cstart64.o
+cflatobjs += lib/arm64/stack.o
cflatobjs += lib/arm64/processor.o
cflatobjs += lib/arm64/spinlock.o
cflatobjs += lib/arm64/gic-v3-its.o lib/arm64/gic-v3-its-cmd.o
@@ -22,6 +22,9 @@ $(TEST_DIR)/sieve.elf: AUXFLAGS = 0x1
##################################################################
AUXFLAGS ?= 0x0
+# stack.o relies on frame pointers.
+KEEP_FRAME_POINTER := y
+
CFLAGS += -std=gnu99
CFLAGS += -ffreestanding
CFLAGS += -O2
@@ -5,4 +5,7 @@
#error Do not directly include <asm/stack.h>. Just use <stack.h>.
#endif
+#define HAVE_ARCH_BACKTRACE_FRAME
+#define HAVE_ARCH_BACKTRACE
+
#endif
new file mode 100644
@@ -0,0 +1,44 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Backtrace support.
+ */
+#include <libcflat.h>
+#include <stdbool.h>
+#include <stack.h>
+
+int backtrace_frame(const void *frame, const void **return_addrs, int max_depth)
+{
+ const void *fp = frame;
+ static bool walking;
+ void *lr;
+ int depth;
+
+ if (walking) {
+ printf("RECURSIVE STACK WALK!!!\n");
+ return 0;
+ }
+ walking = true;
+
+ /*
+ * ARM64 stack grows down. fp points to the previous fp on the stack,
+ * and lr is just above it
+ */
+ for (depth = 0; fp && depth < max_depth; ++depth) {
+
+ asm volatile ("ldp %0, %1, [%2]"
+ : "=r" (fp), "=r" (lr)
+ : "r" (fp)
+ : );
+
+ return_addrs[depth] = lr;
+ }
+
+ walking = false;
+ return depth;
+}
+
+int backtrace(const void **return_addrs, int max_depth)
+{
+ return backtrace_frame(__builtin_frame_address(0),
+ return_addrs, max_depth);
+}