Re: [hatari-devel] Code execution discontinuities and detecting them?

[ Thread Index | Date Index | More lists.tuxfamily.org/hatari-devel Archives ]


Le 25/02/2013 16:10, Eero Tamminen a écrit :

Browsing my m68000 pocket guide, I've come up with following categories
and how to detect them:

1. Direct jumps and branches:
    - Previous PC address contains JMP, BRA, BCC or DBCC instruction.

Hello

I don't think DBcc is used to call subroutine, it's more do handle for/while loop.

JMP is often used for subroutines, but it would be JSR in most case.

BRA is IMO not used for subroutines in most cases, but used to handle if/then/else block or for/while.


2. Subroutine calls:
    - Previous PC address contains BSR or JSR instruction.

3. Returns from subroutine calls:
    - Previous PC address contains RTD, RTR or RTS instruction.

4. PC is just advanced to the next instruction:
    - previous PC value is smaller, but not more than maximum
      instruction lenght (<= 6 bytes?), and it was none of
      above 3 cases

max length on 68000 is 10 bytes (move.l $xxxxx,$yyyyy)

4. Intentionally called exception handlers:
    - Previous PC address contains BKPT, CHK, ILLEGAL, TRAP, TRAPV
      instruction?

5. Returns from exception handlers:
    - Previous PC address contains RTE instruction.

6. Interrupt handlers:
    - Previous PC address contains STOP instruction?

7. Returns from interrupt handlers:
    - Previous PC address contains RTD, RTR or RTS instruction,
      and code was in interrupt handler?

There's no such thing as interrupt handlers. The cpu receives some interrupt signals and call an exception handler.


I'm especially interested how to (reliably) detect code execution
transfer to interrupt handler, and back, as I don't actually know
the details how the interrupt handlers get called...

It's more exception handler ; if PC changes and previous instruction is none of bsr, bra, jsr, rts, rte, jmp, trap, then it's quite possible your code was hit by an exception coming from an interrupt.

So maybe having a list of "instructions that can modify the PC" in your python script is enough to determine the call flow :

- if previous instr is in this list, then you have a potential subroutine call (but it could be a if/then/else block too)

- if current pc differs from ( previous pc + number of bytes for previous instruction ) AND previous instr is not in the above list, then it's quite likely you had an exception.

Nicolas




Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/