9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* Drawterm problems
@ 2008-12-09  5:13 Martín Ferrari
  2008-12-09  5:17 ` [9fans] Fwd: " Martín Ferrari
  2008-12-09  5:41 ` Russ Cox
  0 siblings, 2 replies; 9+ messages in thread
From: Martín Ferrari @ 2008-12-09  5:13 UTC (permalink / raw)
  To: Russ Cox
  Cc: Fans of the OS Plan 9 from Bell Labs, Thiemo Seufer, 508068,
	Marc 'HE' Brockschmidt, 508100, Damián Viano

[-- Attachment #1: Type: text/plain, Size: 2609 bytes --]

(Copying 9fans in case somebody can lend a hand on this, copying the
Debian bug report(er)s)
Hi Russ,

I'm a Plan9 newbie and Debian Developer, and I'm currently tying to
fix bugs that showed after I uploaded drawterm to Debian. However I
have hit some problems that are being difficult to solve. I've managed
to fix most of them, and I'd like to share the patches.

First problem: it doesn't compile on mips at all, the assembly code
seems invalid. In [0] you can find a proposed patch.

Second problem: the arch handling is quite fragile, and it doesn't
work for sparc under linux [1] (uname -m is sparc64, not sun4u), for
example. But the biggest problem is that there are no provisions for
other architectures. I have prepared a big patch for this, see below.

Third: segfaults on amd64, possibly other arches that I couldn't test.
After a lot of guessing, I suspected of these constructs in lib.h:

typedef int            p9_long;
#define long  int

Changing them to match longs with longs made the segfault go away, as
amd64 uses 64bits for longs and the included libX.h was botched
because of the "#define long int". But then it popped many type errors
all around, since there are many inconsistencies (for example,
function prototypes that doesn't match exactly the fuction
definitions) and all the code assumes long==int. I'm trying to fix
this, but the problem is very deep: there are many places where size
specific types should be used instead of longs and ints.

I'm still trying to fix this, and would greatly appreciate any help.


~~~~

I'm including the arch-related patch: it disables all the posix-*/
code (except for the x86 hashing routines, which are now conditionally
complied from libsec) and instead creates a libmachdep directory with
a tas.c file. In tas.c it tries to use the fairly new builtin atomic
operations, and falls back to assemby if it's available. Also, the
getcallerpc function is replaced with other gcc builtin, but I haven't
made provisions for fallback to assembly here as I think that the
builtin I'm using is widely available and that would have made the
patch very complex.

This change enabled drawterm to compile on these architectures: i386
amd64 sparc64 mips mipsel alpha ia64 powerpc s390. But since most of
the porter machines I can use don't have X forwarding, I cannot test
that it works correctly. sparc64 and i386 were tested and it seems to
work ok.


[0] http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=508068
[1] http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=508100

-- 
Martín Ferrari

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: replace-archspecific-with-gcc-extensions.patch --]
[-- Type: text/x-patch; name=replace-archspecific-with-gcc-extensions.patch, Size: 6909 bytes --]

Index: drawterm/include/lib.h
===================================================================
--- drawterm.orig/include/lib.h
+++ drawterm/include/lib.h
@@ -240,7 +240,12 @@ extern	int	fmtprint(Fmt*, char*, ...);
 extern	int	fmtvprint(Fmt*, char*, va_list);
 extern	void*	mallocz(ulong, int);
 
-extern	uintptr	getcallerpc(void*);
+/* Use a GCC extension that provides the same, without specifying the actual
+ * assembly code. In the code is always used to return the caller to the actual
+ * function, so I ignore the argument */
+/* extern	uintptr	getcallerpc(void*); */
+#define		getcallerpc(a) \
+		((uintptr)__builtin_return_address(0))
 extern	char*	cleanname(char*);
 extern	void	sysfatal(char*, ...);
 extern	char*	strecpy(char*, char*, char*);
Index: drawterm/Make.irix
===================================================================
--- drawterm.orig/Make.irix
+++ drawterm/Make.irix
@@ -20,5 +20,4 @@ MAKE=gmake
 
 all: default
 
-libmachdep.a:
-	(cd posix-mips && $(MAKE))
+ARCH=mips
Index: drawterm/Make.osx
===================================================================
--- drawterm.orig/Make.osx
+++ drawterm/Make.osx
@@ -15,6 +15,5 @@ AUDIO=none
 
 all: default
 
-libmachdep.a:
-	arch=`uname -m|sed 's/i.86/386/;s/Power Macintosh/power/'`; \
-	(cd posix-$$arch &&  make)
+ARCH := $(shell uname -m |\
+	sed 's/i.86/386/;s/Power Macintosh/power/;s/x86_64/amd64/' )
Index: drawterm/Make.osx-x11
===================================================================
--- drawterm.orig/Make.osx-x11
+++ drawterm/Make.osx-x11
@@ -16,6 +16,5 @@ AUDIO=none
 
 all: default
 
-libmachdep.a:
-	arch=`uname -m|sed 's/i.86/386/;s/Power Macintosh/power/'`; \
-	(cd posix-$$arch &&  make)
+ARCH := $(shell uname -m |\
+	sed 's/i.86/386/;s/Power Macintosh/power/;s/x86_64/amd64/' )
Index: drawterm/Make.sun
===================================================================
--- drawterm.orig/Make.sun
+++ drawterm/Make.sun
@@ -16,6 +16,5 @@ AUDIO=none
 
 all: default
 
-libmachdep.a:
-	arch=`uname -m|sed 's/i.86/386/;s/Power Macintosh/power/'`; \
-	(cd posix-$$arch &&  make)
+ARCH := $(shell uname -m |\
+	sed 's/i.86/386/;s/Power Macintosh/power/;s/x86_64/amd64/' )
Index: drawterm/Make.unix
===================================================================
--- drawterm.orig/Make.unix
+++ drawterm/Make.unix
@@ -18,6 +18,5 @@ AUDIO=unix
 
 all: default
 
-libmachdep.a:
-	arch=`uname -m|sed 's/i.86/386/;s/Power Macintosh/power/; s/x86_64/amd64/'`; \
-	(cd posix-$$arch &&  make)
+ARCH := $(shell uname -m |\
+	sed 's/i.86/386/;s/Power Macintosh/power/;s/x86_64/amd64/' )
Index: drawterm/Make.win32
===================================================================
--- drawterm.orig/Make.win32
+++ drawterm/Make.win32
@@ -33,10 +33,7 @@ XOFILES=9ball.$O
 
 all: default
 
-# for root
-libmachdep.a:
-	(cd win32-386; make)
-
 9ball.$O: 9ball.rc 9ball.ico
 	$(WINDRES) -i 9ball.rc -o 9ball.o
 
+ARCH=386
Index: drawterm/Makefile
===================================================================
--- drawterm.orig/Makefile
+++ drawterm/Makefile
@@ -25,7 +25,7 @@ LIBS1=\
 	libc/libc.a\
 
 # stupid gcc
-LIBS=$(LIBS1) $(LIBS1) $(LIBS1) libmachdep.a
+LIBS=$(LIBS1) $(LIBS1) $(LIBS1) libmachdep/libmachdep.a
 
 default: $(TARG)
 $(TARG): $(OFILES) $(LIBS)
@@ -69,3 +69,6 @@ libc/libc.a:
 
 gui-$(GUI)/libgui.a:
 	(cd gui-$(GUI); $(MAKE))
+
+libmachdep/libmachdep.a:
+	(cd libmachdep; $(MAKE))
Index: drawterm/libsec/Makefile
===================================================================
--- drawterm.orig/libsec/Makefile
+++ drawterm/libsec/Makefile
@@ -33,6 +33,7 @@ OFILES=\
 	hmac.$O\
 	md4.$O\
 	md5.$O\
+	_md5block.$O\
 	md5pickle.$O\
 	nfastrand.$O\
 	prng.$O\
@@ -45,6 +46,7 @@ OFILES=\
 	rsagen.$O\
 	rsaprivtopub.$O\
 	sha1.$O\
+	_sha1block.$O\
 	sha1pickle.$O\
 	smallprimes.$O
 
@@ -56,3 +58,23 @@ $(LIB): $(OFILES)
 %.$O: %.c
 	$(CC) $(CFLAGS) $*.c
 
+ifeq "$(ARCH)" "386"
+_sha1block.$O: sha1block.s
+	$(AS) -o $@ $<
+
+_md5block.$O: md5block.s
+	$(AS) -o $@ $<
+
+sha1block.s: ../posix-386/sha1block.spp
+	$(CC) -E - < $< > $@
+
+md5block.s: ../posix-386/md5block.spp
+	$(CC) -E - < $< > $@
+else
+_sha1block.$O: sha1block.c
+	echo -$(ARCH)-
+	$(CC) $(CFLAGS) -o $@ $<
+
+_md5block.$O: md5block.c
+	$(CC) $(CFLAGS) -o $@ $<
+endif
Index: drawterm/libmachdep/Makefile
===================================================================
--- /dev/null
+++ drawterm/libmachdep/Makefile
@@ -0,0 +1,14 @@
+ROOT=..
+include ../Make.config
+LIB=libmachdep.a
+
+OFILES=\
+	tas.$O
+
+default: $(LIB)
+$(LIB): $(OFILES)
+	$(AR) r $(LIB) $(OFILES)
+	$(RANLIB) $(LIB)
+
+%.$O: %.c
+	$(CC) $(CFLAGS) $*.c
Index: drawterm/libmachdep/tas.c
===================================================================
--- /dev/null
+++ drawterm/libmachdep/tas.c
@@ -0,0 +1,89 @@
+#include "u.h"
+#include "libc.h"
+
+#define GCC_VERSION (__GNUC__ * 10000 \
+		+ __GNUC_MINOR__ * 100 \
+		+ __GNUC_PATCHLEVEL__)
+
+long
+tas(long *x)
+{
+	long	v = 1;
+#if (! __arm__) && (! __m68k__) && ((GCC_VERSION > 40300) || \
+		(__alpha__ && GCC_VERSION > 40200) || \
+		(__sparc__ && GCC_VERSION > 40200) || \
+		(__s390__ && GCC_VERSION > 40100))
+	v = __sync_lock_test_and_set (x, 1);
+#else /* Old gcc */
+#ifdef __i386__
+	__asm__(	"xchgl  %%eax,(%%ecx)"
+			: "+a" (v)
+			: "c" (x));
+#else /* __i386__ */
+#ifdef __x86_64__
+	__asm__(	"xchgl  %%eax,(%%rcx)"
+			: "+a" (v)
+			: "c" (x));
+#else /* __x86_64__ */
+
+#ifdef __mips__
+#ifdef __linux__
+	__asm__(".set mips2\n");
+#endif
+	__asm__("loop:\n\t"
+			"li	$t1, 12345\n\t"	/* t1 = 12345 */
+			"ll	%0, (%1)\n\t"	/* v0 = *a0 */
+			"sc	$t1, (%1)\n\t"	/* *a0 = t1 if *a0 hasn't changed; t1=success */
+			"beqz	$t1, loop"	/* repeat if *a0 did change */
+			: "=r" (v)
+			: "d" (x)
+			: "t1");
+#ifdef __linux__
+	__asm__(".set mips0\n");
+#endif
+#else /* __mips__ */
+
+#ifdef __powerpc__
+	/*
+	 * this __asm__ works with gcc 2.95.2 (mac os x 10.1).
+	 * this assembly language destroys r0 (0), some other register (v),
+	 * r4 (x) and r5 (temp).
+	 */
+	__asm__("\n	sync\n"
+	"	li	r0,0\n"
+	"	mr	r4,%1		/* &l->val */\n"
+	"	lis	r5,0xdead	/* assemble constant 0xdeaddead */\n"
+	"	ori	r5,r5,0xdead	/* \" */\n"
+	"tas1:\n"
+	"	dcbf	r4,r0	/* cache flush; \"fix for 603x bug\" */\n"
+	"	lwarx	%0,r4,r0	/* v = l->val with reservation */\n"
+	"	cmp	cr0,0,%0,r0	/* v == 0 */\n"
+	"	bne	tas0\n"
+	"	stwcx.	r5,r4,r0   /* if (l->val same) l->val = 0xdeaddead */\n"
+	"	bne	tas1\n"
+	"tas0:\n"
+	"	sync\n"
+	"	isync\n"
+	: "=r" (v)
+	: "r"  (x)
+	: "cc", "memory", "r0", "r4", "r5"
+	);
+
+#else /* __powerpc__ */
+
+#ifdef __sparc__
+	__asm__(	"stbar\n\t"
+			"swap	[ %1 ], %0"
+			: "+g" (v)
+			: "g" (x));
+#else /* __sparc__ */
+#error "Arch not supported with this GCC version"
+#endif /* __sparc__ */
+#endif /* __powerpc__ */
+#endif /* __mips__ */
+#endif /* __x86_64__ */
+#endif /* __i386__ */
+#endif /* Old gcc */
+	return v != 0;
+}
+

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [9fans] Fwd: Drawterm problems
  2008-12-09  5:13 Drawterm problems Martín Ferrari
@ 2008-12-09  5:17 ` Martín Ferrari
  2008-12-09  7:05   ` Michal Hajek
  2008-12-09  5:41 ` Russ Cox
  1 sibling, 1 reply; 9+ messages in thread
From: Martín Ferrari @ 2008-12-09  5:17 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

[-- Attachment #1: Type: text/plain, Size: 3047 bytes --]

---------- Forwarded message ----------
From: Martín Ferrari <martin.ferrari@gmail.com>
Date: Tue, Dec 9, 2008 at 03:13
Subject: Drawterm problems
To: Russ Cox <rsc@swtch.com>
Cc: Fans of the OS Plan 9 from Bell Labs <9fans@9fans.net>, Thiemo
Seufer <ths@networkno.de>, 508068@bugs.debian.org, Marc 'HE'
Brockschmidt <marc@marcbrockschmidt.de>, 508100@bugs.debian.org,
Damián Viano <des@debian.org>


(Copying 9fans in case somebody can lend a hand on this, copying the
Debian bug report(er)s)
Hi Russ,

I'm a Plan9 newbie and Debian Developer, and I'm currently tying to
fix bugs that showed after I uploaded drawterm to Debian. However I
have hit some problems that are being difficult to solve. I've managed
to fix most of them, and I'd like to share the patches.

First problem: it doesn't compile on mips at all, the assembly code
seems invalid. In [0] you can find a proposed patch.

Second problem: the arch handling is quite fragile, and it doesn't
work for sparc under linux [1] (uname -m is sparc64, not sun4u), for
example. But the biggest problem is that there are no provisions for
other architectures. I have prepared a big patch for this, see below.

Third: segfaults on amd64, possibly other arches that I couldn't test.
After a lot of guessing, I suspected of these constructs in lib.h:

typedef int            p9_long;
#define long  int

Changing them to match longs with longs made the segfault go away, as
amd64 uses 64bits for longs and the included libX.h was botched
because of the "#define long int". But then it popped many type errors
all around, since there are many inconsistencies (for example,
function prototypes that doesn't match exactly the fuction
definitions) and all the code assumes long==int. I'm trying to fix
this, but the problem is very deep: there are many places where size
specific types should be used instead of longs and ints.

I'm still trying to fix this, and would greatly appreciate any help.


~~~~

I'm including the arch-related patch: it disables all the posix-*/
code (except for the x86 hashing routines, which are now conditionally
complied from libsec) and instead creates a libmachdep directory with
a tas.c file. In tas.c it tries to use the fairly new builtin atomic
operations, and falls back to assemby if it's available. Also, the
getcallerpc function is replaced with other gcc builtin, but I haven't
made provisions for fallback to assembly here as I think that the
builtin I'm using is widely available and that would have made the
patch very complex.

This change enabled drawterm to compile on these architectures: i386
amd64 sparc64 mips mipsel alpha ia64 powerpc s390. But since most of
the porter machines I can use don't have X forwarding, I cannot test
that it works correctly. sparc64 and i386 were tested and it seems to
work ok.


[0] http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=508068
[1] http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=508100

--
Martín Ferrari



-- 
Martín Ferrari

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: replace-archspecific-with-gcc-extensions.patch --]
[-- Type: text/x-patch; name=replace-archspecific-with-gcc-extensions.patch, Size: 6909 bytes --]

Index: drawterm/include/lib.h
===================================================================
--- drawterm.orig/include/lib.h
+++ drawterm/include/lib.h
@@ -240,7 +240,12 @@ extern	int	fmtprint(Fmt*, char*, ...);
 extern	int	fmtvprint(Fmt*, char*, va_list);
 extern	void*	mallocz(ulong, int);
 
-extern	uintptr	getcallerpc(void*);
+/* Use a GCC extension that provides the same, without specifying the actual
+ * assembly code. In the code is always used to return the caller to the actual
+ * function, so I ignore the argument */
+/* extern	uintptr	getcallerpc(void*); */
+#define		getcallerpc(a) \
+		((uintptr)__builtin_return_address(0))
 extern	char*	cleanname(char*);
 extern	void	sysfatal(char*, ...);
 extern	char*	strecpy(char*, char*, char*);
Index: drawterm/Make.irix
===================================================================
--- drawterm.orig/Make.irix
+++ drawterm/Make.irix
@@ -20,5 +20,4 @@ MAKE=gmake
 
 all: default
 
-libmachdep.a:
-	(cd posix-mips && $(MAKE))
+ARCH=mips
Index: drawterm/Make.osx
===================================================================
--- drawterm.orig/Make.osx
+++ drawterm/Make.osx
@@ -15,6 +15,5 @@ AUDIO=none
 
 all: default
 
-libmachdep.a:
-	arch=`uname -m|sed 's/i.86/386/;s/Power Macintosh/power/'`; \
-	(cd posix-$$arch &&  make)
+ARCH := $(shell uname -m |\
+	sed 's/i.86/386/;s/Power Macintosh/power/;s/x86_64/amd64/' )
Index: drawterm/Make.osx-x11
===================================================================
--- drawterm.orig/Make.osx-x11
+++ drawterm/Make.osx-x11
@@ -16,6 +16,5 @@ AUDIO=none
 
 all: default
 
-libmachdep.a:
-	arch=`uname -m|sed 's/i.86/386/;s/Power Macintosh/power/'`; \
-	(cd posix-$$arch &&  make)
+ARCH := $(shell uname -m |\
+	sed 's/i.86/386/;s/Power Macintosh/power/;s/x86_64/amd64/' )
Index: drawterm/Make.sun
===================================================================
--- drawterm.orig/Make.sun
+++ drawterm/Make.sun
@@ -16,6 +16,5 @@ AUDIO=none
 
 all: default
 
-libmachdep.a:
-	arch=`uname -m|sed 's/i.86/386/;s/Power Macintosh/power/'`; \
-	(cd posix-$$arch &&  make)
+ARCH := $(shell uname -m |\
+	sed 's/i.86/386/;s/Power Macintosh/power/;s/x86_64/amd64/' )
Index: drawterm/Make.unix
===================================================================
--- drawterm.orig/Make.unix
+++ drawterm/Make.unix
@@ -18,6 +18,5 @@ AUDIO=unix
 
 all: default
 
-libmachdep.a:
-	arch=`uname -m|sed 's/i.86/386/;s/Power Macintosh/power/; s/x86_64/amd64/'`; \
-	(cd posix-$$arch &&  make)
+ARCH := $(shell uname -m |\
+	sed 's/i.86/386/;s/Power Macintosh/power/;s/x86_64/amd64/' )
Index: drawterm/Make.win32
===================================================================
--- drawterm.orig/Make.win32
+++ drawterm/Make.win32
@@ -33,10 +33,7 @@ XOFILES=9ball.$O
 
 all: default
 
-# for root
-libmachdep.a:
-	(cd win32-386; make)
-
 9ball.$O: 9ball.rc 9ball.ico
 	$(WINDRES) -i 9ball.rc -o 9ball.o
 
+ARCH=386
Index: drawterm/Makefile
===================================================================
--- drawterm.orig/Makefile
+++ drawterm/Makefile
@@ -25,7 +25,7 @@ LIBS1=\
 	libc/libc.a\
 
 # stupid gcc
-LIBS=$(LIBS1) $(LIBS1) $(LIBS1) libmachdep.a
+LIBS=$(LIBS1) $(LIBS1) $(LIBS1) libmachdep/libmachdep.a
 
 default: $(TARG)
 $(TARG): $(OFILES) $(LIBS)
@@ -69,3 +69,6 @@ libc/libc.a:
 
 gui-$(GUI)/libgui.a:
 	(cd gui-$(GUI); $(MAKE))
+
+libmachdep/libmachdep.a:
+	(cd libmachdep; $(MAKE))
Index: drawterm/libsec/Makefile
===================================================================
--- drawterm.orig/libsec/Makefile
+++ drawterm/libsec/Makefile
@@ -33,6 +33,7 @@ OFILES=\
 	hmac.$O\
 	md4.$O\
 	md5.$O\
+	_md5block.$O\
 	md5pickle.$O\
 	nfastrand.$O\
 	prng.$O\
@@ -45,6 +46,7 @@ OFILES=\
 	rsagen.$O\
 	rsaprivtopub.$O\
 	sha1.$O\
+	_sha1block.$O\
 	sha1pickle.$O\
 	smallprimes.$O
 
@@ -56,3 +58,23 @@ $(LIB): $(OFILES)
 %.$O: %.c
 	$(CC) $(CFLAGS) $*.c
 
+ifeq "$(ARCH)" "386"
+_sha1block.$O: sha1block.s
+	$(AS) -o $@ $<
+
+_md5block.$O: md5block.s
+	$(AS) -o $@ $<
+
+sha1block.s: ../posix-386/sha1block.spp
+	$(CC) -E - < $< > $@
+
+md5block.s: ../posix-386/md5block.spp
+	$(CC) -E - < $< > $@
+else
+_sha1block.$O: sha1block.c
+	echo -$(ARCH)-
+	$(CC) $(CFLAGS) -o $@ $<
+
+_md5block.$O: md5block.c
+	$(CC) $(CFLAGS) -o $@ $<
+endif
Index: drawterm/libmachdep/Makefile
===================================================================
--- /dev/null
+++ drawterm/libmachdep/Makefile
@@ -0,0 +1,14 @@
+ROOT=..
+include ../Make.config
+LIB=libmachdep.a
+
+OFILES=\
+	tas.$O
+
+default: $(LIB)
+$(LIB): $(OFILES)
+	$(AR) r $(LIB) $(OFILES)
+	$(RANLIB) $(LIB)
+
+%.$O: %.c
+	$(CC) $(CFLAGS) $*.c
Index: drawterm/libmachdep/tas.c
===================================================================
--- /dev/null
+++ drawterm/libmachdep/tas.c
@@ -0,0 +1,89 @@
+#include "u.h"
+#include "libc.h"
+
+#define GCC_VERSION (__GNUC__ * 10000 \
+		+ __GNUC_MINOR__ * 100 \
+		+ __GNUC_PATCHLEVEL__)
+
+long
+tas(long *x)
+{
+	long	v = 1;
+#if (! __arm__) && (! __m68k__) && ((GCC_VERSION > 40300) || \
+		(__alpha__ && GCC_VERSION > 40200) || \
+		(__sparc__ && GCC_VERSION > 40200) || \
+		(__s390__ && GCC_VERSION > 40100))
+	v = __sync_lock_test_and_set (x, 1);
+#else /* Old gcc */
+#ifdef __i386__
+	__asm__(	"xchgl  %%eax,(%%ecx)"
+			: "+a" (v)
+			: "c" (x));
+#else /* __i386__ */
+#ifdef __x86_64__
+	__asm__(	"xchgl  %%eax,(%%rcx)"
+			: "+a" (v)
+			: "c" (x));
+#else /* __x86_64__ */
+
+#ifdef __mips__
+#ifdef __linux__
+	__asm__(".set mips2\n");
+#endif
+	__asm__("loop:\n\t"
+			"li	$t1, 12345\n\t"	/* t1 = 12345 */
+			"ll	%0, (%1)\n\t"	/* v0 = *a0 */
+			"sc	$t1, (%1)\n\t"	/* *a0 = t1 if *a0 hasn't changed; t1=success */
+			"beqz	$t1, loop"	/* repeat if *a0 did change */
+			: "=r" (v)
+			: "d" (x)
+			: "t1");
+#ifdef __linux__
+	__asm__(".set mips0\n");
+#endif
+#else /* __mips__ */
+
+#ifdef __powerpc__
+	/*
+	 * this __asm__ works with gcc 2.95.2 (mac os x 10.1).
+	 * this assembly language destroys r0 (0), some other register (v),
+	 * r4 (x) and r5 (temp).
+	 */
+	__asm__("\n	sync\n"
+	"	li	r0,0\n"
+	"	mr	r4,%1		/* &l->val */\n"
+	"	lis	r5,0xdead	/* assemble constant 0xdeaddead */\n"
+	"	ori	r5,r5,0xdead	/* \" */\n"
+	"tas1:\n"
+	"	dcbf	r4,r0	/* cache flush; \"fix for 603x bug\" */\n"
+	"	lwarx	%0,r4,r0	/* v = l->val with reservation */\n"
+	"	cmp	cr0,0,%0,r0	/* v == 0 */\n"
+	"	bne	tas0\n"
+	"	stwcx.	r5,r4,r0   /* if (l->val same) l->val = 0xdeaddead */\n"
+	"	bne	tas1\n"
+	"tas0:\n"
+	"	sync\n"
+	"	isync\n"
+	: "=r" (v)
+	: "r"  (x)
+	: "cc", "memory", "r0", "r4", "r5"
+	);
+
+#else /* __powerpc__ */
+
+#ifdef __sparc__
+	__asm__(	"stbar\n\t"
+			"swap	[ %1 ], %0"
+			: "+g" (v)
+			: "g" (x));
+#else /* __sparc__ */
+#error "Arch not supported with this GCC version"
+#endif /* __sparc__ */
+#endif /* __powerpc__ */
+#endif /* __mips__ */
+#endif /* __x86_64__ */
+#endif /* __i386__ */
+#endif /* Old gcc */
+	return v != 0;
+}
+

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Drawterm problems
  2008-12-09  5:13 Drawterm problems Martín Ferrari
  2008-12-09  5:17 ` [9fans] Fwd: " Martín Ferrari
@ 2008-12-09  5:41 ` Russ Cox
  1 sibling, 0 replies; 9+ messages in thread
From: Russ Cox @ 2008-12-09  5:41 UTC (permalink / raw)
  To: Martín Ferrari

[bcc: everyone but Martín]

Thanks for your note.  Drawterm has been run successfully
on the MIPS under SGI IRIX and the Sparc under Solaris
and the 64-bit Alpha under Digital UNIX.  I'm afraid that
I have not tried Linux on those platforms, nor gcc on some,
so there will be problems.

Drawterm also predates the widespread availability of
correct pthread implementations, so it tries to do many
things itself that it might now be able to use libraries for.

I'm happy to offer help porting it to Linux/gcc on the
architectures you care about.

>  First problem: it doesn't compile on mips at all, the assembly code
>  seems invalid. In [0] you can find a proposed patch.

That seems fine.

>  Second problem: the arch handling is quite fragile, and it doesn't
>  work for sparc under linux [1] (uname -m is sparc64, not sun4u), for
>  example. But the biggest problem is that there are no provisions for
>  other architectures. I have prepared a big patch for this, see below.
>
>  Third: segfaults on amd64, possibly other arches that I couldn't test.
>  After a lot of guessing, I suspected of these constructs in lib.h:
>
>  typedef int            p9_long;
>  #define long  int
>
>  Changing them to match longs with longs made the segfault go away, as
>  amd64 uses 64bits for longs and the included libX.h was botched
>  because of the "#define long int". But then it popped many type errors
>  all around, since there are many inconsistencies (for example,
>  function prototypes that doesn't match exactly the fuction
>  definitions) and all the code assumes long==int. I'm trying to fix
>  this, but the problem is very deep: there are many places where size
>  specific types should be used instead of longs and ints.

As you say, this is a very deep problem, especially in
the graphics code.  It will take you a very long time to find
all the places that say long but mean int32; the #define
is both simpler and helps keep the drawterm sources more
similar to the Plan 9 kernel, so that changes can be incorporated.

The #define is safe provided all system headers are included
before the drawterm headers that redefine long.  If there are
files in which this is not true, those need to be changed.

>  I'm including the arch-related patch: it disables all the posix-*/
>  code (except for the x86 hashing routines, which are now conditionally
>  complied from libsec) and instead creates a libmachdep directory with
>  a tas.c file. In tas.c it tries to use the fairly new builtin atomic
>  operations, and falls back to assemby if it's available. Also, the
>  getcallerpc function is replaced with other gcc builtin, but I haven't
>  made provisions for fallback to assembly here as I think that the
>  builtin I'm using is widely available and that would have made the
>  patch very complex.

It should be just fine to return 0 for getcallerpc,
use a pthread_mutex_t instead of tas, and use the
C versions of the hash functions.  That will make the
code still more portable without introducing any
dependencies on gcc.

I'll follow up in private mail about the patch details.

Russ

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [9fans] Fwd: Drawterm problems
  2008-12-09  5:17 ` [9fans] Fwd: " Martín Ferrari
@ 2008-12-09  7:05   ` Michal Hajek
  2008-12-09  7:12     ` Russ Cox
  2008-12-09 10:54     ` Randall Bohn
  0 siblings, 2 replies; 9+ messages in thread
From: Michal Hajek @ 2008-12-09  7:05 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

Hello,
> From: Mart�n Ferrari <martin.ferrari@gmail.com>
> Subject: Drawterm problems

I am a user of debian an amd64 and also I succeeded to install plan9 on
another machine, although my skills in plan9 are less than mediocre.

However, I am ready to test drawterm and hopefuly be helpful.

Also, I have already downloaded source of drawterm and tried to compile
it (few days ago as a matter of coincidence). Unfortunately, on my
system the source did not compile.  From what has been said in the two
previous emails I understood that just downloading a source and trying
to compile "as is" was almost hopeless anyway.  But if somebody is
interested in details, I can send them.

Best regards
Michal



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [9fans] Fwd: Drawterm problems
  2008-12-09  7:05   ` Michal Hajek
@ 2008-12-09  7:12     ` Russ Cox
  2008-12-09  8:17       ` [9fans] [OT] poetry [was Re: Fwd: Drawterm problems] Skip Tavakkolian
  2008-12-10  1:45       ` [9fans] Fwd: Drawterm problems Martín Ferrari
  2008-12-09 10:54     ` Randall Bohn
  1 sibling, 2 replies; 9+ messages in thread
From: Russ Cox @ 2008-12-09  7:12 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

>  I am a user of debian an amd64 and also I succeeded to install plan9 on
>  another machine, although my skills in plan9 are less than mediocre.
>
>  However, I am ready to test drawterm and hopefuly be helpful.
>
>  Also, I have already downloaded source of drawterm and tried to compile
>  it (few days ago as a matter of coincidence). Unfortunately, on my
>  system the source did not compile.  From what has been said in the two
>  previous emails I understood that just downloading a source and trying
>  to compile "as is" was almost hopeless anyway.  But if somebody is
>  interested in details, I can send them.

If you update from the CVS repository
it should build and run just fine.
If not, please let me know.

Thanks.
Russ


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [9fans] [OT] poetry [was Re:  Fwd: Drawterm problems]
  2008-12-09  7:12     ` Russ Cox
@ 2008-12-09  8:17       ` Skip Tavakkolian
  2008-12-10  1:45       ` [9fans] Fwd: Drawterm problems Martín Ferrari
  1 sibling, 0 replies; 9+ messages in thread
From: Skip Tavakkolian @ 2008-12-09  8:17 UTC (permalink / raw)
  To: 9fans

> If you update from the CVS repository
> it should build and run just fine.
> If not, please let me know.
>
> Russ

or -- with a very slightly modification --  in verse :)

if you update from the CVS
	it should build and run just fine
if not, please let me know,
	i will check it one more time




^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [9fans] Fwd: Drawterm problems
  2008-12-09  7:05   ` Michal Hajek
  2008-12-09  7:12     ` Russ Cox
@ 2008-12-09 10:54     ` Randall Bohn
  1 sibling, 0 replies; 9+ messages in thread
From: Randall Bohn @ 2008-12-09 10:54 UTC (permalink / raw)
  To: 9fans

I've built drawterm successfully from the CVS sources on Ubuntu x86
and Gentoo x86. It also builds on Win32 if you install Mingw and MSYS
(in that order). I use devfs_win32.c from /n/sources/contrib/
cinap_lenrek.

rsbohn



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [9fans] Fwd: Drawterm problems
  2008-12-09  7:12     ` Russ Cox
  2008-12-09  8:17       ` [9fans] [OT] poetry [was Re: Fwd: Drawterm problems] Skip Tavakkolian
@ 2008-12-10  1:45       ` Martín Ferrari
  2008-12-10  2:44         ` Russ Cox
  1 sibling, 1 reply; 9+ messages in thread
From: Martín Ferrari @ 2008-12-10  1:45 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

On Tue, Dec 9, 2008 at 05:12, Russ Cox <rsc@swtch.com> wrote:

> If you update from the CVS repository
> it should build and run just fine.
> If not, please let me know.

I have just uploaded to Debian drawterm with all the fixes.

Thanks a lot for your help!

-- 
Martín Ferrari



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [9fans] Fwd: Drawterm problems
  2008-12-10  1:45       ` [9fans] Fwd: Drawterm problems Martín Ferrari
@ 2008-12-10  2:44         ` Russ Cox
  0 siblings, 0 replies; 9+ messages in thread
From: Russ Cox @ 2008-12-10  2:44 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

Thanks for packaging it.  It will be nice to
be able to apt-get install drawterm.

Russ


On 12/9/08, Martín Ferrari <martin.ferrari@gmail.com> wrote:
> On Tue, Dec 9, 2008 at 05:12, Russ Cox <rsc@swtch.com> wrote:
>
>  > If you update from the CVS repository
>  > it should build and run just fine.
>  > If not, please let me know.
>
>
> I have just uploaded to Debian drawterm with all the fixes.
>
>  Thanks a lot for your help!
>
>  --
>
> Martín Ferrari
>
>

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2008-12-10  2:44 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-12-09  5:13 Drawterm problems Martín Ferrari
2008-12-09  5:17 ` [9fans] Fwd: " Martín Ferrari
2008-12-09  7:05   ` Michal Hajek
2008-12-09  7:12     ` Russ Cox
2008-12-09  8:17       ` [9fans] [OT] poetry [was Re: Fwd: Drawterm problems] Skip Tavakkolian
2008-12-10  1:45       ` [9fans] Fwd: Drawterm problems Martín Ferrari
2008-12-10  2:44         ` Russ Cox
2008-12-09 10:54     ` Randall Bohn
2008-12-09  5:41 ` Russ Cox

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).