code: 9ferno

Download patch

ref: 4790d3a8119e636b8e7562715b1b850c8b22d9ce
parent: 3f5999b1c26a1122ab6eb4da915837014a986495
author: joe9 <joe9mail@gmail.com>
date: Fri Jul 2 17:17:55 EDT 2021

working OpenBSD and 9front amd64 builds

diff: cannot open b/OpenBSD/amd64/include//null: file does not exist: 'b/OpenBSD/amd64/include//null' diff: cannot open b/OpenBSD/amd64//null: file does not exist: 'b/OpenBSD/amd64//null'
--- /dev/null
+++ b/OpenBSD/amd64/include/emu.h
@@ -1,0 +1,34 @@
+/*
+ * system- and machine-specific declarations for emu:
+ * floating-point save and restore, signal handling primitive, and
+ * implementation of the current-process variable `up'.
+ */
+
+/*
+ * This structure must agree with FPsave and FPrestore asm routines
+ */
+typedef struct FPU FPU;
+struct FPU
+{
+	uchar	env[28];
+};
+
+#define KSTACK (64 * 1024)
+
+#ifndef USE_PTHREADS
+static __inline Proc *getup(void) {
+	Proc *p;
+	print("getup asm code called\n");
+	__asm__(	"movq	%%rsp, %%rax\n\t"
+			: "=a" (p)
+	);
+	return *(Proc **)((uintptr)p & ~(KSTACK - 1));
+};
+#else
+extern	Proc*	getup(void);
+#endif
+
+#define	up	(getup())
+
+typedef sigjmp_buf osjmpbuf;
+#define	ossetjmp(buf)	sigsetjmp(buf, 1)
--- /dev/null
+++ b/OpenBSD/amd64/include/fpuctl.h
@@ -1,0 +1,76 @@
+/*
+ * 386 fpu support
+ * Mimic Plan9 floating point support
+ */
+
+static void
+setfcr(ulong fcr)
+{
+	__asm__(	"xorb	$0x3f, %%al\n\t"
+			"pushw	%%ax\n\t"
+			"fwait\n\t"
+			"fldcw	(%%esp)\n\t"
+			"popw	%%ax\n\t"
+			: /* no output */
+			: "al" (fcr)
+	);
+}
+
+static ulong
+getfcr(void)
+{
+	ulong fcr = 0;
+
+	__asm__(	"pushl	%%eax\n\t"
+			"fwait\n\t"
+			"fstcw	(%%esp)\n\t"
+			"popl	%%eax\n\t"
+			"xorb	$0x3f, %%al\n\t"
+			: "=a"  (fcr)
+			: "eax"	(fcr)
+	);
+	return fcr; 
+}
+
+static ulong
+getfsr(void)
+{
+	ulong fsr = -1;
+
+	__asm__(	"fwait\n\t"
+			"fstsw	(%%eax)\n\t"
+			"movl	(%%eax), %%eax\n\t"
+			"andl	$0xffff, %%eax\n\t"
+			: "=a"  (fsr)
+			: "eax" (&fsr)
+	);
+	return fsr;
+}
+
+static void
+setfsr(ulong fsr)
+{
+	__asm__("fclex\n\t");
+}
+
+/* FCR */
+#define	FPINEX	(1<<5)
+#define	FPUNFL	((1<<4)|(1<<1))
+#define	FPOVFL	(1<<3)
+#define	FPZDIV	(1<<2)
+#define	FPINVAL	(1<<0)
+#define	FPRNR	(0<<10)
+#define	FPRZ	(3<<10)
+#define	FPRPINF	(2<<10)
+#define	FPRNINF	(1<<10)
+#define	FPRMASK	(3<<10)
+#define	FPPEXT	(3<<8)
+#define	FPPSGL	(0<<8)
+#define	FPPDBL	(2<<8)
+#define	FPPMASK	(3<<8)
+/* FSR */
+#define	FPAINEX	FPINEX
+#define	FPAOVFL	FPOVFL
+#define	FPAUNFL	FPUNFL
+#define	FPAZDIV	FPZDIV
+#define	FPAINVAL	FPINVAL
--- /dev/null
+++ b/OpenBSD/amd64/include/lib9.h
@@ -1,0 +1,511 @@
+/* define _BSD_SOURCE to use ISO C, POSIX, and 4.3BSD things. */
+#define	USE_PTHREADS
+#ifndef _BSD_SOURCE
+#define _BSD_SOURCE
+#endif
+/* these aren't really needed because OpenBSD does the right thing and makes off_t 64 bits, full stop */
+#define _LARGEFILE64_SOURCE	1
+#define _FILE_OFFSET_BITS 64
+
+#ifdef USE_PTHREADS
+#define	_REENTRANT	1
+#endif
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <unistd.h>
+#include <errno.h>
+#include <string.h>
+#include "math.h"
+#include <fcntl.h>
+#include <setjmp.h>
+#include <float.h>
+#include <time.h>
+
+#define	getwd	infgetwd
+
+#define	round	infround
+#define	fmax	inffmax
+#define	log2	inflog2
+
+#ifndef EMU
+typedef struct Proc Proc;
+#endif
+
+/*
+ * math module dtoa
+ */
+#define __LITTLE_ENDIAN
+
+#define	nil		((void*)0)
+
+typedef unsigned int	mpdigit;	/* for /sys/include/mp.h */
+typedef unsigned char	uchar;
+typedef signed char	schar;
+typedef	unsigned int	Rune;
+typedef unsigned long	usize;
+typedef unsigned char	u8int;
+typedef unsigned short	u16int;
+typedef unsigned int	u32int;
+typedef unsigned long long u64int;
+typedef signed char	s8int;
+typedef signed short	s16int;
+typedef signed int	s32int;
+typedef signed long long s64int;
+typedef	s64int		intptr;
+typedef	u64int		uintptr;
+typedef intptr		WORD;
+typedef uintptr		UWORD;
+typedef signed long long	vlong;
+typedef unsigned long long	uvlong;
+typedef unsigned char	u8;
+typedef unsigned short	u16;
+typedef unsigned int	u32;
+typedef unsigned long long u64;
+typedef signed char s8;
+typedef signed short s16;
+typedef signed int s32;
+typedef signed long long s64;
+
+#define	USED(x)		if(x){}else{}
+#define	SET(x)
+
+#undef nelem
+#define	nelem(x)	(sizeof(x)/sizeof((x)[0]))
+#undef offsetof
+#define	offsetof(s, m)	(uintptr)(&(((s*)0)->m))
+#undef assert
+#define	assert(x)	if(x){}else _assert("x")
+
+/*
+ * most mem and string routines are declared by ANSI/POSIX files above
+ */
+
+extern	char*	strecpy(char*, char*, char*);
+extern	char*	strdup(const char*);
+extern	int	cistrncmp(char*, char*, int);
+extern	int	cistrcmp(char*, char*);
+extern	char*	cistrstr(char*, char*);
+extern	int	tokenize(char*, char**, int);
+
+enum
+{
+	UTFmax		= 4,		/* maximum bytes per rune */
+	Runesync	= 0x80,		/* cannot represent part of a UTF sequence (<) */
+	Runeself	= 0x80,		/* rune and UTF sequences are the same (<) */
+	Runeerror	= 0xFFFD,	/* decoding error in UTF */
+	Runemax		= 0x10FFFF,	/* 21-bit rune */
+	Runemask	= 0x1FFFFF,	/* bits used by runes (see grep) */
+};
+
+/*
+ * rune routines
+ */
+extern	int	runetochar(char*, Rune*);
+extern	int	chartorune(Rune*, char*);
+extern	int	runelen(long);
+extern	int	runenlen(Rune*, int);
+extern	int	fullrune(char*, int);
+extern	int	utflen(char*);
+extern	int	utfnlen(char*, long);
+extern	char*	utfrune(char*, long);
+extern	char*	utfrrune(char*, long);
+extern	char*	utfutf(char*, char*);
+extern	char*	utfecpy(char*, char*, char*);
+
+extern	Rune*	runestrcat(Rune*, Rune*);
+extern	Rune*	runestrchr(Rune*, Rune);
+extern	int	runestrcmp(Rune*, Rune*);
+extern	Rune*	runestrcpy(Rune*, Rune*);
+extern	Rune*	runestrncpy(Rune*, Rune*, int);
+extern	Rune*	runestrecpy(Rune*, Rune*, Rune*);
+extern	Rune*	runestrdup(Rune*);
+extern	Rune*	runestrncat(Rune*, Rune*, int);
+extern	int	runestrncmp(Rune*, Rune*, int);
+extern	Rune*	runestrrchr(Rune*, Rune);
+extern	long	runestrlen(Rune*);
+extern	Rune*	runestrstr(Rune*, Rune*);
+
+extern	Rune	tolowerrune(Rune);
+extern	Rune	totitlerune(Rune);
+extern	Rune	toupperrune(Rune);
+extern	int	isalpharune(Rune);
+extern	int	islowerrune(Rune);
+extern	int	isspacerune(Rune);
+extern	int	istitlerune(Rune);
+extern	int	isupperrune(Rune);
+
+/*
+ * malloc
+ */
+extern	void*	malloc(usize);
+extern	void*	mallocz(usize, int);
+extern	void	free(void*);
+extern	usize	msize(void*);
+extern	void*	calloc(usize, usize);
+extern	void*	realloc(void*, usize);
+extern	void	setmalloctag(void*, uintptr);
+extern	void	setrealloctag(void*, uintptr);
+extern	uintptr	getmalloctag(void*);
+extern	uintptr	getrealloctag(void*);
+extern	void*	malloctopoolblock(void*);
+
+/*
+ * print routines
+ */
+typedef struct Fmt	Fmt;
+struct Fmt{
+	uchar	runes;			/* output buffer is runes or chars? */
+	void	*start;			/* of buffer */
+	void	*to;			/* current place in the buffer */
+	void	*stop;			/* end of the buffer; overwritten if flush fails */
+	int	(*flush)(Fmt *);	/* called when to == stop */
+	void	*farg;			/* to make flush a closure */
+	int	nfmt;			/* num chars formatted so far */
+	va_list	args;			/* args passed to dofmt */
+	int	r;			/* % format Rune */
+	int	width;
+	int	prec;
+	u32int	flags;
+};
+
+enum{
+	FmtWidth	= 1,
+	FmtLeft		= FmtWidth << 1,
+	FmtPrec		= FmtLeft << 1,
+	FmtSharp	= FmtPrec << 1,
+	FmtSpace	= FmtSharp << 1,
+	FmtSign		= FmtSpace << 1,
+	FmtZero		= FmtSign << 1,
+	FmtUnsigned	= FmtZero << 1,
+	FmtShort	= FmtUnsigned << 1,
+	FmtLong		= FmtShort << 1,
+	FmtVLong	= FmtLong << 1,
+	FmtComma	= FmtVLong << 1,
+	FmtByte	= FmtComma << 1,
+
+	FmtFlag		= FmtByte << 1
+};
+
+extern	int	print(char*, ...);
+extern	char*	seprint(char*, char*, char*, ...);
+extern	char*	vseprint(char*, char*, char*, va_list);
+extern	int	snprint(char*, int, char*, ...);
+extern	int	vsnprint(char*, int, char*, va_list);
+extern	char*	smprint(char*, ...);
+extern	char*	vsmprint(char*, va_list);
+extern	int	sprint(char*, char*, ...);
+extern	int	fprint(int, char*, ...);
+extern	int	vfprint(int, char*, va_list);
+
+extern	int	runesprint(Rune*, char*, ...);
+extern	int	runesnprint(Rune*, int, char*, ...);
+extern	int	runevsnprint(Rune*, int, char*, va_list);
+extern	Rune*	runeseprint(Rune*, Rune*, char*, ...);
+extern	Rune*	runevseprint(Rune*, Rune*, char*, va_list);
+extern	Rune*	runesmprint(char*, ...);
+extern	Rune*	runevsmprint(char*, va_list);
+
+extern	int	fmtfdinit(Fmt*, int, char*, int);
+extern	int	fmtfdflush(Fmt*);
+extern	int	fmtstrinit(Fmt*);
+extern	char*	fmtstrflush(Fmt*);
+extern	int	runefmtstrinit(Fmt*);
+extern	Rune*	runefmtstrflush(Fmt*);
+
+extern	int	fmtinstall(int, int (*)(Fmt*));
+extern	int	dofmt(Fmt*, char*);
+extern	int	dorfmt(Fmt*, Rune*);
+extern	int	fmtprint(Fmt*, char*, ...);
+extern	int	fmtvprint(Fmt*, char*, va_list);
+extern	int	fmtrune(Fmt*, int);
+extern	int	fmtstrcpy(Fmt*, char*);
+extern	int	fmtrunestrcpy(Fmt*, Rune*);
+/*
+ * error string for %r
+ * supplied on per os basis, not part of fmt library
+ */
+extern	int	errfmt(Fmt *f);
+
+/*
+ * quoted strings
+ */
+extern	char	*unquotestrdup(char*);
+extern	Rune	*unquoterunestrdup(Rune*);
+extern	char	*quotestrdup(char*);
+extern	Rune	*quoterunestrdup(Rune*);
+extern	int	quotestrfmt(Fmt*);
+extern	int	quoterunestrfmt(Fmt*);
+extern	void	quotefmtinstall(void);
+extern	int	(*doquote)(int);
+
+/*
+ * random number
+ */
+extern	int	nrand(int);
+extern	ulong	truerand(void);
+extern	ulong	ntruerand(ulong);
+
+/*
+ * math
+ */
+extern	int	isNaN(double);
+extern	int	isInf(double, int);
+extern	double	pow(double, double);
+
+/*
+ * Time-of-day
+ */
+
+typedef struct Tm Tm;
+struct Tm {
+	int	sec;
+	int	min;
+	int	hour;
+	int	mday;
+	int	mon;
+	int	year;
+	int	wday;
+	int	yday;
+	char	zone[4];
+	int	tzoff;
+};
+extern	s64int	osnsec(void);
+#define	nsec	osnsec
+	
+/*
+ * one-of-a-kind
+ */
+extern	void	_assert(char*);
+extern	double	charstod(int(*)(void*), void*);
+extern	char*	cleanname(char*);
+extern	double	frexp(double, int*);
+extern	uintptr	getcallerpc(void*);
+extern	int	getfields(char*, char**, int, int, char*);
+extern	char*	getuser(void);
+extern	char*	getwd(char*, int);
+extern	double	ipow10(int);
+extern	double	ldexp(double, int);
+extern	double	modf(double, double*);
+#define	pow10	infpow10
+extern	double	pow10(int);
+extern	s64int	strtoll(const char*, char**, int);
+#define	qsort	infqsort
+extern	void	qsort(void*, long, long, int (*)(void*, void*));
+extern	u64int	strtoull(const char*, char**, int);
+extern	void	sysfatal(char*, ...);
+extern	int	dec64(uchar*, int, char*, int);
+extern	int	enc64(char*, int, uchar*, int);
+extern	int	dec32(uchar*, int, char*, int);
+extern	int	enc32(char*, int, uchar*, int);
+extern	int	dec16(uchar*, int, char*, int);
+extern	int	enc16(char*, int, uchar*, int);
+extern	int	encodefmt(Fmt*);
+
+/*
+ *  synchronization
+ */
+typedef
+struct Lock {
+	u32int	val;
+	u32int	pid;
+} Lock;
+
+extern int	_tas(int*);
+
+extern	void	lock(Lock*);
+extern	void	unlock(Lock*);
+extern	int	canlock(Lock*);
+
+typedef struct QLock QLock;
+struct QLock
+{
+	Lock	use;			/* to access Qlock structure */
+	Proc	*head;			/* next process waiting for object */
+	Proc	*tail;			/* last process waiting for object */
+	int	locked;			/* flag */
+};
+
+extern	void	qlock(QLock*);
+extern	void	qunlock(QLock*);
+extern	int	canqlock(QLock*);
+extern	void	_qlockinit(u32int (*)(u32int, u32int));	/* called only by the thread library */
+
+typedef
+struct RWLock
+{
+	Lock	l;			/* Lock modify lock */
+	QLock	x;			/* Mutual exclusion lock */
+	QLock	k;			/* Lock for waiting writers */
+	int	readers;		/* Count of readers in lock */
+} RWLock;
+
+extern	int	canrlock(RWLock*);
+extern	int	canwlock(RWLock*);
+extern	void	rlock(RWLock*);
+extern	void	runlock(RWLock*);
+extern	void	wlock(RWLock*);
+extern	void	wunlock(RWLock*);
+
+/*
+ * network dialing
+ */
+#define NETPATHLEN 40
+
+/*
+ * system calls
+ *
+ */
+#define	STATMAX	65535U	/* max length of machine-independent stat structure */
+#define	DIRMAX	(sizeof(Dir)+STATMAX)	/* max length of Dir structure */
+#define	ERRMAX	128	/* max length of error string */
+
+#define	MORDER	0x0003	/* mask for bits defining order of mounting */
+#define	MREPL	0x0000	/* mount replaces object */
+#define	MBEFORE	0x0001	/* mount goes before others in union directory */
+#define	MAFTER	0x0002	/* mount goes after others in union directory */
+#define	MCREATE	0x0004	/* permit creation in mounted directory */
+#define	MCACHE	0x0010	/* cache some data */
+#define	MMASK	0x0017	/* all bits on */
+
+#define	OREAD	0	/* open for read */
+#define	OWRITE	1	/* write */
+#define	ORDWR	2	/* read and write */
+#define	OEXEC	3	/* execute, == read but check execute permission */
+#define	OTRUNC	16	/* or'ed in (except for exec), truncate file first */
+#define	OCEXEC	32	/* or'ed in, close on exec */
+#define	ORCLOSE	64	/* or'ed in, remove on close */
+#define	OEXCL	0x1000	/* or'ed in, exclusive use (create only) */
+
+#define	AEXIST	0	/* accessible: exists */
+#define	AEXEC	1	/* execute access */
+#define	AWRITE	2	/* write access */
+#define	AREAD	4	/* read access */
+
+/* bits in Qid.type */
+#define QTDIR		0x80		/* type bit for directories */
+#define QTAPPEND	0x40		/* type bit for append only files */
+#define QTEXCL		0x20		/* type bit for exclusive use files */
+#define QTMOUNT		0x10		/* type bit for mounted channel */
+#define QTAUTH		0x08		/* type bit for authentication file */
+#define QTFILE		0x00		/* plain file */
+
+/* bits in Dir.mode */
+#define DMDIR		0x80000000	/* mode bit for directories */
+#define DMAPPEND	0x40000000	/* mode bit for append only files */
+#define DMEXCL		0x20000000	/* mode bit for exclusive use files */
+#define DMMOUNT		0x10000000	/* mode bit for mounted channel */
+#define DMAUTH		0x08000000	/* mode bit for authentication file */
+#define DMREAD		0x4		/* mode bit for read permission */
+#define DMWRITE		0x2		/* mode bit for write permission */
+#define DMEXEC		0x1		/* mode bit for execute permission */
+
+typedef
+struct Qid
+{
+	u64int	path;
+	u32int	vers;
+	uchar	type;
+} Qid;
+
+typedef
+struct Dir {
+	/* system-modified data */
+	ushort	type;	/* server type */
+	uint	dev;	/* server subtype */
+	/* file data */
+	Qid	qid;	/* unique id from server */
+	u32int	mode;	/* permissions */
+	u32int	atime;	/* last read time */
+	u32int	mtime;	/* last write time */
+	s64int	length;	/* file length */
+	char	*name;	/* last element of path */
+	char	*uid;	/* owner name */
+	char	*gid;	/* group name */
+	char	*muid;	/* last modifier name */
+} Dir;
+
+extern	Dir*	dirstat(char*);
+extern	Dir*	dirfstat(int);
+extern	int	dirwstat(char*, Dir*);
+extern	int	dirfwstat(int, Dir*);
+extern	s32int	dirread(int, Dir**);
+extern	void	nulldir(Dir*);
+extern	s32int	dirreadall(int, Dir**);
+
+typedef
+struct Waitmsg
+{
+	int pid;	/* of loved one */
+	u32int time[3];	/* of loved one & descendants */
+	char	*msg;
+} Waitmsg;
+
+extern	void	_exits(char*);
+
+extern	void	exits(char*);
+extern	int	create(char*, int, int);
+extern	int	errstr(char*, uint);
+
+extern	void	perror(const char*);
+extern	long	readn(int, void*, long);
+extern	int	remove(const char*);
+extern	void	rerrstr(char*, uint);
+extern	vlong	seek(int, vlong, int);
+extern	s32	segflush(void*, u32);
+extern	void	werrstr(char*, ...);
+
+extern char *argv0;
+#define	ARGBEGIN	for((argv0||(argv0=*argv)),argv++,argc--;\
+			    argv[0] && argv[0][0]=='-' && argv[0][1];\
+			    argc--, argv++) {\
+				char *_args, *_argt;\
+				Rune _argc;\
+				_args = &argv[0][1];\
+				if(_args[0]=='-' && _args[1]==0){\
+					argc--; argv++; break;\
+				}\
+				_argc = 0;\
+				while(*_args && (_args += chartorune(&_argc, _args)))\
+				switch(_argc)
+#define	ARGEND		SET(_argt);USED(_argt);USED(_argc); USED(_args);}USED(argv); USED(argc);
+#define	ARGF()		(_argt=_args, _args="",\
+				(*_argt? _argt: argv[1]? (argc--, *++argv): 0))
+#define	EARGF(x)	(_argt=_args, _args="",\
+				(*_argt? _argt: argv[1]? (argc--, *++argv): ((x), abort(), (char*)0)))
+
+#define	ARGC()		_argc
+
+/*
+ *	Extensions for Inferno to basic libc.h
+ */
+
+#define	setbinmode()
+
+/* FCR */
+#define FPINEX  (1<<5)
+#define FPUNFL  ((1<<4)|(1<<1))
+#define FPOVFL  (1<<3)
+#define FPZDIV  (1<<2)
+#define FPINVAL (1<<0)
+#define FPRNR   (0<<10)
+#define FPRZ    (3<<10)
+#define FPRPINF (2<<10)
+#define FPRNINF (1<<10)
+#define FPRMASK (3<<10)
+#define FPPEXT  (3<<8)
+#define FPPSGL  (0<<8)
+#define FPPDBL  (2<<8)
+#define FPPMASK (3<<8)
+/* FSR */
+#define FPAINEX FPINEX
+#define FPAOVFL FPOVFL
+#define FPAUNFL FPUNFL
+#define FPAZDIV FPZDIV
+#define FPAINVAL        FPINVAL
+
+extern  void    setfcr(u32int);
+extern  void    setfsr(u32int);
+extern  u32int   getfcr(void);
+extern  u32int   getfsr(void);
--- /dev/null
+++ b/emu/OpenBSD/asm-amd64.S
@@ -1,0 +1,97 @@
+	.file	"asm-OpenBSD-amd64.S"
+
+#include <sys/syscall.h>
+#include <machine/asm.h>
+
+/*
+ * executeonnewstack(void *tos, void (*tramp)(void *arg), void *arg)
+ */
+
+	.type	 ournewstack,@function
+	.global	executeonnewstack
+executeonnewstack:
+	pushq	%rbp
+	movq	%rsp, %rbp
+	pushq	%rsi
+
+	movq	16(%rbp), %rsi	/* get tos */
+	subq	$8, %rsi
+	movq	32(%rbp), %rax
+	movq	%rax, (%rsi)	/* stash arg on new stack */
+	subq	$8, %rsi
+	movq	24(%rbp), %rax
+	movq	%rax, (%rsi)	/* stash tramp on new stack */
+	mov	%rsi, %rsp	/* swap stacks pronto */
+	popq	%rax		/* recover the tramp address */
+	call	*%rax		/* and jump to it (ho ho) */
+
+	/* if we return here, tramp didn't do it's job */
+
+	addq	$16, %rsp	/* clean up for pose value */
+
+	leaq	SYS_exit, %rax
+	int	$0x80
+
+/*
+ * unlockandexit(int *key)
+ *
+ * NB: the return status may be rubbish if the stack is reused
+ *	between the unlock and the system call, but this should
+ *	not matter since no task is waiting for the result
+ */
+
+	.type	unlockandexit,@function
+	.global	unlockandexit
+unlockandexit:
+	pushq	%rbp
+	movq	%rsp, %rbp
+
+	movq	16(%rbp), %rsi		/* get the key address */
+	pushq	$0			/* exit status 0 */
+	movq	$0, %rax		/* unlock the stack allocator */
+	movq	%rax, (%rsi)
+	leaq	SYS_exit, %rax		/* call exit */
+	int	$0x80
+
+/*
+ * umult(ulong m1, ulong m2, ulong *hi)
+ * umult(rdi, rsi, rdx) - as per system v abi
+ * 	store rdx in rbp as mul returns the high value in rdx 
+ */
+
+	.type	umult,@function
+	.global	umult
+umult:
+	pushq	%rbp
+	movq	%rdx, %rbp	/* save the 3rd argument (for the high of the result) */
+	movq	%rdi, %rax	/* loading the 1st argument */
+	movq	%rsi, %rdx	/* loading the 2nd argument */
+	mul	%rdx
+	movq	%rdx, (%rbp)
+	popq	%rbp
+	ret
+
+	.type	FPsave,@function
+	.global	FPsave
+FPsave:
+	fstenv	(%rdi)
+	ret
+
+	.type	FPrestore,@function
+	.global	FPrestore
+FPrestore:
+	fldenv	(%rdi)
+	ret
+
+	.type	getcallerpc,@function
+	.global	getcallerpc
+getcallerpc:
+	movq	8(%rbp), %rax
+	ret
+
+	.type	_tas,@function
+	.globl	_tas
+_tas:
+	movl	$1, %eax
+	xchgl	%eax, 0(%rdi)		/* rdi has the first argument to a function */
+	ret
--- /dev/null
+++ b/lib9/getcallerpc-OpenBSD-amd64.S
@@ -1,0 +1,8 @@
+	.file	"getcallerpc-OpenBSD-amd64.S"
+
+	.type	getcallerpc,@function
+	.global	getcallerpc
+getcallerpc:
+	movq	8(%rsp), %rax
+	movq	-8(%rax), %rax
+	ret
--- /dev/null
+++ b/lib9/setfcr-OpenBSD-amd64.S
@@ -1,0 +1,34 @@
+
+#define	FN(x)	.type x,@function; .global x; x
+#define	ENT	subq $32, %rsp
+#define	RET	addq $32, %rsp; ret
+
+	.file	"setfcr-OpenBSD-amd64.S"
+FN(setfcr):
+	ENT
+	xorb	$0x3f, %al
+	movq	%rax, (%rsp)
+	fwait
+	fldcw	(%rsp)
+	RET
+
+FN(getfcr):
+	ENT
+	fwait
+	fstcw	(%rsp)
+	movw	(%rsp), %ax
+	andq	$0xffffff, %rax
+	xorb	$0x3f, %al
+	RET
+
+FN(getfsr):
+	ENT
+	fwait
+	fstsw	(%rsp)
+	movw	(%rsp), %ax
+	andq	$0xffffff, %rax
+	RET
+
+FN(setfsr):
+	fclex
+	ret
--- /dev/null
+++ b/mkfiles/mkfile-OpenBSD-amd64
@@ -1,0 +1,30 @@
+TARGMODEL=	Posix
+TARGSHTYPE=	sh
+CPUS=		amd64
+
+O=		o
+OS=		o
+
+AR=		ar
+ARFLAGS=	ruvs
+
+AS=		cc -c
+ASFLAGS=
+
+CC=		cc -c
+CFLAGS=	-g\
+		-O\
+		-Wno-deprecated-declarations -Wuninitialized -Wunused -Wreturn-type -Wimplicit\
+		-I$ROOT/OpenBSD/amd64/include\
+		-I$ROOT/include\
+ 		-I/usr/X11R6/include\
+		-DOPENBSD_amd64 -fno-stack-protector
+
+ANSICPP=
+LD=		cc
+LDFLAGS=	-L/usr/X11R6/lib
+
+SYSLIBS=
+
+YACC=		iyacc
+YFLAGS=		-d
--- /dev/null
+++ b/mkfiles/mkmany-rc
@@ -1,0 +1,49 @@
+PROGS=${TARG:%=$O.%}
+libs=${LIBS:%=$ROOT/$OBJDIR/lib/lib%.a}
+
+all:V:	$PROGS
+
+install:V:
+	for (i in $TARG)
+		mk $MKFLAGS $i.install
+
+installall:V:
+	for(objtype in $CPUS)
+		mk $MKFLAGS install
+
+nuke:V:	nuke-std
+
+clean:V:
+	rm -f *.[$OS] *.a[$OS] y.tab.? lex.yy.c y.debug y.output [$OS].??* $TARG $CLEANFILES
+
+$O.%:	%.$O $OFILES $libs
+	$LD $LDFLAGS -o $target $prereq
+
+%.$O:	$HFILES		# don't combine with following %.$O rules
+
+%.$O:	%.c
+	$CC $CFLAGS -I^$ROOT/libinterp $stem.c
+
+%.$O:	%.s
+	$AS $ASFLAGS $stem.s
+
+y.tab.h y.tab.c:	$YFILES
+	$YACC $YFLAGS $YFILES
+
+nuke-std:V:	clean-std
+	rm -f y.tab.? y.debug y.output
+
+$BIN/%:	$O.%
+	rm -f $BIN/$stem && cp $O.$stem $BIN/$stem
+
+tests:V:
+	for (i in $PROGS){
+		mk $MKFLAGS $i
+		./$i || echo $i status: $status
+		status=()
+	}
+	echo '-- limbo test programs --'
+	for (i in $DISTARG){
+		limbo $i^'.b'
+		@{ rfork ens; emu -v -d tests/$i^'.dis' || echo $status }
+	}
--- /dev/null
+++ b/mkfiles/mkmany-sh
@@ -1,0 +1,54 @@
+PROGS=${TARG:%=$O.%}
+libs=${LIBS:%=$ROOT/$OBJDIR/lib/lib%.a}
+
+all:V:	$PROGS
+
+install:V:
+	for i in $TARG
+	do
+		mk $MKFLAGS $i.install
+	done
+
+installall:V:
+	for objtype in $CPUS
+	do
+		mk $MKFLAGS install
+	done
+
+nuke:V:	nuke-std
+
+clean:V:
+	rm -f *.[$OS] *.a[$OS] y.tab.? lex.yy.c y.debug y.output [$OS].??* $TARG $CLEANFILES
+
+$O.%:	%.$O $OFILES $libs
+	$LD $LDFLAGS -o $target $prereq
+
+%.$O:	$HFILES		# don't combine with following %.$O rules
+
+%.$O:	%.c
+	$CC $CFLAGS -I^$ROOT/libinterp $stem.c
+
+%.$O:	%.s
+	$AS $ASFLAGS $stem.s
+
+y.tab.h y.tab.c:	$YFILES
+	$YACC $YFLAGS $YFILES
+
+nuke-std:V:	clean-std
+	rm -f y.tab.? y.debug y.output
+
+$BIN/%:	$O.%
+	rm -f $BIN/$stem && cp $O.$stem $BIN/$stem
+
+tests:V:
+	for i in $PROGS
+	do
+		mk $MKFLAGS $i
+		./$i || echo 'status ' $?
+	done
+	echo '-- limbo test programs --'
+	for i in $DISTARG
+	do
+		limbo $i'.b'
+		( set -m; emu -v -d tests/$i'.dis' || echo 'status ' $? )
+	done