[OpenBIOS] [PATCH v2 1/4] switch-arch: factorize code to compute architecture properties.

Laurent Vivier laurent at vivier.eu
Sun Oct 25 16:48:50 CET 2015


Put in two functions code that computes if given architecture
is big endian or not, and the size of long (32bit or 64bit).

Signed-off-by: Laurent Vivier <laurent at vivier.eu>
---
 config/scripts/switch-arch | 64 ++++++++++++++++++++++------------------------
 1 file changed, 30 insertions(+), 34 deletions(-)

diff --git a/config/scripts/switch-arch b/config/scripts/switch-arch
index 7b8b457..5adaa59 100755
--- a/config/scripts/switch-arch
+++ b/config/scripts/switch-arch
@@ -17,48 +17,44 @@ if [ x"$1" = x -o "$1" = "-help" ]; then
   exit 0
 fi
 
-crosscflags()
+is_bigendian()
 {
-    host=$1
-    target=$2
-
-    if test "$host" = "powerpc" -o "$host" = "ppc" \
-        -o "$host" = "mips" -o "$host" = "s390" \
-        -o "$host" = "sparc32" -o "$host" = "sparc64" \
-        -o "$host" = "m68k" -o "$host" = "armv4b"; then
-        hostbigendian="yes"
+    cpu=$1
+
+    if test "$cpu" = "powerpc" -o "$cpu" = "ppc" \
+        -o "$cpu" = "powerpc64" -o "$cpu" = "ppc64" \
+        -o "$cpu" = "mips" -o "$cpu" = "s390" \
+        -o "$cpu" = "sparc32" -o "$cpu" = "sparc64" \
+        -o "$cpu" = "m68k" -o "$cpu" = "armv4b"; then
+        echo yes
     else
-        hostbigendian="no"
+        echo no
     fi
+}
 
-# host long bits test
-    if test "$host" = "sparc64" -o "$host" = "ia64" \
-        -o "$host" = "amd64" -o "$host" = "x86_64" \
-        -o "$host" = "alpha"; then
-        hostlongbits="64"
+longbits()
+{
+    cpu=$1
+    if test "$cpu" = "sparc64" -o "$cpu" = "ia64" \
+        -o "$cpu" = "amd64" -o "$cpu" = "x86_64" \
+        -o "$cpu" = "powerpc64" -o "$cpu" = "ppc64" \
+        -o "$cpu" = "alpha"; then
+        echo 64
     else
-        hostlongbits="32"
+        echo 32
     fi
+}
 
-    if test "$target" = "powerpc" -o "$target" = "ppc" \
-        -o "$target" = "powerpc64" -o "$target" = "ppc64" \
-        -o "$target" = "mips" -o "$target" = "s390" \
-        -o "$target" = "sparc32" -o "$target" = "sparc64" \
-        -o "$target" = "m68k" -o "$target" = "armv4b"; then
-        targetbigendian="yes"
-    else
-        targetbigendian="no"
-    fi
+crosscflags()
+{
+    host=$1
+    target=$2
 
-# target long bits test
-    if test "$target" = "sparc64" -o "$target" = "ia64" \
-        -o "$target" = "amd64"  -o "$target" = "x86_64" \
-        -o "$target" = "powerpc64" -o "$target" = "ppc64" \
-        -o "$target" = "alpha"; then
-        targetlongbits="64"
-    else
-        targetlongbits="32"
-    fi
+    hostbigendian=$(is_bigendian $host)
+    hostlongbits=$(longbits $host)
+
+    targetbigendian=$(is_bigendian $target)
+    targetlongbits=$(longbits $target)
 
     if test "$targetbigendian" = "$hostbigendian"; then
         cflags="-USWAP_ENDIANNESS"
-- 
2.4.3




More information about the OpenBIOS mailing list