debug a kernel
debug a kernel
my kernel is loaded by boot sector, it runs in protected mode and the computer usually reboots when i add some more code. How to debug such a kernel when it is in protected mode?
Hi,
I would strongly advise using bochs. If you add the line:
Or use a bochs output file, you will be able to see the register dump even if the CPU triple-faults. Start by looking at EIP and ESP - are they where you would expect? Do all segment registers contain the expected offsets in to your GDT? Is the last instruction executed (just below the register dump) something sensible? Have you tried to STI without loading a valid Interrupt Descriptor Table or IRQ handlers?
On some faults (particularly GPF exceptions), Bochs often displays a very helpful message above the final register dump (e.g. CS: rpl > dpl on non-conforming code segment, or something like that!).
Cheers,
Adam
I would strongly advise using bochs. If you add the line:
Code: Select all
cpu: reset_on_triple_fault=0
On some faults (particularly GPF exceptions), Bochs often displays a very helpful message above the final register dump (e.g. CS: rpl > dpl on non-conforming code segment, or something like that!).
Cheers,
Adam
- JackScott
- Member
- Posts: 1036
- Joined: Thu Dec 21, 2006 3:03 am
- Location: Hobart, Australia
- Mastodon: https://aus.social/@jackscottau
- Matrix: @JackScottAU:matrix.org
- GitHub: https://github.com/JackScottAU
- Contact:
http://www.osdev.org/wiki/Help_My_Kernel_Crashed
http://www.osdev.org/wiki/Troubleshooting
Read those two pages. One thing I did (and I found so useful it wasn't funny) was to use a serial port to write debugging messages. I wrote them after pretty much every line of code at one stage, and I fixed the problem.
http://www.osdev.org/wiki/Serial_ports
Hope that helps.
http://www.osdev.org/wiki/Troubleshooting
Read those two pages. One thing I did (and I found so useful it wasn't funny) was to use a serial port to write debugging messages. I wrote them after pretty much every line of code at one stage, and I fixed the problem.
http://www.osdev.org/wiki/Serial_ports
Hope that helps.
I would also recommend using the serial port for early debugging, it is easy to set up and write to, pretty robust against bugs (just a few lines of code) and it works even when you start fiddling with video modes. The link posted by Yayyak is an excellent starting point.
You say bochs complains about not finding a bootable device? Now that's probably a different problem, are you sure you've set up the disk correctly?
You say bochs complains about not finding a bootable device? Now that's probably a different problem, are you sure you've set up the disk correctly?