I'm currently developing a boot manager for my own os, I divided the code into some modules but something strange happens. Each module works individually, but as soon as I link them together the emulator (Qemu) begins to reboot, to show random characters, to jump from one location to another and so on.. I tried to understand the relationship between the "symptoms" but they seems to be totally random. For instance, the emulator reboots when I call a function twice. Another example is when I load the module A, I call a function defined in module B (that has nothing to do with A) and qemu reboots, when I unload the module A, the function in B starts working again.
I compile and link the modules with: i686-elf-gcc -ffreestanding -nostdlib -Tld_script -e "boot" -o $bin_3 $src_3
, where ld_script is the linker script and $src_3 is the list of the modules.
Here's the linker script:
SECTIONS
{
. = 0x8600;
.text : { *(.text) }
. = 0x18600;
.data : { *(.data) }
. = 0x20600;
.rodata : { *(.rodata) }
. = 0x28600;
.bss : { *(.bss) }
}
The output elf file is parsed by another program I wrote which loads each section in specific sectors of the iso file, when the system boots, the boot loader loads those sectors in memory at the locations specified by the linker script and jumps to the code entry.
Qemu is launched with: qemu-system-x86_64 -drive format=raw,file=$disk_name -monitor stdio -vga std