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

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


Hi,

To get good callgraphs from a profile data, it's not enough just to record
from what addresses code arrives to symbol addresses, as discussed here:
http://www.atari-forum.com/viewtopic.php?f=68&t=24561&start=100

There needs to be some extra information about how the code execution
changed from address A to B, because of things like interrupts and user
inadvertly giving symbols [1] to loop labels etc.

[1] loaded symbols indicate addresses for which caller info should
    be recorded.  Currently execution of an instruction on a symbol
    address is assumed to be a call to it.  Giving loop labels as
    symbols can give funny looking callgraphs.


Detecting subroutine calls should in 99% [2] of the cases give good
function callgraphs, but I would like to categorize all ways of changing
code exection flow, so that one can get separate callgraphs for each of
them.

So, can you tell:
* what are the ways that code execution can be changed to another
  address at assembly level, and
* how one can detect them, preferably just from the previous and
  current PC address and their memory contents


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.

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

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?

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



	- Eero

[2] C-compiler might optimize call to a static function to a jump/branch,
    that's why assuming method 2) catches all (C-level) subroutine calls
    might not be a good idea with compilers like GCC.



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