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; +} +