Page MenuHomeFreeBSD

amd64: set the correct LMA values
ClosedPublic

Authored by royger on Jun 11 2015, 4:39 PM.
Tags
None
Referenced Files
Unknown Object (File)
Fri, May 3, 8:09 AM
Unknown Object (File)
Fri, May 3, 8:08 AM
Unknown Object (File)
Fri, May 3, 8:08 AM
Unknown Object (File)
Fri, May 3, 8:08 AM
Unknown Object (File)
Thu, May 2, 4:35 AM
Unknown Object (File)
Fri, Apr 26, 7:50 AM
Unknown Object (File)
Fri, Apr 26, 7:50 AM
Unknown Object (File)
Feb 16 2024, 8:10 AM
Subscribers

Details

Summary

The current linker script generates program headers with VMA == LMA:

Entry point 0xffffffff802e7000
There are 6 program headers, starting at offset 64

Program Headers:

Type           Offset             VirtAddr           PhysAddr
               FileSiz            MemSiz              Flags  Align
PHDR           0x0000000000000040 0xffffffff80200040 0xffffffff80200040
               0x0000000000000150 0x0000000000000150  R E    8
INTERP         0x0000000000000190 0xffffffff80200190 0xffffffff80200190
               0x000000000000000d 0x000000000000000d  R      1
    [Requesting program interpreter: /red/herring]
LOAD           0x0000000000000000 0xffffffff80200000 0xffffffff80200000
               0x00000000010559b0 0x00000000010559b0  R E    200000
LOAD           0x0000000001056000 0xffffffff81456000 0xffffffff81456000
               0x0000000000132638 0x000000000052ecf8  RW     200000
DYNAMIC        0x0000000001056000 0xffffffff81456000 0xffffffff81456000
               0x00000000000000d0 0x00000000000000d0  RW     8
GNU_STACK      0x0000000000000000 0x0000000000000000 0x0000000000000000
               0x0000000000000000 0x0000000000000000  RWE    8

This is fine for the FreeBSD loader, because it completely ignores p_paddr
and instead uses p_vaddr with a hardcoded offset. Other loaders however
acknowledge p_paddr (like the Xen ELF loader), in which case they will try
to load the kernel at the wrong place. Fix this by adding an AT keyword to
the first section specifying the physical address, other sections will
follow suit, so it ends up looking like:

Entry point 0xffffffff802e7000
There are 6 program headers, starting at offset 64

Program Headers:

Type           Offset             VirtAddr           PhysAddr
               FileSiz            MemSiz              Flags  Align
PHDR           0x0000000000000040 0xffffffff80200040 0x0000000000200040
               0x0000000000000150 0x0000000000000150  R E    8
INTERP         0x0000000000000190 0xffffffff80200190 0x0000000000200190
               0x000000000000000d 0x000000000000000d  R      1
    [Requesting program interpreter: /red/herring]
LOAD           0x0000000000000000 0xffffffff80200000 0x0000000000200000
               0x00000000010559b0 0x00000000010559b0  R E    200000
LOAD           0x0000000001056000 0xffffffff81456000 0x0000000001456000
               0x0000000000132638 0x000000000052ecf8  RW     200000
DYNAMIC        0x0000000001056000 0xffffffff81456000 0x0000000001456000
               0x00000000000000d0 0x00000000000000d0  RW     8
GNU_STACK      0x0000000000000000 0x0000000000000000 0x0000000000000000
               0x0000000000000000 0x0000000000000000  RWE    8

Sponsored by: Citrix Systems R&D

Tested on bare metal using the native FreeBSD loader.

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

royger retitled this revision from to amd64: set the correct LMA values.
royger updated this object.
royger edited the test plan for this revision. (Show Details)
royger added reviewers: alc, dim, kib, jhb, peter.

This looks fine, but did you tested with e.g. Grub ? Or asked pcbsd people to test.

Also, I think that a comment is due in the ldscript.amd64.

royger edited edge metadata.

Thanks for the review. Added a comment in the linker script and tested on
grub2.

kib edited edge metadata.

Thank you for testing grub.

sys/conf/ldscript.amd64
15 ↗(On Diff #6130)

I really mean a comment about native loader using VMA, but grub and xen relying on LMA. Explanation of the AT keyword operation might be not needed.

This revision is now accepted and ready to land.Jun 12 2015, 9:50 AM
This revision was automatically updated to reflect the committed changes.