implement va_list for ARMv7 - cu_va_start and cu_va_arg works now based on frame-pointer (r11) for variable arguments, indexed differently than x86 stack ABI does

This commit is contained in:
mykola2312 2022-05-21 10:38:35 +03:00
parent 5448323450
commit 003e51b692
4 changed files with 24 additions and 5 deletions

View file

@ -182,7 +182,14 @@ cu_memtest:
bx lr
cu_va_start:
add r1, r11, #8
str r1, [r0]
bx lr
cu_va_arg:
// r0 - va_list, r1 - index
mov r1, r1, lsl #2
ldr r0, [r0]
add r0, r0, r1
ldr r0, [r0]
bx lr

View file

@ -273,8 +273,11 @@ void cu_sprintf(char* dst, size_t maxLen, const char* fmt, ...)
uword idx;
char* cur,*end,c;
char numbuf[64];
#ifdef CU_ARCH_ARM
idx = 0;
#else
idx = 3;
#endif
cur = dst;
end = dst+maxLen;
while((c = *fmt++) && cur != end)
@ -360,8 +363,11 @@ void cu_sscanf(char* buf, char* fmt, ...)
char* sptr;
} u;
char c,*stk;
#ifdef CU_ARCH_ARM
idx = 0;
#else
idx = 2;
#endif
while((c = *fmt))
{
//kprintf("%c %c\n",c,*buf);

6
test.c
View file

@ -177,7 +177,7 @@ int main()
printf("cu_memset\tc0\t%p\n", cu_memtest(&c0, 1));
printf("[va_list]\n");
//va_test(1337, 1, 2, 3, 4, 5);
va_test(1337, 1, 2, 3, 4, 5);
printf("[string]\n");
printf("cu_memcmp\t%u\n", cu_memcmp(val3, val3, sizeof(val3)));
@ -188,7 +188,7 @@ int main()
printf("cu_strcpy\tstr2\t\"%s\"\n", str2);
printf("cu_strcmp\t%u\n", cu_strcmp(str2, str1));
/*char str3[64] = {0};
char str3[64] = {0};
cu_sprintf(str3, 64, "hello %u world \"%s\"", 2312, "test");
printf("cu_sprintf\t%s\n", str3);
@ -196,7 +196,7 @@ int main()
char str5[8] = {0};
iword val5 = 0;
cu_sscanf((char*)str4, "\"%s\" %d", str5, 8, &val5);
printf("cu_sscanf\t%s\t%u\n", str5, val5);*/
printf("cu_sscanf\t%s\t%u\n", str5, val5);
printf("[heap]\n");
static u8 heap_data[4096];

View file

@ -13,9 +13,15 @@
# define VA_NUM 0
#endif
#ifdef CU_ARCH_X86
typedef struct {
uword args[VA_NUM];
} cu_va_list;
#elif (defined(CU_ARCH_ARM))
typedef struct {
uword fp;
} cu_va_list;
#endif
extern void cu_va_start(cu_va_list* va);
extern uword cu_va_arg(cu_va_list* va, unsigned idx);