[OpenBIOS] patch: machine dependent config

Stefan Reinauer stepan at suse.de
Thu Jun 6 14:59:01 CEST 2002


Hi,

ok, this time I redid the patch to make paflof sane on 64bit platforms
in a cleaner way, using abstracted defines that are dependent on certain
platform specifics. As this is platform dependent stuff which has
basically nothing to do with paflof itself, I moved it to a new file:
machdep.h. I moved the sanity check out of paflof.c into machdep.c, 
which we will probably not need to link in case we know an
architecture/compiler combination is sane.

We really need to make sure we are 64bit clean from the beginning so we 
recognize early what problems we might have to face getting paflof 
portable.

Segher, is this ok to check in from your side? If so, please do!

  Stefan

-- 
The x86 isn't all that complex - it just doesn't make a lot of
sense.          -- Mike Johnson, Leader of 80x86 Design at AMD
	                          Microprocessor Report (1994)
-------------- next part --------------
diff -urN paflof/Makefile paflof-machdep/Makefile
--- paflof/Makefile	2002-06-05 01:37:34.000000000 +0200
+++ paflof-machdep/Makefile	2002-06-06 13:45:58.000000000 +0200
@@ -11,11 +11,12 @@
 dict.xt: $(DICT) ref.pl
 	cat $(DICT) | perl ref.pl > dict.xt
 
-paflof: paflof.o
+paflof: paflof.o machdep.o
 
-paflof.o paflof.s: paflof.c prim.code prep.h dict.xt
+paflof.o paflof.s: paflof.c machdep.h prim.code prep.h dict.xt
+machdep.o: machdep.h
 
 asm: paflof.s
 
 clean:
-	-rm paflof.[os] paflof dict.xt
+	-rm -f paflof.[os] machdep.o paflof dict.xt
diff -urN paflof/machdep.c paflof-machdep/machdep.c
--- paflof/machdep.c	1970-01-01 01:00:00.000000000 +0100
+++ paflof-machdep/machdep.c	2002-06-06 13:45:58.000000000 +0200
@@ -0,0 +1,46 @@
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "machdep.h"
+
+#define assert(expr, message, flag) {	\
+	if (!(expr)) {				\
+		fprintf(stderr,"%s, ", message);\
+		errors|=flag;			\
+	}					\
+}
+
+int sanity(void)
+{
+	int errors=0;
+	
+	fprintf(stderr, "evaluator sanity check... ");
+	
+	assert(sizeof(type_c)==1, "big chars", 0x1);
+	assert(sizeof(type_w)==2, "big words", 0x2);
+	assert(sizeof(type_l)==4, "big quads", 0x4);
+	assert(sizeof(type_n)==sizeof(type_u),
+			"signed/unsigned cell size differs",0x8);
+	assert(sizeof(type_n)==sizeof(void *),
+			"cell/pointer size differs",0x10);
+	assert(sizeof(type_d)==sizeof(type_du),
+			"signed/unsigned double cell size differs",0x20);
+	assert(sizeof(type_d)==2*sizeof(type_n),
+			"double cell/2*cell size differs",0x40);
+	
+
+	if (errors) {
+		fprintf(stderr, "failed.\n");
+		fprintf(stderr, "(%ld==1 %ld==2 %ld==4 "
+				"%ld==%ld==%ld %ld==%ld %ld==%ld)\n", 
+		  (long)sizeof(type_c), (long)sizeof(type_w),
+		  (long)sizeof(type_l), (long)sizeof(type_n), 
+		  (long)sizeof(type_u), (long)sizeof(void *),
+		  (long)sizeof(type_d), (long)sizeof(type_du),
+		  (long)sizeof(type_d), (long)(2*sizeof(type_n))
+		);
+	} else 
+		fprintf(stderr,"ok.\n");
+	
+	return errors;
+}
diff -urN paflof/machdep.h paflof-machdep/machdep.h
--- paflof/machdep.h	1970-01-01 01:00:00.000000000 +0100
+++ paflof-machdep/machdep.h	2002-06-06 13:45:58.000000000 +0200
@@ -0,0 +1,73 @@
+/* machine/compiler dependent definitions 
+ * 
+ * USE_STDINT: standard integer type include is available.
+ *             This should work on almost all platforms.
+ *             
+ * USE_TIMODE: Use TI mode for double cell arithmetic. This
+ *             is needed for some GNU 64bit platforms, but
+ *             definitely wrong for 32bit platforms. Only 
+ *             supported by GCC.
+ */
+
+
+
+#if defined(__i386__) || defined(__ppc__) || \
+    defined(__m68k__)
+#  define	USE_STDINT
+#  undef	USE_TIMODE
+
+#elif defined(__x86_64__) || defined(__alpha__) || \
+      defined(__ia64__)   || defined(__ppc64__)
+#  define	USE_STDINT
+#  if defined(__GNUC__)
+#    define	USE_TIMODE
+#  else
+#    undef	USE_TIMODE
+#    warning	"double cell arithmetic might cause problems."
+#  endif
+
+#else
+#  define	USE_STDINT
+#  undef	USE_TIMODE
+#  warning	"Platform unknown. Edit machdep.h in case of problems."
+#endif
+
+#ifdef USE_STDINT 
+#include <stdint.h>
+
+typedef uint8_t		type_c;		/* 1 byte    */
+typedef uint16_t	type_w;		/* 2 bytes   */
+typedef uint32_t	type_l;		/* 4 bytes   */
+typedef intptr_t	type_n;		/* cell size */
+typedef uintptr_t	type_u;		/* cell size */
+/* 2 * cell size */
+#ifdef USE_TIMODE
+typedef intmax_t       type_d __attribute__ ((mode (TI)));
+typedef uintmax_t      type_du __attribute__ ((mode (TI)));
+#else
+typedef intmax_t       type_d;
+typedef uintmax_t      type_du;
+#endif
+#else
+typedef unsigned char	type_c;		/* 1 byte    */
+typedef short		type_w;		/* 2 bytes   */
+typedef int		type_l;		/* 4 bytes   */
+typedef long		type_n;		/* cell size */
+typedef unsigned long	type_u;		/* cell size */
+/* 2 * cell size */
+#ifdef USE_TIMODE
+typedef long long		type_d __attribute__ ((mode (TI)));
+typedef unsigned long long	type_du __attribute__ ((mode (TI)));
+#else
+typedef long long		type_d;
+typedef unsigned long long	type_du;
+#endif
+#endif
+
+#define CELLSIZE (sizeof(type_u) / sizeof(type_c))
+
+#define DATA_STACK_SIZE 1024
+#define RETURN_STACK_SIZE 256
+#define DICTIONARY_SIZE 1048576
+#define TIBSIZE 256
+
diff -urN paflof/paflof.c paflof-machdep/paflof.c
--- paflof/paflof.c	2002-06-05 19:14:32.000000000 +0200
+++ paflof-machdep/paflof.c	2002-06-06 13:46:55.000000000 +0200
@@ -4,28 +4,7 @@
 #include <stdlib.h>
 #include <termios.h>
 
-
-#if 1
-#include <stdint.h>
-
-typedef uint8_t		type_c;		// 1 byte
-typedef uint16_t	type_w;		// 2 bytes
-typedef uint32_t	type_l;		// 4 bytes
-typedef intptr_t	type_n;		// cell size
-typedef uintptr_t	type_u;		// cell size
-typedef intmax_t	type_d;		// 2 * cell size
-typedef uintmax_t	type_du;	// 2 * cell size
-#else
-typedef unsigned char	type_c;		// 1 byte
-typedef short		type_w;		// 2 bytes
-typedef int		type_l;		// 4 bytes
-typedef long		type_n;		// cell size
-typedef unsigned long	type_u;		// cell size
-typedef long long	type_d;		// 2 * cell size
-typedef unsigned long long	type_du;// 2 * cell size
-#endif
-
-#define CELLSIZE (sizeof(type_u) / sizeof(type_c))
+#include "machdep.h"
 
 typedef union cell {
 	type_n n;
@@ -36,14 +15,6 @@
 	type_l l[CELLSIZE/4];
 } cell;
 
-
-
-#define DATA_STACK_SIZE 1024
-#define RETURN_STACK_SIZE 256
-#define DICTIONARY_SIZE 1048576
-#define TIBSIZE 256
-
-
 struct interpreter {
 	cell *restrict data_stack;
 	cell *restrict return_stack;
@@ -133,25 +104,22 @@
 
 int main()
 {
+	int sanity(void);
 	int i;
 	struct interpreter *interpreter;
 
-fprintf(stderr, "SANITY CHECK: (%ld==1 %ld==2 %ld==4 %ld==%ld==%ld %ld==%ld %ld==%ld)\n", 
-(long)sizeof(type_c),
-(long)sizeof(type_w),
-(long)sizeof(type_l),
-(long)sizeof(type_n), (long)sizeof(type_u), (long)sizeof(void *),
-(long)sizeof(type_d), (long)sizeof(type_du),
-(long)sizeof(type_d), (long)(2*sizeof(type_n))
-);
-
+	sanity();
 	init_terminal();
 
 	interpreter = init_engine();
 	for (i = 0; i < 1; i++) run_engine(interpreter);
-{ cell *p;
-for (p = interpreter->dictionary; (void *)p < interpreter->here; p++) fprintf(stderr, "%p: 0x%0*lx\n", p, (int)(2 * CELLSIZE), (long)p->n);
-}
+	{
+		cell *p;
+		for ( p = interpreter->dictionary; 
+				(void *)p < interpreter->here; p++)
+			fprintf(stderr, "%p: 0x%0*lx\n", p, 
+					(int)(2 * CELLSIZE), (long)p->n);
+	}
 	fini_engine(interpreter);
 
 	fini_terminal();


More information about the openbios mailing list