From owner-svn-src-head@freebsd.org Sat Apr 1 21:51:35 2017 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id E8EB3D28BAC; Sat, 1 Apr 2017 21:51:35 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id B971DEF9; Sat, 1 Apr 2017 21:51:35 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v31LpY6I096986; Sat, 1 Apr 2017 21:51:34 GMT (envelope-from ian@FreeBSD.org) Received: (from ian@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v31LpYad096985; Sat, 1 Apr 2017 21:51:34 GMT (envelope-from ian@FreeBSD.org) Message-Id: <201704012151.v31LpYad096985@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ian set sender to ian@FreeBSD.org using -f From: Ian Lepore Date: Sat, 1 Apr 2017 21:51:34 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r316374 - head/sys/boot/arm/uboot X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 01 Apr 2017 21:51:36 -0000 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 /*