Skip to main content

IAR Embedded Workbench for RX 5.20

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, after it has been cleaned up for increased readability:

        NAME cfiExample
    
        EXTERN _F
    
        PUBLIC _cfiExample
            
        CFI Names cfiNames0
        CFI StackFrame CFA SP DATA
        CFI VirtualResource ?RET:32
        CFI Resource R1:32, R2:32, R3:32, R4:32, R5:32, R6:32, R7:32, R8:32
        CFI Resource R9:32, R10:32, R11:32, R12:32, R13:32, R14:32, R15:32
        CFI Resource SP:32
        CFI EndNames cfiNames0
            
        CFI Common cfiCommon0 Using cfiNames0
        CFI CodeAlign 1
        CFI DataAlign 1
        CFI ReturnAddress ?RET CODE
        CFI CFA SP+4
        CFI ?RET Frame(CFA, -4)
        CFI R1 Undefined
        CFI R2 Undefined
        CFI R3 Undefined
        CFI R4 Undefined
        CFI R5 Undefined
        CFI R6 SameValue
        CFI R7 SameValue
        CFI R8 SameValue
        CFI R9 SameValue
        CFI R10 SameValue
        CFI R11 SameValue
        CFI R12 SameValue
        CFI R13 SameValue
        CFI R14 Undefined
        CFI R15 Undefined
        CFI EndCommon cfiCommon0
        
        SECTION .text:CODE:NOROOT(0)
        CFI Block cfiBlock0 Using cfiCommon0
        CFI Function _cfiExample
        CODE
    _cfiExample:
        PUSH.L    R6
        CFI R6 Frame(CFA, -8)
        CFI CFA SP+8
        MOV.L     R1,R6
        BSR.A     _F
        ADD       R1,R6
        MOV.L     R6,R1
        RTSD      #0x4,R6,R6
        CFI EndBlock cfiBlock0
    
        END

    Note

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