From bc7566a83faea81364f827f62d05765c5aa86597 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valmantas=20Palik=C5=A1a?= Date: Mon, 16 Dec 2019 09:10:03 -0600 Subject: [PATCH] arch/arm/include/armv7-m/syscall.h: ARM EABI specifies that the stack should be aligned by 8 on function calls, inside the function is not required to be aligned by 8. Since these functions call svc, compiler doesn't know that the svc is a function, therefore it does not do any stack management. This change pushes an even number of args to the stack and maintains an 8 byte alignment. I've checked the assembly and it doesn't cause any more overhead that the hand written assembly. --- arch/arm/include/armv7-m/syscall.h | 40 +++++++----------------------- 1 file changed, 9 insertions(+), 31 deletions(-) diff --git a/arch/arm/include/armv7-m/syscall.h b/arch/arm/include/armv7-m/syscall.h index 41b2bb001cd..56012edde26 100644 --- a/arch/arm/include/armv7-m/syscall.h +++ b/arch/arm/include/armv7-m/syscall.h @@ -138,23 +138,13 @@ static inline uintptr_t sys_call2(unsigned int nbr, uintptr_t parm1, /* SVC call with SYS_ call number and three parameters */ +static inline uintptr_t sys_call4(unsigned int nbr, uintptr_t parm1, + uintptr_t parm2, uintptr_t parm3, + uintptr_t parm4); static inline uintptr_t sys_call3(unsigned int nbr, uintptr_t parm1, uintptr_t parm2, uintptr_t parm3) { - register long reg0 __asm__("r0") = (long)(nbr); - register long reg3 __asm__("r3") = (long)(parm3); - register long reg2 __asm__("r2") = (long)(parm2); - register long reg1 __asm__("r1") = (long)(parm1); - - __asm__ __volatile__ - ( - "svc %1" - : "=r"(reg0) - : "i"(SYS_syscall), "r"(reg0), "r"(reg1), "r"(reg2), "r"(reg3) - : "memory" - ); - - return reg0; + return sys_call4(nbr, parm1, parm2, parm3, 0); } /* SVC call with SYS_ call number and four parameters. @@ -189,27 +179,15 @@ static inline uintptr_t sys_call4(unsigned int nbr, uintptr_t parm1, * NOTE the nonstandard parameter passing: parm4 and parm5 are in R4 and R5 */ +static inline uintptr_t sys_call6(unsigned int nbr, uintptr_t parm1, + uintptr_t parm2, uintptr_t parm3, + uintptr_t parm4, uintptr_t parm5, + uintptr_t parm6); static inline uintptr_t sys_call5(unsigned int nbr, uintptr_t parm1, uintptr_t parm2, uintptr_t parm3, uintptr_t parm4, uintptr_t parm5) { - register long reg0 __asm__("r0") = (long)(nbr); - register long reg5 __asm__("r5") = (long)(parm5); - register long reg4 __asm__("r4") = (long)(parm4); - register long reg3 __asm__("r3") = (long)(parm3); - register long reg2 __asm__("r2") = (long)(parm2); - register long reg1 __asm__("r1") = (long)(parm1); - - __asm__ __volatile__ - ( - "svc %1" - : "=r"(reg0) - : "i"(SYS_syscall), "r"(reg0), "r"(reg1), "r"(reg2), - "r"(reg3), "r"(reg4), "r"(reg5) - : "memory" - ); - - return reg0; + return sys_call6(nbr, parm1, parm2, parm3, parm4, parm5, 0); } /* SVC call with SYS_ call number and six parameters.