Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 1 Apr 2017 21:51:34 +0000 (UTC)
From:      Ian Lepore <ian@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r316374 - head/sys/boot/arm/uboot
Message-ID:  <201704012151.v31LpYad096985@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: ian
Date: Sat Apr  1 21:51:34 2017
New Revision: 316374
URL: https://svnweb.freebsd.org/changeset/base/316374

Log:
  Preserve the registers containing argc, argv, and return address values
  passed in from u-boot across the call to self_reloc and any other early-init
  code, and restore them before calling main().
  
  The self_reloc() routine uses r0 and r1 (and calling it uses lr), and
  depending on what values get left in them, main() would intermittantly lock
  up trying to interpret them as argc and argv values.  This problem affected
  the self-relocatable ubldr.bin but not ubldr (the elf version).

Modified:
  head/sys/boot/arm/uboot/start.S

Modified: head/sys/boot/arm/uboot/start.S
==============================================================================
--- head/sys/boot/arm/uboot/start.S	Sat Apr  1 21:06:22 2017	(r316373)
+++ head/sys/boot/arm/uboot/start.S	Sat Apr  1 21:51:34 2017	(r316374)
@@ -45,6 +45,13 @@ _start:
 	orr	ip, ip, #(CPU_CONTROL_AFLT_ENABLE)
 	mcr     p15, 0, ip, c1, c0, 0
 #endif
+
+	/*
+	 * Save r0 and r1 (argc and argv passed from u-boot), and lr (trashed
+	 * by the call to self_reloc below) until we're ready to call main().
+	 */
+	push	{r0, r1, lr}
+
 	/* 
 	 * Do self-relocation when the weak external symbol _DYNAMIC is non-NULL.
 	 * When linked as a dynamic relocatable file, the linker automatically
@@ -71,9 +78,11 @@ _start:
 	str	r9, [ip, #4]
 
 	/* 
+	 * First restore argc, argv, and the u-boot return address, then
 	 * Start loader.  This is basically a tail-recursion call; if main()
 	 * returns, it returns to u-boot (which reports the value returned r0).
 	 */
+	pop	{r0, r1, lr}
 	b	main
 
 	/* 



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