Skip to main content

IAR Embedded Workbench for RL78 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 (the file has been trimmed down for reasons of space):

            NAME Cfi
    
            RTMODEL "__SystemLibrary", "DLib"
            RTMODEL "__calling_convention", "iar"
            RTMODEL "__code_model", "near"
            RTMODEL "__core", "rl78_2"
            RTMODEL "__data_model", "near"
            RTMODEL "__double_size", "32"
            RTMODEL "__far_rt_calls", "false"
            RTMODEL "__rt_version", "1"
    
            #define SHT_PROGBITS 0x1
    
            EXTERN F
    
            PUBLIC cfiExample
    
            CFI Names cfiNames0
            CFI StackFrame CFA SP NEARDATA
            CFI Resource A:8, X:8, B:8, C:8, D:8, E:8, H:8, L:8,
                         CS_REG:4, ES_REG:4
            CFI VirtualResource ?RET:20
            CFI Resource MACRH:16, MACRL:16, W0:8, W1:8, W2:8,
                         W3:8, W4:8, W5:8
            CFI Resource W6:8, W7:8, W8:8, W9:8, W10:8, W11:8,
                         W12:8, W13:8, W14:8
            CFI Resource W15:8, W16:8, W17:8, W18:8, W19:8, W20:8,
                         W21:8, W22:8
            CFI Resource W23:8, W24:8, W25:8, W26:8, W27:8, W28:8,
                         W29:8, W30:8
            CFI Resource W31:8, W32:8, W33:8, W34:8, W35:8, W36:8,
                         W37:8, W38:8
            CFI Resource W39:8, W40:8, W41:8, W42:8, W43:8, W44:8,
                         W45:8, W46:8
            CFI Resource W47:8, W48:8, W49:8, W50:8, W51:8, W52:8,
                         W53:8, W54:8
            CFI Resource W55:8, W56:8, W57:8, W58:8, W59:8, W60:8,
                         W61:8, W62:8
            CFI Resource W63:8, W64:8, W65:8, W66:8, W67:8, W68:8,
                         W69:8, W70:8
            CFI Resource W71:8, W72:8, W73:8, W74:8, W75:8, W76:8,
                         W77:8, W78:8
            CFI Resource W79:8, W80:8, W81:8, W82:8, W83:8, W84:8,
                         W85:8, W86:8
            CFI Resource W87:8, W88:8, W89:8, W90:8, W91:8, W92:8,
                         W93:8, W94:8
            CFI Resource W95:8, W96:8, W97:8, W98:8, W99:8, W100:8,
                         W101:8, W102:8
            CFI Resource W103:8, W104:8, W105:8, W106:8, W107:8,
                         W108:8, W109:8
            CFI Resource W110:8, W111:8, W112:8, W113:8, W114:8,
                         W115:8, W116:8
            CFI Resource W117:8, W118:8, W119:8, W120:8, W121:8,
                         W122:8, W123:8
            CFI Resource W124:8, W125:8, W126:8, W127:8, SP:16,
                         ?SPH:4
            CFI EndNames cfiNames0
            CFI Common cfiCommon0 Using cfiNames0
            CFI CodeAlign 1
            CFI DataAlign 1
            CFI ReturnAddress ?RET CODE
            CFI CFA SP+4
            CFI A Undefined
            CFI X Undefined
            CFI B SameValue
            CFI C SameValue
            CFI D SameValue
            CFI E SameValue
            CFI H Undefined
            CFI L Undefined
            CFI CS_REG Undefined
            CFI ES_REG Undefined
            CFI ?RET Frame(CFA, -4)
            CFI MACRH Undefined
            CFI MACRL Undefined
            CFI W0 SameValue
            CFI W1 SameValue
                 ...
            CFI Wn SameValue
                 ...
            CFI W126 SameValue
            CFI W127 SameValue
            CFI ?SPH Undefined
            CFI EndCommon cfiCommon0
    
            SECTION LOVE:CODE:NOROOT(0)
    cfiExample:
            CFI Block cfiBlock0 Using cfiCommon0
            CFI Function cfiExample
    
            PUSH      DE
            CFI E Frame(CFA, -6)
            CFI D Frame(CFA, -5)
            CFI CFA SP+6
            MOVW      DE, AX
            CALL      _F
            MOVW      HL, AX
            MOVW      AX, DE
            ADDW      AX, HL
            POP       DE
            CFI E SameValue
            CFI D SameValue
            CFI CFA SP+4
            RET       
            CFI EndBlock cfiBlock0
    
            END

    Note

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