hi, i want to port a function from x86 to arm for a PocketPC2003 app. It's a "simple" asm chunk. For this tasks I found myself reading the APCS, instruction set reference cards, arm macros, studying the stack frame layout, parameter passing, etc. too long for this task, so I ask for help.
I don't understand how to translate alloca() and the move data (arguments) from memory to memory in the block of code below. I've seen this related post http://www.pocketmatrix.com/forums/view ... hp?t=15487
How is the stack data aligned? (sp must point to 8-bytes boundaries?) and it is necessary to ensure the 8-byte alignment, so i must use AREA+ALIGN ? (i'm using ms evc++) First the x86 chunk
So, I make this try.
Sorry for such big post. Hope someone can help me.
Regards
I don't understand how to translate alloca() and the move data (arguments) from memory to memory in the block of code below. I've seen this related post http://www.pocketmatrix.com/forums/view ... hp?t=15487
How is the stack data aligned? (sp must point to 8-bytes boundaries?) and it is necessary to ensure the 8-byte alignment, so i must use AREA+ALIGN ? (i'm using ms evc++) First the x86 chunk
- Code:
/* Max stack size */
#define FFI_MAX_ARGS 128
/* The stack used to assemble the arguments for a call */
static int dataArgs[FFI_MAX_ARGS];
/* The stack pointer while filling the stack */
static int argIndex = 0;
volatile static int intReturnValue;
volatile static int intReturnValue2;
volatile static double floatReturnValue;
....
int callAddress(int fn)
__asm {
push ebx
mov ebx, fn
push ecx
push edx
push edi
push esi
push ebp
/* mark the frame */
mov ebp, esp
/* alloca() stackIndex size bytes */
mov ecx, argIndex
shl ecx, 2
sub esp, ecx
/* copy stack */
mov edi, esp
lea esi, dataArgs
shr ecx, 2
cld
rep movsd
/* go calling */
call ebx
/* restore frame */
mov esp, ebp
/* store the return values */
mov intReturnValue, eax
mov intReturnValue2, edx
fstp floatReturnValue
/* restore register values */
pop ebp
pop esi
pop edi
pop edx
pop ecx
pop ebx
}
So, I make this try.
- Code:
int callAddress(int fn) {
/* already know that evc doesn't allow inline asm,
just here for figure out fn purpose */
__asm {
mov ??
mov ??, fn
stmfd sp!, {r0-r3,lr} /* or Pre-incremental load stmed ? */
/* mark the frame */
mov r14,r13
/* alloca() stackIndex size bytes
.... see msdn comment below .... */
/* go calling */
bl ??
/* restore frame */
mov r13, r14
/* store the return values
check parameter passing and restore values doc */
mov ??, intReturnValue
mov r1, intReturnValue2
/* fstp floatReturnValue I must convert this float to fixed point ? */
/* restore register values */
ldmfd sp!, {r0-r3, lr}
}
...
alloca() asm version
mov argIndex, r0
/* it's necessary to do this sub and shifts ? */
sub r0, r0, r13, lsl#2
/* copy stack
study the stack frame layout :)
??
...
ldr r2, dataArgs
...
*/
* If a routine has alloca() locals, a frame pointer register (R11 for ARM or R7 for Thumb) is required to access the incoming arguments and locals. The routine must not modify the frame pointer register between the prolog and epilog
* In a routine that uses alloca(), everything in the frame below (at a lower address than) the alloca() area is referenced relative to R13 and never contains a defined value at the time of an alloca() call. Thus, the alloca() operation never has to copy this part of the stack frame, and no data relocation problems arise. Everything in the frame above (at an address higher than) the alloca() area is referenced relative to the frame pointer (R11 for ARM or R7 for Thumb).
Sorry for such big post. Hope someone can help me.
Regards