bootloader icon indicating copy to clipboard operation
bootloader copied to clipboard

vga_printline causes GPF in stage_3 protected mode

Open asoderman opened this issue 3 years ago • 0 comments

Hello I've been stepping through the bootloader code to learn more about osdev. Upon entering stage_3 I attempted to add a call vga_printline with a test string I defined in stage_3.s this caused repeated rebooting. I verified it wasn't just me invoking vga_printline incorrectly by adding jmp no_cpuid after call check_cpuid so as to simulate a no_cpuid result and invoke vga_printline as it was intended but received the same rebooting. Running qemu with -d int outputs check_exception old: 0x8 new 0xd which I believe is Double Fault -> GPF.

Some investigation revealed the faulting instruction is mov eax, vga_position line 121 in stage_2.s but I'm not sure why that would be. My method for determining this was not the best as I would mov a dummy value into edi then would check edi after the fault for the dummy value using qemu's monitor. If the dummy value was there I would move the instruction further along in the execution then repeat the process. So maybe double check this 😄 .

Steps to reproduce (using master branch):

  1. add jmp no_cpuid to line 17 in src/asm/stage_3.s
  2. in examples/basic create a disk image with cargo kimage
  3. invoke qemu-system-x86_64 --no-shutdown --no-reboot -drive format=raw,file=target/x86_64-custom/debug/boot-bios-basic_example.img -monitor stdio -d int (I believe the default runner behavior just exits immediately)

asoderman avatar Jan 30 '22 03:01 asoderman