So, I have this assembly file, which I assemble with GNU as and link with GNU ld using a linker script.
Linker script (boot.ld
):
INPUT(boot.o)
OUTPUT(boot.out)
ENTRY(boot_start)
SECTIONS {
. = 0x7c00;
.text : { *(.text) }
.data : { *(.data) }
. = 0x7dfe;
.boot_end : { *(.boot_end) }
}
As you see I try to make the file exactly 512 bytes as needed for a bootloader by doing . = 0x7cdfe
. .boot_end
contains the boot signature and thus fills up the remaining two bytes.
I create the bootloader as follows:
m4 boot.S | as -o boot.o
ld -T boot.ld
objcopy -O binary boot.out boot.img
boot.out
contains the sections already with absolute addresses and everything seems fine. .boot_end
is at 0x7dfe
and I expect the holes to be filled with zeros, but no, boot.img
is a total of 55 bytes. The, for me, weird thing is that the file does not even contain the boot signature. It's just .text
and .data
without either .boot_end
or the skipped bytes.
How do I move ld to skip those bytes? And where is my boot signature gone?