Subject: Re: Adding Multiboot support (or not)
To: The Wise and Sagicious Keepers of <port-i386@netbsd.org>
From: Jason Thorpe <thorpej@shagadelic.org>
List: tech-kern
Date: 02/10/2006 20:08:46
On Feb 10, 2006, at 4:51 PM, Pavel Cahyna wrote:

> I think this bug
> (https://savannah.gnu.org/bugs/?func=detailitem&item_id=15590) is  
> more a
> deficiency in NetBSD. The ELF format has the ability to tell the boot
> loader where the program should be loaded (the p_paddr field, see  
> PhysAddr
> in the output of readelf). But the NetBSD kernel has this field set  
> to the
> virtual address, which is incorrect. Instead of using a not very well
> defined feature of the multiboot specification, why not use a standard
> way? If the paddr fields are set correctly, unpatched grub (from  
> Debian
> 3.1) can load a multiboot NetBSD kernel.

Yes, I think we should use the "phys addr" field in the ELF headers  
properly.  It would allow us to get rid of a great deal of evil with  
loadfile() in libsa, too.

> As doing this with a linker script seems unfortunately impossible,  
> I have
> written a small program to change physical adresses of an ELF32  
> binary.
> Beware, it currently would not work on a big-endian machine.

Nonsense!  Consider the following (note the LOADADDR() and AT()  
directives):

ENTRY(KERNEL_BASE_phys)
SECTIONS
{
   KERNEL_BASE_phys = 0x00100000;
   KERNEL_BASE_virt = 0xc0100000;

   /* Read-only sections, merged into text segment: */
   .text (KERNEL_BASE_virt) :
   AT (KERNEL_BASE_phys)
   {
     *(.text)
     *(.text.*)
     *(.stub)
     *(.rodata)
   } =0
   PROVIDE (__etext = .);
   PROVIDE (_etext = .);
   PROVIDE (etext = .);

   /* Align the data segment to start on a page boundary. */
   . = ALIGN(0x1000);
   .data :
   AT (LOADADDR(.text) + (ADDR(.data) - ADDR(.text)))
   {
     __data_start = . ;
     *(.data)
     *(.data.*)
   }
   PROVIDE (_edata = .);
   PROVIDE (edata = .);
   __bss_start = . ;
   .bss :
   {
     *(.bss)
     *(.bss.*)
     *(COMMON)
     . = ALIGN(32 / 8);
   }
   . = ALIGN(32 / 8);
   PROVIDE (_end) = . ;
   PROVIDE (end) = . ;
}

-- thorpej