PATCH: ARM INTERNAL_SYSCALL cleanup

Bernhard Fischer rep.dot.nop at gmail.com
Tue Apr 22 07:53:20 UTC 2008


On Mon, Apr 21, 2008 at 12:33:06AM -0700, Khem Raj wrote:
>Hi
>
>There was some duplication when defining INTERNAL_SYSCALL macro for ARM.
>I have tried to clean this up with attached patch. Tested on ARM EABI
>and ARM OABI. Deleted commented out code too.
>OK for trunk ?

Ok, from the looks (didn't test it) with two minor changes:
s/asm/__asm__/g
s/volatile/__volatile__/g

thanks,
>Thanks
>
>-Khem
>
>Signed-off-by: Khem Raj <raj.khem at gmail.com>
>
>Index: libc/sysdeps/linux/arm/bits/syscalls.h
>===================================================================
>--- libc/sysdeps/linux/arm/bits/syscalls.h	(revision 21775)
>+++ libc/sysdeps/linux/arm/bits/syscalls.h	(working copy)
>@@ -106,100 +106,55 @@
> #define INTERNAL_SYSCALL_DECL(err) do { } while (0)
> 
> #undef INTERNAL_SYSCALL
>-#if defined(__ARM_EABI__)
> #if !defined(__thumb__)
>-#define INTERNAL_SYSCALL(name, err, nr, args...)			\
>-  ({unsigned int __sys_result;						\
>-     {									\
>-       register int _a1 __asm__ ("r0"), _nr __asm__ ("r7");			\
>-       LOAD_ARGS_##nr (args)						\
>-       _nr = SYS_ify(name);						\
>-       __asm__ volatile ("swi	0x0	@ syscall " #name		\
>-		     : "=r" (_a1)					\
>-		     : "r" (_nr) ASM_ARGS_##nr				\
>-		     : "memory");					\
>-       __sys_result = _a1;						\
>-     }									\
>-     (int) __sys_result; })
>-#else /* !defined(__thumb__) */
>-/* So hide the use of r7 from the compiler, this would be a lot
>- * easier but for the fact that the syscalls can exceed 255.
>- * For the moment the LOAD_ARG_7 is sacrificed.
>- */
>-#define INTERNAL_SYSCALL(name, err, nr, args...)                \
>-  ({ unsigned int __sys_result;                                  \
>-    {                                                           \
>-      register int _a1 asm ("a1");                              \
>-      LOAD_ARGS_##nr (args)                                     \
>-        register int _v3 asm ("v3") = (int) (SYS_ify(name));    \
>-      asm volatile ("push       {r7}\n"                         \
>-                    "\tmov      r7, v3\n"                       \
>-                    "\tswi      0       @ syscall " #name "\n"  \
>-                    "\tpop      {r7}"                           \
>-                   : "=r" (_a1)                                 \
>-                    : "r" (_v3) ASM_ARGS_##nr                   \
>-                    : "memory");                                \
>-      __sys_result = _a1;                                        \
>-    }                                                           \
>-    (int) __sys_result; })
>-#endif /*!defined(__thumb__)*/
>-#else /* !defined(__ARM_EABI__) */ 
>-#if !defined(__thumb__)
>+#if defined(__ARM_EABI__)
> #define INTERNAL_SYSCALL(name, err, nr, args...)		\
>-  ({ unsigned int __sys_result;					\
>+  ({unsigned int __sys_result;					\
>      {								\
>-       register int _a1 __asm__ ("a1");				\
>+       register int _a1 __asm__ ("r0"), _nr __asm__ ("r7");	\
>        LOAD_ARGS_##nr (args)					\
>-       __asm__ volatile ("swi	%1	@ syscall " #name	\
>+       _nr = SYS_ify(name);					\
>+       __asm__ volatile ("swi	0x0	@ syscall " #name	\
> 		     : "=r" (_a1)				\
>-		     : "i" (SYS_ify(name)) ASM_ARGS_##nr	\
>+		     : "r" (_nr) ASM_ARGS_##nr			\
> 		     : "memory");				\
>        __sys_result = _a1;					\
>      }								\
>      (int) __sys_result; })
>-#else
>-#if 0
>-/* This doesn't work because GCC uses r7 as a frame pointer in
>- * some cases and doesn't notice that the _r7 value changes
>- * it, resulting in mysterious crashes after the SWI.
>- */
>+#else /* defined(__ARM_EABI__) */
>+
> #define INTERNAL_SYSCALL(name, err, nr, args...)		\
>   ({ unsigned int __sys_result;					\
>      {								\
>        register int _a1 __asm__ ("a1");				\
>        LOAD_ARGS_##nr (args)					\
>-       register int _r7 __asm__ ("r7") = (int) (SYS_ify(name));	\
>-       __asm__ volatile ("swi	0	@ syscall " #name	\
>+       __asm__ volatile ("swi	%1	@ syscall " #name	\
> 		     : "=r" (_a1)				\
>-		     : "r" (_r7) ASM_ARGS_##nr			\
>+		     : "i" (SYS_ify(name)) ASM_ARGS_##nr	\
> 		     : "memory");				\
>        __sys_result = _a1;					\
>      }								\
>      (int) __sys_result; })
>-#else
>-/* So hide the use of r7 from the compiler, this would be a lot
>- * easier but for the fact that the syscalls can exceed 255.
>- * For the moment the LOAD_ARG_7 is sacrificed.
>- */
>+#endif
>+#else /* !defined(__thumb__) */
>+
> #define INTERNAL_SYSCALL(name, err, nr, args...)		\
>   ({ unsigned int __sys_result;					\
>-     {								\
>-       register int _a1 __asm__ ("a1");				\
>-       LOAD_ARGS_##nr (args)					\
>-       register int _v3 __asm__ ("v3") = (int) (SYS_ify(name));	\
>-       __asm__ volatile ("push	{r7}\n"				\
>-	       	     "\tmov	r7, v3\n"			\
>-	       	     "\tswi	0	@ syscall " #name "\n"	\
>-		     "\tpop	{r7}"				\
>-		     : "=r" (_a1)				\
>-		     : "r" (_v3) ASM_ARGS_##nr			\
>-		     : "memory");				\
>-       __sys_result = _a1;					\
>-     }								\
>-     (int) __sys_result; })
>-#endif
>-#endif
>-#endif /* !defined(__ARM_EABI__) */
>+    {								\
>+      register int _a1 asm ("a1");				\
>+      LOAD_ARGS_##nr (args)					\
>+      register int _v3 asm ("v3") = (int) (SYS_ify(name));	\
>+      asm volatile ("push       {r7}\n"				\
>+                    "\tmov      r7, v3\n"			\
>+                    "\tswi      0       @ syscall " #name "\n"	\
>+                    "\tpop      {r7}"				\
>+                   : "=r" (_a1)					\
>+                    : "r" (_v3) ASM_ARGS_##nr			\
>+                    : "memory");				\
>+      __sys_result = _a1;					\
>+    }								\
>+    (int) __sys_result; })
>+#endif /*!defined(__thumb__)*/
> 
> #undef INTERNAL_SYSCALL_ERROR_P
> #define INTERNAL_SYSCALL_ERROR_P(val, err) \
>



>_______________________________________________
>uClibc mailing list
>uClibc at uclibc.org
>http://busybox.net/cgi-bin/mailman/listinfo/uclibc



More information about the uClibc mailing list