debug a kernel

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
Philip
Member
Member
Posts: 59
Joined: Thu Mar 06, 2008 11:37 pm
Location: Singapore

debug a kernel

Post by Philip »

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? :?
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Post by AJ »

Hi,

I would strongly advise using bochs. If you add the line:

Code: Select all

cpu: reset_on_triple_fault=0
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
User avatar
Philip
Member
Member
Posts: 59
Joined: Thu Mar 06, 2008 11:37 pm
Location: Singapore

Post by Philip »

i'm testing my os directly on a hdisk partition
bochs says no bootable device and hangs
User avatar
JackScott
Member
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:

Post by JackScott »

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.
User avatar
JoeKayzA
Member
Member
Posts: 79
Joined: Wed Aug 24, 2005 11:00 pm
Location: Graz/Austria

Post by JoeKayzA »

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?
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Post by JamesM »

Sounds like your disk image or bochsrc is FUBAR. Tried it on qemu?
Post Reply