Skip to main content

IAR Embedded Workbench for RH850 3.20.x

Creating assembler source with CFI support

In this section:

The recommended way to create an assembler language routine that handles call frame information correctly is to start with an assembler language source file created by the compiler.

  1. Start with suitable C source code, for example:

    int F(int);
    int cfiExample(int i)
    {
      return i + F(i);
    }
  2. Compile the C source code, and make sure to create a list file that contains call frame information—the CFI directives.

    Danger

    On the command line, use the option -lA.

    Caution

    In the IDE, choose Project>Options>C/C++ Compiler>List and make sure the suboption Include call frame information is selected.

    For the source code in this example, the list file looks like this:

            NAME test
    
            RTMODEL "__SystemLibrary", "DLib"
            RTMODEL "__core", "g3"
            RTMODEL "__data_model", "small"
            RTMODEL "__double_size", "64"
            RTMODEL "__eight_byte_alignment", "disabled"
            RTMODEL "__enum_size", "*"
            RTMODEL "__fpu", "double"
            RTMODEL "__reg_ep", "frame"
            RTMODEL "__reg_gp_lock", "0"
            RTMODEL "__reg_r5", "brel_const"
            RTMODEL "__rt_version", "2"
            #define SHT_PROGBITS 0x1
    
            EXTERN _F
    
            PUBLIC _cfiExample
            
              CFI Names cfiNames0
              CFI StackFrame CFA SP DATA
              CFI Resource R0:32, R1:32, R2:32, SP:32, R4:32, R5:32,
                           R6:32, R7:32
              CFI Resource R8:32, R9:32, R10:32, R11:32, R12:32,
                           R13:32, R14:32
              CFI Resource R15:32, R16:32, R17:32, R18:32, R19:32,
                           R20:32, R21:32
              CFI Resource R22:32, R23:32, R24:32, R25:32, R26:32,
                           R27:32, R28:32
              CFI Resource R29:32, EP:32, LP:32, EIPC:32, EIPSW:32,
                           FEPC:32, FEPSW:32
              CFI Resource PSW:32, CTPC:32, CTPSW:32
              CFI VirtualResource ?RET:32
              CFI EndNames cfiNames0
            
              CFI Common cfiCommon0 Using cfiNames0
              CFI CodeAlign 2
              CFI DataAlign 4
              CFI ReturnAddress ?RET DATA
              CFI CFA SP+0
              CFI R0 SameValue
              CFI R1 Undefined
              CFI R2 SameValue
              CFI R4 SameValue
              CFI R5 SameValue
              CFI R6 Undefined
              CFI R7 Undefined
              CFI R8 Undefined
              CFI R9 Undefined
              CFI R10 Undefined
              CFI R11 Undefined
              CFI R12 Undefined
              CFI R13 Undefined
              CFI R14 Undefined
              CFI R15 Undefined
              CFI R16 Undefined
              CFI R17 Undefined
              CFI R18 Undefined
              CFI R19 Undefined
              CFI R20 SameValue
              CFI R21 SameValue
              CFI R22 SameValue
              CFI R23 SameValue
              CFI R24 SameValue
              CFI R25 SameValue
              CFI R26 SameValue
              CFI R27 SameValue
              CFI R28 SameValue
              CFI R29 SameValue
              CFI EP SameValue
              CFI LP Undefined
              CFI EIPC SameValue
              CFI EIPSW SameValue
              CFI FEPC SameValue
              CFI FEPSW SameValue
              CFI PSW SameValue
              CFI CTPC SameValue
              CFI CTPSW SameValue
              CFI ?RET LP
              CFI EndCommon cfiCommon0
            SECTION `.text`:CODE:NOROOT(2)
              CFI Block cfiBlock0 Using cfiCommon0
              CFI Function _cfiExample
            CODE
    _cfiExample:
            PREPARE     {r29,lp},0
              CFI R29 Frame(CFA, -4)
              CFI ?RET Frame(CFA, -8)
              CFI CFA SP+8
            MOV         r6,r29
            MOV         r29,r6
              CFI FunCall _F
            JARL        _F,lp
            ADD         r29,r10
            DISPOSE     0,{r29,lp},[lp]
              CFI EndBlock cfiBlock0
    
            SECTION `.iar_vfe_header`:DATA:NOALLOC:NOROOT(2)
            SECTION_TYPE SHT_PROGBITS, 0
            DATA
            DC32 0
            END

    Note

    The header file cfi.h contains the macros CFNAMES and CFCOMMON0, which declare a typical names block and a typical common block. These two macros declare several resources, both concrete and virtual.