shithub: drawcpu

Download patch

ref: a93a7fbe83b91c2275b84796a7e6b1fbb4e69656
parent: f69f735ebcf41200cc3817019a862a8d7bd76961
author: halfwit <michaelmisch1985@gmail.com>
date: Mon Dec 1 19:38:27 EST 2025

Starting a refactor over more modern drawterm

--- a/Make.dragonfly
+++ b/Make.dragonfly
@@ -13,10 +13,5 @@
 LDFLAGS=$(PTHREAD)
 TARG=drawcpu
 AUDIO=none
-ARCH=$(shell uname -m|sed 's/i.86/386/;s/Power Macintosh/power/; s/x86_64/amd64/')
 
 all: default
-
-libmachdep.a:
-	arch=`uname -m|sed 's/i.86/386/;s/Power Macintosh/power/; s/x86_64/amd64/'`; \
-	(cd posix-$$arch &&  make)
--- a/Make.fbdev
+++ b/Make.fbdev
@@ -14,10 +14,5 @@
 TARG=drawcpu
 # AUDIO=none
 AUDIO=alsa
-ARCH=$(shell uname -m|sed 's/i.86/386/;s/Power Macintosh/power/; s/x86_64/amd64/; s/armv[567].*/arm/; s/aarch64/arm64/')
 
 all: default
-
-libmachdep.a:
-	arch=`uname -m|sed 's/i.86/386/;s/Power Macintosh/power/; s/x86_64/amd64/; s/armv[567].*/arm/; s/aarch64/arm64/'`; \
-	(cd posix-$$arch &&  make)
--- a/Make.freebsd
+++ b/Make.freebsd
@@ -13,10 +13,5 @@
 LDFLAGS=$(PTHREAD)
 TARG=drawcpu
 AUDIO=unix
-ARCH=$(shell uname -m|sed 's/i.86/386/;s/Power Macintosh/power/; s/x86_64/amd64/')
 
 all: default
-
-libmachdep.a:
-	arch=`uname -m|sed 's/i.86/386/;s/Power Macintosh/power/; s/x86_64/amd64/'`; \
-	(cd posix-$$arch &&  make)
--- /dev/null
+++ b/Make.haiku
@@ -1,0 +1,16 @@
+# Haiku
+AR=ar
+AS=as
+RANLIB=ranlib
+CC=gcc
+CXX=g++
+CFLAGS=-Wall -Wno-missing-braces -Wno-parentheses -ggdb -I$(ROOT) -I$(ROOT)/include -I$(ROOT)/kern -c -D_THREAD_SAFE -D_POSIX_C_SOURCE -O2
+O=o
+OS=posix
+GUI=haiku
+AUDIO=haiku
+LDADD=-ggdb -lbe -lnetwork -lmedia -lstdc++
+LDFLAGS=
+TARG=drawcpu
+
+all: default
--- a/Make.irix
+++ b/Make.irix
@@ -17,9 +17,5 @@
 LDFLAGS=$(PTHREAD)
 TARG=drawcpu
 MAKE=gmake
-ARCH=mips
 
 all: default
-
-libmachdep.a:
-	(cd posix-mips && $(MAKE))
--- a/Make.linux
+++ b/Make.linux
@@ -13,10 +13,5 @@
 TARG=drawcpu
 # AUDIO=none
 AUDIO=pipewire
-ARCH=$(shell uname -m|sed 's/i.86/386/;s/Power Macintosh/power/; s/x86_64/amd64/; s/armv[567].*/arm/; s/aarch64/arm64/')
 
 all: default
-
-libmachdep.a:
-	arch=`uname -m|sed 's/i.86/386/;s/Power Macintosh/power/; s/x86_64/amd64/; s/armv[567].*/arm/; s/aarch64/arm64/'`; \
-	(cd posix-$$arch &&  make)
--- a/Make.linux386
+++ b/Make.linux386
@@ -14,10 +14,5 @@
 TARG=drawcpu
 # AUDIO=none
 AUDIO=unix
-ARCH=386
 
 all: default
-
-libmachdep.a:
-	arch=386; \
-	(cd posix-$$arch &&  make)
--- a/Make.netbsd
+++ b/Make.netbsd
@@ -13,11 +13,6 @@
 LDFLAGS=$(PTHREAD)
 TARG=drawcpu
 AUDIO=unix
-ARCH=$(shell uname -m|sed 's/i.86/386/;s/Power Macintosh/power/; s/x86_64/amd64/')
 
 all: default
-
-libmachdep.a:
-	arch=`uname -m|sed 's/i.86/386/;s/Power Macintosh/power/; s/x86_64/amd64/'`; \
-	(cd posix-$$arch &&  make)
 
--- a/Make.openbsd
+++ b/Make.openbsd
@@ -12,10 +12,5 @@
 LDFLAGS=$(PTHREAD)
 TARG=drawcpu
 AUDIO=sndio
-ARCH=$(shell uname -m|sed 's/i.86/386/; s/macppc/power/; s/socppc/power/; s/x86_64/amd64/; s/sparc64/sun4u/')
 
 all: default
-
-libmachdep.a:
-	arch=`uname -m|sed 's/i.86/386/; s/macppc/power/; s/socppc/power/; s/x86_64/amd64/; s/sparc64/sun4u/'`; \
-	(cd posix-$$arch &&  make)
--- a/Make.osx-cocoa
+++ b/Make.osx-cocoa
@@ -12,10 +12,5 @@
 LDFLAGS=$(PTHREAD)
 TARG=drawcpu
 AUDIO=none
-ARCH=$(shell uname -m|sed 's/i.86/386/;s/x86_64/amd64/')
 
 all: default
-
-libmachdep.a:
-	arch=`uname -m|sed 's/i.86/386/;s/x86_64/amd64/'`; \
-	(cd posix-$$arch &&  make)
--- a/Make.pthread
+++ b/Make.pthread
@@ -15,10 +15,5 @@
 TARG=drawcpu
 # AUDIO=none
 AUDIO=unix
-ARCH=$(shell uname -m|sed 's/i.86/386/;s/Power Macintosh/power/; s/x86_64/amd64/; s/armv[567].*/arm/; s/aarch64/arm64/')
 
 all: default
-
-libmachdep.a:
-	arch=`uname -m|sed 's/i.86/386/;s/Power Macintosh/power/; s/x86_64/amd64/; s/armv[567].*/arm/; s/aarch64/arm64/'`; \
-	(cd posix-$$arch &&  make)
--- /dev/null
+++ b/Make.sun
@@ -1,0 +1,17 @@
+# Sun-specific
+PTHREAD=
+AR=ar
+AS=as
+RANLIB=ranlib
+X11=/usr/X11R6
+CC=cc
+CFLAGS=-xCC -I$(ROOT) -I$(ROOT)/include -I$(ROOT)/kern -c -g -D_THREAD_SAFE
+O=o
+OS=posix
+GUI=x11
+LDADD=-L$(X11)/lib -lX11 -lrt -lpthread -lsocket -lnsl
+LDFLAGS=
+TARG=drawcpu
+AUDIO=none
+
+all: default
--- a/Make.unix
+++ b/Make.unix
@@ -15,10 +15,5 @@
 TARG=drawcpu
 # AUDIO=none
 AUDIO=unix
-ARCH=$(shell uname -m|sed 's/i.86/386/;s/Power Macintosh/power/; s/x86_64/amd64/; s/armv[567].*/arm/; s/aarch64/arm64/')
 
 all: default
-
-libmachdep.a:
-	arch=`uname -m|sed 's/i.86/386/;s/Power Macintosh/power/; s/x86_64/amd64/; s/armv[567].*/arm/; s/aarch64/arm64/'`; \
-	(cd posix-$$arch &&  make)
--- a/Make.win32
+++ b/Make.win32
@@ -30,13 +30,8 @@
 #IP=win32
 #OS=win32
 #GUI=win32
-ARCH=386
 
 all: default
-
-# for root
-libmachdep.a:
-	(cd win32-386; make)
 
 glenda-t.$O: glenda-t.rc glenda-t.ico
 	$(WINDRES) -i glenda-t.rc -o glenda-t.o
--- a/Make.win64
+++ b/Make.win64
@@ -20,14 +20,8 @@
 LDADD=-lgdi32 -lws2_32 -lwinmm -mwindows
 TARG=drawcpu.exe
 XOFILES=glenda-t.$O
-ARCH=386
 
 all: default
 
-# for root
-libmachdep.a:
-	(cd posix-amd64; make)
-
 glenda-t.$O: glenda-t.rc glenda-t.ico
 	$(WINDRES) -i glenda-t.rc -o glenda-t.o
-
--- a/Makefile
+++ b/Makefile
@@ -7,6 +7,9 @@
 	aan.$O\
 	latin1.$O\
 	getuser.$O\
+	getcallerpc.$O\
+	tas.$O\
+	cas.$O\
 	$(XOFILES)\
 
 LIBS1=\
@@ -23,7 +26,7 @@
 	libc/libc.a\
 
 # stupid gcc
-LIBS=$(LIBS1) libmachdep.a
+LIBS=$(LIBS1)
 
 default: $(TARG)
 $(TARG): $(OFILES) $(LIBS)
--- a/arg.h
+++ /dev/null
@@ -1,20 +1,0 @@
-/* SPDX-License-Identifier: Unlicense */
-#define ARGBEGIN \
-	for (;;) { \
-		if (argc > 0) \
-			++argv, --argc; \
-		if (argc == 0 || (*argv)[0] != '-') \
-			break; \
-		if ((*argv)[1] == '-' && !(*argv)[2]) { \
-			++argv, --argc; \
-			break; \
-		} \
-		for (char *opt_ = &(*argv)[1], done_ = 0; !done_ && *opt_; ++opt_) { \
-			switch (*opt_)
-
-#define ARGEND \
-		} \
-	}
-
-#define EARGF(x) \
-	(done_ = 1, opt_[1] ? ++opt_ : argv[1] ? --argc, *++argv : ((x), abort(), (char *)0))
\ No newline at end of file
--- /dev/null
+++ b/cas.c
@@ -1,0 +1,8 @@
+#include "u.h"
+#include "libc.h"
+
+int
+cas(int *x, int old, int new)
+{
+	return __atomic_compare_exchange_n(x, &old, new, 0, __ATOMIC_ACQ_REL, __ATOMIC_ACQUIRE);
+}
\ No newline at end of file
--- /dev/null
+++ b/getcallerpc.c
@@ -1,0 +1,9 @@
+#include "u.h"
+#include "libc.h"
+
+uintptr
+getcallerpc(void *a)
+{
+	USED(a);
+	return (uintptr)__builtin_extract_return_addr(__builtin_return_address(0));
+}
--- a/include/u.h
+++ b/include/u.h
@@ -28,4 +28,3 @@
 #undef pipe
 #undef iounit
 extern int debug;
-extern char *ninepath;
\ No newline at end of file
--- a/kern/allocb.c
+++ b/kern/allocb.c
@@ -3,7 +3,6 @@
 #include	"dat.h"
 #include	"fns.h"
 #include	"error.h"
-#include	"mem.h"
 
 enum
 {
--- a/kern/arm.c
+++ b/kern/arm.c
@@ -18,6 +18,18 @@
 	fH = 1<<5,
 };
 
+
+void
+dump(void)
+{
+	print("R00 %.8ux\tR01 %.8ux\tR02 %.8ux\tR03 %.8ux\tpid: %d\nR04 %.8ux\tR05 %.8ux\tR06 %.8ux\tR07 %.8ux\nR08 %.8ux\tR09 %.8ux\tR10 %.8ux\tR11 %.8ux\nR12 %.8ux\tR13 %.8ux\tR14 %.8ux\tR15 %.8ux\n", 
+		up->R[0], up->R[1], up->R[2], up->R[3], up->pid,
+		up->R[4], up->R[5], up->R[6], up->R[7], 
+		up->R[8], up->R[9], up->R[10], up->R[11], 
+		up->R[12], up->R[13], up->R[14], up->R[15]
+	);
+}
+
 void
 invalid(u32int instr)
 {
--- a/kern/dat.h
+++ b/kern/dat.h
@@ -415,6 +415,7 @@
 enum
 {
 	Dead = 0,
+	New,
 	Moribund,
 	Ready,
 	Running,
--- a/kern/data.c
+++ b/kern/data.c
@@ -14,4 +14,4 @@
 char *eve = "eve";
 ulong kerndate;
 int cpuserver;
-char hostdomain[] = "drawcpu.net";
+char hostdomain[] = "9front";
--- a/kern/devcap.c
+++ b/kern/devcap.c
@@ -1,6 +1,5 @@
 #include	"u.h"
 #include	"lib.h"
-#include	"mem.h"
 #include	"dat.h"
 #include	"fns.h"
 #include	"error.h"
--- a/kern/devfs-win32.c
+++ b/kern/devfs-win32.c
@@ -9,8 +9,7 @@
 #include	"fns.h"
 #include	"error.h"
 
-// TODO: get sha1 without pulling in libsec
-//#include	<libsec.h>	/* for sha1 in pathhash() */
+#include	<libsec.h>	/* for sha1 in pathhash() */
 
 typedef struct DIR	DIR;
 typedef	struct Ufsinfo	Ufsinfo;
--- a/kern/devproc.c
+++ b/kern/devproc.c
@@ -55,7 +55,6 @@
 };
 
 #define	STATSIZE	(2*28+12+9*12)
-#define REGSIZE     (15*16) /* TODO */ 
 
 #define QSHIFT 	5
 #define	QID(q)		((((ulong)(q).path)&0x0000001F)>>0)
--- a/kern/fns.h
+++ b/kern/fns.h
@@ -1,4 +1,4 @@
-//#define	ROUND(s, sz)	(((s)+((sz)-1))&~((sz)-1))
+#define	ROUND(s, sz)	(((s)+(sz-1))&~(sz-1))
 
 void        addnote(char*);
 Block*		adjustblock(Block*, int);
--- a/kern/posix.c
+++ b/kern/posix.c
@@ -34,7 +34,6 @@
 #include "lib.h"
 #include "dat.h"
 #include "fns.h"
-#include "mem.h"
 #include <a.out.h>
 
 pthread_t thids[64];
--- a/kern/procinit.c
+++ b/kern/procinit.c
@@ -3,7 +3,6 @@
 #include "dat.h"
 #include "fns.h"
 #include "error.h"
-#include "mem.h"
 
 void
 procinit0(void)
--- a/kern/stub.c
+++ b/kern/stub.c
@@ -31,14 +31,15 @@
 long
 hostdomainwrite(char *a, int n)
 {
-
-	return (long)setdomainname(a, n);
+	strncpy(hostdomain, a, n);
+	return n;
 }
 
 long
 hostownerwrite(char *a, int n)
 {
-	return (long)sethostname(a, n);
+	strncpy(eve, a, n);
+	return n;
 }
 
 void
--- a/kern/sysproc.c
+++ b/kern/sysproc.c
@@ -5,7 +5,6 @@
 #include "error.h"
 #include "proc.h"
 #include "user.h"
-#include "mem.h"
 #include "sys.h"
 #include <a.out.h>
 #include <signal.h>
@@ -190,27 +189,26 @@
 }
 
 void*
-vmemchr(void *s, int c, ulong n)
+vmemchr(void *vs, int c, ulong n)
 {
-    uintptr a;
-    ulong m, i;
-    void *t;
+    jmp_buf env;
+    volatile int ok;
 
-    i = n;
-    a = (uintptr)s;
-    for(;;){
-        m = BY2PG - (a & (BY2PG-1));
-        if(i <= m)
-            break;
-        t = memchr((void*)a, c, m);
-        if(t != nil)
-            return t;
-        a += m;
-        i -= m;
-        if(a < KZERO)
-            validaddr(a, 1, 0);
+    if (vs == NULL)
+        return NULL;
+    ok = setjmp(env);
+    if (ok == 0) {
+        const unsigned char *s = vs;
+        const unsigned char *end = s + n;
+
+        while (s < end) {
+            if (*s == (unsigned char)c)
+                return (void *)(uintptr_t)s;
+            s++;
+        }
     }
-    return memchr((void*)a, c, i);
+    /* fault → ok != 0 */
+    return NULL;
 }
 
 void
--- a/main.c
+++ b/main.c
@@ -4,7 +4,7 @@
 #include "kern/fns.h"
 #include "user.h"
 #include "drawcpu.h"
-#include "arg.h"
+#include "args.h"
 #include "proc.h"
 
 char *argv0;
@@ -97,17 +97,6 @@
 		panic("open env/cputype: %r");
 	fprint(fd, "arm");
 	close(fd);
-}
-
-void
-dump(void)
-{
-	print("R00 %.8ux\tR01 %.8ux\tR02 %.8ux\tR03 %.8ux\tpid: %d\nR04 %.8ux\tR05 %.8ux\tR06 %.8ux\tR07 %.8ux\nR08 %.8ux\tR09 %.8ux\tR10 %.8ux\tR11 %.8ux\nR12 %.8ux\tR13 %.8ux\tR14 %.8ux\tR15 %.8ux\n", 
-		up->R[0], up->R[1], up->R[2], up->R[3], up->pid,
-		up->R[4], up->R[5], up->R[6], up->R[7], 
-		up->R[8], up->R[9], up->R[10], up->R[11], 
-		up->R[12], up->R[13], up->R[14], up->R[15]
-	);
 }
 
 int
--- a/posix-386/Makefile
+++ /dev/null
@@ -1,21 +1,0 @@
-ROOT=..
-include ../Make.config
-LIB=../libmachdep.a
-CFLAGS+=-fpie
-LDFLAGS+=-fpie
-
-OFILES=\
-	getcallerpc.$O\
-	tas.$O\
-	cas.$O\
-
-default: $(LIB)
-$(LIB): $(OFILES)
-	$(AR) r $(LIB) $(OFILES)
-	$(RANLIB) $(LIB)
-
-%.$O: %.c
-	$(CC) $(CFLAGS) $*.c
-
-%.$O: %.s
-	$(AS) -o $*.$O $*.s
--- a/posix-386/cas.c
+++ /dev/null
@@ -1,23 +1,0 @@
-#include "u.h"
-#include "libc.h"
-
-#ifndef __has_builtin
-#define __has_builtin(x) 0
-#endif
-
-int
-cas(int *x, int old, int new)
-{
-#if __has_builtin(__atomic_compare_exchange_n)
-    return __atomic_compare_exchange_n(x, &old, new, 0, __ATOMIC_ACQ_REL, __ATOMIC_ACQUIRE);
-#else
-    int result;
-    __asm__ __volatile__(
-        "lock cmpxchg %2, %1\n\t"
-        "sete %0"
-        : "=r" (result), "+m" (*x), "+r" (new)
-        : "a" (old)
-        : "cc");
-    return result;
-#endif
-}
\ No newline at end of file
--- a/posix-386/getcallerpc.c
+++ /dev/null
@@ -1,8 +1,0 @@
-#include "u.h"
-#include "libc.h"
-
-uintptr
-getcallerpc(void *a)
-{
-	return ((uintptr*)a)[-1];
-}
--- a/posix-386/mem.h
+++ /dev/null
@@ -1,167 +1,0 @@
-/*
- * Memory and machine-specific definitions.  Used in C and assembler.
- */
-
-#define MIN(a, b)	((a) < (b)? (a): (b))
-#define MAX(a, b)	((a) > (b)? (a): (b))
-
-/*
- * Sizes
- */
-#define	BI2BY		8			/* bits per byte */
-#define	BI2WD		32			/* bits per word */
-#define	BY2WD		4			/* bytes per word */
-#define	BY2V		8			/* bytes per double word */
-#define	BY2PG		4096			/* bytes per page */
-#define	WD2PG		(BY2PG/BY2WD)		/* words per page */
-#define	BY2XPG		(4096*1024)		/* bytes per big page */
-#define	PGSHIFT		12			/* log(BY2PG) */
-#define	ROUND(s, sz)	(((s)+((sz)-1))&~((sz)-1))
-#define	PGROUND(s)	ROUND(s, BY2PG)
-#define	FPalign		16
-
-#define	MAXMACH		32			/* max # cpus system can run */
-#define	KSTACK		4096			/* Size of kernel stack */
-
-/*
- * Time
- */
-#define	HZ		(100)			/* clock frequency */
-#define	MS2HZ		(1000/HZ)		/* millisec per clock tick */
-#define	TK2SEC(t)	((t)/HZ)		/* ticks to seconds */
-
-/*
- *  Address spaces
- */
-#define	KZERO		0xF0000000		/* base of kernel address space */
-#define	KTZERO		(KZERO+0x100000)	/* first address in kernel text - 9load sits below */
-#define	VPT		(KZERO-VPTSIZE)
-#define	VPTSIZE		BY2XPG
-#define	NVPT		(VPTSIZE/BY2WD)
-#define	KMAP		(VPT-KMAPSIZE)
-#define	KMAPSIZE	BY2XPG
-#define	VMAP		(KMAP-VMAPSIZE)
-#define	VMAPSIZE	(0x10000000-VPTSIZE-KMAPSIZE)
-
-/*
- * Fundamental addresses
- */
-#define	CONFADDR	(KZERO+0x1200)		/* info passed from boot loader */
-#define	APBOOTSTRAP	(KZERO+0x7000)		/* AP bootstrap code (overlaps CONFADDR) */
-#define	TMPADDR		(KZERO+0x8000)		/* used for temporary mappings */
-#define	IDTADDR		(KZERO+0x10800)		/* idt */
-#define	REBOOTADDR	(0x11000)		/* reboot code - physical address */
-#define	CPU0PDB		(KZERO+0x12000)		/* bootstrap processor PDB */
-#define	CPU0PTE		(KZERO+0x13000)		/* bootstrap processor PTE's for 0-4MB */
-#define	CPU0PTE1	(KZERO+0x14000)		/* bootstrap processor PTE's for 4-8MB */
-#define	CPU0PTE2	(KZERO+0x15000)		/* bootstrap processor PTE's for 8-12MB */
-#define	CPU0PTE3	(KZERO+0x16000)		/* bootstrap processor PTE's for 12-16MB */
-#define	CPU0GDT		(KZERO+0x17000)		/* bootstrap processor GDT */
-#define	MACHADDR	(KZERO+0x18000)		/* as seen by current processor */
-#define	CPU0MACH	(KZERO+0x19000)		/* Mach for bootstrap processor */
-#define	MACHSIZE	BY2PG
-#define	CPU0END		(CPU0MACH+BY2PG)
-/*
- * N.B.  ramscan knows that CPU0END is the end of reserved data
- * N.B.  _startPADDR knows that CPU0PDB is the first reserved page
- * and that there are 6 of them.
- */
-
-/*
- * Where configuration info is left for the loaded programme.
- * There are 24064 bytes available at CONFADDR.
- */
-#define BOOTLINE	((char*)CONFADDR)
-#define BOOTLINELEN	64
-#define BOOTARGS	((char*)(CONFADDR+BOOTLINELEN))
-#define BOOTARGSLEN	(0x6000-0x200-BOOTLINELEN)
-
-/*
- *  known x86 segments (in GDT) and their selectors
- */
-#define	NULLSEG	0	/* null segment */
-#define	KDSEG	1	/* kernel data/stack */
-#define	KESEG	2	/* kernel executable */	
-#define	UDSEG	3	/* user data/stack */
-#define	UESEG	4	/* user executable */
-#define	TSSSEG	5	/* task segment */
-#define	APMCSEG		6	/* APM code segment */
-#define	APMCSEG16	7	/* APM 16-bit code segment */
-#define	APMDSEG		8	/* APM data segment */
-#define	KESEG16		9	/* kernel executable 16-bit */
-#define	LDTSEG		10	/* local descriptor table */
-#define	PROCSEG0	11	/* per process descriptor0 */
-#define	NPROCSEG	3	/* number of per process descriptors */
-#define	NGDT		14	/* number of GDT entries required */
-
-#define	SELGDT	(0<<2)	/* selector is in gdt */
-#define	SELLDT	(1<<2)	/* selector is in ldt */
-
-#define	SELECTOR(i, t, p)	(((i)<<3) | (t) | (p))
-
-#define	NULLSEL	SELECTOR(NULLSEG, SELGDT, 0)
-#define	KDSEL	SELECTOR(KDSEG, SELGDT, 0)
-#define	KESEL	SELECTOR(KESEG, SELGDT, 0)
-#define	UESEL	SELECTOR(UESEG, SELGDT, 3)
-#define	UDSEL	SELECTOR(UDSEG, SELGDT, 3)
-#define	TSSSEL	SELECTOR(TSSSEG, SELGDT, 0)
-#define	APMCSEL 	SELECTOR(APMCSEG, SELGDT, 0)
-#define	APMCSEL16	SELECTOR(APMCSEG16, SELGDT, 0)
-#define	APMDSEL		SELECTOR(APMDSEG, SELGDT, 0)
-#define	LDTSEL	SELECTOR(LDTSEG, SELGDT, 0)
-
-/*
- *  fields in segment descriptors
- */
-#define	SEGDATA	(0x10<<8)	/* data/stack segment */
-#define	SEGEXEC	(0x18<<8)	/* executable segment */
-#define	SEGTSS	(0x9<<8)	/* TSS segment */
-#define	SEGCG	(0x0C<<8)	/* call gate */
-#define	SEGIG	(0x0E<<8)	/* interrupt gate */
-#define	SEGTG	(0x0F<<8)	/* trap gate */
-#define	SEGLDT	(0x02<<8)	/* local descriptor table */
-#define	SEGTYPE	(0x1F<<8)
-
-#define	SEGP	(1<<15)		/* segment present */
-#define	SEGPL(x) ((x)<<13)	/* priority level */
-#define	SEGB	(1<<22)		/* granularity 1==4k (for expand-down) */
-#define	SEGG	(1<<23)		/* granularity 1==4k (for other) */
-#define	SEGE	(1<<10)		/* expand down */
-#define	SEGW	(1<<9)		/* writable (for data/stack) */
-#define	SEGR	(1<<9)		/* readable (for code) */
-#define	SEGD	(1<<22)		/* default 1==32bit (for code) */
-
-/*
- *  virtual MMU
- */
-#define	PTEMAPMEM	(1024*1024)	
-#define	PTEPERTAB	(PTEMAPMEM/BY2PG)
-#define	SEGMAPSIZE	1984
-#define	SSEGMAPSIZE	16
-#define	PPN(x)		((x)&~(BY2PG-1))
-
-/*
- *  physical MMU
- */
-#define	PTEVALID	(1<<0)
-#define	PTEWT		(1<<3)
-#define	PTEUNCACHED	(1<<4)
-#define	PTECACHED	(0<<4)
-#define	PTEWRITE	(1<<1)
-#define	PTERONLY	(0<<1)
-#define	PTEKERNEL	(0<<2)
-#define	PTEUSER		(1<<2)
-#define	PTESIZE		(1<<7)
-#define	PTEGLOBAL	(1<<8)
-
-/*
- * Macros for calculating offsets within the page directory base
- * and page tables. 
- */
-#define	PDX(va)		((((ulong)(va))>>22) & 0x03FF)
-#define	PTX(va)		((((ulong)(va))>>12) & 0x03FF)
-
-#define	getpgcolor(a)	0
-
-/* PAT entry used for write combining */
-#define PATWC	7
\ No newline at end of file
--- a/posix-386/tas.c
+++ /dev/null
@@ -1,23 +1,0 @@
-#include "u.h"
-#include "libc.h"
-
-int
-tas(int *x)
-{
-	int     v;
-
-	__asm__(	"movl   $1, %%eax\n\t"
-			"xchgl  %%eax,(%%ecx)"
-			: "=a" (v)
-			: "c" (x)
-	);
-	switch(v) {
-	case 0:
-	case 1:
-		return v;
-	default:
-		print("canlock: corrupted 0x%lux\n", v);
-		return 1;
-	}
-}
-
--- a/posix-amd64/Makefile
+++ /dev/null
@@ -1,18 +1,0 @@
-ROOT=..
-include ../Make.config
-LIB=../libmachdep.a
-CFLAGS+=-fpie
-LDFLAGS+=-fpie
-
-OFILES=\
-	getcallerpc.$O\
-	tas.$O\
-	cas.$O\
-
-default: $(LIB)
-$(LIB): $(OFILES)
-	$(AR) r $(LIB) $(OFILES)
-	$(RANLIB) $(LIB)
-
-%.$O: %.c
-	$(CC) $(CFLAGS) $*.c
--- a/posix-amd64/cas.c
+++ /dev/null
@@ -1,23 +1,0 @@
-#include "u.h"
-#include "libc.h"
-
-#ifndef __has_builtin
-#define __has_builtin(x) 0
-#endif
-
-int
-cas(int *x, int old, int new)
-{
-#if __has_builtin(__atomic_compare_exchange_n)
-    return __atomic_compare_exchange_n(x, &old, new, 0, __ATOMIC_ACQ_REL, __ATOMIC_ACQUIRE);
-#else
-    int result;
-    __asm__ __volatile__(
-        "lock cmpxchg %2, %1\n\t"
-        "sete %0"
-        : "=r" (result), "+m" (*x), "+r" (new)
-        : "a" (old)
-        : "cc");
-    return result;
-#endif
-}
\ No newline at end of file
--- a/posix-amd64/getcallerpc.c
+++ /dev/null
@@ -1,8 +1,0 @@
-#include "u.h"
-#include "libc.h"
-
-uintptr
-getcallerpc(void *a)
-{
-	return ((uintptr*)a)[-1];
-}
--- a/posix-amd64/mem.h
+++ /dev/null
@@ -1,181 +1,0 @@
-/*
- * Memory and machine-specific definitions.  Used in C and assembler.
- */
-#define KiB		1024u			/* Kibi 0x0000000000000400 */
-#define MiB		1048576u		/* Mebi 0x0000000000100000 */
-#define GiB		1073741824u		/* Gibi 000000000040000000 */
-#define TiB		1099511627776ull	/* Tebi 0x0000010000000000 */
-#define PiB		1125899906842624ull	/* Pebi 0x0004000000000000 */
-#define EiB		1152921504606846976ull	/* Exbi 0x1000000000000000 */
-
-#define MIN(a, b)	((a) < (b)? (a): (b))
-#define MAX(a, b)	((a) > (b)? (a): (b))
-
-#define ALIGNED(p, a)	(!(((uintptr)(p)) & ((a)-1)))
-
-/*
- * Sizes
- */
-#define	BI2BY		8			/* bits per byte */
-#define	BI2WD		32			/* bits per word */
-#define	BY2WD		8			/* bytes per word */
-#define	BY2V		8			/* bytes per double word */
-#define	BY2PG		(0x1000ull)		/* bytes per page */
-#define	WD2PG		(BY2PG/BY2WD)		/* words per page */
-#define	PGSHIFT		12			/* log(BY2PG) */
-#define	ROUND(s, sz)	(((s)+((sz)-1))&~((sz)-1))
-#define	PGROUND(s)	ROUND(s, BY2PG)
-#define	FPalign		64
-
-#define	MAXMACH		128			/* max # cpus system can run */
-
-#define KSTACK		(8*KiB)			/* Size of Proc kernel stack */
-
-/*
- * Time
- */
-#define HZ		(100)			/* clock frequency */
-#define MS2HZ		(1000/HZ)		/* millisec per clock tick */
-#define TK2SEC(t)	((t)/HZ)		/* ticks to seconds */
-
-/*
- *  Address spaces. User:
- */
-#define UADDRMASK	(0x00007fffffffffffull)		/* canonical address mask */
-
-/*
- *  Address spaces. Kernel, sorted by address.
- */
-#define KZERO		(0xffffffff80000000ull)
-#define KTZERO		(KZERO+1*MiB+64*KiB)
-
-#define VMAP		(0xfffffe8000000000ull)
-#define VMAPSIZE	(1024ull*GiB)
-
-#define	KMAP		(0xfffffe0000000000ull)
-#define KMAPSIZE	(2*MiB)
-
-/*
- * Fundamental addresses
- */
-#define	CONFADDR	(KZERO+0x1200ull)		/* info passed from boot loader */
-#define	APBOOTSTRAP	(KZERO+0x7000ull)		/* AP bootstrap code */
-#define	IDTADDR		(KZERO+0x10000ull)		/* idt */
-#define	REBOOTADDR	(0x11000)			/* reboot code - physical address */
-
-#define CPU0PML4	(KZERO+0x13000ull)
-#define CPU0PDP		(KZERO+0x14000ull)
-#define CPU0PD0		(KZERO+0x15000ull)		/* KZERO */
-#define CPU0PD1		(KZERO+0x16000ull)		/* KZERO+1GB */
-
-#define	CPU0GDT		(KZERO+0x17000ull)		/* bootstrap processor GDT */
-
-#define	CPU0MACH	(KZERO+0x18000ull)		/* Mach for bootstrap processor */
-#define CPU0END		(CPU0MACH+MACHSIZE)
-
-#define	MACHSIZE	(2*KSTACK)
-
-/*
- * Where configuration info is left for the loaded programme.
- * There are 24064 bytes available at CONFADDR.
- */
-#define BOOTLINE	((char*)CONFADDR)
-#define BOOTLINELEN	64
-#define BOOTARGS	((char*)(CONFADDR+BOOTLINELEN))
-#define BOOTARGSLEN	(0x6000-0x200-BOOTLINELEN)
-
-/*
- *  known x86 segments (in GDT) and their selectors
- */
-#define	NULLSEG	0	/* null segment */
-#define	KESEG	1	/* kernel executable */
-#define KDSEG	2	/* kernel data */
-#define UE32SEG	3	/* user executable 32bit */
-#define	UDSEG	4	/* user data/stack */
-#define	UESEG	5	/* user executable 64bit */
-#define	TSSSEG	8	/* task segment (two descriptors) */
-
-#define	NGDT	10	/* number of GDT entries required */
-
-#define	SELGDT	(0<<2)	/* selector is in gdt */
-#define	SELLDT	(1<<2)	/* selector is in ldt */
-
-#define	SELECTOR(i, t, p)	(((i)<<3) | (t) | (p))
-
-#define	NULLSEL	SELECTOR(NULLSEG, SELGDT, 0)
-#define KDSEL	NULLSEL
-#define	KESEL	SELECTOR(KESEG, SELGDT, 0)
-#define	UE32SEL	SELECTOR(UE32SEG, SELGDT, 3)
-#define	UDSEL	SELECTOR(UDSEG, SELGDT, 3)
-#define	UESEL	SELECTOR(UESEG, SELGDT, 3)
-#define	TSSSEL	SELECTOR(TSSSEG, SELGDT, 0)
-
-/*
- *  fields in segment descriptors
- */
-#define	SEGDATA	(0x10<<8)	/* data/stack segment */
-#define	SEGEXEC	(0x18<<8)	/* executable segment */
-#define	SEGTSS	(0x9<<8)	/* TSS segment */
-#define	SEGCG	(0x0C<<8)	/* call gate */
-#define	SEGIG	(0x0E<<8)	/* interrupt gate */
-#define	SEGTG	(0x0F<<8)	/* trap gate */
-#define	SEGLDT	(0x02<<8)	/* local descriptor table */
-#define	SEGTYPE	(0x1F<<8)
-
-#define	SEGP	(1<<15)		/* segment present */
-#define	SEGPL(x) ((x)<<13)	/* priority level */
-#define	SEGB	(1<<22)		/* granularity 1==4k (for expand-down) */
-#define	SEGD	(1<<22)		/* default 1==32bit (for code) */
-#define	SEGE	(1<<10)		/* expand down */
-#define	SEGW	(1<<9)		/* writable (for data/stack) */
-#define	SEGR	(1<<9)		/* readable (for code) */
-#define SEGL	(1<<21)		/* 64 bit */
-#define	SEGG	(1<<23)		/* granularity 1==4k (for other) */
-
-/*
- *  virtual MMU
- */
-#define	PTEMAPMEM	(1ull*MiB)	
-#define	PTEPERTAB	(PTEMAPMEM/BY2PG)
-#define	SEGMAPSIZE	65536
-#define	SSEGMAPSIZE	16
-#define	PPN(x)		((x)&~(1ull<<63 | BY2PG-1))
-
-/*
- *  physical MMU
- */
-#define	PTEVALID	(1ull<<0)
-#define	PTEWT		(1ull<<3)
-#define	PTEUNCACHED	(1ull<<4)
-#define	PTECACHED	(0ull<<4)
-#define	PTEWRITE	(1ull<<1)
-#define	PTERONLY	(0ull<<1)
-#define	PTEKERNEL	(0ull<<2)
-#define	PTEUSER		(1ull<<2)
-#define	PTEACCESSED	(1ull<<5)
-#define	PTEDIRTY	(1ull<<6)
-#define	PTESIZE		(1ull<<7)
-#define	PTEGLOBAL	(1ull<<8)
-#define	PTENOEXEC	((uvlong)m->havenx<<63)
-
-/*
- * Hierarchical Page Tables.
- * For example, traditional IA-32 paging structures have 2 levels,
- * level 1 is the PD, and level 0 the PT pages; with IA-32e paging,
- * level 3 is the PML4(!), level 2 the PDP, level 1 the PD,
- * and level 0 the PT pages. The PTLX macro gives an index into the
- * page-table page at level 'l' for the virtual address 'v'.
- */
-#define PTSZ		(4*KiB)			/* page table page size */
-#define PTSHIFT		9			/*  */
-
-#define PTLX(v, l)	(((v)>>(((l)*PTSHIFT)+PGSHIFT)) & ((1<<PTSHIFT)-1))
-#define PGLSZ(l)	(1ull<<(((l)*PTSHIFT)+PGSHIFT))
-
-#define	getpgcolor(a)	0
-
-/* PAT entry used for write combining */
-#define PATWC	7
-
-#define RMACH		R15			/* m-> */
-#define RUSER		R14			/* up-> */
\ No newline at end of file
--- a/posix-amd64/tas.c
+++ /dev/null
@@ -1,23 +1,0 @@
-#include "u.h"
-#include "libc.h"
-
-int
-tas(int *x)
-{
-	int     v;
-
-	__asm__(	"movl   $1, %%eax\n\t"
-				"xchgl  %%eax,(%%rcx)"
-				: "=a" (v)
-				: "c" (x)
-	);
-	switch(v) {
-	case 0:
-	case 1:
-		return v;
-	default:
-		print("canlock: corrupted 0x%lux\n", v);
-		return 1;
-	}
-}
-
--- a/posix-arm/Makefile
+++ /dev/null
@@ -1,26 +1,0 @@
-ROOT=..
-include ../Make.config
-LIB=../libmachdep.a
-CFLAGS+=-fpie
-LDFLAGS+=-fpie
-
-OFILES=\
-	getcallerpc.$O\
-	tas.$O\
-	cas.$O\
-
-default: $(LIB)
-$(LIB): $(OFILES)
-	$(AR) r $(LIB) $(OFILES)
-	$(RANLIB) $(LIB)
-
-%.$O: %.c
-	$(CC) $(CFLAGS) $*.c
-
-%.$O: %.s
-	$(AS) -o $*.$O $*.s
-
-%.s: %.spp
-	cpp $*.spp >$*.s
-
-
--- a/posix-arm/cas.c
+++ /dev/null
@@ -1,36 +1,0 @@
-#include "u.h"
-#include "libc.h"
-
-int
-cas(int *x, int old, int new)
-{
-	int     v, t;
-
-#if ARMv5
-	__asm__(
-		"1:	ldr	%0, [%2]\n"
-		"	cmp	%0, %3\n"
-		"	bne	2f\n"
-		"	swp	%1, %4, [%2]\n"
-		"	cmp	%1, %3\n"
-		"	bne	1b\n"
-		"2:"
-		: "=&r" (v), "=&r" (t)
-		: "r" (x), "r" (old), "r" (new)
-		: "cc", "memory"
-	);
-#else
-	__asm__ (
-		"1:	ldrex	%0, [%2]\n"
-		"	cmp	%0, %3\n"
-		"	bne	2f\n"
-		"	strex	%1, %4, [%2]\n"
-		"	teq	%1, #0\n"
-		"	bne	1b\n"
-		"2:"
-		: "=&r" (v), "=&r" (t)
-		: "r" (x), "r" (old), "r" (new)
-		: "cc");
-#endif
-	return (v == old);
-}
\ No newline at end of file
--- a/posix-arm/getcallerpc.c
+++ /dev/null
@@ -1,8 +1,0 @@
-#include "u.h"
-#include "libc.h"
-
-uintptr
-getcallerpc(void *a)
-{
-	return ((uintptr*)a)[-1];
-}
--- a/posix-arm/mem.h
+++ /dev/null
@@ -1,90 +1,0 @@
-/*
- * Memory and machine-specific definitions.  Used in C and assembler.
- */
-#define KiB		1024u			/* Kibi 0x0000000000000400 */
-#define MiB		1048576u		/* Mebi 0x0000000000100000 */
-#define GiB		1073741824u		/* Gibi 000000000040000000 */
-
-/*
- * Sizes
- */
-#define	BY2PG		(4*KiB)			/* bytes per page */
-#define	PGSHIFT		12			/* log(BY2PG) */
-#define	PGROUND(s)	ROUND(s, BY2PG)
-#define	ROUND(s, sz)	(((s)+(sz-1))&~(sz-1))
-
-#define	MAXMACH		4			/* max # cpus system can run */
-#define	MACHSIZE	BY2PG
-#define L1SIZE		(4 * BY2PG)
-
-#define KSTACK		(8*KiB)
-#define STACKALIGN(sp)	((sp) & ~3)		/* bug: assure with alloc */
-
-/*
- * Magic registers
- */
-
-#define	USER		9		/* R9 is up-> */
-#define	MACH		10		/* R10 is m-> */
-
-/*
- * Address spaces.
- * KTZERO is used by kprof and dumpstack (if any).
- *
- * KZERO is mapped to physical 0 (start of ram).
- *
- * vectors are at 0, plan9.ini is at KZERO+256 and is limited to 16K by
- * devenv.
- */
-
-#define	KSEG0		0x80000000		/* kernel segment */
-/* mask to check segment; good for 1GB dram */
-#define	KSEGM		0xC0000000
-#define	KZERO		KSEG0			/* kernel address space */
-#define CONFADDR	(KZERO+0x100)		/* unparsed plan9.ini */
-#define	REBOOTADDR	(0x1c00)		/* reboot code - physical address */
-#define	MACHADDR	(KZERO+0x2000)		/* Mach structure */
-#define	L2		(KZERO+0x3000)		/* L2 ptes for vectors etc */
-#define	VCBUFFER	(KZERO+0x3400)		/* videocore mailbox buffer */
-#define	FIQSTKTOP	(KZERO+0x4000)		/* FIQ stack */
-#define	L1		(KZERO+0x4000)		/* tt ptes: 16KiB aligned */
-#define	KTZERO		(KZERO+0x8000)		/* kernel text start */
-#define VIRTIO		(0x7E000000)		/* i/o registers */
-#define	ARMLOCAL	(0x7F000000)		/* armv7 only */
-#define	VGPIO		(ARMLOCAL+MiB)		/* virtual gpio for pi3 ACT LED */
-#define	FRAMEBUFFER	0xC0000000		/* video framebuffer */
-
-/*
- * Sizes
- */
-#define BI2BY		8			/* bits per byte */
-#define BY2SE		4
-#define BY2WD		4
-#define BY2V		8			/* only used in xalloc.c */
-
-#define	PTEMAPMEM	(1024*1024)
-#define	PTEPERTAB	(PTEMAPMEM/BY2PG)
-#define	SEGMAPSIZE	1984
-#define	SSEGMAPSIZE	16
-#define	PPN(x)		((x)&~(BY2PG-1))
-
-/*
- * These bits are completely artificial.
- * With a little work these move to port.
- */
-#define	PTEVALID	(1<<0)
-#define	PTERONLY	0
-#define	PTEWRITE	(1<<1)
-#define	PTECACHED	0
-#define	PTEUNCACHED	(1<<2)
-#define	PTENOEXEC	(1<<4)
-
-/*
- * Physical machine information from here on.
- *	PHYS addresses as seen from the arm cpu.
- *	BUS  addresses as seen from the videocore gpu.
- */
-#define	PHYSDRAM	0
-
-#define MIN(a, b)	((a) < (b)? (a): (b))
-#define MAX(a, b)	((a) > (b)? (a): (b))
\ No newline at end of file
--- a/posix-arm/tas.c
+++ /dev/null
@@ -1,35 +1,0 @@
-#include "u.h"
-#include "libc.h"
-
-int
-tas(int *x)
-{
-	int     v, t, i = 1;
-
-#if ARMv5
-	__asm__(
-		"swp  %0, %1, [%2]"
-		: "=&r" (v)
-		: "r" (1), "r" (x)
-		: "memory"
-	);
-#else
-	__asm__ (
-		"1:	ldrex	%0, [%2]\n"
-		"	strex	%1, %3, [%2]\n"
-		"	teq	%1, #0\n"
-		"	bne	1b"
-		: "=&r" (v), "=&r" (t)
-		: "r" (x), "r" (i)
-		: "cc");
-#endif
-	switch(v) {
-	case 0:
-	case 1:
-		return v;
-	default:
-		print("canlock: corrupted 0x%lux\n", v);
-		return 1;
-	}
-}
-
--- a/posix-arm64/Makefile
+++ /dev/null
@@ -1,25 +1,0 @@
-ROOT=..
-include ../Make.config
-LIB=../libmachdep.a
-CFLAGS+=-arch arm64
-LDFLAGS+=-fpie
-
-OFILES=\
-	getcallerpc.$O\
-	tas.$O\
-	cas.$O\
-
-default: $(LIB)
-$(LIB): $(OFILES)
-	$(AR) r $(LIB) $(OFILES)
-	$(RANLIB) $(LIB)
-
-%.$O: %.c
-	$(CC) $(CFLAGS) $*.c
-
-%.$O: %.s
-	$(AS) -o $*.$O $*.s
-
-%.s: %.spp
-	cpp $*.spp >$*.s
-
--- a/posix-arm64/cas.c
+++ /dev/null
@@ -1,30 +1,0 @@
-#include "u.h"
-#include "libc.h"
-
-#ifndef __has_builtin
-#define __has_builtin(x) 0
-#endif
-
-int
-cas(int *x, int old, int new)
-{
-#if __has_builtin(__atomic_compare_exchange_n) || (defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 7)))
-	return __atomic_compare_exchange_n(x, &old, new, 0, __ATOMIC_ACQ_REL, __ATOMIC_ACQUIRE);
-#else
-	int     v, t;
-
-	__asm__ (
-		"1:	ldxr	%0, [%3]\n"
-		"	cmp	%0, %4\n"
-		"	bne	2f\n"
-		"	stxr	%w1, %5, [%3]\n"
-		"	cmp	%1, #0\n"
-		"	bne	1b\n"
-		"2:"
-		: "=&r" (v), "=&r" (t)
-		: "m" (*x), "r" (x), "r" (old), "r" (new)
-		: "cc");
-
-	return (v == old);
-#endif
-}
\ No newline at end of file
--- a/posix-arm64/getcallerpc.c
+++ /dev/null
@@ -1,8 +1,0 @@
-#include "u.h"
-#include "libc.h"
-
-uintptr
-getcallerpc(void *a)
-{
-	return ((uintptr*)a)[-1];
-}
--- a/posix-arm64/mem.h
+++ /dev/null
@@ -1,146 +1,0 @@
-/*
- * Memory and machine-specific definitions.  Used in C and assembler.
- */
-#define KiB		1024u			/* Kibi 0x0000000000000400 */
-#define MiB		1048576u		/* Mebi 0x0000000000100000 */
-#define GiB		1073741824u		/* Gibi 000000000040000000 */
-
-/*
- * Sizes:
- * 	L0	L1	L2	L3
- *	4K	2M	1G	512G
- *	16K	32M	64G	128T
- *	64K	512M	4T	-
- */
-#define	PGSHIFT		12		/* log(BY2PG) */
-#define	BY2PG		(1ULL<<PGSHIFT)	/* bytes per page */
-#define	ROUND(s, sz)	(((s)+(sz-1))&~(sz-1))
-#define	PGROUND(s)	ROUND(s, BY2PG)
-
-/* effective virtual address space */
-#define EVASHIFT	36
-#define EVAMASK		((1ULL<<EVASHIFT)-1)
-
-#define PTSHIFT		(PGSHIFT-3)
-#define PTLEVELS	(((EVASHIFT-PGSHIFT)+PTSHIFT-1)/PTSHIFT)	
-#define PTLX(v, l)	((((v) & EVAMASK) >> (PGSHIFT + (l)*PTSHIFT)) & ((1 << PTSHIFT)-1))
-#define PGLSZ(l)	(1ULL << (PGSHIFT + (l)*PTSHIFT))
-
-#define PTL1X(v, l)	(L1TABLEX(v, l) | PTLX(v, l))
-#define L1TABLEX(v, l)	(L1TABLE(v, l) << PTSHIFT)
-#define L1TABLES	((-KSEG0+PGLSZ(2)-1)/PGLSZ(2))
-#define L1TABLE(v, l)	(L1TABLES - ((PTLX(v, 2) % L1TABLES) >> (((l)-1)*PTSHIFT)) + (l)-1)
-#define L1TOPSIZE	(1ULL << (EVASHIFT - PTLEVELS*PTSHIFT))
-
-#define	MAXMACH		16			/* max # cpus system can run */
-#define	MACHSIZE	(8*KiB)
-
-#define KSTACK		(8*KiB)
-#define STACKALIGN(sp)	((sp) & ~7)		/* bug: assure with alloc */
-#define TRAPFRAMESIZE	(38*8)
-
-#define DTBADDR		0x40000000
-
-#define VDRAM		(0xFFFFFFFFC0000000ULL)	/* 0x40000000 - 0x80000000 */
-#define	KTZERO		(VDRAM + 0x100000)	/* 0x40100000 - kernel text start */
-
-#define PHYSIO		0x8000000
-#define PHYSIOEND	0x10000000
-
-#define	VIRTIO		(0xFFFFFFFFB0000000ULL)
-
-#define	KZERO		(0xFFFFFFFF80000000ULL)	/* 0x00000000 - kernel address space */
-
-#define VMAP		(0xFFFFFFFF00000000ULL)	/* 0x00000000 - 0x40000000 */
-
-#define KMAPEND		(0xFFFFFFFF00000000ULL)	/* 0x140000000 */
-#define KMAP		(0xFFFFFFFE00000000ULL)	/*  0x40000000 */
-
-#define KLIMIT		(VDRAM - KZERO + KMAPEND - KMAP)	/* 0x140000000 */
-
-#define KSEG0		(0xFFFFFFFE00000000ULL)
-
-/* temporary identity map for TTBR0 (using only top-level) */
-#define L1BOT		((L1-L1TOPSIZE)&-BY2PG)
-
-/* shared kernel page table for TTBR1 */
-#define L1		(L1TOP-L1SIZE)
-#define L1SIZE		((L1TABLES+PTLEVELS-2)*BY2PG)
-#define L1TOP		((MACHADDR(MAXMACH-1)-L1TOPSIZE)&-BY2PG)
-
-#define MACHADDR(n)	(KTZERO-((n)+1)*MACHSIZE)
-
-#define CONFADDR	(VDRAM + 0x10000)	/* 0x40010000 */
-
-#define BOOTARGS	((char*)CONFADDR)
-#define BOOTARGSLEN	0x10000
-
-#define	REBOOTADDR	(VDRAM-KZERO + 0x20000)	/* 0x40020000 */
-
-#define _NSYS		53
-#define TRAMPSIZE   232                /* Size of the trampoline, padded */
-/*
- * Sizes
- */
-#define BI2BY		8			/* bits per byte */
-#define BY2SE		4
-#define BY2WD		8
-#define BY2V		8			/* only used in xalloc.c */
-
-#define	PTEMAPMEM	(1024*1024)
-#define	PTEPERTAB	(PTEMAPMEM/BY2PG)
-#define	SEGMAPSIZE	8192
-#define	SSEGMAPSIZE	16
-#define	PPN(x)		((x)&~(BY2PG-1))
-
-#define SHARE_NONE	0
-#define SHARE_OUTER	2
-#define SHARE_INNER	3
-
-#define CACHE_UC	0
-#define CACHE_WB	1
-#define CACHE_WT	2
-#define CACHE_WB_NA	3
-
-#define MA_MEM_WB	0
-#define MA_MEM_WT	1
-#define MA_MEM_UC	2
-#define MA_DEV_nGnRnE	3
-#define MA_DEV_nGnRE	4
-#define MA_DEV_nGRE	5
-#define MA_DEV_GRE	6
-
-#define	PTEVALID	1
-#define PTEBLOCK	0
-#define PTETABLE	2
-#define PTEPAGE		2
-
-#define PTEMA(x)	((x)<<2)
-#define PTEAP(x)	((x)<<6)
-#define PTESH(x)	((x)<<8)
-
-#define PTEAF		(1<<10)
-#define PTENG		(1<<11)
-#define PTEPXN		(1ULL<<53)
-#define PTEUXN		(1ULL<<54)
-
-#define PTEKERNEL	PTEAP(0)
-#define PTEUSER		PTEAP(1)
-#define PTEWRITE	PTEAP(0)
-#define PTERONLY	PTEAP(2)
-#define PTENOEXEC	(PTEPXN|PTEUXN)
-
-#define PTECACHED	PTEMA(MA_MEM_WB)
-#define PTEWT		PTEMA(MA_MEM_WT)
-#define PTEUNCACHED	PTEMA(MA_MEM_UC)
-#define PTEDEVICE	PTEMA(MA_DEV_nGnRE)
-
-/*
- * Physical machine information from here on.
- *	PHYS addresses as seen from the arm cpu.
- *	BUS  addresses as seen from peripherals
- */
-#define	PHYSDRAM	0
-
-#define MIN(a, b)	((a) < (b)? (a): (b))
-#define MAX(a, b)	((a) > (b)? (a): (b))
\ No newline at end of file
--- a/posix-arm64/tas.c
+++ /dev/null
@@ -1,34 +1,0 @@
-#include "u.h"
-#include "libc.h"
-
-#ifndef __has_builtin
-#define __has_builtin(x) 0
-#endif
-
-int
-tas(int *x)
-{
-#if __has_builtin(__atomic_test_and_set) || (defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 7)))
-	return __atomic_test_and_set(x, __ATOMIC_ACQ_REL);
-#else
-	int     v,t, i = 1;
-
-	__asm__ (
-		"1:	ldxr	%0, [%2]\n"
-		"	stxr	%w1, %3, [%2]\n"
-		"	cmp	%1, #0\n"
-		"	bne	1b"
-		: "=&r" (v), "=&r" (t)
-		: "r" (x), "r" (i)
-		: "cc");
-
-	switch(v) {
-	case 0:
-	case 1:
-		return v;
-	default:
-		print("canlock: corrupted 0x%lux\n", v);
-		return 1;
-	}
-#endif
-}
--- a/posix-mips/Makefile
+++ /dev/null
@@ -1,19 +1,0 @@
-ROOT=..
-include ../Make.config
-LIB=../libmachdep.a
-CFLAGS+=-fpie
-LDFLAGS+=-fpie
-
-OFILES=\
-	getcallerpc.$O\
-	tas.$O\
-	cas.$O\
-	
-default: $(LIB)
-$(LIB): $(OFILES)
-	$(AR) r $(LIB) $(OFILES)
-	$(RANLIB) $(LIB)
-
-tas.$O: tas.s
-	ln -sf tas.s tas.S
-	$(CC) -c -o tas.$O -mips3 tas.S
--- a/posix-mips/cas.c
+++ /dev/null
@@ -1,26 +1,0 @@
-#include "u.h"
-#include "libc.h"
-
-#ifndef __has_builtin
-#define __has_builtin(x) 0
-#endif
-
-int
-cas(int *x, int old, int new)
-{
-#if __has_builtin(__atomic_compare_exchange_n)
-    return __atomic_compare_exchange_n(x, &old, new, 0, __ATOMIC_ACQ_REL, __ATOMIC_ACQUIRE);
-#else
-    int result;
-    __asm__ __volatile__(
-        "ll %0, 0(%2)\n"
-        "bne %0, %3, 1f\n"
-        "move %0, %4\n"
-        "sc %0, 0(%2)\n"
-        "1:"
-        : "=&r" (result), "=m" (*x)
-        : "r" (x), "r" (old), "r" (new)
-        : "memory");
-    return result;
-#endif
-}
\ No newline at end of file
--- a/posix-mips/getcallerpc.c
+++ /dev/null
@@ -1,8 +1,0 @@
-#include "u.h"
-#include "libc.h"
-
-uintptr
-getcallerpc(void *a)
-{
-	return ((ulong*)a)[-1];
-}
--- a/posix-mips/tas.s
+++ /dev/null
@@ -1,20 +1,0 @@
-#include <machine/regdef.h>
-
-.globl tas
-.ent tas 2
-
-tas:
-.set noreorder
-1:
-	ori	t1, zero, 12345	/* t1 = 12345 */
-	ll	t0, (a0)		/* t0 = *a0 */
-	sc	t1, (a0)		/* *a0 = t1 if *a0 hasn't changed; t1=success */
-	beq	t1, zero, 1b		/* repeat if *a0 did change */
-	nop
-
-	j $31				/* return */
-	or	v0, t0, zero		/* set return value on way out */
-
-.set reorder
-.end tas
-
--- a/posix-port/Makefile
+++ /dev/null
@@ -1,22 +1,0 @@
-ROOT=..
-include ../Make.config
-LIB=../libmachdep.a
-
-OFILES=\
-	getcallerpc.$O\
-
-default: $(LIB)
-$(LIB): $(OFILES)
-	$(AR) r $(LIB) $(OFILES)
-	$(RANLIB) $(LIB)
-
-%.$O: %.c
-	$(CC) $(CFLAGS) $*.c
-
-%.$O: %.s
-	$(AS) -o $*.$O $*.s
-
-%.s: %.spp
-	cpp $*.spp >$*.s
-
-
--- a/posix-port/getcallerpc.c
+++ /dev/null
@@ -1,8 +1,0 @@
-#include "u.h"
-#include "libc.h"
-
-uintptr
-getcallerpc(void *a)
-{
-	return 0;
-}
--- a/posix-power/Makefile
+++ /dev/null
@@ -1,28 +1,0 @@
-ROOT=..
-include ../Make.config
-LIB=../libmachdep.a
-LAGS+= -Wa,-mregnames,-fpie
-LDFLAGS+=-fpie
-
-CFLAGS+= -Wa,-mregnames
-
-OFILES=\
-	getcallerpc.$O\
-	tas.$O\
-	cas.$O\
-
-default: $(LIB)
-$(LIB): $(OFILES)
-	$(AR) r $(LIB) $(OFILES)
-	$(RANLIB) $(LIB)
-
-%.$O: %.c
-	$(CC) $(CFLAGS) $*.c
-
-%.$O: %.s
-	$(AS) -o $*.$O $*.s
-
-%.s: %.spp
-	cpp $*.spp >$*.s
-
-
--- a/posix-power/cas.c
+++ /dev/null
@@ -1,30 +1,0 @@
-#include "u.h"
-#include "libc.h"
-
-#ifndef __has_builtin
-#define __has_builtin(x) 0
-#endif
-
-int
-cas(int *x, int old, int new)
-{
-#if __has_builtin(__atomic_compare_exchange_n)
-    return __atomic_compare_exchange_n(x, &old, new, 0, __ATOMIC_ACQ_REL, __ATOMIC_ACQUIRE);
-#else
-    int result;
-    __asm__ __volatile__(
-        "lwarx %0, 0, %2\n"
-        "cmpw %0, %3\n"
-        "bne 1f\n"
-        "stwcx. %4, 0, %2\n"
-        "bne 1f\n"
-        "li %0, 1\n"
-        "b 2f\n"
-        "1: li %0, 0\n"
-        "2:"
-        : "=&r" (result), "=m" (*x)
-        : "r" (x), "r" (old), "r" (new)
-        : "cc", "cr0");
-    return result;
-#endif
-}
\ No newline at end of file
--- a/posix-power/getcallerpc.c
+++ /dev/null
@@ -1,8 +1,0 @@
-#include "u.h"
-#include "libc.h"
-
-uintptr
-getcallerpc(void *a)
-{
-	return ((uintptr*)a)[-1];
-}
--- a/posix-power/tas.c
+++ /dev/null
@@ -1,42 +1,0 @@
-#include "u.h"
-#include "libc.h"
-
-/*
- * first argument (l) is in r3 at entry.
- * r3 contains return value upon return.
- */
-int
-tas(int *x)
-{
-	int     v;
-	/*
-	 * 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"
-	);
-	switch(v) {
-	case 0:		return 0;
-	case 0xdeaddead: return 1;
-	default:	print("tas: corrupted 0x%lux\n", v);
-	}
-	return 0;
-}
--- a/posix-riscv64/Makefile
+++ /dev/null
@@ -1,21 +1,0 @@
-ROOT=..
-include ../Make.config
-LIB=../libmachdep.a
-CFLAGS+=-fpie
-LDFLAGS+=-fpie
-
-OFILES=\
-	getcallerpc.$O\
-	tas.$O\
-	cas.$O\
-
-default: $(LIB)
-$(LIB): $(OFILES)
-	$(AR) r $(LIB) $(OFILES)
-	$(RANLIB) $(LIB)
-
-%.$O: %.c
-	$(CC) $(CFLAGS) $*.c
-
-%.$O: %.s
-	$(AS) -o $*.$O $*.s
--- a/posix-riscv64/cas.c
+++ /dev/null
@@ -1,26 +1,0 @@
-#include "u.h"
-#include "libc.h"
-
-#ifndef __has_builtin
-#define __has_builtin(x) 0
-#endif
-
-int
-cas(int *x, int old, int new)
-{
-#if __has_builtin(__atomic_compare_exchange_n)
-    return __atomic_compare_exchange_n(x, &old, new, 0, __ATOMIC_ACQ_REL, __ATOMIC_ACQUIRE);
-#else
-    int result;
-    __asm__ __volatile__(
-        "lr.w %0, %2\n"
-        "bne %0, %3, 1f\n"
-        "sc.w %0, %4, %2\n"
-        "seqz %0, %0\n"
-        "1:"
-        : "=&r" (result), "=m" (*x)
-        : "m" (*x), "r" (old), "r" (new)
-        : "cc");
-    return result;
-#endif
-}
\ No newline at end of file
--- a/posix-riscv64/getcallerpc.c
+++ /dev/null
@@ -1,8 +1,0 @@
-#include "u.h"
-#include "libc.h"
-
-uintptr
-getcallerpc(void *a)
-{
-	return ((uintptr*)a)[-1];
-}
--- a/posix-riscv64/tas.c
+++ /dev/null
@@ -1,28 +1,0 @@
-#include "u.h"
-#include "libc.h"
-
-int
-tas(int *x)
-{
-	int v, i = 1;
-
-	__asm__(
-		"1:	lr.w t0, (%1)\n"
-		"	sc.w t1, %2, (%1)\n"
-		"	bnez t1, 1b\n"
-		"       mv %0, t0"
-		: "=r" (v)
-		: "r" (x), "r" (i)
-		: "t1", "t0"
-	);
-
-	switch(v) {
-	case 0:
-	case 1:
-		return v;
-	default:
-		print("canlock: corrupted 0x%lux\n", v);
-		return 1;
-	}
-}
-
--- a/posix-sun4u/Makefile
+++ /dev/null
@@ -1,25 +1,0 @@
-ROOT=..
-include ../Make.config
-LIB=../libmachdep.a
-
-OFILES=\
-	getcallerpc.$O\
-	tas.$O\
-	cas.$O\
-
-default: $(LIB)
-$(LIB): $(OFILES)
-	$(AR) r $(LIB) $(OFILES)
-	$(RANLIB) $(LIB)
-
-%.$O: %.c
-	$(CC) $(CFLAGS) $*.c
-
-%.$O: %.s
-	$(AS) -o $*.$O $*.s
-
-%.s: %.spp
-	cpp $*.spp >$*.s
-
-
-
--- a/posix-sun4u/cas.c
+++ /dev/null
@@ -1,25 +1,0 @@
-#include "u.h"
-#include "libc.h"
-
-#ifndef __has_builtin
-#define __has_builtin(x) 0
-#endif
-
-int
-cas(int *x, int old, int new)
-{
-#if __has_builtin(__atomic_compare_exchange_n)
-    return __atomic_compare_exchange_n(x, &old, new, 0, __ATOMIC_ACQ_REL, __ATOMIC_ACQUIRE);
-#else
-    int result;
-    __asm__ __volatile__(
-        "casa [%2] %%asi, %3, %1\n"
-        "cmp %3, %1\n"
-        "mov %4, %0\n"
-        "movne %4, 0, %0"
-        : "=&r" (result), "+r" (new), "+m" (*x)
-        : "r" (x), "r" (old)
-        : "cc");
-    return result;
-#endif
-}
\ No newline at end of file
--- a/posix-sun4u/getcallerpc.c
+++ /dev/null
@@ -1,9 +1,0 @@
-#include "u.h"
-#include "libc.h"
-
-uintptr
-getcallerpc(void *a)
-{
-	return ((ulong*)a)[-1];
-}
-
--- a/posix-sun4u/tas.s
+++ /dev/null
@@ -1,5 +1,0 @@
-.globl tas
-tas:
-	retl
-	ldstub [%o0], %o0
-
--- /dev/null
+++ b/tas.c
@@ -1,0 +1,9 @@
+#include "u.h"
+#include "libc.h"
+
+int
+tas(int *x)
+{
+	return __atomic_test_and_set(x, __ATOMIC_ACQ_REL);
+}
+
--- a/win32-386/Makefile
+++ /dev/null
@@ -1,24 +1,0 @@
-ROOT=..
-include ../Make.config
-LIB=../libmachdep.a
-
-OFILES=\
-	getcallerpc.$O\
-	tas.$O\
-	cas.$O
-
-default: $(LIB)
-$(LIB): $(OFILES)
-	$(AR) r $(LIB) $(OFILES)
-	$(RANLIB) $(LIB)
-
-%.$O: %.c
-	$(CC) $(CFLAGS) $*.c
-
-%.$O: %.s
-	$(AS) -o $*.$O $*.s
-
-%.s: %.spp
-	cpp $*.spp >$*.s
-
-
--- a/win32-386/cas.c
+++ /dev/null
@@ -1,9 +1,0 @@
-#include "u.h"
-#include "libc.h"
-#include <windows.h>
-
-int
-cas(int *x, int old, int new)
-{
-	return InterlockedCompareExchange((volatile LONG *)x, new, old) == old;
-}
\ No newline at end of file
--- a/win32-386/getcallerpc.c
+++ /dev/null
@@ -1,8 +1,0 @@
-#include "u.h"
-#include "libc.h"
-
-uintptr
-getcallerpc(void *a)
-{
-	return ((uintptr*)a)[-1];
-}
--- a/win32-386/tas.c
+++ /dev/null
@@ -1,23 +1,0 @@
-#include "u.h"
-#include "libc.h"
-
-int
-tas(int *x)
-{
-	int     v;
-
-	__asm__(	"movl   $1, %%eax\n\t"
-			"xchgl  %%eax,(%%ecx)"
-			: "=a" (v)
-			: "c" (x)
-	);
-	switch(v) {
-	case 0:
-	case 1:
-		return v;
-	default:
-		print("canlock: corrupted 0x%lux\n", v);
-		return 1;
-	}
-}
-
--