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

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


Hi,

On maanantai 25 helmikuu 2013, Nicolas Pomarède wrote:
> 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.
> 
> I don't think DBcc is used to call subroutine, it's more do handle
> for/while loop.
> 
> JMP is often used for subroutines,

Is JMP used for subroutines in C-compiler (e.g. gcc) generated code or
just in hand-coded assembly?

And in how many cases approximately, 1%? 50%?


> but it would be JSR in most case.
....
> > 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)

What about other m68k CPU models?


> > 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.

What about BKPT, CHK, ILLEGAL instructions?  Aren't those used at all?


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

That checking will be done in Hatari profiler code, as that check needs to
be done for every symbol address "call" and have information about current
CPU state, not just averages over whole profiling run (like the post-
processing script has).

Also, post-processor doesn't know anything about the processor itself,
I'm going to use just flags for the callers, those will be the same
for both CPU and DSP caller information.


>   - 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.

Hatari profiler code has also access to CPU state variables,
like state register value.

Can those be used to (more) reliably detect interrupt handlers or
exceptions?


Thanks for answering!


	- Eero



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