Subject: Re: Adding Multiboot support (or not)
To: None <tech-kern@netbsd.org>
From: Pavel Cahyna <pavel@netbsd.org>
List: tech-kern
Date: 05/03/2006 15:30:28
--uAKRQypu60I7Lcqm
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

On Fri, Feb 10, 2006 at 08:08:46PM -0800, Jason Thorpe wrote:
> 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) = . ;
> }

I see that Nick committed the change to ld which makes the provided script
work. (It is necessary to change PROVIDE (_end) = . ; to 
PROVIDE (_end = .) ; and so on.)

Is it appropriate to commit it? I see that the current ldscript for i386
is very different, it has many things which apparently make sense only for
userland.

And, could please somebody test that a kernel made with this ldscript is
bootable with the native bootloader? (I have only grub.)

Thanks	Pavel

--uAKRQypu60I7Lcqm
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="kern.ldscript"

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 :
   AT (LOADADDR(.text) + (ADDR(.bss) - ADDR(.text)))
   {
     *(.bss)
     *(.bss.*)
     *(COMMON)
     . = ALIGN(32 / 8);
   }
   . = ALIGN(32 / 8);
  PROVIDE (_end = .) ;
  PROVIDE (end = .) ;
}

--uAKRQypu60I7Lcqm--