4.7 Interworking using veneers

When branching between ARM and Thumb state using the BL instruction, the instruction set state change can be handled by an interworking veneer.

This example shows interworking in assembly source code to set registers R0 to R2 to the values 1, 2, and 3 respectively. Registers R0 and R2 are set by ARM code. R1 is set by Thumb code. The linker automatically adds an interworking veneer. To use veneers:

  • you must assemble the code with the --apcs=/interwork option

  • use a BX lr instruction to return, instead of MOV pc,lr.

Example of assembly language interworking using veneers

     ; *****
     ; arm.s
     ; *****
     AREA     Arm,CODE,READONLY   ; Name this block of code.
     IMPORT   ThumbProg
     ENTRY                        ; Mark 1st instruction to call.
     MOV  R0,#1                   ; Set R0 to show in ARM code.
     BL   ThumbProg               ; Call Thumb subroutine.
     MOV R2,#3                    ; Set R2 to show returned to ARM.
                                  ; Terminate execution.
     MOV  R0, #0x18               ; angel_SWIreason_ReportException
     LDR  R1, =0x20026            ; ADP_Stopped_ApplicationExit
     SVC 0x123456                 ; ARM semihosting (formerly SWI)
     ; *******
     ; thumb.s
     ; *******
     AREA  Thumb,CODE,READONLY    ; Name this block of code.
     THUMB                        ; Subsequent instructions are Thumb.
     EXPORT ThumbProg
     MOVS  R1, #2                 ; Set R1 to show reached Thumb code.
     BX   lr                      ; Return to the ARM function.
     END                          ; Mark end of this file.

Building the example

Follow these steps to build and link the modules:

  1. To assemble the ARM code for interworking, type:

    armasm --debug --apcs=/interwork arm.s
  2. To assemble the Thumb code for interworking, type:

    armasm --thumb --debug --apcs=/interwork thumb.s
  3. To link the object files, type:

    armlink arm.o thumb.o -o count.axf

    Alternatively, to view the size of the interworking veneers, type:

    armlink arm.o thumb.o -o count.axf --info=veneers
  4. Run the image using a compatible debugger with an appropriate debug target.

Non-ConfidentialPDF file icon PDF versionARM DUI0471M
Copyright © 2010-2016 ARM Limited or its affiliates. All rights reserved.