Questions about using ld script to generate multiboot header
Posted: Sun Jun 01, 2014 9:21 am
I want to make a flat binary kernel, booting it with GRUB, and I tried write Multiboot header using ld script like this.
the code works well, But I want to know why I have to use other than . In the latter case, if I use xxd to examine the hexidemical value I'll discover 0x1badb002 becomes 0x1bbdb002.
Code: Select all
OUTPUT_FORMAT(binary)
SECTIONS {
. = 1M;
.boot : ALIGN(4) {
multiboot_magic = 0x1badb002;
multiboot_flags = 1<<0 | 1<<1 | 1<<16;
multiboot_check = - (multiboot_magic + multiboot_flags);
LONG(multiboot_magic - 1M);
LONG(multiboot_flags - 1M);
LONG(multiboot_check - 1M);
LONG(1M); /* multiboot header_addr */
LONG(1M); /* multiboot load_addr */
LONG(seg_data_end_addr); /* multiboot load_end_addr */
LONG(seg_bss_end_addr); /* multiboot bss_end_addr */
LONG(multiboot_entry); /* multiboot entry_addr */
*(.bootstrap) /* Assembly code for invoking C */
}
... text rodata data and bss ...
}
Code: Select all
LONG(multiboot_magic - 1M);
Code: Select all
LONG(multiboot_magic);