Port-arm archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[PATCH] thumb fixes



    Fixes from Ilya Dogolazky for running binaries compiled
    to thumb instructions set. Full dynamic userspace does not
    work yet, but at least some statically linked programs like
    /bin/cat work when compiled on an ARM board. Cross compiled
    thumb binaries have some problems as well.

diff --git a/sys/arch/arm/include/asm.h b/sys/arch/arm/include/asm.h
index 32c86f8..07ce733 100644
--- a/sys/arch/arm/include/asm.h
+++ b/sys/arch/arm/include/asm.h
@@ -146,10 +146,17 @@
 #endif
 
 #ifdef __ELF__
+#ifdef __thumb__
+#define        WEAK_ALIAS(alias,sym)                                           
\
+       .thumb_set alias,sym;                                           \
+       .weak alias;                                                    \
+       alias = sym
+#else
 #define        WEAK_ALIAS(alias,sym)                                           
\
        .weak alias;                                                    \
        alias = sym
 #endif
+#endif
 
 /*
  * STRONG_ALIAS: create a strong alias.
diff --git a/sys/sys/cdefs_aout.h b/sys/sys/cdefs_aout.h
index 69a4113..b15f5e1 100644
--- a/sys/sys/cdefs_aout.h
+++ b/sys/sys/cdefs_aout.h
@@ -25,9 +25,16 @@
 #define        __strong_alias(alias,sym)                                       
\
     __asm(".global " _C_LABEL_STRING(#alias) "\n"                      \
            _C_LABEL_STRING(#alias) " = " _C_LABEL_STRING(#sym));
+#ifdef __thumb__
+#define        __weak_alias(alias,sym)                                         
\
+    __asm(".weak " _C_LABEL_STRING(#alias) "\n"                                
\
+           _C_LABEL_STRING(#alias) " = " _C_LABEL_STRING(#sym));       \
+    __asm(".thumb_set " _C_LABEL_STRING(#alias) "," _C_LABEL_STRING(#sym));
+#else /* __thumb__ */
 #define        __weak_alias(alias,sym)                                         
\
     __asm(".weak " _C_LABEL_STRING(#alias) "\n"                        \
            _C_LABEL_STRING(#alias) " = " _C_LABEL_STRING(#sym));
+#endif /* __thumb__ */
 
 /* Do not use __weak_extern, use __weak_reference instead */
 #define        __weak_extern(sym)                                              
\
@@ -44,8 +51,15 @@
        __asm(".stabs \"_" #sym "\",1,0,0,0");
 #else /* __STDC__ */
 #define        __weak_alias(alias,sym) ___weak_alias(_/**/alias,_/**/sym)
+#ifdef __thumb__
+#define        ___weak_alias(alias,sym)                                        
\
+    __asm(".weak " _C_LABEL_STRING(#alias) "\n"                        \
+       _C_LABEL_STRING(#alias) " = " _C_LABEL_STRING(#sym));           \
+    __asm(".thumb_set " _C_LABEL_STRING(#alias) "," _C_LABEL_STRING(#sym));
+#else /* __thumb__ */
 #define        ___weak_alias(alias,sym)                                        
\
     __asm(".weak alias\nalias = sym");
+#endif /* __thumb__ */
 /* Do not use __weak_extern, use __weak_reference instead */
 #define        __weak_extern(sym) ___weak_extern(_/**/sym)
 #define        ___weak_extern(sym)                                             
\
diff --git a/sys/sys/cdefs_elf.h b/sys/sys/cdefs_elf.h
index 913ff5d..958ab30 100644
--- a/sys/sys/cdefs_elf.h
+++ b/sys/sys/cdefs_elf.h
@@ -56,9 +56,16 @@
     __asm(".global " _C_LABEL_STRING(#alias) "\n"                      \
            _C_LABEL_STRING(#alias) " = " _C_LABEL_STRING(#sym));
 
+#ifdef __thumb__
+#define        __weak_alias(alias,sym)                                         
\
+    __asm(".weak " _C_LABEL_STRING(#alias) "\n"                                
\
+           _C_LABEL_STRING(#alias) " = " _C_LABEL_STRING(#sym));       \
+    __asm(".thumb_set " _C_LABEL_STRING(#alias) "," _C_LABEL_STRING(#sym));
+#else /* __thumb__ */
 #define        __weak_alias(alias,sym)                                         
\
     __asm(".weak " _C_LABEL_STRING(#alias) "\n"                        \
            _C_LABEL_STRING(#alias) " = " _C_LABEL_STRING(#sym));
+#endif /* __thumb__ */
 
 /* Do not use __weak_extern, use __weak_reference instead */
 #define        __weak_extern(sym)                                              
\
@@ -77,6 +84,19 @@
 
 #else /* !__STDC__ */
 
+#ifdef __thumb__
+#ifdef __LEADING_UNDERSCORE
+#define __weak_alias(alias,sym) ___weak_alias(_/**/alias,_/**/sym)
+#define        ___weak_alias(alias,sym)                                        
\
+    __asm(".weak " _C_LABEL_STRING(#alias) "\n"                        \
+       _C_LABEL_STRING(#alias) " = " _C_LABEL_STRING(#sym));           \
+    __asm(".thumb_set " _C_LABEL_STRING(#alias) "," _C_LABEL_STRING(#sym));
+#else
+#define        __weak_alias(alias,sym)                                         
\
+    __asm(".weak alias\n" _C_LABEL_STRING(#alias) " = " 
_C_LABEL_STRING(#sym));\
+    __asm(".thumb_set " _C_LABEL_STRING(#alias) "," _C_LABEL_STRING(#sym));
+#endif
+#else /* __thumb__ */
 #ifdef __LEADING_UNDERSCORE
 #define __weak_alias(alias,sym) ___weak_alias(_/**/alias,_/**/sym)
 #define        ___weak_alias(alias,sym)                                        
\
@@ -85,6 +105,8 @@
 #define        __weak_alias(alias,sym)                                         
\
     __asm(".weak alias\nalias = sym");
 #endif
+#endif /* __thumb__ */
+
 #ifdef __LEADING_UNDERSCORE
 #define __weak_extern(sym) ___weak_extern(_/**/sym)
 #define        ___weak_extern(sym)                                             
\


Home | Main Index | Thread Index | Old Index