SPRU514Z July 2001 – October 2023 SM320F28335-EP
The error in the C28x linker to prevent linking code with a 64-word page size (C28x) and a 128-word page size (C2XLP) has been changed to a warning. It is possible to call a C2XLP assembly function from C28x C/C++ code. One possible way is to replace the call to the C2XLP function with a veneer function that correctly sets up the arguments and call stack for the C2XLP code. For example, to make a call to a C2XLP function expecting five integer arguments, change the C28x code to:
extern void foo_veneer(int, int, int, int, int);
void bar()
{
/* replace the C2XLP call with a veneer call */
/* foo(1, 2, 3, 4, 5); */
foo_veneer(1, 2, 3, 4, 5);
}
Veneer Function for Linking C2xx and C2XLP Code illustrates how the veneer function might look:
.sect ".text"
.global _foo_veneer
.global _foo
_foo_veneer:
;save registers
PUSH AR1:AR0
PUSH AR3:AR2
PUSH AR5:AR4
;set the size of the C2XLP frame (including args size)
ADDB SP,#10
;push args onto the C2XLP frame
MOV *-SP[10],AL ;copy arg 1
MOV *-SP[9],AH ;copy arg 2
MOV *-SP[8],AR4 ;copy arg 3
MOV *-SP[7],AR5 ;copy arg 4
MOV AL,*-SP[19]
MOV *-SP[6],AL ;copy arg 5
;save the return address
MOV *-SP[5],#_label
;set AR1,ARP
MOV AL,SP
SUBB AL,#3
MOV AR1,AL
NOP *ARP1
;jump to C2XLP function
LB _foo
_label:
;restore register
POP AR5:AR4
POP AR3:AR2
POP AR1:AR0LRETR
Since the veneer function frame will act as the frame for all C2XLP calls, it is necessary to add sufficient size to the frame for any subsequent calls made by the first C2XLP function.
Global variables will be placed in the .ebss sections for C28x C/C++ code compiled for the COFF ABI. A C2XLP .ebss section is not guaranteed to begin on a 128-word boundary when linked with C28x code. To avoid this problem, define a new section, change the C2XLP globals to the new section, and update the linker command file to ensure this new section begins at a 128-word boundary.