From owner-freebsd-hackers@FreeBSD.ORG Mon May 7 14:05:31 2012 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 344B41065673; Mon, 7 May 2012 14:05:31 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from bigwig.baldwin.cx (bigknife-pt.tunnel.tserv9.chi1.ipv6.he.net [IPv6:2001:470:1f10:75::2]) by mx1.freebsd.org (Postfix) with ESMTP id 0A2B78FC12; Mon, 7 May 2012 14:05:31 +0000 (UTC) Received: from jhbbsd.localnet (unknown [209.249.190.124]) by bigwig.baldwin.cx (Postfix) with ESMTPSA id 6CD6BB95D; Mon, 7 May 2012 10:05:30 -0400 (EDT) From: John Baldwin To: freebsd-hackers@freebsd.org Date: Mon, 7 May 2012 09:57:03 -0400 User-Agent: KMail/1.13.5 (FreeBSD/8.2-CBSD-20110714-p13; KDE/4.5.5; amd64; ; ) References: <3B2A320B-3ADE-4F48-B94E-4F0886178251@freebsd.org> In-Reply-To: <3B2A320B-3ADE-4F48-B94E-4F0886178251@freebsd.org> MIME-Version: 1.0 Content-Type: Text/Plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Message-Id: <201205070957.03842.jhb@freebsd.org> X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.2.7 (bigwig.baldwin.cx); Mon, 07 May 2012 10:05:30 -0400 (EDT) Cc: arm@freebsd.org, Tim Kientzle Subject: Re: How does loader(8) decide where to load the kernel? X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 07 May 2012 14:05:31 -0000 On Saturday, May 05, 2012 1:06:13 am Tim Kientzle wrote: > I have ubldr loading the ELF kernel on BeagleBone and am now > trying to untangle some of the hacks I used to get this working. > > Unfortunately, there's one area of the common loader(8) code > that I really don't understand: How does sys/boot/common/load_elf.c > determine the physical address at which to load the kernel? > > __elfN(loadfile) has the following comment: > > [The file] will be stored at (dest). > > But that's not really true. For starters, loadfile maps dest > through archsw.arch_loadaddr. (This mechanism seems > to only be used on ia64 and pc98, though the result is > later discarded on those platforms.) > > Loadfile then passes the value to loadimage which does > very strange things: > > On i386, amd64, powerpc, and arm, loadimage subtracts > the dest value from the address declared in the actual ELF > headers so that the kernel always gets loaded into low memory. > (there's some intermediate bit-twiddling I'm glossing over, but > this is the general idea). The bit twiddling is supposed to be the equivalent of subtracting KERNBASE from the load address. On both i386 and amd64, there is a direct mapping of the kernel text such that KERNBASE maps address 0, etc. By default on i386 KERNBASE is 0xc0000000. -- John Baldwin