From owner-freebsd-hackers@FreeBSD.ORG Sat May 5 05:06:18 2012 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 7D1081065670 for ; Sat, 5 May 2012 05:06:18 +0000 (UTC) (envelope-from tim@kientzle.com) Received: from mail-pb0-f54.google.com (mail-pb0-f54.google.com [209.85.160.54]) by mx1.freebsd.org (Postfix) with ESMTP id 4B2048FC12 for ; Sat, 5 May 2012 05:06:18 +0000 (UTC) Received: by pbbro2 with SMTP id ro2so5054371pbb.13 for ; Fri, 04 May 2012 22:06:18 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=sender:from:content-type:content-transfer-encoding:subject:date :message-id:to:mime-version:x-mailer:x-gm-message-state; bh=wk04EFSI5GcP8IvsBQzSR5GGbdrHIJ+/4za+A2gPA9I=; b=aRcHtxJsvmoWNRmdtda7ZAJ72793hB0BoTTY7gSHYTbOGq6nqeIlmgSyOrE2xv31Ej N7Jpb+FTxWZ7H0W49rLoCyLtmBCbPUsAyAtrO12pBeLaGODWzr6SghKYmUrmtb0b+4/S FqBNvmI7qz8X/QevJ6CSqWAc8uuJ7wdW4T/Dmj2Z4Sc9wbT6ISV9fNVEcZ6TQMoEafWI 5I2gFHCTFlfSd/8xXrBBiUyJlwKJTfXXQ8TavfMiLQvY47wC/68enXHND4q/wqun7yaK 7/7G8uqssBoETT6q830o2oueKb6h+r+4PHiJxrEK5CFKCuCcydA/6ilGdyML8Ww/jQvw iVsA== Received: by 10.68.195.71 with SMTP id ic7mr25288730pbc.34.1336194377937; Fri, 04 May 2012 22:06:17 -0700 (PDT) Received: from [192.168.1.69] (99-74-169-43.lightspeed.sntcca.sbcglobal.net. [99.74.169.43]) by mx.google.com with ESMTPS id x1sm10722282pbp.50.2012.05.04.22.06.15 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 04 May 2012 22:06:16 -0700 (PDT) Sender: Tim Kientzle From: Tim Kientzle Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Date: Fri, 4 May 2012 22:06:13 -0700 Message-Id: <3B2A320B-3ADE-4F48-B94E-4F0886178251@freebsd.org> To: arm@freebsd.org, freebsd-hackers Mime-Version: 1.0 (Apple Message framework v1257) X-Mailer: Apple Mail (2.1257) X-Gm-Message-State: ALoCoQlHU87bl+FAwP8wMDdOXq7hOYTG9jllaPXcprnoFZAEncMZ0IcAnB5diCoVYAweCQCsnvns Cc: Subject: 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: Sat, 05 May 2012 05:06:18 -0000 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