From owner-svn-src-all@FreeBSD.ORG Tue Feb 26 03:24:46 2013 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.FreeBSD.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id 754B4709; Tue, 26 Feb 2013 03:24:46 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) by mx1.freebsd.org (Postfix) with ESMTP id 507709B4; Tue, 26 Feb 2013 03:24:46 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.5/8.14.5) with ESMTP id r1Q3Ojb0039627; Tue, 26 Feb 2013 03:24:45 GMT (envelope-from ian@svn.freebsd.org) Received: (from ian@localhost) by svn.freebsd.org (8.14.5/8.14.5/Submit) id r1Q3Oj56039626; Tue, 26 Feb 2013 03:24:45 GMT (envelope-from ian@svn.freebsd.org) Message-Id: <201302260324.r1Q3Oj56039626@svn.freebsd.org> From: Ian Lepore Date: Tue, 26 Feb 2013 03:24:45 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r247301 - head/sys/boot/common X-SVN-Group: head 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.14 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: Tue, 26 Feb 2013 03:24:46 -0000 Author: ian Date: Tue Feb 26 03:24:45 2013 New Revision: 247301 URL: http://svnweb.freebsd.org/changeset/base/247301 Log: Adjust the arm kernel entry point address properly regardless of whether the e_entry field holds a physical or a virtual address. Add a comment block that explains the assumptions being made by the adjustment code. Modified: head/sys/boot/common/load_elf.c Modified: head/sys/boot/common/load_elf.c ============================================================================== --- head/sys/boot/common/load_elf.c Tue Feb 26 02:13:02 2013 (r247300) +++ head/sys/boot/common/load_elf.c Tue Feb 26 03:24:45 2013 (r247301) @@ -290,14 +290,25 @@ __elfN(loadimage)(struct preloaded_file } else off = 0; #elif defined(__arm__) - if (off & 0xf0000000u) { - off = -(off & 0xf0000000u); - ehdr->e_entry += off; + /* + * The elf headers in some kernels specify virtual addresses in all + * header fields. More recently, the e_entry and p_paddr fields are the + * proper physical addresses. Even when the p_paddr fields are correct, + * the MI code below uses the p_vaddr fields with an offset added for + * loading (doing so is arguably wrong). To make loading work, we need + * an offset that represents the difference between physical and virtual + * addressing. ARM kernels are always linked at 0xC0000000. Depending + * on the headers, the offset value passed in may be physical or virtual + * (because it typically comes from e_entry), but we always replace + * whatever is passed in with the va<->pa offset. On the other hand, we + * only adjust the entry point if it's a virtual address to begin with. + */ + off = -0xc0000000u; + if ((ehdr->e_entry & 0xc0000000u) == 0xc000000u) + ehdr->e_entry += off; #ifdef ELF_VERBOSE - printf("Converted entry 0x%08x\n", ehdr->e_entry); + printf("ehdr->e_entry 0x%08x, va<->pa off %llx\n", ehdr->e_entry, off); #endif - } else - off = 0; #else off = 0; /* other archs use direct mapped kernels */ #endif