code: 9ferno

Download patch

ref: de5fee8aa45bf9af85583b87009c23a219efd155
parent: 5904f303924ad043240d56ee1875a5f8a1916afc
author: 9ferno <gophone2015@gmail.com>
date: Wed Nov 3 19:40:08 EDT 2021

working acid generation

--- /dev/null
+++ b/include/aml.h
@@ -1,0 +1,76 @@
+#pragma	lib	"libaml.a"
+#pragma	src	"/libaml"
+
+/*
+ *	b	uchar*	buffer		amllen() returns number of bytes
+ *	s	char*	string		amllen() is strlen()
+ *	n	char*	undefined name	amllen() is strlen()
+ *	i	uvlong*	integer
+ *	p	void**	package		amllen() is # of elements
+ *	r	void*	region
+ *	f	void*	field
+ *	u	void*	bufferfield
+ *	N	void*	name
+ *	R	void*	reference
+ */
+int		amltag(void *);
+void*		amlval(void *);
+uvlong		amlint(void *);
+int		amllen(void *);
+
+void*		amlnew(char tag, int len);
+
+void		amlinit(void);
+void		amlexit(void);
+
+int		amlload(uchar *data, int len);
+void*		amlwalk(void *dot, char *name);
+int		amleval(void *dot, char *fmt, ...);
+void		amlenum(void *dot, char *seg, int (*proc)(void *, void *), void *arg);
+
+/*
+ * exclude from garbage collection
+ */
+void		amltake(void *);
+void		amldrop(void *);
+
+void*		amlroot;
+int		amldebug;
+uvlong		amlintmask;
+
+#pragma	varargck	type	"V"	void*
+#pragma	varargck	type	"N"	void*
+
+/* to be provided by operating system */
+extern void*	amlalloc(int);
+extern void	amlfree(void*);
+
+extern void	amldelay(int);	/* microseconds */
+
+enum {
+	MemSpace	= 0x00,
+	IoSpace		= 0x01,
+	PcicfgSpace	= 0x02,
+	EbctlSpace	= 0x03,
+	SmbusSpace	= 0x04,
+	CmosSpace	= 0x05,
+	PcibarSpace	= 0x06,
+	IpmiSpace	= 0x07,
+};
+
+typedef struct Amlio Amlio;
+struct Amlio
+{
+	int	space;
+	uvlong	off;
+	uvlong	len;
+	void	*name;
+	uchar	*va;
+
+	void	*aux;
+	int	(*read)(Amlio *io, void *data, int len, int off);
+	int	(*write)(Amlio *io, void *data, int len, int off);
+};
+
+extern int	amlmapio(Amlio *io);
+extern void	amlunmapio(Amlio *io);
--- a/include/fis.h
+++ b/include/fis.h
@@ -1,5 +1,5 @@
 #pragma	lib	"libfis.a"
-#pragma	src	"/usr/inferno/libfis"
+#pragma	src	"/libfis"
 
 /* ata errors */
 enum {
--- a/libfis/fis.c
+++ b/libfis/fis.c
@@ -2,9 +2,8 @@
  * sata fises and sas frames
  * copyright © 2009-2010 erik quanstrom
  */
-#include <u.h>
-#include <libc.h>
-#include <fis.h>
+#include "lib9.h"
+#include "fis.h"
 
 static char *flagname[9] = {
 	"lba",
--- a/libinterp/ipint.c
+++ b/libinterp/ipint.c
@@ -1,10 +1,10 @@
 #include "lib9.h"
 #include "kernel.h"
-#include <isa.h>
+#include "isa.h"
 #include "interp.h"
 #include "runt.h"
-#include <mp.h>
-#include <libsec.h>
+#include "../include/mp.h"
+#include "libsec.h"
 #include "pool.h"
 #include "ipint.h"
 #include "raise.h"
--- a/libinterp/keyring.c
+++ b/libinterp/keyring.c
@@ -1,9 +1,9 @@
 #include "lib9.h"
 #include "kernel.h"
-#include <isa.h>
+#include "isa.h"
 #include "interp.h"
-#include <mp.h>
-#include <libsec.h>
+#include "../include/mp.h"
+#include "libsec.h"
 #include "pool.h"
 #include "raise.h"
 
--- a/libkeyring/dsaalg.c
+++ b/libkeyring/dsaalg.c
@@ -1,9 +1,9 @@
-#include <lib9.h>
-#include <kernel.h>
-#include <isa.h>
+#include "lib9.h"
+#include "kernel.h"
+#include "isa.h"
 #include "interp.h"
 #include "../libinterp/keyringif.h"
-#include "mp.h"
+#include "../include/mp.h"
 #include "libsec.h"
 #include "keys.h"
 
--- a/libkeyring/egalg.c
+++ b/libkeyring/egalg.c
@@ -1,9 +1,9 @@
-#include <lib9.h>
-#include <kernel.h>
-#include <isa.h>
+#include "lib9.h"
+#include "kernel.h"
+#include "isa.h"
 #include "interp.h"
 #include "../libinterp/keyringif.h"
-#include "mp.h"
+#include "../include/mp.h"
 #include "libsec.h"
 #include "keys.h"
 
--- a/libkeyring/rsaalg.c
+++ b/libkeyring/rsaalg.c
@@ -1,9 +1,9 @@
-#include <lib9.h>
-#include <kernel.h>
-#include <isa.h>
+#include "lib9.h"
+#include "kernel.h"
+#include "isa.h"
 #include "interp.h"
 #include "../libinterp/keyringif.h"
-#include "mp.h"
+#include "../include/mp.h"
 #include "libsec.h"
 #include "keys.h"
 
--- a/libmemdraw/draw.c
+++ b/libmemdraw/draw.c
@@ -1640,7 +1640,7 @@
 writebyte(Param *p, uchar *w, Buffer src)
 {
 	Memimage *img;
-	int i, isalpha, isgrey, nb, delta, dx, adelta;
+	int i, isalph, isgrey, nb, delta, dx, adelta;
 	uchar ff, *red, *grn, *blu, *grey, *alpha;
 	u32 u, mask;
 
@@ -1657,11 +1657,11 @@
 	nb = img->depth/8;
 	mask = (nb==4) ? 0 : ~((1<<img->depth)-1);
 
-	isalpha = img->flags&Falpha;
+	isalph = img->flags&Falpha;
 	isgrey = img->flags&Fgrey;
 	adelta = src.delta;
 
-	if(isalpha && (alpha == nil || alpha == &ones)){
+	if(isalph && (alpha == nil || alpha == &ones)){
 		ff = 0xFF;
 		alpha = &ff;
 		adelta = 0;
@@ -1686,7 +1686,7 @@
 DBG print("|rgb %.8ux...", u);
 		}
 
-		if(isalpha){
+		if(isalph){
 			u |= ((*alpha >> (8-img->nbits[CAlpha])) & img->mask[CAlpha]) << img->shift[CAlpha];
 			alpha += adelta;
 DBG print("|alpha %.8ux...", u);
--- a/libmp/port/betomp.c
+++ b/libmp/port/betomp.c
@@ -1,5 +1,5 @@
 #include "os.h"
-#include <mp.h>
+#include "../include/mp.h"
 #include "dat.h"
 
 // convert a big-endian byte array (most significant byte first) to an mpint
--- a/libmp/port/cnfield.c
+++ b/libmp/port/cnfield.c
@@ -1,5 +1,5 @@
 #include "os.h"
-#include <mp.h>
+#include "../include/mp.h"
 #include "dat.h"
 
 /*
--- a/libmp/port/crt.c
+++ b/libmp/port/crt.c
@@ -1,5 +1,5 @@
 #include "os.h"
-#include <mp.h>
+#include "../include/mp.h"
 #include <libsec.h>
 
 // chinese remainder theorem
--- a/libmp/port/crttest.c
+++ b/libmp/port/crttest.c
@@ -1,5 +1,5 @@
 #include "os.h"
-#include <mp.h>
+#include "../include/mp.h"
 #include <libsec.h>
 
 void
--- a/libmp/port/gmfield.c
+++ b/libmp/port/gmfield.c
@@ -1,5 +1,5 @@
 #include "os.h"
-#include <mp.h>
+#include "../include/mp.h"
 #include "dat.h"
 
 /*
--- a/libmp/port/letomp.c
+++ b/libmp/port/letomp.c
@@ -1,5 +1,5 @@
 #include "os.h"
-#include <mp.h>
+#include "../include/mp.h"
 #include "dat.h"
 
 // convert a little endian byte array (least significant byte first) to an mpint
--- a/libmp/port/mpadd.c
+++ b/libmp/port/mpadd.c
@@ -1,5 +1,5 @@
 #include "os.h"
-#include <mp.h>
+#include "../include/mp.h"
 #include "dat.h"
 
 // sum = abs(b1) + abs(b2), i.e., add the magnitudes
--- a/libmp/port/mpaux.c
+++ b/libmp/port/mpaux.c
@@ -1,5 +1,5 @@
 #include "os.h"
-#include <mp.h>
+#include "../include/mp.h"
 #include "dat.h"
 
 static mpdigit _mptwodata[1] = { 2 };
--- a/libmp/port/mpcmp.c
+++ b/libmp/port/mpcmp.c
@@ -1,5 +1,5 @@
 #include "os.h"
-#include <mp.h>
+#include "../include/mp.h"
 #include "dat.h"
 
 // return neg, 0, pos as abs(b1)-abs(b2) is neg, 0, pos
--- a/libmp/port/mpdigdiv.c
+++ b/libmp/port/mpdigdiv.c
@@ -1,5 +1,5 @@
 #include "os.h"
-#include <mp.h>
+#include "../include/mp.h"
 #include "dat.h"
 
 //
--- a/libmp/port/mpdiv.c
+++ b/libmp/port/mpdiv.c
@@ -1,5 +1,5 @@
 #include "os.h"
-#include <mp.h>
+#include "../include/mp.h"
 #include "dat.h"
 
 // division ala knuth, seminumerical algorithms, pp 237-238
--- a/libmp/port/mpeuclid.c
+++ b/libmp/port/mpeuclid.c
@@ -1,5 +1,5 @@
 #include "os.h"
-#include <mp.h>
+#include "../include/mp.h"
 
 // extended euclid
 //
--- a/libmp/port/mpexp.c
+++ b/libmp/port/mpexp.c
@@ -1,5 +1,5 @@
 #include "os.h"
-#include <mp.h>
+#include "../include/mp.h"
 #include "dat.h"
 
 // res = b**e
--- a/libmp/port/mpextendedgcd.c
+++ b/libmp/port/mpextendedgcd.c
@@ -1,5 +1,5 @@
 #include "os.h"
-#include <mp.h>
+#include "../include/mp.h"
 
 #define iseven(a)	(((a)->p[0] & 1) == 0)
 
--- a/libmp/port/mpfactorial.c
+++ b/libmp/port/mpfactorial.c
@@ -1,5 +1,5 @@
 #include "os.h"
-#include <mp.h>
+#include "../include/mp.h"
 #include <libsec.h>
 #include "dat.h"
 
--- a/libmp/port/mpfield.c
+++ b/libmp/port/mpfield.c
@@ -1,5 +1,5 @@
 #include "os.h"
-#include <mp.h>
+#include "../include/mp.h"
 #include "dat.h"
 
 mpint*
--- a/libmp/port/mpfmt.c
+++ b/libmp/port/mpfmt.c
@@ -1,5 +1,5 @@
 #include "os.h"
-#include <mp.h>
+#include "../include/mp.h"
 #include <libsec.h>
 #include "dat.h"
 
--- a/libmp/port/mpinvert.c
+++ b/libmp/port/mpinvert.c
@@ -1,5 +1,5 @@
 #include "os.h"
-#include <mp.h>
+#include "../include/mp.h"
 
 #define iseven(a)	(((a)->p[0] & 1) == 0)
 
--- a/libmp/port/mpleft.c
+++ b/libmp/port/mpleft.c
@@ -1,5 +1,5 @@
 #include "os.h"
-#include <mp.h>
+#include "../include/mp.h"
 #include "dat.h"
 
 // res = b << shift
--- a/libmp/port/mplogic.c
+++ b/libmp/port/mplogic.c
@@ -1,5 +1,5 @@
 #include "os.h"
-#include <mp.h>
+#include "../include/mp.h"
 #include "dat.h"
 
 /*
--- a/libmp/port/mpmod.c
+++ b/libmp/port/mpmod.c
@@ -1,5 +1,5 @@
 #include "os.h"
-#include <mp.h>
+#include "../include/mp.h"
 #include "dat.h"
 
 // remainder = b mod m
--- a/libmp/port/mpmodop.c
+++ b/libmp/port/mpmodop.c
@@ -1,5 +1,5 @@
 #include "os.h"
-#include <mp.h>
+#include "../include/mp.h"
 
 /* operands need to have m->top+1 digits of space and satisfy 0 ≤ a ≤ m-1 */
 static mpint*
--- a/libmp/port/mpmul.c
+++ b/libmp/port/mpmul.c
@@ -1,5 +1,5 @@
 #include "os.h"
-#include <mp.h>
+#include "../include/mp.h"
 #include "dat.h"
 
 //
--- a/libmp/port/mprand.c
+++ b/libmp/port/mprand.c
@@ -1,5 +1,5 @@
 #include "os.h"
-#include <mp.h>
+#include "../include/mp.h"
 #include <libsec.h>
 #include "dat.h"
 
--- a/libmp/port/mpright.c
+++ b/libmp/port/mpright.c
@@ -1,5 +1,5 @@
 #include "os.h"
-#include <mp.h>
+#include "../include/mp.h"
 #include "dat.h"
 
 // res = b >> shift
--- a/libmp/port/mpsel.c
+++ b/libmp/port/mpsel.c
@@ -1,5 +1,5 @@
 #include "os.h"
-#include <mp.h>
+#include "../include/mp.h"
 #include "dat.h"
 
 // res = s != 0 ? b1 : b2
--- a/libmp/port/mpsub.c
+++ b/libmp/port/mpsub.c
@@ -1,5 +1,5 @@
 #include "os.h"
-#include <mp.h>
+#include "../include/mp.h"
 #include "dat.h"
 
 // diff = abs(b1) - abs(b2), i.e., subtract the magnitudes
--- a/libmp/port/mptobe.c
+++ b/libmp/port/mptobe.c
@@ -1,5 +1,5 @@
 #include "os.h"
-#include <mp.h>
+#include "../include/mp.h"
 #include "dat.h"
 
 // convert an mpint into a big endian byte array (most significant byte first)
--- a/libmp/port/mptober.c
+++ b/libmp/port/mptober.c
@@ -1,5 +1,5 @@
 #include "os.h"
-#include <mp.h>
+#include "../include/mp.h"
 #include "dat.h"
 
 void
--- a/libmp/port/mptod.c
+++ b/libmp/port/mptod.c
@@ -1,5 +1,5 @@
 #include "os.h"
-#include <mp.h>
+#include "../include/mp.h"
 #include "dat.h"
 
 double
--- a/libmp/port/mptoi.c
+++ b/libmp/port/mptoi.c
@@ -1,5 +1,5 @@
 #include "os.h"
-#include <mp.h>
+#include "../include/mp.h"
 #include "dat.h"
 
 /*
--- a/libmp/port/mptole.c
+++ b/libmp/port/mptole.c
@@ -1,5 +1,5 @@
 #include "os.h"
-#include <mp.h>
+#include "../include/mp.h"
 #include "dat.h"
 
 // convert an mpint into a little endian byte array (least significant byte first)
--- a/libmp/port/mptolel.c
+++ b/libmp/port/mptolel.c
@@ -1,5 +1,5 @@
 #include "os.h"
-#include <mp.h>
+#include "../include/mp.h"
 #include "dat.h"
 
 void
--- a/libmp/port/mptoui.c
+++ b/libmp/port/mptoui.c
@@ -1,5 +1,5 @@
 #include "os.h"
-#include <mp.h>
+#include "../include/mp.h"
 #include "dat.h"
 
 /*
--- a/libmp/port/mptouv.c
+++ b/libmp/port/mptouv.c
@@ -1,5 +1,5 @@
 #include "os.h"
-#include <mp.h>
+#include "../include/mp.h"
 #include "dat.h"
 
 #define VLDIGITS (sizeof(vlong)/sizeof(mpdigit))
--- a/libmp/port/mptov.c
+++ b/libmp/port/mptov.c
@@ -1,5 +1,5 @@
 #include "os.h"
-#include <mp.h>
+#include "../include/mp.h"
 #include "dat.h"
 
 #define VLDIGITS (sizeof(vlong)/sizeof(mpdigit))
--- a/libmp/port/mpvecadd.c
+++ b/libmp/port/mpvecadd.c
@@ -1,5 +1,5 @@
 #include "os.h"
-#include <mp.h>
+#include "../include/mp.h"
 #include "dat.h"
 
 // prereq: alen >= blen, sum has at least blen+1 digits
--- a/libmp/port/mpveccmp.c
+++ b/libmp/port/mpveccmp.c
@@ -1,5 +1,5 @@
 #include "os.h"
-#include <mp.h>
+#include "../include/mp.h"
 #include "dat.h"
 
 int
--- a/libmp/port/mpvecdigmuladd.c
+++ b/libmp/port/mpvecdigmuladd.c
@@ -1,5 +1,5 @@
 #include "os.h"
-#include <mp.h>
+#include "../include/mp.h"
 #include "dat.h"
 
 #define LO(x) ((x) & ((1<<(Dbits/2))-1))
--- a/libmp/port/mpvecsub.c
+++ b/libmp/port/mpvecsub.c
@@ -1,5 +1,5 @@
 #include "os.h"
-#include <mp.h>
+#include "../include/mp.h"
 #include "dat.h"
 
 // prereq: a >= b, alen >= blen, diff has at least alen digits
--- a/libmp/port/os.h
+++ b/libmp/port/os.h
@@ -1,3 +1,3 @@
-#include <lib9.h>
+#include "lib9.h"
 extern ulong truerand(void);
 extern vlong nsec(void);
--- a/libmp/port/strtomp.c
+++ b/libmp/port/strtomp.c
@@ -1,5 +1,5 @@
 #include "os.h"
-#include <mp.h>
+#include "../include/mp.h"
 #include <libsec.h>
 #include "dat.h"
 
--- a/libsec/port/aes.c
+++ b/libsec/port/aes.c
@@ -29,7 +29,7 @@
  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 #include "os.h"
-#include <libsec.h>
+#include "libsec.h"
 
 #define GETU32(pt) (((u32)(pt)[0]<<24) ^ ((u32)(pt)[1]<<16) ^ \
 		    ((u32)(pt)[2]<< 8) ^ ((u32)(pt)[3]))
--- a/libsec/port/aesCBC.c
+++ b/libsec/port/aesCBC.c
@@ -1,5 +1,5 @@
 #include "os.h"
-#include <libsec.h>
+#include "libsec.h"
 
 /*
  * Define by analogy with desCBCencrypt;  AES modes are not standardized yet.
--- a/libsec/port/aesCFB.c
+++ b/libsec/port/aesCFB.c
@@ -1,5 +1,5 @@
 #include "os.h"
-#include <libsec.h>
+#include "libsec.h"
 
 void
 aesCFBencrypt(uchar *p, int len, AESstate *s)
--- a/libsec/port/aesOFB.c
+++ b/libsec/port/aesOFB.c
@@ -1,5 +1,5 @@
 #include "os.h"
-#include <libsec.h>
+#include "libsec.h"
 
 void
 aesOFBencrypt(uchar *p, int len, AESstate *s)
--- a/libsec/port/aesXCBmac.c
+++ b/libsec/port/aesXCBmac.c
@@ -1,5 +1,5 @@
 #include "os.h"
-#include <libsec.h>
+#include "libsec.h"
 
 /*
  * AES-XCBC-MAC-96 message authentication, per rfc3566.
--- a/libsec/port/aes_gcm.c
+++ b/libsec/port/aes_gcm.c
@@ -1,5 +1,5 @@
 #include "os.h"
-#include <libsec.h>
+#include "libsec.h"
 
 static void
 load128(uchar b[16], u32 W[4])
--- a/libsec/port/aes_xts.c
+++ b/libsec/port/aes_xts.c
@@ -1,5 +1,5 @@
 #include "os.h"
-#include <libsec.h>
+#include "libsec.h"
 
 /* little-endian data order */
 #define	GET4(p)		((p)[0]|((p)[1]<<8)|((p)[2]<<16)|((p)[3]<<24))
--- a/libsec/port/aesgcmtest.c
+++ b/libsec/port/aesgcmtest.c
@@ -1,7 +1,7 @@
 #include <u.h>
 #include <libc.h>
-#include <mp.h>
-#include <libsec.h>
+#include "../include/mp.h"
+#include "libsec.h"
 
 typedef struct Test Test;
 struct Test
--- a/libsec/port/bftest.c
+++ b/libsec/port/bftest.c
@@ -1,6 +1,6 @@
 #include <u.h>
 #include <libc.h>
-#include <libsec.h>
+#include "libsec.h"
 
 enum{
 	Bsz = 8,
--- a/libsec/port/blowfish.c
+++ b/libsec/port/blowfish.c
@@ -1,5 +1,5 @@
 #include "os.h"
-#include <libsec.h>
+#include "libsec.h"
 
 // Blowfish block cipher.  See:
 // 	Lecture Notes in Computer Science 809
--- a/libsec/port/ccpoly.c
+++ b/libsec/port/ccpoly.c
@@ -1,5 +1,5 @@
 #include "os.h"
-#include <libsec.h>
+#include "libsec.h"
 
 static void
 ccpolyotk(Chachastate *cs, DigestState *ds)
--- a/libsec/port/chacha.c
+++ b/libsec/port/chacha.c
@@ -8,7 +8,7 @@
 */
 
 #include "os.h"
-#include <libsec.h>
+#include "libsec.h"
 
 /* from chachablock.$O */
 extern void _chachablock(u32int x[16], int rounds);
--- a/libsec/port/chachatest.c
+++ b/libsec/port/chachatest.c
@@ -1,6 +1,6 @@
 #include <u.h>
 #include <libc.h>
-#include <libsec.h>
+#include "libsec.h"
 
 static void
 printblock(uchar *b, usize n)
--- a/libsec/port/curve25519.c
+++ b/libsec/port/curve25519.c
@@ -46,7 +46,7 @@
  * from the sample implementation.
  */
 #include "os.h"
-#include <libsec.h>
+#include "libsec.h"
 
 typedef vlong felem;
 
--- a/libsec/port/curve25519_dh.c
+++ b/libsec/port/curve25519_dh.c
@@ -1,6 +1,6 @@
 #include "os.h"
-#include <mp.h>
-#include <libsec.h>
+#include "../include/mp.h"
+#include "libsec.h"
 
 static uchar nine[32] = {9};
 static uchar zero[32] = {0};
--- a/libsec/port/decodepem.c
+++ b/libsec/port/decodepem.c
@@ -1,5 +1,5 @@
 #include "os.h"
-#include <libsec.h>
+#include "libsec.h"
 
 #define STRLEN(s)	(sizeof(s)-1)
 
--- a/libsec/port/des.c
+++ b/libsec/port/des.c
@@ -1,5 +1,5 @@
 #include "os.h"
-#include <libsec.h>
+#include "libsec.h"
 
 /*
  * integrated sbox & p perm
--- a/libsec/port/des3CBC.c
+++ b/libsec/port/des3CBC.c
@@ -1,5 +1,5 @@
 #include "os.h"
-#include <libsec.h>
+#include "libsec.h"
 
 // Because of the way that non multiple of 8
 // buffers are handled, the decryptor must
--- a/libsec/port/des3ECB.c
+++ b/libsec/port/des3ECB.c
@@ -1,5 +1,5 @@
 #include "os.h"
-#include <libsec.h>
+#include "libsec.h"
 
 // I wasn't sure what to do when the buffer was not
 // a multiple of 8.  I did what lacy's cryptolib did
--- a/libsec/port/desCBC.c
+++ b/libsec/port/desCBC.c
@@ -1,5 +1,5 @@
 #include "os.h"
-#include <libsec.h>
+#include "libsec.h"
 
 // Because of the way that non multiple of 8
 // buffers are handled, the decryptor must
--- a/libsec/port/desECB.c
+++ b/libsec/port/desECB.c
@@ -1,5 +1,5 @@
 #include "os.h"
-#include <libsec.h>
+#include "libsec.h"
 
 // I wasn't sure what to do when the buffer was not
 // a multiple of 8.  I did what lacy's cryptolib did
--- a/libsec/port/desmodes.c
+++ b/libsec/port/desmodes.c
@@ -1,5 +1,5 @@
 #include "os.h"
-#include <libsec.h>
+#include "libsec.h"
 
 /*
  *  these routines use the 64bit format for
--- a/libsec/port/dh.c
+++ b/libsec/port/dh.c
@@ -1,6 +1,6 @@
 #include "os.h"
-#include <mp.h>
-#include <libsec.h>
+#include "../include/mp.h"
+#include "libsec.h"
 
 mpint*
 dh_new(DHstate *dh, mpint *p, mpint *q, mpint *g)
--- a/libsec/port/dsaalloc.c
+++ b/libsec/port/dsaalloc.c
@@ -1,6 +1,6 @@
 #include "os.h"
-#include <mp.h>
-#include <libsec.h>
+#include "../include/mp.h"
+#include "libsec.h"
 
 DSApub*
 dsapuballoc(void)
--- a/libsec/port/dsagen.c
+++ b/libsec/port/dsagen.c
@@ -1,6 +1,6 @@
 #include "os.h"
-#include <mp.h>
-#include <libsec.h>
+#include "../include/mp.h"
+#include "libsec.h"
 
 DSApriv*
 dsagen(DSApub *opub)
--- a/libsec/port/dsaprimes.c
+++ b/libsec/port/dsaprimes.c
@@ -1,6 +1,6 @@
 #include "os.h"
-#include <mp.h>
-#include <libsec.h>
+#include "../include/mp.h"
+#include "libsec.h"
 
 // NIST algorithm for generating DSA primes
 // Menezes et al (1997) Handbook of Applied Cryptography, p.151
--- a/libsec/port/dsaprivtopub.c
+++ b/libsec/port/dsaprivtopub.c
@@ -1,6 +1,6 @@
 #include "os.h"
-#include <mp.h>
-#include <libsec.h>
+#include "../include/mp.h"
+#include "libsec.h"
 
 DSApub*
 dsaprivtopub(DSApriv *priv)
--- a/libsec/port/dsasign.c
+++ b/libsec/port/dsasign.c
@@ -1,6 +1,6 @@
 #include "os.h"
-#include <mp.h>
-#include <libsec.h>
+#include "../include/mp.h"
+#include "libsec.h"
 
 DSAsig*
 dsasign(DSApriv *priv, mpint *m)
--- a/libsec/port/dsaverify.c
+++ b/libsec/port/dsaverify.c
@@ -1,6 +1,6 @@
 #include "os.h"
-#include <mp.h>
-#include <libsec.h>
+#include "../include/mp.h"
+#include "libsec.h"
 
 int
 dsaverify(DSApub *pub, DSAsig *sig, mpint *m)
--- a/libsec/port/ecc.c
+++ b/libsec/port/ecc.c
@@ -1,6 +1,6 @@
 #include "os.h"
-#include <mp.h>
-#include <libsec.h>
+#include "../include/mp.h"
+#include "libsec.h"
 #include <ctype.h>
 
 extern void jacobian_affine(mpint *p,
--- a/libsec/port/egalloc.c
+++ b/libsec/port/egalloc.c
@@ -1,6 +1,6 @@
 #include "os.h"
-#include <mp.h>
-#include <libsec.h>
+#include "../include/mp.h"
+#include "libsec.h"
 
 EGpub*
 egpuballoc(void)
--- a/libsec/port/egdecrypt.c
+++ b/libsec/port/egdecrypt.c
@@ -1,6 +1,6 @@
 #include "os.h"
-#include <mp.h>
-#include <libsec.h>
+#include "../include/mp.h"
+#include "libsec.h"
 
 mpint*
 egdecrypt(EGpriv *priv, mpint *in, mpint *out)
--- a/libsec/port/egencrypt.c
+++ b/libsec/port/egencrypt.c
@@ -1,6 +1,6 @@
 #include "os.h"
-#include <mp.h>
-#include <libsec.h>
+#include "../include/mp.h"
+#include "libsec.h"
 
 mpint*
 egencrypt(EGpub *pub, mpint *in, mpint *out)
--- a/libsec/port/eggen.c
+++ b/libsec/port/eggen.c
@@ -1,6 +1,6 @@
 #include "os.h"
-#include <mp.h>
-#include <libsec.h>
+#include "../include/mp.h"
+#include "libsec.h"
 
 EGpriv*
 eggen(int nlen, int rounds)
--- a/libsec/port/egprivtopub.c
+++ b/libsec/port/egprivtopub.c
@@ -1,6 +1,6 @@
 #include "os.h"
-#include <mp.h>
-#include <libsec.h>
+#include "../include/mp.h"
+#include "libsec.h"
 
 EGpub*
 egprivtopub(EGpriv *priv)
--- a/libsec/port/egsign.c
+++ b/libsec/port/egsign.c
@@ -1,6 +1,6 @@
 #include "os.h"
-#include <mp.h>
-#include <libsec.h>
+#include "../include/mp.h"
+#include "libsec.h"
 
 EGsig*
 egsign(EGpriv *priv, mpint *m)
--- a/libsec/port/egtest.c
+++ b/libsec/port/egtest.c
@@ -1,6 +1,6 @@
 #include "os.h"
-#include <mp.h>
-#include <libsec.h>
+#include "../include/mp.h"
+#include "libsec.h"
 
 void
 main(void)
--- a/libsec/port/egverify.c
+++ b/libsec/port/egverify.c
@@ -1,6 +1,6 @@
 #include "os.h"
-#include <mp.h>
-#include <libsec.h>
+#include "../include/mp.h"
+#include "libsec.h"
 
 int
 egverify(EGpub *pub, EGsig *sig, mpint *m)
--- a/libsec/port/fastrand.c
+++ b/libsec/port/fastrand.c
@@ -1,5 +1,5 @@
 #include "os.h"
-#include <libsec.h>
+#include "libsec.h"
 
 /* 
  *  use the X917 random number generator to create random
--- a/libsec/port/genprime.c
+++ b/libsec/port/genprime.c
@@ -1,6 +1,6 @@
 #include "os.h"
-#include <mp.h>
-#include <libsec.h>
+#include "../include/mp.h"
+#include "libsec.h"
 
 //  generate a probable prime.  accuracy is the miller-rabin interations
 void
--- a/libsec/port/genrandom.c
+++ b/libsec/port/genrandom.c
@@ -1,5 +1,5 @@
 #include "os.h"
-#include <libsec.h>
+#include "libsec.h"
 
 extern	s32	getpid(void);
 
@@ -31,7 +31,7 @@
 	memset(&c, 0, sizeof(c));
 }
 
-void
+/*void
 genrandom(uchar *p, int n)
 {
 	static QLock lk;
@@ -40,7 +40,7 @@
 	qlock(&lk);
 	if(cs.rounds == 0)
 		init(&cs);
-	cs.input[4] ^= getpid();	/* fork protection */
+	cs.input[4] ^= getpid();	*//* fork protection *//*
 	fill(&cs, p, n);
 	qunlock(&lk);
-}
+}*/
--- a/libsec/port/gensafeprime.c
+++ b/libsec/port/gensafeprime.c
@@ -1,6 +1,6 @@
 #include "os.h"
-#include <mp.h>
-#include <libsec.h>
+#include "../include/mp.h"
+#include "libsec.h"
 
 // find a prime p of length n and a generator alpha of Z^*_p
 // Alg 4.86 Menezes et al () Handbook, p.164
--- a/libsec/port/genstrongprime.c
+++ b/libsec/port/genstrongprime.c
@@ -1,6 +1,6 @@
 #include "os.h"
-#include <mp.h>
-#include <libsec.h>
+#include "../include/mp.h"
+#include "libsec.h"
 
 // Gordon's algorithm for generating a strong prime
 //	Menezes et al () Handbook, p.150
--- a/libsec/port/hkdf.c
+++ b/libsec/port/hkdf.c
@@ -1,5 +1,5 @@
 #include "os.h"
-#include <libsec.h>
+#include "libsec.h"
 
 /* rfc5869 */
 void
--- a/libsec/port/hmac.c
+++ b/libsec/port/hmac.c
@@ -1,5 +1,5 @@
 #include "os.h"
-#include <libsec.h>
+#include "libsec.h"
 
 /* rfc2104 */
 DigestState*
--- a/libsec/port/hmactest.c
+++ b/libsec/port/hmactest.c
@@ -1,6 +1,6 @@
 #include "os.h"
-#include <mp.h>
-#include <libsec.h>
+#include "../include/mp.h"
+#include "libsec.h"
 
 uchar key[] = "Jefe";
 uchar data[] = "what do ya want for nothing?";
--- a/libsec/port/idea.c
+++ b/libsec/port/idea.c
@@ -1,5 +1,5 @@
 #include "os.h"
-#include "mp.h"
+#include "../include/mp.h"
 #include "libsec.h"
 
 #define KEYLEN	52
--- a/libsec/port/jacobian.c
+++ b/libsec/port/jacobian.c
@@ -1,5 +1,5 @@
 #include "os.h"
-#include <mp.h>
+#include "../include/mp.h"
 void jacobian_new(mpint *x, mpint *y, mpint *z, mpint *X, mpint *Y, mpint *Z){
 	mpassign(x, X);
 	mpassign(y, Y);
--- a/libsec/port/md4.c
+++ b/libsec/port/md4.c
@@ -1,5 +1,5 @@
 #include "os.h"
-#include <libsec.h>
+#include "libsec.h"
 
 /*
  *  This MD4 is implemented from the description in Stinson's Cryptography,
--- a/libsec/port/md4test.c
+++ b/libsec/port/md4test.c
@@ -1,6 +1,6 @@
 #include "os.h"
-#include <mp.h>
-#include <libsec.h>
+#include "../include/mp.h"
+#include "libsec.h"
 
 char *tests[] = {
 	"",
--- a/libsec/port/md5.c
+++ b/libsec/port/md5.c
@@ -1,5 +1,5 @@
 #include "os.h"
-#include <libsec.h>
+#include "libsec.h"
 
 /*
  *  rfc1321 requires that I include this.  The code is new.  The constants
--- a/libsec/port/md5block.c
+++ b/libsec/port/md5block.c
@@ -1,5 +1,5 @@
 #include "os.h"
-#include <libsec.h>
+#include "libsec.h"
 
 /*
  *  rfc1321 requires that I include this.  The code is new.  The constants
--- a/libsec/port/md5pickle.c
+++ b/libsec/port/md5pickle.c
@@ -1,5 +1,5 @@
 #include "os.h"
-#include <libsec.h>
+#include "libsec.h"
 
 char*
 md5pickle(MD5state *s)
--- a/libsec/port/nfastrand.c
+++ b/libsec/port/nfastrand.c
@@ -1,5 +1,5 @@
 #include "os.h"
-#include <libsec.h>
+#include "libsec.h"
 
 #define Maxrand	((1UL<<31)-1)
 
--- a/libsec/port/pbkdf2.c
+++ b/libsec/port/pbkdf2.c
@@ -1,5 +1,5 @@
 #include "os.h"
-#include <libsec.h>
+#include "libsec.h"
 
 /* rfc2898 */
 void
--- a/libsec/port/poly1305.c
+++ b/libsec/port/poly1305.c
@@ -1,5 +1,5 @@
 #include "os.h"
-#include <libsec.h>
+#include "libsec.h"
 
 /*
 	poly1305 implementation using 32 bit * 32 bit = 64 bit multiplication and 64 bit addition
--- a/libsec/port/primetest.c
+++ b/libsec/port/primetest.c
@@ -1,6 +1,6 @@
 #include "os.h"
-#include <mp.h>
-#include <libsec.h>
+#include "../include/mp.h"
+#include "libsec.h"
 
 void
 main(void)
--- a/libsec/port/prng.c
+++ b/libsec/port/prng.c
@@ -1,5 +1,5 @@
 #include "os.h"
-#include <libsec.h>
+#include "libsec.h"
 
 //
 //  just use the libc prng to fill a buffer
--- a/libsec/port/probably_prime.c
+++ b/libsec/port/probably_prime.c
@@ -1,6 +1,6 @@
 #include "os.h"
-#include <mp.h>
-#include <libsec.h>
+#include "../include/mp.h"
+#include "libsec.h"
 
 /*
  * Miller-Rabin probabilistic primality testing
--- a/libsec/port/rc4.c
+++ b/libsec/port/rc4.c
@@ -1,5 +1,5 @@
 #include "os.h"
-#include <libsec.h>
+#include "libsec.h"
 
 void
 setupRC4state(RC4state *key, uchar *start, int n)
--- a/libsec/port/readcert.c
+++ b/libsec/port/readcert.c
@@ -1,5 +1,5 @@
 #include "os.h"
-#include <libsec.h>
+#include "libsec.h"
 
 static char*
 readfile(char *name)
--- a/libsec/port/ripemd.c
+++ b/libsec/port/ripemd.c
@@ -1,6 +1,6 @@
 #include "os.h"
 
-#include <libsec.h>
+#include "libsec.h"
 
 #define BYTES_TO_DWORD(strptr)                    \
             (((u32int) *((strptr)+3) << 24) | \
--- a/libsec/port/rsaalloc.c
+++ b/libsec/port/rsaalloc.c
@@ -1,6 +1,6 @@
 #include "os.h"
-#include <mp.h>
-#include <libsec.h>
+#include "../include/mp.h"
+#include "libsec.h"
 
 RSApub*
 rsapuballoc(void)
--- a/libsec/port/rsadecrypt.c
+++ b/libsec/port/rsadecrypt.c
@@ -1,6 +1,6 @@
 #include "os.h"
-#include <mp.h>
-#include <libsec.h>
+#include "../include/mp.h"
+#include "libsec.h"
 
 // decrypt rsa using garner's algorithm for the chinese remainder theorem
 //	seminumerical algorithms, knuth, pp 253-254
--- a/libsec/port/rsaencrypt.c
+++ b/libsec/port/rsaencrypt.c
@@ -1,6 +1,6 @@
 #include "os.h"
-#include <mp.h>
-#include <libsec.h>
+#include "../include/mp.h"
+#include "libsec.h"
 
 mpint*
 rsaencrypt(RSApub *rsa, mpint *in, mpint *out)
--- a/libsec/port/rsafill.c
+++ b/libsec/port/rsafill.c
@@ -1,6 +1,6 @@
 #include "os.h"
-#include <mp.h>
-#include <libsec.h>
+#include "../include/mp.h"
+#include "libsec.h"
 
 RSApriv*
 rsafill(mpint *n, mpint *e, mpint *d, mpint *p, mpint *q)
--- a/libsec/port/rsagen.c
+++ b/libsec/port/rsagen.c
@@ -1,6 +1,6 @@
 #include "os.h"
-#include <mp.h>
-#include <libsec.h>
+#include "../include/mp.h"
+#include "libsec.h"
 
 RSApriv*
 rsagen(int nlen, int elen, int rounds)
--- a/libsec/port/rsaprivtopub.c
+++ b/libsec/port/rsaprivtopub.c
@@ -1,6 +1,6 @@
 #include "os.h"
-#include <mp.h>
-#include <libsec.h>
+#include "../include/mp.h"
+#include "libsec.h"
 
 RSApub*
 rsaprivtopub(RSApriv *priv)
--- a/libsec/port/rsatest.c
+++ b/libsec/port/rsatest.c
@@ -1,6 +1,6 @@
 #include "os.h"
-#include <mp.h>
-#include <libsec.h>
+#include "../include/mp.h"
+#include "libsec.h"
 #include <bio.h>
 
 void
--- a/libsec/port/salsa.c
+++ b/libsec/port/salsa.c
@@ -1,5 +1,5 @@
 #include "os.h"
-#include <libsec.h>
+#include "libsec.h"
 
 /* little-endian data order */
 #define	GET4(p)		((p)[0]|((p)[1]<<8)|((p)[2]<<16)|((p)[3]<<24))
--- a/libsec/port/scrypt.c
+++ b/libsec/port/scrypt.c
@@ -1,5 +1,5 @@
 #include "os.h"
-#include <libsec.h>
+#include "libsec.h"
 
 #define movw(w, S, D)	memmove(D, S, (w)*4)
 
--- a/libsec/port/secp256k1.c
+++ b/libsec/port/secp256k1.c
@@ -1,5 +1,5 @@
 #include "os.h"
-#include <mp.h>
+#include "../include/mp.h"
 void secp256k1(mpint *p, mpint *a, mpint *b, mpint *x, mpint *y, mpint *n, mpint *h){
 	strtomp("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F", nil, 16, p);
 	mpassign(mpzero, a);
--- a/libsec/port/secp256r1.c
+++ b/libsec/port/secp256r1.c
@@ -1,5 +1,5 @@
 #include "os.h"
-#include <mp.h>
+#include "../include/mp.h"
 void secp256r1(mpint *p, mpint *a, mpint *b, mpint *x, mpint *y, mpint *n, mpint *h){
 	strtomp("FFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFF", nil, 16, p);
 	uitomp(3UL, a);
--- a/libsec/port/secp384r1.c
+++ b/libsec/port/secp384r1.c
@@ -1,5 +1,5 @@
 #include "os.h"
-#include <mp.h>
+#include "../include/mp.h"
 void secp384r1(mpint *p, mpint *a, mpint *b, mpint *x, mpint *y, mpint *n, mpint *h){
 	strtomp("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFF0000000000000000FFFFFFFF", nil, 16, p);
 	uitomp(3UL, a);
--- a/libsec/port/sha1.c
+++ b/libsec/port/sha1.c
@@ -1,5 +1,5 @@
 #include "os.h"
-#include <libsec.h>
+#include "libsec.h"
 
 static void encode(uchar*, u32int*, u32);
 
--- a/libsec/port/sha1pickle.c
+++ b/libsec/port/sha1pickle.c
@@ -1,5 +1,5 @@
 #include "os.h"
-#include <libsec.h>
+#include "libsec.h"
 
 char*
 sha1pickle(SHA1state *s)
--- a/libsec/port/sha2.c
+++ b/libsec/port/sha2.c
@@ -1,5 +1,5 @@
 #include "os.h"
-#include <libsec.h>
+#include "libsec.h"
 
 extern void _sha256block(SHA256state*, uchar*);
 extern void _sha512block(SHA512state*, uchar*);
--- a/libsec/port/sha256block.c
+++ b/libsec/port/sha256block.c
@@ -1,5 +1,5 @@
 #include "os.h"
-#include <libsec.h>
+#include "libsec.h"
 
 enum {
 	SHA256rounds =  64,
--- a/libsec/port/sha2_128.c
+++ b/libsec/port/sha2_128.c
@@ -3,7 +3,7 @@
  */
 #include <u.h>
 #include <libc.h>
-#include <libsec.h>
+#include "libsec.h"
 
 static void encode64(uchar*, u64int*, u32);
 static DigestState* sha2_128(uchar *, u32, uchar *, SHA2_256state *, int);
--- a/libsec/port/sha2_64.c
+++ b/libsec/port/sha2_64.c
@@ -3,7 +3,7 @@
  */
 #include <u.h>
 #include <libc.h>
-#include <libsec.h>
+#include "libsec.h"
 
 static void encode32(uchar*, u32int*, u32);
 static DigestState* sha2_64(uchar *, u32, uchar *, SHA2_256state *, int);
--- a/libsec/port/sha512block.c
+++ b/libsec/port/sha512block.c
@@ -1,5 +1,5 @@
 #include "os.h"
-#include <libsec.h>
+#include "libsec.h"
 
 
 enum {
--- a/libsec/port/smallprimetest.c
+++ b/libsec/port/smallprimetest.c
@@ -1,6 +1,6 @@
 #include "os.h"
-#include <mp.h>
-#include <libsec.h>
+#include "../include/mp.h"
+#include "libsec.h"
 
 static ulong smallprimes[] = {
 	2,	3,	5,	7,	11,	13,	17,	19,	23,	29,
--- a/libsec/port/thumb.c
+++ b/libsec/port/thumb.c
@@ -1,6 +1,6 @@
 #include "os.h"
 #include <bio.h>
-#include <libsec.h>
+#include "libsec.h"
 
 enum{ ThumbTab = 1<<10 };
 
--- a/libsec/port/tlshand.c
+++ b/libsec/port/tlshand.c
@@ -1,8 +1,8 @@
 #include <u.h>
 #include <libc.h>
 #include <auth.h>
-#include <mp.h>
-#include <libsec.h>
+#include "../include/mp.h"
+#include "libsec.h"
 
 // The main groups of functions are:
 //		client/server - main handshake protocol definition
--- a/libsec/port/tsmemcmp.c
+++ b/libsec/port/tsmemcmp.c
@@ -1,5 +1,5 @@
 #include "os.h"
-#include <libsec.h>
+#include "libsec.h"
 
 /*
  * timing safe memcmp()
--- a/libsec/port/x509.c
+++ b/libsec/port/x509.c
@@ -1,7 +1,7 @@
 #include <u.h>
 #include <libc.h>
-#include <mp.h>
-#include <libsec.h>
+#include "../include/mp.h"
+#include "libsec.h"
 
 /*=============================================================*/
 /*  general ASN1 declarations and parsing
--- a/os/pc/dat.h
+++ b/os/pc/dat.h
@@ -1,6 +1,10 @@
+typedef struct BIOS32si	BIOS32si;
+typedef struct BIOS32ci	BIOS32ci;
 typedef struct Conf	Conf;
-typedef struct FPU	FPU;
-typedef struct FPenv	FPenv;
+typedef union FPsave	FPsave;
+typedef struct FPx87state FPx87state;
+typedef struct FPssestate FPssestate;
+typedef struct PFPU	PFPU;
 typedef ulong Instr;
 typedef struct ISAConf	ISAConf;
 typedef struct Label	Label;
@@ -15,9 +19,13 @@
 typedef struct Page	Page;
 typedef struct PMMU	PMMU;
 typedef struct Segdesc	Segdesc;
+typedef struct Tss	Tss;
+typedef s64		Tval;
 typedef struct Ureg	Ureg;
 typedef struct Vctl	Vctl;
 
+#pragma incomplete BIOS32si
+#pragma incomplete Pcidev
 #pragma incomplete Ureg
 #pragma incomplete Vctl
 
@@ -24,10 +32,14 @@
 
 struct Lock
 {
-	ulong	key;
-	ulong	sr;
-	ulong	pc;
-	ulong	pri;
+	u32	key;
+	u32	sr;	/* value returned by splhi() */
+	uintptr	pc;	/* lock() caller */
+	u32	priority;
+	void *p;	/* Proc */
+	Mach *m;
+	u16 isilock;
+	u32 lockcycles;
 };
 
 struct Label
@@ -36,21 +48,8 @@
 	ulong	pc;
 };
 
-/*
- * FPenv.status
- */
-enum
+struct	FPx87state		/* x87 fp state */
 {
-	FPINIT,
-	FPACTIVE,
-	FPINACTIVE,
-};
-
-/*
- * This structure must agree with FPsave and FPrestore asm routines
- */
-struct FPenv
-{
 	ushort	control;
 	ushort	r1;
 	ushort	status;
@@ -59,21 +58,52 @@
 	ushort	r3;
 	ulong	pc;
 	ushort	selector;
-	ushort	r4;
+	ushort	opcode;
 	ulong	operand;
 	ushort	oselector;
-	ushort	r5;
+	ushort	r4;
+	uchar	regs[80];	/* floating point registers */
 };
 
-/*
- * This structure must agree with fpsave and fprestore asm routines
- */
-struct	FPU
+struct	FPssestate		/* SSE fp state */
 {
-	FPenv	env;
-	uchar	regs[80];	/* floating point registers */
+	ushort	fcw;		/* control */
+	ushort	fsw;		/* status */
+	ushort	ftw;		/* tag */
+	ushort	fop;		/* opcode */
+	ulong	fpuip;		/* pc */
+	ushort	cs;		/* pc segment */
+	ushort	rsrvd1;		/* reserved */
+	ulong	fpudp;		/* data pointer */
+	ushort	ds;		/* data pointer segment */
+	ushort	rsrvd2;
+	ulong	mxcsr;		/* MXCSR register state */
+	ulong	mxcsr_mask;	/* MXCSR mask register */
+	uchar	xregs[480];	/* extended registers */
 };
 
+union FPsave {
+	FPx87state;
+	FPssestate;
+};
+
+struct PFPU
+{
+	int	fpstate;
+	FPsave	*fpsave;
+};
+
+enum
+{
+	/* this is a state */
+	FPinit=		0,
+	FPactive=	1,
+	FPinactive=	2,
+
+	/* the following is a bit that can be or'd into the state */
+	FPillegal=	0x100,
+};
+
 struct Conf
 {
 	ulong	nmach;		/* processors */
@@ -90,9 +120,37 @@
 	int	nuart;		/* number of uart devices */
 };
 
+struct Segdesc
+{
+	ulong	d0;
+	ulong	d1;
+};
+
+/*
+ *  MMU stuff in proc
+ */
+#define NCOLOR 1
+#define	NPROCSEG	3	/* number of per process descriptors */
+struct PMMU
+{
+	Page*	mmupdb;			/* page directory base */
+	Page*	mmufree;		/* unused page table pages */
+	Page*	mmuused;		/* used page table pages */
+	Page*	kmaptable;		/* page table used by kmap */
+	uint	lastkmap;		/* last entry used by kmap */
+	int	nkmap;			/* number of current kmaps */
+
+	Segdesc	gdt[NPROCSEG];	/* per process descriptors */
+	Segdesc	*ldt;	/* local descriptor table */
+	int	nldt;	/* number of ldt descriptors allocated */
+	
+	u32int	dr[8];			/* debug registers */
+	void	*vmx;
+};
+
 #include "../port/portdat.h"
 
-typedef struct {
+typedef struct Tss {
 	ulong	link;			/* link (old TSS selector) */
 	ulong	esp0;			/* privilege level 0 stack pointer */
 	ulong	ss0;			/* privilege level 0 stack selector */
@@ -119,12 +177,6 @@
 	ulong	gs;
 	ulong	ldt;			/* selector for task's LDT */
 	ulong	iomap;			/* I/O map base address + T-bit */
-} Tss;
-
-struct Segdesc
-{
-	ulong	d0;
-	ulong	d1;
 };
 
 struct Mach
@@ -190,19 +242,23 @@
 struct PCArch
 {
 	char*	id;
-	int	(*ident)(void);		/* this should be in the model */
+	s32	(*ident)(void);		/* this should be in the model */
 	void	(*reset)(void);		/* this should be in the model */
-	int	(*serialpower)(int);	/* 1 == on, 0 == off */
-	int	(*modempower)(int);	/* 1 == on, 0 == off */
+	s32	(*serialpower)(s32);	/* 1 == on, 0 == off */
+	s32	(*modempower)(s32);	/* 1 == on, 0 == off */
 
 	void	(*intrinit)(void);
-	int	(*intrenable)(Vctl*);
-	int	(*intrvecno)(int);
-	int	(*intrdisable)(int);
+	s32	(*intrassign)(Vctl*);
+	s32	(*intrirqno)(s32, s32);
+	s32	(*intrvecno)(s32);
+	s32	(*intrspurious)(s32);
+	void	(*introff)(void);
+	void	(*intron)(void);
 
+	void	(*clockinit)(void);
 	void	(*clockenable)(void);
-	uvlong	(*fastclock)(uvlong*);
-	void	(*timerset)(uvlong);
+	u64	(*fastclock)(u64*);
+	void	(*timerset)(u64);
 };
 
 /*
@@ -256,3 +312,12 @@
 	int	nports;			/* Number of ports */
 	Devport	*ports;			/* The ports themselves */
 };
+
+typedef struct BIOS32ci {		/* BIOS32 Calling Interface */
+	u32	eax;
+	u32	ebx;
+	u32	ecx;
+	u32	edx;
+	u32	esi;
+	u32	edi;
+} BIOS32ci;
--- a/os/pc/devkbd.c
+++ b/os/pc/devkbd.c
@@ -196,6 +196,7 @@
 /*
  *  keyboard interrupt
  */
+char kickpanic[3] = {0};
 static void
 i8042intr(Ureg*, void*)
 {
--- a/os/pc/errstr.h
+++ /dev/null
@@ -1,61 +1,0 @@
-char Enoerror[] = "no error";
-char Emount[] = "inconsistent mount";
-char Eunmount[] = "not mounted";
-char Eunion[] = "not in union";
-char Emountrpc[] = "mount rpc error";
-char Eshutdown[] = "mounted device shut down";
-char Enocreate[] = "mounted directory forbids creation";
-char Enonexist[] = "file does not exist";
-char Eexist[] = "file already exists";
-char Ebadsharp[] = "unknown device in # filename";
-char Enotdir[] = "not a directory";
-char Eisdir[] = "file is a directory";
-char Ebadchar[] = "bad character in file name";
-char Efilename[] = "file name syntax";
-char Eperm[] = "permission denied";
-char Ebadusefd[] = "inappropriate use of fd";
-char Ebadarg[] = "bad arg in system call";
-char Einuse[] = "device or object already in use";
-char Eio[] = "i/o error";
-char Etoobig[] = "read or write too large";
-char Etoosmall[] = "read or write too small";
-char Enetaddr[] = "bad network address";
-char Emsgsize[] = "message is too big for protocol";
-char Enetbusy[] = "network device is busy or allocated";
-char Enoproto[] = "network protocol not supported";
-char Enoport[] = "network port not available";
-char Enoifc[] = "bad interface or no free interface slots";
-char Enolisten[] = "not announced";
-char Ehungup[] = "i/o on hungup channel";
-char Ebadctl[] = "bad process or channel control request";
-char Enodev[] = "no free devices";
-char Enoenv[] = "no free environment resources";
-char Ethread[] = "thread exited";
-char Estopped[] = "thread must be stopped";
-char Enochild[] = "no living children";
-char Eioload[] = "i/o error in demand load";
-char Enovmem[] = "out of memory: virtual memory";
-char Ebadld[] = "illegal line discipline";
-char Ebadfd[] = "fd out of range or not open";
-char Eisstream[] = "seek on a stream";
-char Ebadexec[] = "exec header invalid";
-char Etimedout[] = "connection timed out";
-char Econrefused[] = "connection refused";
-char Econinuse[] = "connection in use";
-char Eintr[] = "interrupted";
-char Eneedservice[] = "service required for tcp/udp/il calls";
-char Enomem[] = "out of memory: kernel";
-char Esfnotcached[] = "subfont not cached";
-char Esoverlap[] = "segments overlap";
-char Emouseset[] = "mouse type already set";
-char Erecover[] = "failed to recover fd";
-char Eshort[] = "i/o count too small";
-char Enobitstore[] = "out of screen memory";
-char Egreg[] = "jim'll fix it";
-char Ebadspec[] = "bad attach specifier";
-char Enoattach[] = "mount/attach disallowed";
-char Eshortstat[] = "stat buffer too small";
-char Enegoff[] = "negative i/o offset";
-char Ecmdargs[] = "wrong #args in control message";
-char Ebadstat[] = "malformed stat buffer";
-char	Enofd[] = "no free file descriptors";
--- a/os/pc/fns.h
+++ b/os/pc/fns.h
@@ -1,6 +1,6 @@
 #include "../port/portfns.h"
 void	aamloop(int);
-Dirtab*	addarchfile(char*, int, long(*)(Chan*,void*,long,vlong), long(*)(Chan*,void*,long,vlong));
+Dirtab*	addarchfile(char*, u32, s32(*)(Chan*,void*,s32,s64), s32(*)(Chan*,void*,s32,s64));
 void	archinit(void);
 void	bootargs(ulong);
 int	cistrcmp(char*, char*);
@@ -17,14 +17,14 @@
 int	dmadone(int);
 void	dmaend(int);
 int	dmainit(int, int);
-long	dmasetup(int, void*, long, int);
+s32	dmasetup(int, void*, s32, s32);
 void	dumpregs(Ureg*);
 #define	evenaddr(x)				/* x86 doesn't care */
+void	fpclear(void);
 void	fpinit(void);
 void	fpoff(void);
-void	fprestore(FPU*);
-void	fpsave(FPU*);
-ulong	fpstatus(void);
+void	(*fprestore)(FPsave*);
+void	(*fpsave)(FPsave*);
 u32	getcr0(void);
 u32	getcr2(void);
 u32	getcr3(void);
@@ -55,7 +55,7 @@
 void	inss(int, void*, int);
 ulong	inl(int);
 void	insl(int, void*, int);
-int	intrdisable(int, void (*)(Ureg *, void *), void*, int, char*);
+void	intrdisable(int, void (*)(Ureg *, void *), void*, int, char*);
 void	intrenable(int, void (*)(Ureg*, void*), void*, int, char*);
 void	iofree(int);
 void	ioinit(void);
@@ -86,8 +86,13 @@
 ulong	mmukmap(ulong, ulong, int);
 int	mmukmapsync(ulong);
 ulong*	mmuwalk(ulong*, ulong, int, int);
-uchar	nvramread(int);
-void	nvramwrite(int, uchar);
+char*	mtrr(u64, u64, char *);
+char*	mtrrattr(u64, u64 *);
+void	mtrrclock(void);
+int	mtrrprint(char *, s32);
+void	mtrrsync(void);
+uchar	nvramread(intptr);
+void	nvramwrite(intptr, uchar);
 void	outb(int, int);
 void	outsb(int, void*, int);
 void	outs(int, ushort);
@@ -94,8 +99,8 @@
 void	outss(int, void*, int);
 void	outl(int, ulong);
 void	outsl(int, void*, int);
-int	pciscan(int, Pcidev**);
-ulong	pcibarsize(Pcidev*, int);
+int	pciscan(int bno, Pcidev **list, Pcidev *parent);
+s32	pcibarsize(Pcidev*, int);
 int	pcicfgr8(Pcidev*, int);
 int	pcicfgr16(Pcidev*, int);
 int	pcicfgr32(Pcidev*, int);
--- a/os/pc/io.h
+++ b/os/pc/io.h
@@ -59,160 +59,10 @@
 } Vctl;
 
 enum {
-	BusCBUS		= 0,		/* Corollary CBUS */
-	BusCBUSII,			/* Corollary CBUS II */
-	BusEISA,			/* Extended ISA */
-	BusFUTURE,			/* IEEE Futurebus */
-	BusINTERN,			/* Internal bus */
-	BusISA,				/* Industry Standard Architecture */
-	BusMBI,				/* Multibus I */
-	BusMBII,			/* Multibus II */
-	BusMCA,				/* Micro Channel Architecture */
-	BusMPI,				/* MPI */
-	BusMPSA,			/* MPSA */
-	BusNUBUS,			/* Apple Macintosh NuBus */
-	BusPCI,				/* Peripheral Component Interconnect */
-	BusPCMCIA,			/* PC Memory Card International Association */
-	BusTC,				/* DEC TurboChannel */
-	BusVL,				/* VESA Local bus */
-	BusVME,				/* VMEbus */
-	BusXPRESS,			/* Express System Bus */
-};
-
-#define MKBUS(t,b,d,f)	(((t)<<24)|(((b)&0xFF)<<16)|(((d)&0x1F)<<11)|(((f)&0x07)<<8))
-#define BUSFNO(tbdf)	(((tbdf)>>8)&0x07)
-#define BUSDNO(tbdf)	(((tbdf)>>11)&0x1F)
-#define BUSBNO(tbdf)	(((tbdf)>>16)&0xFF)
-#define BUSTYPE(tbdf)	((tbdf)>>24)
-#define BUSBDF(tbdf)	((tbdf)&0x00FFFF00)
-#define BUSUNKNOWN	(-1)
-
-enum {
 	MaxEISA		= 16,
 	CfgEISA		= 0xC80,
 };
 
-/*
- * PCI support code.
- */
-enum {					/* type 0 & type 1 pre-defined header */
-	PciVID		= 0x00,		/* vendor ID */
-	PciDID		= 0x02,		/* device ID */
-	PciPCR		= 0x04,		/* command */
-	PciPSR		= 0x06,		/* status */
-	PciRID		= 0x08,		/* revision ID */
-	PciCCRp		= 0x09,		/* programming interface class code */
-	PciCCRu		= 0x0A,		/* sub-class code */
-	PciCCRb		= 0x0B,		/* base class code */
-	PciCLS		= 0x0C,		/* cache line size */
-	PciLTR		= 0x0D,		/* latency timer */
-	PciHDT		= 0x0E,		/* header type */
-	PciBST		= 0x0F,		/* BIST */
-
-	PciBAR0		= 0x10,		/* base address */
-	PciBAR1		= 0x14,
-
-	PciINTL		= 0x3C,		/* interrupt line */
-	PciINTP		= 0x3D,		/* interrupt pin */
-};
-
-/* ccrb (base class code) values; controller types */
-enum {
-	Pcibcpci1	= 0,		/* pci 1.0; no class codes defined */
-	Pcibcstore	= 1,		/* mass storage */
-	Pcibcnet	= 2,		/* network */
-	Pcibcdisp	= 3,		/* display */
-	Pcibcmmedia	= 4,		/* multimedia */
-	Pcibcmem	= 5,		/* memory */
-	Pcibcbridge	= 6,		/* bridge */
-	Pcibccomm	= 7,		/* simple comms (e.g., serial) */
-	Pcibcbasesys	= 8,		/* base system */
-	Pcibcinput	= 9,		/* input */
-	Pcibcdock	= 0xa,		/* docking stations */
-	Pcibcproc	= 0xb,		/* processors */
-	Pcibcserial	= 0xc,		/* serial bus (e.g., USB) */
-	Pcibcwireless	= 0xd,		/* wireless */
-	Pcibcintell	= 0xe,		/* intelligent i/o */
-	Pcibcsatcom	= 0xf,		/* satellite comms */
-	Pcibccrypto	= 0x10,		/* encryption/decryption */
-	Pcibcdacq	= 0x11,		/* data acquisition & signal proc. */
-};
-
-/* ccru (sub-class code) values; common cases only */
-enum {
-	/* mass storage */
-	Pciscscsi	= 0,		/* SCSI */
-	Pciscide	= 1,		/* IDE (ATA) */
-
-	/* network */
-	Pciscether	= 0,		/* Ethernet */
-
-	/* display */
-	Pciscvga	= 0,		/* VGA */
-	Pciscxga	= 1,		/* XGA */
-	Pcisc3d		= 2,		/* 3D */
-
-	/* bridges */
-	Pcischostpci	= 0,		/* host/pci */
-	Pciscpcicpci	= 1,		/* pci/pci */
-
-	/* simple comms */
-	Pciscserial	= 0,		/* 16450, etc. */
-	Pciscmultiser	= 1,		/* multiport serial */
-
-	/* serial bus */
-	Pciscusb	= 3,		/* USB */
-};
-
-enum {					/* type 0 pre-defined header */
-	PciCIS		= 0x28,		/* cardbus CIS pointer */
-	PciSVID		= 0x2C,		/* subsystem vendor ID */
-	PciSID		= 0x2E,		/* cardbus CIS pointer */
-	PciEBAR0	= 0x30,		/* expansion ROM base address */
-	PciMGNT		= 0x3E,		/* burst period length */
-	PciMLT		= 0x3F,		/* maximum latency between bursts */
-};
-
-enum {					/* type 1 pre-defined header */
-	PciPBN		= 0x18,		/* primary bus number */
-	PciSBN		= 0x19,		/* secondary bus number */
-	PciUBN		= 0x1A,		/* subordinate bus number */
-	PciSLTR		= 0x1B,		/* secondary latency timer */
-	PciIBR		= 0x1C,		/* I/O base */
-	PciILR		= 0x1D,		/* I/O limit */
-	PciSPSR		= 0x1E,		/* secondary status */
-	PciMBR		= 0x20,		/* memory base */
-	PciMLR		= 0x22,		/* memory limit */
-	PciPMBR		= 0x24,		/* prefetchable memory base */
-	PciPMLR		= 0x26,		/* prefetchable memory limit */
-	PciPUBR		= 0x28,		/* prefetchable base upper 32 bits */
-	PciPULR		= 0x2C,		/* prefetchable limit upper 32 bits */
-	PciIUBR		= 0x30,		/* I/O base upper 16 bits */
-	PciIULR		= 0x32,		/* I/O limit upper 16 bits */
-	PciEBAR1	= 0x28,		/* expansion ROM base address */
-	PciBCR		= 0x3E,		/* bridge control register */
-};
-
-enum {					/* type 2 pre-defined header */
-	PciCBExCA	= 0x10,
-	PciCBSPSR	= 0x16,
-	PciCBPBN	= 0x18,		/* primary bus number */
-	PciCBSBN	= 0x19,		/* secondary bus number */
-	PciCBUBN	= 0x1A,		/* subordinate bus number */
-	PciCBSLTR	= 0x1B,		/* secondary latency timer */
-	PciCBMBR0	= 0x1C,
-	PciCBMLR0	= 0x20,
-	PciCBMBR1	= 0x24,
-	PciCBMLR1	= 0x28,
-	PciCBIBR0	= 0x2C,		/* I/O base */
-	PciCBILR0	= 0x30,		/* I/O limit */
-	PciCBIBR1	= 0x34,		/* I/O base */
-	PciCBILR1	= 0x38,		/* I/O limit */
-	PciCBSVID	= 0x40,		/* subsystem vendor ID */
-	PciCBSID	= 0x42,		/* subsystem ID */
-	PciCBLMBAR	= 0x44,		/* legacy mode base address */
-};
-
 typedef struct Pcisiz Pcisiz;
 struct Pcisiz
 {
@@ -221,49 +71,12 @@
 	int	bar;
 };
 
-typedef struct Pcidev Pcidev;
-struct Pcidev
-{
-	int	tbdf;			/* type+bus+device+function */
-	ushort	vid;			/* vendor ID */
-	ushort	did;			/* device ID */
-
-	ushort	pcr;
-
-	uchar	rid;
-	uchar	ccrp;
-	uchar	ccru;
-	uchar	ccrb;
-	uchar	cls;
-	uchar	ltr;
-
-	struct {
-		ulong	bar;		/* base address */
-		int	size;
-	} mem[6];
-
-	struct {
-		ulong	bar;	
-		int	size;
-	} rom;
-	uchar	intl;			/* interrupt line */
-
-	Pcidev*	list;
-	Pcidev*	link;			/* next device on this bno */
-
-	Pcidev*	bridge;			/* down a bus */
-	struct {
-		ulong	bar;
-		int	size;
-	} ioa, mema;
-
-	int	pmrb;			/* power management register block */
-};
-
 #define PCIWINDOW	0
 #define PCIWADDR(va)	(PADDR(va)+PCIWINDOW)
 #define ISAWINDOW	0
 #define ISAWADDR(va)	(PADDR(va)+ISAWINDOW)
+
+#define	BUSUNKNOWN	(-1)
 
 /* SMBus transactions */
 enum
--- a/os/pc/mp.h
+++ b/os/pc/mp.h
@@ -238,8 +238,8 @@
 extern void lapicerror(Ureg*, void*);
 extern void lapicicrw(ulong, ulong);
 extern void lapicinit(Apic*);
-extern int lapicintroff(int);
-extern int lapicintron(Vctl*);
+extern void lapicintroff(void);
+extern void lapicintron(void);
 extern int lapicisr(int);
 extern void lapicnmidisable(void);
 extern void lapicnmienable(void);
--- a/os/pc/pc.root.s
+++ /dev/null
@@ -1,1 +1,0 @@
-/* Generated by /os/port/mkroot */
--- a/os/pc/screen.h
+++ b/os/pc/screen.h
@@ -79,7 +79,7 @@
 	void	(*enable)(VGAscr*);
 	void	(*disable)(VGAscr*);
 	void	(*page)(VGAscr*, int);
-	ulong	(*linear)(VGAscr*, int*, int*);
+	void	(*linear)(VGAscr*, int, int);
 	void	(*drawinit)(VGAscr*);
 	int	(*fill)(VGAscr*, Rectangle, ulong);
 	void	(*ovlctl)(VGAscr*, Chan*, void*, int);
@@ -159,9 +159,9 @@
 extern int		hwblank;	/* use hw blanking; default on */
 extern int		panning;	/* use virtual screen panning; default off */
 extern void addvgaseg(char*, u32, u32);
-extern uchar* attachscreen(Rectangle*, ulong*, int*, int*, int*);
+extern Memdata* attachscreen(Rectangle*, ulong*, int*, int*, int*);
 extern void	flushmemscreen(Rectangle);
-extern int	cursoron(int);
+extern void	cursoron(void);
 extern void	cursoroff(void);
 extern void	setcursor(Cursor*);
 extern int	screensize(int, int, int, ulong);
--- a/os/pc64/main.c
+++ b/os/pc64/main.c
@@ -173,9 +173,9 @@
 	i8250console();
 	quotefmtinstall();
 	screeninit();
+	consdebug = rdb;
 	print("\nInferno release built at %lud\n", kerndate);
 	showconfig();
-ffmain();
 	cpuidentify();
 	meminit0();			/* builds the memmap */
 	doc("archinit");
--- a/os/pc64/mkfile
+++ b/os/pc64/mkfile
@@ -32,7 +32,6 @@
 	memmap.$O\
 	memory.$O\
 	mmu.$O\
-	irq.$O\
 	trap.$O\
 	bootargs.$O\
 	$CONF.root.$O\
@@ -52,10 +51,11 @@
 	fns.h\
 	io.h\
 
-CFLAGS=-wFVT -I$ROOT/Inferno/$OBJTYPE/include -I$ROOT/include -I$ROOT/libinterp -I$ROOT/libip -I../port
+# use the CFLAGS set in ../../mkfiles/mkfile-Inferno-amd64
+CFLAGS=$CFLAGS -I$ROOT/libinterp -I$ROOT/libip -I../port
 KERNDATE=`{$NDATE}
 
-default:V: i$CONF
+default:V: i$CONF i$CONF.acid
 
 ETHERS=`{cd ../pc; echo devether.c ether*.c | sed 's/\.c/.'$O'/g'}
 AUDIO=`{cd ../pc; echo devaudio.c audio*.c | sed 's/\.c/.'$O'/g'}
--- a/os/pc64/pc64
+++ b/os/pc64/pc64
@@ -6,7 +6,7 @@
 	env
 	mnt
 	pipe
-#	proc
+	proc
 	prog
 	rtc
 	srv
@@ -147,6 +147,7 @@
 	exportfs
 	inferno
 	iomap
+	irq
 	latin1
 	nocache
 	nodynld
@@ -157,6 +158,7 @@
 	qio
 	qlock
 	random
+	rdb
 	swcursor
 	sysfile
 	taslock
--- a/os/port/devcons.c
+++ b/os/port/devcons.c
@@ -11,6 +11,7 @@
 
 extern int cflag;
 extern int keepbroken;
+extern int rdbstarted;
 
 void	(*serwrite)(char *, int);
 
@@ -167,7 +168,10 @@
 		screenputs(str, n);
 	}
 
+	if(rdbstarted == 1)
+		return;
 	if(serialoq == nil){
+		uartputs("putstrn0 ", 9);
 		uartputs(str, n);
 		return;
 	}
--- a/os/port/portdat.h
+++ b/os/port/portdat.h
@@ -754,6 +754,7 @@
 };
 
 extern	Uart*	consuart;
+extern	int	rdbstarted;
 
 enum
 {
--- a/os/port/portfns.h
+++ b/os/port/portfns.h
@@ -36,6 +36,7 @@
 void		cnameclose(Cname*);
 Block*		concatblock(Block*);
 void		confinit(void);
+void		(*consdebug)(void);
 int		copen(Chan*);
 void		cclunk(Chan*);
 Block*		copyblock(Block*, int);
@@ -256,6 +257,7 @@
 int		qwrite(Queue*, void*, int);
 void		randominit(void);
 ulong	randomread(void*, ulong);
+void		rdb(void);
 void*	realloc(void*, ulong);
 long		readblist(Block*, uchar*, long, ulong);
 int		readnum(ulong, char*, ulong, ulong, int);
--- a/os/port/portmkfile
+++ b/os/port/portmkfile
@@ -41,7 +41,7 @@
 			echo '//FILE: ' $i
 			$CC -I. $CFLAGS $LIBHDIRS '-DKERNDATE='$KERNDATE -a $i
 		}
-		echo 'include ("inferno");'
+		echo 'include ("'$ROOT'/lib/acid/9ferno");'
 	} >i$CONF.acid
 
 sh-i$CONF.acid:V: i$CONF
--- a/os/port/rdb.c
+++ b/os/port/rdb.c
@@ -6,13 +6,11 @@
 #include "io.h"
 #include "ureg.h"
 
-/*
- * alternative debug protocol for plan 9's rdbfs(4) for plan 9's own acid
- */
-#define DBG	if(0)scrprint
+int rdbstarted;
+
+#define DBG	if(1)scrprint
 #pragma varargck argpos scrprint 1
 static Ureg ureg;
-extern Queue *klogq;
 
 static void
 scrprint(char *fmt, ...)