Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 31 Jul 2015 15:32:32 +0000 (UTC)
From:      Andrew Turner <andrew@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r286133 - in head/sys: arm64/arm64 conf
Message-ID:  <201507311532.t6VFWWFt086097@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: andrew
Date: Fri Jul 31 15:32:32 2015
New Revision: 286133
URL: https://svnweb.freebsd.org/changeset/base/286133

Log:
  Load the stack in stack_save and stack_save_td. This uses the generalised
  unwind_frame function to read each stack frame until either the pc or stack
  are no longer withing the kernel's address space.
  
  Obtained from:	ABT Systems Ltd
  Sponsored by:	The FreeBSD Foundation

Modified:
  head/sys/arm64/arm64/stack_machdep.c
  head/sys/conf/files.arm64

Modified: head/sys/arm64/arm64/stack_machdep.c
==============================================================================
--- head/sys/arm64/arm64/stack_machdep.c	Fri Jul 31 15:25:07 2015	(r286132)
+++ head/sys/arm64/arm64/stack_machdep.c	Fri Jul 31 15:32:32 2015	(r286133)
@@ -40,21 +40,49 @@ __FBSDID("$FreeBSD$");
 #include <machine/pcb.h>
 #include <machine/stack.h>
 
+static void
+stack_capture(struct stack *st, struct unwind_state *frame)
+{
+
+	stack_zero(st);
+	while (1) {
+		unwind_frame(frame);
+		if (!INKERNEL((vm_offset_t)frame->fp) ||
+		     !INKERNEL((vm_offset_t)frame->pc))
+			break;
+		if (stack_put(st, frame->pc) == -1)
+			break;
+	}
+}
+
 void
 stack_save_td(struct stack *st, struct thread *td)
 {
+	struct unwind_state frame;
 
 	if (TD_IS_SWAPPED(td))
 		panic("stack_save_td: swapped");
 	if (TD_IS_RUNNING(td))
 		panic("stack_save_td: running");
 
-	stack_zero(st); /* ARM64TODO */
+	frame.sp = td->td_pcb->pcb_sp;
+	frame.fp = td->td_pcb->pcb_x[29];
+	frame.pc = td->td_pcb->pcb_x[30];
+
+	stack_capture(st, &frame);
 }
 
 void
 stack_save(struct stack *st)
 {
+	struct unwind_state frame;
+	uint64_t sp;
+
+	__asm __volatile("mov %0, sp" : "=&r" (sp));
+
+	frame.sp = sp;
+	frame.fp = (uint64_t)__builtin_frame_address(0);
+	frame.pc = (uint64_t)stack_save;
 
-	stack_zero(st); /* ARM64TODO */
+	stack_capture(st, &frame);
 }

Modified: head/sys/conf/files.arm64
==============================================================================
--- head/sys/conf/files.arm64	Fri Jul 31 15:25:07 2015	(r286132)
+++ head/sys/conf/files.arm64	Fri Jul 31 15:32:32 2015	(r286133)
@@ -40,14 +40,14 @@ arm64/arm64/mp_machdep.c	optional	smp
 arm64/arm64/nexus.c		standard
 arm64/arm64/pic_if.m		standard
 arm64/arm64/pmap.c		standard
-arm64/arm64/stack_machdep.c	standard
+arm64/arm64/stack_machdep.c	optional	ddb | stack
 arm64/arm64/support.S		standard
 arm64/arm64/swtch.S		standard
 arm64/arm64/sys_machdep.c	standard
 arm64/arm64/trap.c		standard
 arm64/arm64/uio_machdep.c	standard
 arm64/arm64/uma_machdep.c	standard
-arm64/arm64/unwind.c		optional	ddb | kdtrace_hooks
+arm64/arm64/unwind.c		optional	ddb | kdtrace_hooks | stack
 arm64/arm64/vfp.c		standard
 arm64/arm64/vm_machdep.c	standard
 crypto/blowfish/bf_enc.c	optional	crypto | ipsec



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201507311532.t6VFWWFt086097>