
                GET             Asm:s.regs
                GET             Asm:s.general

                IMPORT          |Image$$RO$$Base|
                IMPORT          |_Lib$Reloc$Off$DP|

                AREA            Veneer, REL, CODE, READONLY

; Call a C function
;
; R8  ==> Address of function to call
; R12 ==> Private word pointer

wrapper         STMFD           sp!, {r0-r9, sl, fp, ip, lr}  ; Store the input registers onto the stack
                MOV             sl, sp, LSR #20
                MOV             sl, sl, LSL #20  ; SP_LWM
                LDMIA           sl, {v1, v2}    ; save old reloc modifiers over fn call
                LDR             r12, [r12]      ; private word pointer
                LDMIB           r12, {fp, r12}  ; new relocation modifiers
                STMIA           sl, {fp, r12}   ; set by module init
                MOV             fp, #0          ; halt C backtrace here!

                DCD             |_Lib$Reloc$Off$DP| + &E28AA000  ; This is equivalent of 'ADD r10, r10, #0' + |_Lib$Reloc$Off$DP|

                MOV             a1, sp          ; Pass a pointer to the structure on the stack
                MOV             lr, pc
                MOV             pc, r8

                DCD             |_Lib$Reloc$Off$DP| + &E24AA000  ; This is equivalent of 'SUB r10, r10, #0' + |_Lib$Reloc$Off$DP|

                STMIA           sl, {v1, v2}    ; restore old reloc modifiers
                TEQ             a1, #0
                STRNE           a1, [sp]
                LDMFD           sp!, {r0-r9, sl, fp, ip, lr}  ; Get the stuff off the stack
                ORRNES          pc, lr, #V_bit
                BICS            pc, lr, #V_bit

; Veneer generates two labels, for example
;
; file          Veneer
;
; would create vec_file and xFiles_file 

                MACRO
$label          Veneer
                EXPORT         Entry_$label
                IMPORT         User_$label

Entry_$label    STMFD          sp!, {r8-r12, lr}
                LDR            r8, =User_$label
                BL             wrapper
                LDMFD          sp!, {r8-r12, lr}
                ORRVSS         pc, lr, #V_bit
                BICS           pc, lr, #V_bit

                LTORG
                MEND

Vector          Veneer

                END
