I've been lurking around these forums for a while now, telling myself that one day I'll get around to trying to write my own toy operating system. I finally started earlier today, but I have encountered a small roadblock.
I'm experimenting with getting multiple source files to work properly. My problem: I have two source files, bootstrap.s and kmain.c. bootstrap.s contains my Multiboot header and program entry point (called bootstrap, imaginatively enough), kmain.c contains my kmain() function and some other assorted random stuff.
My problem: my generated kernel.bin file is >8KB now, with all my experimental code and global data. For some reason, the contents of bootstrap.o are placed after kmain.o (confirmed via a hex dump and search for the Multiboot magic string), and since kmain.o is more than 8KB . . . GRUB can't find the multiboot header.
From the ld documentation, I spotted STARTUP(), which appears to be what I am looking for in this case, but it appears to have no effect, whether it is placed at the top or bottom of the script.
I'm currently using the following linker script: (heavily plagiarized from the Wiki, apologies to the original authors . . .)
Code: Select all
OUTPUT_FORMAT(elf64-x86-64)
ENTRY(bootstrap)
STARTUP(bootstrap.o)
KERNEL_LMA = 0x100000;
KERNEL_VMA = 0x800000;
SECTIONS {
. = KERNEL_LMA;
.bootstrap : {
bootstrap.o (.text)
. = ALIGN(4096);
}
. = KERNEL_VMA;
.text : AT(ADDR(.text) - KERNEL_VMA) {
_code = .;
*(EXCLUDE_FILE(*bootstrap.o) .text)
*(.rodata*)
. = ALIGN(4096);
}
.data : AT(ADDR(.data) - KERNEL_VMA) {
_data = .;
*(.data)
. = ALIGN(4096);
}
.ehframe : AT(ADDR(.ehframe) - KERNEL_VMA) {
_ehframe = .;
*(.ehframe)
. = ALIGN(4096);
}
.bss : AT(ADDR(.bss) - KERNEL_VMA) {
_bss = .;
*(.bss)
*(COMMON)
. = ALIGN(4096);
}
_end = .;
/DISCARD/ : {
*(.comment)
}
}
My thanks in advance for any advice that can be given.
- ethereal