Hello ARM asm gurus 
I would like to port C/Invoke project to cl/arm architecture(then use it with Lua as ctypes in Python), so I'm looking for some kind of workaround for missing __asm keyword in cl/arm compiler. The workaround seems to be using __emit hackery - I don't have any other idea how to do it with this incomplete compiler anyway...
So, I just wanted to know if it's possible with __emit so as a proof I'm trying to port 'ARCH_SAVE_REGPARMS' macro(sample code taken from cl/x86 arch):
but for cl/arm I will have regparams struct which will save all four r0-r3 registers, something like:
arm_macros.asm
test.c
The concept of 'ARCH_SAVE_REGPARMS' macro in test.c seems to work as is - I'm getting right values for r0-r3, but it's my first asm code for ARM so I would like to get some feedback/optimizations/suggestions first before I move forward. Thanks
-- ynezz
I would like to port C/Invoke project to cl/arm architecture(then use it with Lua as ctypes in Python), so I'm looking for some kind of workaround for missing __asm keyword in cl/arm compiler. The workaround seems to be using __emit hackery - I don't have any other idea how to do it with this incomplete compiler anyway...
So, I just wanted to know if it's possible with __emit so as a proof I'm trying to port 'ARCH_SAVE_REGPARMS' macro(sample code taken from cl/x86 arch):
- Code:
#define ARCH_SAVE_REGPARMS(regparms) \
__asm mov [(regparms).first], ecx \
__asm mov [(regparms).second], edx
but for cl/arm I will have regparams struct which will save all four r0-r3 registers, something like:
- Code:
typedef struct _ArchRegParms {
int first; /* r0 */
int second; /* r1 */
int third; /* r2 */
int fourth; /* r3 */
} regparams;
arm_macros.asm
- Code:
AREA arm_macros, CODE, READONLY
EXPORT arm_save_registers
arm_save_registers proc
mov r12, lr
str r4, [r0]
str r5, [r1]
str r6, [r2]
str r7, [r3]
mov pc, r12
endp
END
test.c
- Code:
#include <windows.h>
#include <stdio.h>
#include <armintr.h>
void arm_save_registers(int *r0, int *r1, int *r2, int *r3);
int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
{
wchar_t *buf[MAX_PATH+1];
int r0=0x72307230; /* r0r0 */
int r1=0x72317231;
int r2=0x72327232;
int r3=0x72337233;
__emit(0xE28DD064); //add sp, sp, #0x64
__emit(0xE88D00F0); //stmia sp, {r4-r7}
__emit(0xE24DD064); //sub sp, sp, #0x64
__emit(0xE1A04000); //mov r4, r0
__emit(0xE1A05001); //mov r5, r1
__emit(0xE1A06002); //mov r6, r2
__emit(0xE1A07003); //mov r7, r3
arm_save_registers(&r0, &r1, &r2, &r3);
__emit(0xE28DD074); //add sp, sp, #0x74 (0x74 = 0x64 + (4 * 4 = 0x10))
__emit(0xE91D00F0); //ldmdb sp, {r4-r7}
__emit(0xE24DD074); //sub sp, sp, #0x74
_snwprintf(buf, MAX_PATH, L"r0: 0x%x r1: 0x%x\nr2: 0x%x r3: 0x%x\n", r0, r1, r2, r3);
MessageBox(GetForegroundWindow(), buf, L"Registers", MB_OK);
return 0;
}}
The concept of 'ARCH_SAVE_REGPARMS' macro in test.c seems to work as is - I'm getting right values for r0-r3, but it's my first asm code for ARM so I would like to get some feedback/optimizations/suggestions first before I move forward. Thanks
-- ynezz