From owner-svn-src-all@freebsd.org Mon Sep 11 00:55:20 2017 Return-Path: Delivered-To: svn-src-all@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 2AE71E0E34F; Mon, 11 Sep 2017 00:55:20 +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 EB9F967EBA; Mon, 11 Sep 2017 00:55:19 +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 v8B0tJnk032178; Mon, 11 Sep 2017 00:55:19 GMT (envelope-from ian@FreeBSD.org) Received: (from ian@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v8B0tISa032176; Mon, 11 Sep 2017 00:55:18 GMT (envelope-from ian@FreeBSD.org) Message-Id: <201709110055.v8B0tISa032176@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ian set sender to ian@FreeBSD.org using -f From: Ian Lepore Date: Mon, 11 Sep 2017 00:55:18 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r323409 - in stable/11/sys/boot: arm/uboot uboot/common X-SVN-Group: stable-11 X-SVN-Commit-Author: ian X-SVN-Commit-Paths: in stable/11/sys/boot: arm/uboot uboot/common X-SVN-Commit-Revision: 323409 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 11 Sep 2017 00:55:20 -0000 Author: ian Date: Mon Sep 11 00:55:18 2017 New Revision: 323409 URL: https://svnweb.freebsd.org/changeset/base/323409 Log: MFC r316374, r316377: 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(). Correct a comment... the stack used by ubldr is the same stack u-boot was running on when it jumped to the ubldr entry point. None of the arches that use this code set up a different stack in their start.S routines. Modified: stable/11/sys/boot/arm/uboot/start.S stable/11/sys/boot/uboot/common/main.c Directory Properties: stable/11/ (props changed) Modified: stable/11/sys/boot/arm/uboot/start.S ============================================================================== --- stable/11/sys/boot/arm/uboot/start.S Mon Sep 11 00:51:47 2017 (r323408) +++ stable/11/sys/boot/arm/uboot/start.S Mon Sep 11 00:55:18 2017 (r323409) @@ -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 /* Modified: stable/11/sys/boot/uboot/common/main.c ============================================================================== --- stable/11/sys/boot/uboot/common/main.c Mon Sep 11 00:51:47 2017 (r323408) +++ stable/11/sys/boot/uboot/common/main.c Mon Sep 11 00:55:18 2017 (r323409) @@ -416,7 +416,9 @@ main(int argc, char **argv) /* * Initialise the heap as early as possible. Once this is done, - * alloc() is usable. The stack is buried inside us, so this is safe. + * alloc() is usable. We are using the stack u-boot set up near the top + * of physical ram; hopefully there is sufficient space between the end + * of our bss and the bottom of the u-boot stack to avoid overlap. */ uboot_heap_start = round_page((uintptr_t)end); uboot_heap_end = uboot_heap_start + 512 * 1024;