I am using bochs
enhanced debugger (bochs
debugger with gui), but it's also debugging the BIOS code, and this is too complicated for me. So how can I set a breakpoint manually at the start of my code?
I tried int3
but it doesn't stop on it.
The osdev wiki describes the key features:
Magic Breakpoint
When you're using Bochs with the internal debugger, you can trigger the debugger via a facility called magic breakpoints. To trigger a breakpoint, you can insert
xchg bx, bx
(in GAS syntax,xchgw %bx, %bx
) anywhere in the code and Bochs will trap into the debugger as soon as it executes it. On real hardware this has no effect as it merely replaces the BX register with itself.You should put the following line in your Bochs configuration file to have it listen to magic breakpoints:
magic_break: enabled=1
Presumably Bochs doesn't trap int3
because normal guest code might be using it. (e.g. if you're using Bochs to debug a debugger or a kernel with debug facilities, you'd want to follow how int3
is handled in the guest, not have Bochs eat it.)
Apparently there's also an I/O debug-breakpoint mechanism using the out
instruction to output two words to a special port number, 0x8A00
, so you can get Bochs to break that way without making it break on xchg bx,bx
. The xchg
way is definitely easier to use (less intrusive; drop-in NOP with no register setup needed) and more compact. OSdev.org uses C to describe what to output:
//outputs a character to the debug console
#define BochsConsolePrintChar(c) outportb(0xe9, c)
//stops simulation and breaks into the debug console
#define BochsBreak() outportw(0x8A00,0x8A00); outportw(0x8A00,0x08AE0);