Skip to content

Commit d41feaf

Browse files
committed
Add ARM EABI support to LuaCOCO.
1 parent b21c88d commit d41feaf

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

src/lcoco.c

+30
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,36 @@ static inline void coco_switch(coco_ctx from, coco_ctx to)
169169
buf[7] = (void *)0; \
170170
stack[0] = 0xdeadc0c0deadc0c0; /* Dummy return address. */ \
171171

172+
#elif defined(__arm__)
173+
174+
static void coco_wrap_main(void)
175+
{
176+
__asm__ __volatile__ ("\tmov r0, r4\n\tbx r3\n");
177+
}
178+
179+
typedef void *coco_ctx[5]; /* pc, r3, r4, sp, lr */
180+
static inline void coco_switch(coco_ctx from, coco_ctx to)
181+
{
182+
__asm__ __volatile__ (
183+
"adr r2, 1f\n\t"
184+
"stmia %0, {r2, r3, r4, sp, lr}\n\t"
185+
"ldmia %1, {r2, r3, r4, sp, lr}\n\t"
186+
"bx r2\n\t"
187+
"1:\n\t"
188+
: "+r" (from), "+r" (to) :
189+
: "r2", "r5", "r6", "r7", "r8", "r9", "r10", "r11", "r12", "memory");
190+
}
191+
192+
#define COCO_CTX coco_ctx
193+
#define COCO_SWITCH(from, to) coco_switch(from, to);
194+
#define COCO_MAKECTX(coco, buf, func, stack, a0) \
195+
buf[0] = (void *)(coco_wrap_main); \
196+
buf[1] = (void *)(func); \
197+
buf[2] = (void *)(a0); \
198+
buf[3] = (void *)(stack); \
199+
buf[4] = (void *)0xdeadc0c0; /* Dummy return address. */ \
200+
stack[0]= 0xdeadc0c0; /* Dummy return address. */
201+
172202
#elif __mips && !defined(__mips_eabi) && \
173203
((defined(_ABIO32) && _MIPS_SIM == _ABIO32) || \
174204
(defined(_MIPS_SIM_ABI32) && _MIPS_SIM == _MIPS_SIM_ABI32))

0 commit comments

Comments
 (0)