__RETADDR - Specify the return address location

Given a non-leaf function, that is, one that contains JSR/BSR instructions, the value of the Shadow PC (SPC) register must be saved and restored accordingly. The value is stored to a temporary in the compiler-generated entry code, and subsequently restored to the register in the exit code, which is also generated by the compiler. If, however, the function contains only inline assembly and has #pragma NO_ENTRY applied to it, even though the SPC value has been properly manipulated, this time by the programmer, the generated debug information might be incomplete (the debugger might not be able to recreate the stack trace) - unless the __RETADDR pseudo-opcode is used to specify in which variable has the return address been stored. The following listing contains an example of using __RETADDR

Listing: Using __RETADDR to specify the return address location


#pragma NO_ENTRY

#pragma NO_EXIT

void foo(void) {

  unsigned int ret;

  asm {

    STA  tmp

    SHA

    STA  ret

    SLA        

    STA  ret+1

    __RETADDR ret  /* starting from this PC value on, the return 
address resides in variable 'ret' */

    LDA  tmp

    ...

  }

}