tech-toolchain archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
amd64 kernels and text address
Hi,
[ Please CC me as I'm not subscribed to this list. ]
I am trying to add Multiboot support to amd64 kernels. The first
step in doing so is adding the Multiboot header at the beginning of
the file (within the first 8KB of the _file_). Unfortunately, adding
that as the very first thing in the entry point at locore.S does not
have the desired effect.
Upon further inspection, I noticed the following in the resulting
binaries:
Idx Name Size VMA LMA File
off Algn
0 .text 005c4548 ffffffff80100000 ffffffff80100000
00100000 2**6
CONTENTS, ALLOC, LOAD, READONLY, CODE
Note the offset at which the section is stored in the file:
0x100000. Effectively, doing an od -h on the kernel reveals a 1MB
gap of zeros at the beginning of the file.
I have tried messing with the kern.ldscript and changing the text's
AT statement to use different values. If they are >= 0x100000, the
kernel links and the offset in the file is still 100000. Using a
smaller value raises:
ld: kernel: Not enough room for program headers, try linking with -N
On the other hand, if I try to change the value passed to ld in -
Ttext to something smaller to 0x100000 (say 0x50000), then the
address correctly changes _and_ the file offset changes too.
Similarly, passing the -N flag lowers the file offsets to much lower
values.
One other thing I tried was putting the multiboot header in its own
section, and then making the linker script put that section before
text. Which had no effect, because this custom section ended
after .text but before .data and .bss.
At last, doing this same analysis on an i386 kernel shows:
Idx Name Size VMA LMA File off Algn
0 .text 006d86cc c0100000 00100000 00001000 2**6
CONTENTS, ALLOC, LOAD, READONLY, CODE
As you can see, the file offset is much smaller, and it need not
match the LMA.
So why oh why, in the amd64 case, .text is forced to be at an offset
of 0x100000 in the _file_? It looks like a bug to me. (Not to
mention that the LMA is wrong, but that's easy to correct.)
Thanks.
Home |
Main Index |
Thread Index |
Old Index