cnvogelg / bare68k

A Python 2/3 package to write m68k system emulators
15 stars 4 forks source link

Breakpoints #1

Open maximumspatium opened 4 years ago

maximumspatium commented 4 years ago

Thank you very much for bringing us this amazing library!

I'm trying to create an interactive debugger for exploring legacy 68k code based on bare68k. While implementing breakpoints based on the built-in tools, I noticed that the code execution always stops at the next instruction AFTER the breakpoint location:

0x21a84   * LINK.W  A6, #$0
0x21a88   X MOVE.L  A3, -(A7)
0x21a8a     MOVEA.L $8(A6), A3
0x21a8e     BSET.B  #$7, $C2C.W
0x21a94     CLR.L   (A3)

In the above code, the asterisk indicates the breakpoint location and "X" is the location where the execution actually halts. I'm using the following code:

tools.set_breakpoint(0, addr, MEM_FC_SUPER_MASK, "BKPT1")
rt.run()
tools.disable_breakpoint(0)

When I set addr to 0x21a84, the execution actually stops at 0x21a88 as confirmed by the following log message:

2020-10-01 12:35:26,535          bare68k.handler:   INFO:  BREAKPOINT: @00021a84 #0 flags=SD data=BKPT1

PC=00021a88  SR=--S--210-----Z--
D0=00020400  D1=00000001  D2=00000000  D3=00000000
D4=00000000  D5=00000000  D6=00000000  D7=00000000
A0=00020404  A1=000239b2  A2=00000000  A3=00000000
A4=00020000  A5=00000000  A6=00000790  A7=00000790
USP=00000000 ISP=00000790 MSP=00000000 VBR=00000000

I'd like to make my debugger to behave just like GDB - the execution should halt at the specified location before executing the marked instruction.

What do I need to change to make it work? Thank you in advance!