[OpenBIOS] [RFC 2/3] ppc64: Switch to 64-bit cell size

Andreas Färber andreas.faerber at web.de
Sat May 28 13:37:16 CEST 2011


To avoid some of the cell size vs. pointer size issues,
use 64-bit cells on ppc64. Suggested by Segher.

This involves handling lack of 128-bit type and compiling
64-bit libgcc parts, copied from sparc64.

Hopefully fixes compilation on 64-bit host, too.

Cc: Segher Boessenkool <segher at kernel.crashing.org>
Cc: Alexander Graf <agraf at suse.de>
Cc: Blue Swirl <blauwirbel at gmail.com>
Cc: Kenneth Salerno <kennethsalerno at yahoo.com>
---
 Unfortunately this appears to introduce a regression for Debian,
 no longer getting to the Yaboot prompt.
 
 arch/ppc/qemu/kernel.c     |    4 +-
 config/scripts/switch-arch |    1 +
 drivers/macio.c            |    4 +-
 include/arch/ppc/types.h   |   48 ++++++++++++++++++++++++++++++++++++-------
 include/kernel/stack.h     |    4 +-
 libgcc/build.xml           |    7 ++++++
 6 files changed, 54 insertions(+), 14 deletions(-)

diff --git a/arch/ppc/qemu/kernel.c b/arch/ppc/qemu/kernel.c
index b26fba5..732bca4 100644
--- a/arch/ppc/qemu/kernel.c
+++ b/arch/ppc/qemu/kernel.c
@@ -55,10 +55,10 @@ forth_segv_handler( char *segv_addr )
 		addr = *(ucell *)cell2pointer(PC);
 
 	printk("panic: segmentation violation at 0x%p\n", segv_addr);
-	printk("dict=0x%p here=0x%p(dict+0x%x) pc=0x%x(dict+0x%x)\n",
+	printk("dict=0x%p here=0x%p(dict+0x" FMT_ucellx ") pc=0x" FMT_ucellx "(dict+0x" FMT_ucellx ")\n",
 	       dict, (char*)dict + dicthead, dicthead,
 	       PC, PC - pointer2cell(dict));
-	printk("dstackcnt=%d rstackcnt=%d instruction=%x\n",
+	printk("dstackcnt=%d rstackcnt=%d instruction=" FMT_ucellx "\n",
 	       dstackcnt, rstackcnt, addr);
 
 #ifdef DEBUG_DSTACK
diff --git a/config/scripts/switch-arch b/config/scripts/switch-arch
index 1e630da..e2bfeed 100755
--- a/config/scripts/switch-arch
+++ b/config/scripts/switch-arch
@@ -76,6 +76,7 @@ crosscflags()
 
     if test "$target" = "sparc64" -o "$target" = "ia64" \
          -o "$target" = "amd64" -o "$target" = "x86_64" \
+         -o "$target" = "powerpc64" -o "$target" = "ppc64" \
          -o "$target" = "alpha"; then
         if test "$host" = "x86"; then
             cflags="$cflags -DNEED_FAKE_INT128_T"
diff --git a/drivers/macio.c b/drivers/macio.c
index 2baf295..c2090fc 100644
--- a/drivers/macio.c
+++ b/drivers/macio.c
@@ -223,11 +223,11 @@ ob_macio_decode_unit(void *private)
 static void
 ob_macio_encode_unit(void *private)
 {
-	char buf[8];
+	char buf[16];
 
 	ucell addr = POP();
 
-	snprintf(buf, sizeof(buf), "%x", addr);
+	snprintf(buf, sizeof(buf), "%" PRIxCELL, addr);
 
 	push_str(buf);
 }
diff --git a/include/arch/ppc/types.h b/include/arch/ppc/types.h
index cd71a62..001c82d 100644
--- a/include/arch/ppc/types.h
+++ b/include/arch/ppc/types.h
@@ -50,20 +50,54 @@ typedef uint32_t phys_addr_t;
 
 /* cell based types */
 
-typedef int32_t		cell;
-typedef uint32_t	ucell;
-typedef int64_t		dcell;
-typedef uint64_t	ducell;
+#ifdef CONFIG_PPC64
+
+typedef int64_t     cell;
+typedef uint64_t    ucell;
+
+#ifdef NEED_FAKE_INT128_T
+typedef struct {
+    uint64_t hi;
+    uint64_t lo;
+} blob_128_t;
+
+typedef blob_128_t  dcell;
+typedef blob_128_t  ducell;
+#else
+typedef __int128_t  dcell;
+typedef __uint128_t ducell;
+#endif
+
+#define PRIdCELL PRId64
+#define PRIuCELL PRIu64
+#define PRIxCELL PRIx64
+#define PRIXCELL PRIX64
+#define FMT_ucellx  "%08" PRIxCELL
+#define FMT_ucellX  "%08" PRIXCELL
+
+#define BITS		64
+
+#else
+
+typedef int32_t     cell;
+typedef uint32_t    ucell;
+typedef int64_t     dcell;
+typedef uint64_t    ducell;
 
 #define PRIdCELL PRId32
 #define PRIuCELL PRIu32
 #define PRIxCELL PRIx32
 #define PRIXCELL PRIX32
-#define FMT_cell    "%" PRIdCELL
-#define FMT_ucell   "%" PRIuCELL
 #define FMT_ucellx  "%08" PRIxCELL
 #define FMT_ucellX  "%08" PRIXCELL
 
+#define BITS		32
+
+#endif
+
+#define FMT_cell    "%" PRIdCELL
+#define FMT_ucell   "%" PRIuCELL
+
 typedef int32_t         prom_arg_t;
 typedef uint32_t        prom_uarg_t;
 
@@ -81,8 +115,6 @@ typedef uint32_t        prom_uarg_t;
 #define bitspercell	(sizeof(cell)<<3)
 #define bitsperdcell	(sizeof(dcell)<<3)
 
-#define BITS		32
-
 /* size named types */
 
 typedef unsigned char   u8;
diff --git a/include/kernel/stack.h b/include/kernel/stack.h
index 5edfc5c..732268d 100644
--- a/include/kernel/stack.h
+++ b/include/kernel/stack.h
@@ -34,12 +34,12 @@ typedef ucell phandle_t;
 
 static inline ucell pointer2cell(const void* x)
 {
-    return (ucell)(uintptr_t)x;
+    return (ucell)x;
 }
 
 static inline void* cell2pointer(ucell x)
 {
-    return (void*)(uintptr_t)x;
+    return (void*)x;
 }
 
 #endif
diff --git a/libgcc/build.xml b/libgcc/build.xml
index 1b7724c..85c99ee 100644
--- a/libgcc/build.xml
+++ b/libgcc/build.xml
@@ -19,6 +19,13 @@
   <object source="__umodti3.c" condition="SPARC64"/>
   <object source="multi3.c" condition="SPARC64"/>
   <object source="__negti2.c" condition="SPARC64"/>
+
+  <object source="__divti3.c" condition="PPC64"/>
+  <object source="__udivti3.c" condition="PPC64"/>
+  <object source="__udivmodti4.c" condition="PPC64"/>
+  <object source="__umodti3.c" condition="PPC64"/>
+  <object source="multi3.c" condition="PPC64"/>
+  <object source="__negti2.c" condition="PPC64"/>
  </library>
 
 </build>
-- 
1.7.3.4




More information about the OpenBIOS mailing list