SH Attributes (Using the GNU Compiler Collection (GCC))

#### 6.4.2.27 SH Attributes ¶

These attributes are supported on the SH family of processors:

`function_vector` ¶

  This attribute applies to functions.

  On SH2A targets, this attribute declares a function to be called using the TBR relative addressing mode. The argument to this attribute is the entry number of the same function in a vector table containing all the TBR relative addressable functions. For correct operation the TBR must be setup accordingly to point to the start of the vector table before any functions with this attribute are invoked. Usually a good place to do the initialization is the startup routine. The TBR relative vector table can have at max 256 function entries. The jumps to these functions are generated using a SH2A specific, non delayed branch instruction JSR/N @(disp8,TBR).

  In an application, for a function being called once, this attribute saves at least 8 bytes of code; and if other successive calls are being made to the same function, it saves 2 bytes of code per each of these calls.

`interrupt_handler` ¶

  This attribute applies to functions.

  It indicates that the specified function is an interrupt handler. The compiler generates function entry and exit sequences suitable for use in an interrupt handler when this attribute is present.

`nosave_low_regs` ¶

  This attribute applies to functions.

  Use this attribute on SH targets to indicate that an `interrupt_handler` function should not save and restore registers R0..R7. This can be used on SH3* and SH4* targets that have a second R0..R7 register bank for non-reentrant interrupt handlers.

`renesas` ¶

  This attribute applies to functions.

  On SH targets this attribute specifies that the function or struct follows the Renesas ABI.

`resbank` ¶

  This attribute applies to functions.

  On the SH2A target, this attribute enables the high-speed register saving and restoration using a register bank for `interrupt_handler` routines. Saving to the bank is performed automatically after the CPU accepts an interrupt that uses a register bank.

  The nineteen 32-bit registers comprising general register R0 to R14, control register GBR, and system registers MACH, MACL, and PR and the vector table address offset are saved into a register bank. Register banks are stacked in first-in last-out (FILO) sequence. Restoration from the bank is executed by issuing a RESBANK instruction.

`sp_switch` ¶

  This attribute applies to functions.

  Use this attribute on the SH to indicate an `interrupt_handler` function should switch to an alternate stack. It expects a string argument that names a global variable holding the address of the alternate stack.

      void *alt_stack;
      void f () __attribute__ ((interrupt_handler,
                                sp_switch ("alt_stack")));

`trap_exit` ¶

  This attribute applies to functions.

  Use this attribute on the SH for an `interrupt_handler` to return using `trapa` instead of `rte`. This attribute expects an integer argument specifying the trap number to be used.

`trapa_handler` ¶

  This attribute applies to functions.

  On SH targets this attribute is similar to `interrupt_handler` but it does not save and restore all registers.