16

There seems to be a problem with the Freedos bootloader. (It appears that the bootcode can't find the kernel in certain circumstances.)

So I'm trying to debug the bootloader in qemu with gdb. Following the instructions found on several wiki and freely available online course materials, I run qemu like this

qemu-system-i386 -fda fdboot.img -boot a -s -S

And then connect gdb like this

$ gdb
(gdb) target remote localhost:1234

I can step through the first 10 - 12 instructions with si which I assume is the SeaBIOS.

But past that, when I try to step into bootloader code, it continues execution without breaking, all the way up to the FreeDos menu prompt. This totally skips the bootloader code which I would like to examine step by step as it is executed.

What do I need to do so that I can step though the bootloader?

[You can download the freedos floppy images from the project website if you want to try yourself.]

1
  • 1
    Alternative suggestion: BOCHS has a built-in debugger that will let you single-step a boot sector. Commented Dec 1, 2017 at 9:14

1 Answer 1

22

Works fine here using qemu 1.3 and gdb 7.3.50.20111117 (you didn't say what versions you used). I was able to single step tons of instructions until I got bored and placed a breakpoint to catch the bootloader:

(gdb) br *0x7c00
Breakpoint 1 at 0x7c00
(gdb) c
Continuing.

Breakpoint 1, 0x00007c00 in ?? ()
(gdb) x/i $eip
=> 0x7c00:      jmp    0x7c3e

Note that I have set gdb to 16 bit mode first using set architecture i8086.

Sign up to request clarification or add additional context in comments.

10 Comments

I'm using gdb 7.5-ubuntu and qemu 1.2.0 (qemu-kvm-1.2.0+noroms-0ubuntu2, Debian). Yes I tried breakpointing at *0x7c00, but it just seems to go past that address, never breaking, reaching Freedos' interactive menu. I also tried setting the achitecture to i8086, with no difference. I'll try compiling qemu and gdb from trunk/head to see if it makes any difference.
Yep, I compile qemu from HEAD and I can successfully step through all the instructions now.
What do you mean compile qemu from HEAD? I've never heard that before. I have this same issue but I don't know what compile from HEAD means. Care to elaborate? :)
@Rob HEAD means current version from the revision control system, that is the freshest state of development. It is usually recommended to only do that if the latest release (package) doesn't work for you.
Adding -enable-kvm to qemu's startup parameters will invalidate gdb breakpoints.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.