Date: Fri, 4 May 2012 22:06:13 -0700 From: Tim Kientzle <kientzle@freebsd.org> To: arm@freebsd.org, freebsd-hackers <freebsd-hackers@freebsd.org> Subject: How does loader(8) decide where to load the kernel? Message-ID: <3B2A320B-3ADE-4F48-B94E-4F0886178251@freebsd.org>
next in thread | raw e-mail | index | archive | help
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). On other platforms, the dest value passed into loadimage is entirely ignored. So it looks like the arch_loadaddr manipulations used on ia64 and pc98 are in fact not used. In my case, I have a kernel linked against a virtual address of 0xc0200000 that I want to load into a physical address of 0x80200000. I can make it work by having arch_loadaddr return a value of 0x40000000 (which then gets subtracted from the virtual address in the ELF file to produce the physical address I need), but this seems really byzantine. How is this *supposed* to work? Anybody know? Tim
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?3B2A320B-3ADE-4F48-B94E-4F0886178251>