0

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

cam0347
  • 23
  • 3
  • 1
    You'll want to run qemu with the ```-no-reboot```, ```-no-shutdown```, and ```-d int``` options to see exactly which event is causing the reboot. If it's rebooting, you likely have a triple fault from an unhandled exception. You'll need to catch the event in a debugger (either qemu + gdb, or Bochs). – sj95126 Aug 10 '21 at 17:59
  • Do you have a github repo? There really isn't enough in this question to provide any real answer beyond how to use a debugger to track the bug. – Michael Petch Aug 10 '21 at 19:29
  • @MichaelPetch yea sure: github.com/camilloZavattaro003/CamOS – cam0347 Aug 10 '21 at 20:51
  • I can see your github account, but the project `CamOS` is not available. Is it private by any chance? – Michael Petch Aug 10 '21 at 20:54
  • @MichaelPetch oh right sry, I made it public now – cam0347 Aug 11 '21 at 09:02
  • I'm not on OS/X, and the bootm_loader program seems to be a precompiled Macho64 binary. Do you have a version that is 64-bit Linux Elf or a way to rebuild it? – Michael Petch Aug 11 '21 at 17:56
  • @MichaelPetch bootm_loader has to load the elf file of the boot manager into the disk, is not executed by qemu, is part of the building process – cam0347 Aug 12 '21 at 09:16
  • Yes, I know it is part of the build process. But bootm_loader when executed will only run OS/X because it is an OS/X executable. I use Linux. I can't actually use/run it because I don't have an OS/X system so the build fails. Which is why I ask if you have the code or a project for it so I can rebuild it for Linux or if you have a 64-bit Linux version of it I can run. The wholoe idea of asking for the github project was so I could build and run your code, but I can't get past the build process so can't run it. – Michael Petch Aug 12 '21 at 12:11
  • @MichaelPetch the code is in boot/elf_parser, but the master script expects the executable (bootm_loader) in boot – cam0347 Aug 12 '21 at 17:28
  • Ok I fixed the problem.. I had set the stack in the middle of the boot manager code, this explains the strange bugs – cam0347 Aug 13 '21 at 09:27

0 Answers0