code: 9ferno

Download patch

ref: df70f131db320bebb7ec12c9334c9dfe96c10cf4
parent: 25c285c73fcdcd402844aa76da667e5b55b26cce
author: joe9 <joe9mail@gmail.com>
date: Sat Jul 10 03:57:30 EDT 2021

changes to get the 64 bit inferno kernel to build on purgatorio

--- a/Inferno/amd64/include/lib9.h
+++ b/Inferno/amd64/include/lib9.h
@@ -1,13 +1,5 @@
-#include <u.h>
-#include <kern.h>
-
-/*
- *	Extensions for Inferno to basic libc.h
- */
-
-#define __LITTLE_ENDIAN	/* math/dtoa.c only */
-#include <u.h>
-#include <kern.h>
+#include "u.h"
+#include "kern.h"
 
 /*
  *	Extensions for Inferno to basic libc.h
--- a/Inferno/amd64/include/u.h
+++ b/Inferno/amd64/include/u.h
@@ -86,91 +86,3 @@
 
 typedef intptr WORD;
 typedef uintptr        UWORD;
-#define nil		((void*)0)
-typedef	unsigned short	ushort;
-typedef	unsigned char	uchar;
-typedef unsigned long	ulong;
-typedef unsigned int	uint;
-typedef signed char	schar;
-typedef	long long	vlong;
-typedef	unsigned long long uvlong;
-typedef long long	intptr;
-typedef unsigned long long uintptr;
-typedef unsigned long	usize;
-typedef	uint		Rune;
-typedef union FPdbleword FPdbleword;
-typedef uintptr		jmp_buf[2];
-#define	JMPBUFSP	0
-#define	JMPBUFPC	1
-#define	JMPBUFDPC	0
-typedef unsigned int	mpdigit;	/* for /sys/include/mp.h */
-typedef unsigned char	u8int;
-typedef unsigned short	u16int;
-typedef unsigned int	u32;
-typedef unsigned long long u64int;
-typedef signed char s8int;
-typedef signed short s16int;
-typedef signed int s32;
-typedef signed long long s64int;
-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;
-
-/* MXCSR */
-/* fcr */
-#define	FPFTZ	(1<<15)	/* amd64 */
-#define	FPINEX	(1<<12)
-#define	FPUNFL	(1<<11)
-#define	FPOVFL	(1<<10)
-#define	FPZDIV	(1<<9)
-#define	FPDNRM	(1<<8)	/* amd64 */
-#define	FPINVAL	(1<<7)
-#define	FPDAZ	(1<<6)	/* amd64 */
-#define	FPRNR	(0<<13)
-#define	FPRZ	(3<<13)
-#define	FPRPINF	(2<<13)
-#define	FPRNINF	(1<<13)
-#define	FPRMASK	(3<<13)
-#define	FPPEXT	0
-#define	FPPSGL	0
-#define	FPPDBL	0
-#define	FPPMASK	0
-/* fsr */
-#define	FPAINEX	(1<<5)
-#define	FPAUNFL	(1<<4)
-#define	FPAOVFL	(1<<3)
-#define	FPAZDIV	(1<<2)
-#define	FPADNRM	(1<<1)	/* not in plan 9 */
-#define	FPAINVAL	(1<<0)
-union FPdbleword
-{
-	double	x;
-	struct {	/* little endian */
-		uint lo;
-		uint hi;
-	};
-};
-
-typedef	char*	va_list;
-#define va_start(list, start) list =\
-	(sizeof(start) < 8?\
-		(char*)((vlong*)&(start)+1):\
-		(char*)(&(start)+1))
-#define va_end(list)\
-	USED(list)
-#define va_arg(list, mode)\
-	((sizeof(mode) == 1)?\
-		((list += 8), (mode*)list)[-8]:\
-	(sizeof(mode) == 2)?\
-		((list += 8), (mode*)list)[-4]:\
-	(sizeof(mode) == 4)?\
-		((list += 8), (mode*)list)[-2]:\
-		((list += sizeof(mode)), (mode*)list)[-1])
-
-typedef intptr WORD;
-typedef uintptr        UWORD;
--- a/Inferno/amd64/include/ureg.h
+++ b/Inferno/amd64/include/ureg.h
@@ -31,36 +31,3 @@
 	};
 	u64	ss;				/* old stack segment */
 };
-struct Ureg {
-	u64	ax;
-	u64	bx;
-	u64	cx;
-	u64	dx;
-	u64	si;
-	u64	di;
-	u64	bp;
-	u64	r8;
-	u64	r9;
-	u64	r10;
-	u64	r11;
-	u64	r12;
-	u64	r13;
-	u64	r14;
-	u64	r15;
-
-	u16	ds;
-	u16	es;
-	u16	fs;
-	u16	gs;
-
-	u64	trap;				/* trap type */
-	u64	ecode;				/* error code (or zero) */
-	u64	pc;				/* pc */
-	u64	cs;				/* old context */
-	u64	flags;				/* old flags */
-	union {					/* sp */
-		u64	usp;
-		u64	sp;
-	};
-	u64	ss;				/* old stack segment */
-};
--- a/os/ip/bootp.c
+++ b/os/ip/bootp.c
@@ -75,7 +75,7 @@
 	if(waserror())
 		pexit("", 0);
 	rcvprocp = up;	/* store for postnote below */
-	fd = (int)a;
+	fd = (int)a;	/* at compilation: warning: ../ip/bootp.c:78 conversion of pointer to shorter integer */
 	while(done == 0) {
 		n = kread(fd, rcvbuf, sizeof(rcvbuf));
 		if(n <= 0)
--- a/os/pc/devether.c
+++ /dev/null
@@ -1,539 +1,0 @@
-#include "u.h"
-#include "../port/lib.h"
-#include "mem.h"
-#include "dat.h"
-#include "fns.h"
-#include "io.h"
-#include "ureg.h"
-#include "../port/error.h"
-#include "../port/netif.h"
-
-#include "etherif.h"
-
-static Ether *etherxx[MaxEther];
-
-Chan*
-etherattach(char* spec)
-{
-	ulong ctlrno;
-	char *p;
-	Chan *chan;
-
-	ctlrno = 0;
-	if(spec && *spec){
-		ctlrno = strtoul(spec, &p, 0);
-		if((ctlrno == 0 && p == spec) || *p || (ctlrno >= MaxEther))
-			error(Ebadarg);
-	}
-	if(etherxx[ctlrno] == 0)
-		error(Enodev);
-
-	chan = devattach('l', spec);
-	chan->dev = ctlrno;
-	if(etherxx[ctlrno]->attach)
-		etherxx[ctlrno]->attach(etherxx[ctlrno]);
-	return chan;
-}
-
-static Walkqid*
-etherwalk(Chan* chan, Chan* nchan, char** name, int nname)
-{
-	return netifwalk(etherxx[chan->dev], chan, nchan, name, nname);
-}
-
-static int
-etherstat(Chan* chan, uchar* dp, int n)
-{
-	return netifstat(etherxx[chan->dev], chan, dp, n);
-}
-
-static Chan*
-etheropen(Chan* chan, int omode)
-{
-	return netifopen(etherxx[chan->dev], chan, omode);
-}
-
-static void
-ethercreate(Chan*, char*, int, ulong)
-{
-}
-
-static void
-etherclose(Chan* chan)
-{
-	netifclose(etherxx[chan->dev], chan);
-}
-
-static long
-etherread(Chan* chan, void* buf, long n, vlong off)
-{
-	Ether *ether;
-	ulong offset = off;
-
-	ether = etherxx[chan->dev];
-	if((chan->qid.type & QTDIR) == 0 && ether->ifstat){
-		/*
-		 * With some controllers it is necessary to reach
-		 * into the chip to extract statistics.
-		 */
-		if(NETTYPE(chan->qid.path) == Nifstatqid)
-			return ether->ifstat(ether, buf, n, offset);
-		else if(NETTYPE(chan->qid.path) == Nstatqid)
-			ether->ifstat(ether, buf, 0, offset);
-	}
-
-	return netifread(ether, chan, buf, n, offset);
-}
-
-static Block*
-etherbread(Chan* chan, long n, ulong offset)
-{
-	return netifbread(etherxx[chan->dev], chan, n, offset);
-}
-
-static int
-etherwstat(Chan* chan, uchar* dp, int n)
-{
-	return netifwstat(etherxx[chan->dev], chan, dp, n);
-}
-
-static void
-etherrtrace(Netfile* f, Etherpkt* pkt, int len)
-{
-	int i, n;
-	Block *bp;
-
-	if(qwindow(f->in) <= 0)
-		return;
-	if(len > 58)
-		n = 58;
-	else
-		n = len;
-	bp = iallocb(64);
-	if(bp == nil)
-		return;
-	memmove(bp->wp, pkt->d, n);
-	i = TK2MS(MACHP(0)->ticks);
-	bp->wp[58] = len>>8;
-	bp->wp[59] = len;
-	bp->wp[60] = i>>24;
-	bp->wp[61] = i>>16;
-	bp->wp[62] = i>>8;
-	bp->wp[63] = i;
-	bp->wp += 64;
-	qpass(f->in, bp);
-}
-
-Block*
-etheriq(Ether* ether, Block* bp, int fromwire)
-{
-	Etherpkt *pkt;
-	ushort type;
-	int len, multi, tome, fromme;
-	Netfile **ep, *f, **fp, *fx;
-	Block *xbp;
-
-	ether->inpackets++;
-
-	pkt = (Etherpkt*)bp->rp;
-	len = BLEN(bp);
-	type = (pkt->type[0]<<8)|pkt->type[1];
-	fx = 0;
-	ep = &ether->f[Ntypes];
-
-	multi = pkt->d[0] & 1;
-	/* check for valid multcast addresses */
-	if(multi && memcmp(pkt->d, ether->bcast, sizeof(pkt->d)) != 0 && ether->prom == 0){
-		if(!activemulti(ether, pkt->d, sizeof(pkt->d))){
-			if(fromwire){
-				freeb(bp);
-				bp = 0;
-			}
-			return bp;
-		}
-	}
-
-	/* is it for me? */
-	tome = memcmp(pkt->d, ether->ea, sizeof(pkt->d)) == 0;
-	fromme = memcmp(pkt->s, ether->ea, sizeof(pkt->s)) == 0;
-
-	/*
-	 * Multiplex the packet to all the connections which want it.
-	 * If the packet is not to be used subsequently (fromwire != 0),
-	 * attempt to simply pass it into one of the connections, thereby
-	 * saving a copy of the data (usual case hopefully).
-	 */
-	for(fp = ether->f; fp < ep; fp++){
-		if(f = *fp)
-		if(f->type == type || f->type < 0)
-		if(tome || multi || f->prom){
-			/* Don't want to hear bridged packets */
-			if(f->bridge && !fromwire && !fromme)
-				continue;
-			if(!f->headersonly){
-				if(fromwire && fx == 0)
-					fx = f;
-				else if(xbp = iallocb(len)){
-					memmove(xbp->wp, pkt, len);
-					xbp->wp += len;
-					if(qpass(f->in, xbp) < 0)
-						ether->soverflows++;
-				}
-				else
-					ether->soverflows++;
-			}
-			else
-				etherrtrace(f, pkt, len);
-		}
-	}
-
-	if(fx){
-		if(qpass(fx->in, bp) < 0)
-			ether->soverflows++;
-		return 0;
-	}
-	if(fromwire){
-		freeb(bp);
-		return 0;
-	}
-
-	return bp;
-}
-
-static int
-etheroq(Ether* ether, Block* bp)
-{
-	int len, loopback, s;
-	Etherpkt *pkt;
-
-	ether->outpackets++;
-
-	/*
-	 * Check if the packet has to be placed back onto the input queue,
-	 * i.e. if it's a loopback or broadcast packet or the interface is
-	 * in promiscuous mode.
-	 * If it's a loopback packet indicate to etheriq that the data isn't
-	 * needed and return, etheriq will pass-on or free the block.
-	 * To enable bridging to work, only packets that were originated
-	 * by this interface are fed back.
-	 */
-	pkt = (Etherpkt*)bp->rp;
-	len = BLEN(bp);
-	loopback = memcmp(pkt->d, ether->ea, sizeof(pkt->d)) == 0;
-	if(loopback || memcmp(pkt->d, ether->bcast, sizeof(pkt->d)) == 0 || ether->prom){
-		s = splhi();
-		etheriq(ether, bp, 0);
-		splx(s);
-	}
-
-	if(!loopback){
-		qbwrite(ether->oq, bp);
-		if(ether->transmit != nil)
-			ether->transmit(ether);
-	} else
-		freeb(bp);
-
-	return len;
-}
-
-static long
-etherwrite(Chan* chan, void* buf, long n, vlong)
-{
-	Ether *ether;
-	Block *bp;
-	int nn, onoff;
-	Cmdbuf *cb;
-
-	ether = etherxx[chan->dev];
-	if(NETTYPE(chan->qid.path) != Ndataqid) {
-		nn = netifwrite(ether, chan, buf, n);
-		if(nn >= 0)
-			return nn;
-		cb = parsecmd(buf, n);
-		if(strcmp(cb->f[0], "nonblocking") == 0){
-			if(cb->nf <= 1)
-				onoff = 1;
-			else
-				onoff = atoi(cb->f[1]);
-			qnoblock(ether->oq, onoff);
-			free(cb);
-			return n;
-		}
-		free(cb);
-		if(ether->ctl!=nil)
-			return ether->ctl(ether,buf,n);
-			
-		error(Ebadctl);
-	}
-
-	if(n > ether->maxmtu)
-		error(Etoobig);
-	if(n < ether->minmtu)
-		error(Etoosmall);
-
-	bp = allocb(n);
-	if(waserror()){
-		freeb(bp);
-		nexterror();
-	}
-	memmove(bp->rp, buf, n);
-	memmove(bp->rp+Eaddrlen, ether->ea, Eaddrlen);
-	poperror();
-	bp->wp += n;
-
-	return etheroq(ether, bp);
-}
-
-static long
-etherbwrite(Chan* chan, Block* bp, ulong)
-{
-	Ether *ether;
-	long n;
-
-	n = BLEN(bp);
-	if(NETTYPE(chan->qid.path) != Ndataqid){
-		if(waserror()) {
-			freeb(bp);
-			nexterror();
-		}
-		n = etherwrite(chan, bp->rp, n, 0);
-		poperror();
-		freeb(bp);
-		return n;
-	}
-	ether = etherxx[chan->dev];
-
-	if(n > ether->maxmtu){
-		freeb(bp);
-		error(Etoobig);
-	}
-	if(n < ether->minmtu){
-		freeb(bp);
-		error(Etoosmall);
-	}
-
-	return etheroq(ether, bp);
-}
-
-static struct {
-	char*	type;
-	int	(*reset)(Ether*);
-} cards[MaxEther+1];
-
-void
-addethercard(char* t, int (*r)(Ether*))
-{
-	static int ncard;
-
-	if(ncard == MaxEther)
-		panic("too many ether cards");
-	cards[ncard].type = t;
-	cards[ncard].reset = r;
-	ncard++;
-}
-
-int
-parseether(uchar *to, char *from)
-{
-	char nip[4];
-	char *p;
-	int i;
-
-	p = from;
-	for(i = 0; i < Eaddrlen; i++){
-		if(*p == 0)
-			return -1;
-		nip[0] = *p++;
-		if(*p == 0)
-			return -1;
-		nip[1] = *p++;
-		nip[2] = 0;
-		to[i] = strtoul(nip, 0, 16);
-		if(*p == ':')
-			p++;
-	}
-	return 0;
-}
-
-static Ether*
-etherprobe(int cardno, int ctlrno)
-{
-	int i;
-	Ether *ether;
-	char buf[128], name[32];
-
-	ether = malloc(sizeof(Ether));
-	memset(ether, 0, sizeof(Ether));
-	ether->ctlrno = ctlrno;
-	ether->tbdf = BUSUNKNOWN;
-	ether->mbps = 10;
-	ether->minmtu = ETHERMINTU;
-	ether->maxmtu = ETHERMAXTU;
-
-	if(cardno < 0){
-		if(isaconfig("ether", ctlrno, ether) == 0){
-			free(ether);
-			return nil;
-		}
-		for(cardno = 0; cards[cardno].type; cardno++){
-			if(cistrcmp(cards[cardno].type, ether->type))
-				continue;
-			for(i = 0; i < ether->nopt; i++){
-				if(strncmp(ether->opt[i], "ea=", 3))
-					continue;
-				if(parseether(ether->ea, &ether->opt[i][3]))
-					memset(ether->ea, 0, Eaddrlen);
-			}
-			break;
-		}
-	}
-
-	if(cardno >= MaxEther || cards[cardno].type == nil){
-		free(ether);
-		return nil;
-	}
-	if(cards[cardno].reset(ether) < 0){
-		free(ether);
-		return nil;
-	}
-
-	/*
-	 * IRQ2 doesn't really exist, it's used to gang the interrupt
-	 * controllers together. A device set to IRQ2 will appear on
-	 * the second interrupt controller as IRQ9.
-	 */
-	if(ether->irq == 2)
-		ether->irq = 9;
-	snprint(name, sizeof(name), "ether%d", ctlrno);
-
-	/*
-	 * If ether->irq is <0, it is a hack to indicate no interrupt
-	 * used by ethersink.
-	 */
-	if(ether->irq >= 0)
-		intrenable(ether->irq, ether->interrupt, ether, ether->tbdf, name);
-
-	i = sprint(buf, "#l%d: %s: %dMbps port 0x%luX irq %d",
-		ctlrno, cards[cardno].type, ether->mbps, ether->port, ether->irq);
-	if(ether->mem)
-		i += sprint(buf+i, " addr 0x%luX", PADDR(ether->mem));
-	if(ether->size)
-		i += sprint(buf+i, " size 0x%luX", ether->size);
-	i += sprint(buf+i, ": %2.2ux%2.2ux%2.2ux%2.2ux%2.2ux%2.2ux",
-		ether->ea[0], ether->ea[1], ether->ea[2],
-		ether->ea[3], ether->ea[4], ether->ea[5]);
-	sprint(buf+i, "\n");
-	print(buf);
-
-	if (ether->mbps >= 1000) {
-		netifinit(ether, name, Ntypes, 512*1024);
-		if(ether->oq == 0)
-			ether->oq = qopen(512*1024, Qmsg, 0, 0);
-	} else if(ether->mbps >= 100){
-		netifinit(ether, name, Ntypes, 256*1024);
-		if(ether->oq == 0)
-			ether->oq = qopen(256*1024, Qmsg, 0, 0);
-	}
-	else{
-		netifinit(ether, name, Ntypes, 128*1024);
-		if(ether->oq == 0)
-			ether->oq = qopen(128*1024, Qmsg, 0, 0);
-	}
-	if(ether->oq == 0)
-		panic("etherreset %s", name);
-	ether->alen = Eaddrlen;
-	memmove(ether->addr, ether->ea, Eaddrlen);
-	memset(ether->bcast, 0xFF, Eaddrlen);
-
-	return ether;
-}
-
-static void
-etherreset(void)
-{
-	Ether *ether;
-	int cardno, ctlrno;
-
-	for(ctlrno = 0; ctlrno < MaxEther; ctlrno++){
-		if((ether = etherprobe(-1, ctlrno)) == nil)
-			continue;
-		etherxx[ctlrno] = ether;
-	}
-
-	if(getconf("*noetherprobe"))
-		return;
-
-	cardno = ctlrno = 0;
-	while(cards[cardno].type != nil && ctlrno < MaxEther){
-		if(etherxx[ctlrno] != nil){
-			ctlrno++;
-			continue;
-		}
-		if((ether = etherprobe(cardno, ctlrno)) == nil){
-			cardno++;
-			continue;
-		}
-		etherxx[ctlrno] = ether;
-		ctlrno++;
-	}
-}
-
-static void
-ethershutdown(void)
-{
-	Ether *ether;
-	int i;
-
-	for(i = 0; i < MaxEther; i++){
-		ether = etherxx[i];
-		if(ether == nil)
-			continue;
-		if(ether->shutdown == nil) {
-			print("#l%d: no shutdown fuction\n", i);
-			continue;
-		}
-		(*ether->shutdown)(ether);
-	}
-}
-
-
-#define POLY 0xedb88320
-
-/* really slow 32 bit crc for ethers */
-ulong
-ethercrc(uchar *p, int len)
-{
-	int i, j;
-	ulong crc, b;
-
-	crc = 0xffffffff;
-	for(i = 0; i < len; i++){
-		b = *p++;
-		for(j = 0; j < 8; j++){
-			crc = (crc>>1) ^ (((crc^b) & 1) ? POLY : 0);
-			b >>= 1;
-		}
-	}
-	return crc;
-}
-
-Dev etherdevtab = {
-	'l',
-	"ether",
-
-	etherreset,
-	devinit,
-	ethershutdown,
-	etherattach,
-	etherwalk,
-	etherstat,
-	etheropen,
-	ethercreate,
-	etherclose,
-	etherread,
-	etherbread,
-	etherwrite,
-	etherbwrite,
-	devremove,
-	etherwstat,
-};
--- a/os/pc/ethervirtio.c
+++ b/os/pc/ethervirtio.c
@@ -154,7 +154,7 @@
 	int	active;
 	int	id;
 	int	typ;
-	ulong	feat;
+	u32	feat;
 	int	nqueue;
 
 	/* virtioether has 3 queues: rx, tx and ctl */
@@ -449,11 +449,11 @@
 
 	p = smalloc(READSTR);
 
-	l = snprint(p, READSTR, "devfeat %32.32lub\n", ctlr->feat);
+	l = snprint(p, READSTR, "devfeat %32.32ub\n", ctlr->feat);
 	l += snprint(p+l, READSTR-l, "drvfeat %32.32lub\n", inl(ctlr->port+Qdrvfeat));
-	l += snprint(p+l, READSTR-l, "devstatus %8.8ub\n", inb(ctlr->port+Qstatus));
+	l += snprint(p+l, READSTR-l, "devstatus %8.8b\n", inb(ctlr->port+Qstatus));
 	if(ctlr->feat & Fstatus)
-		l += snprint(p+l, READSTR-l, "netstatus %8.8ub\n",  inb(ctlr->port+Qnetstatus));
+		l += snprint(p+l, READSTR-l, "netstatus %8.8b\n",  inb(ctlr->port+Qnetstatus));
 
 	for(i = 0; i < ctlr->nqueue; i++){
 		q = &ctlr->queue[i];
--- a/os/pc64/fns.h
+++ b/os/pc64/fns.h
@@ -82,7 +82,7 @@
 void	iofree(u32);
 void	ioinit(void);
 s32	iounused(u32, u32);
-u32	ioalloc(u32, u32, u32, char*);
+s32	ioalloc(s32, u32, u32, char*);
 u32	ioreserve(u32, u32, u32, char*);
 int	iprint(char*, ...);
 int	isaconfig(char*, int, ISAConf*);
--- a/os/pc64/fpu.c
+++ b/os/pc64/fpu.c
@@ -222,7 +222,7 @@
 		up->fpstate = FPactive | (up->fpstate & (FPnouser|FPkernel|FPindexm));
 		break;
 	case FPactive:
-		panic("math emu pid %ld %s pc %#p", 
+		panic("math emu pid %d %s pc %#p", 
 			up->pid, up->text, ureg->pc);
 		break;
 	}
--- a/os/pc64/main.c
+++ b/os/pc64/main.c
@@ -85,9 +85,9 @@
 	pdpe = mmuwalk((uintptr*)PML4ADDR, pa, 2, 0);
 	pde = mmuwalk((uintptr*)PML4ADDR, pa, 1, 0);
 	print("pml4 @ 0x%p pa 0x%zux page is \n"
-		"\tpml4 entry @ 0x%p i %d\n"
-		"\tpdp entry @ 0x%p i %d\n"
-		"\tpd entry @ 0x%p i %d\n",
+		"\tpml4 entry @ 0x%p i %zd\n"
+		"\tpdp entry @ 0x%p i %zd\n"
+		"\tpd entry @ 0x%p i %zd\n",
 		m->pml4, pa,
 		pml4e, (pml4e-m->pml4)/sizeof(intptr),
 		pdpe, ((intptr)pdpe-(intptr)PDPADDR)/sizeof(intptr),
@@ -101,7 +101,7 @@
 		"\tcpu0mach 0x%p cpu0sp 0x%p cpu0gdt 0x%p\n"
 		"\tcpu0pml4 0x%p cpu0pdp 0x%p  cpu0pd 0x%p\n"
 		"\tcpu0end 0x%p\n",
-		KDZERO, CONFADDR,APBOOTSTRAP,
+		(void*)KDZERO, CONFADDR,APBOOTSTRAP,
 		IDTADDR, CPU0MACH, CPU0SP, GDTADDR,
 		PML4ADDR, PDPADDR, PD0ADDR, CPU0END);
 	ptedebug(1*MiB);
@@ -296,7 +296,7 @@
 	conf.npage = 0;
 	for(i=0; i<nelem(conf.mem); i++)
 		conf.npage += conf.mem[i].npage;
-	print("conf.npage %ld\n", conf.npage);
+	print("conf.npage %d\n", conf.npage);
 
 	conf.nproc = 10 /*+ ((conf.npage*BY2PG)/MiB)*5*/;
 }
--- a/os/pc64/memory.c
+++ b/os/pc64/memory.c
@@ -87,7 +87,7 @@
 			panic("kernelro");
 		}
 		if((*pte & PTEVALID) == 0){
-			print("kernelro invalid page va 0x%p pte 0x%zux *pte 0x%zux\n",
+			print("kernelro invalid page va 0x%p pte 0x%p *pte 0x%zux\n",
 				va, pte, *pte);
 			panic("kernelro invalid page\n");
 		}
@@ -431,9 +431,9 @@
 ramscan(uintptr pa, uintptr top)
 {
 	uintptr save, pat, seed, *v, *k0, *pte;
-	int i, n, w;
+	uintptr i, n, w;
 	char *attr;
-	u32 chunk;
+	uintptr chunk;
 
 	chunk = PGLSZ(0);
 	pa += chunk-1;
@@ -533,7 +533,7 @@
 					continue;
 				pde = *pd;
 				pt = (uintptr*)(pde&(~0xFFF));
-				print("\t\tpd 0x%p has 0x%zx page base address 0x%zx\n",
+				print("\t\tpd 0x%p has 0x%zx page base address 0x%4\n",
 					pd, pde, pt);
 				ept = pt + 512;
 				for(; pt != ept; pt++){
@@ -557,8 +557,8 @@
 {
 	uintptr prevbase = 0, base, size = 0;
 
-	print("MemMin 0x%llux end 0x%p KZERO 0x%x KDZERO 0x%p\n"
-		"\tKTZERO 0x%x etext 0x%zux\n\tCPU0END 0x%llux\n"
+	print("MemMin 0x%llux end 0x%p KZERO 0x%x KDZERO 0x%x\n"
+		"\tKTZERO 0x%x etext 0x%p\n\tCPU0END 0x%llux\n"
 		"\tPADDR(PGROUND((uintptr)end)) 0x%zux MemMin-PADDR(PGROUND((uintptr)end)) 0x%zux\n",
 		MemMin, end, KZERO, KDZERO, KTZERO, etext, (uintptr)CPU0END,
 		PADDR(PGROUND((uintptr)end)), MemMin-PADDR(PGROUND((uintptr)end)));
@@ -667,7 +667,7 @@
 			continue;
 		}
 		if(base < MemMin){
-			print("meminit: ignoring RAM below MemMin base 0x%p size 0x%d\n", base, size);
+			print("meminit: ignoring RAM below MemMin base 0x%p size 0x%zd\n", base, size);
 			continue;
 		}
 		cm->base = memmapalloc(base, size, BY2PG, MemRAM);
--- a/os/pc64/mmu.c
+++ b/os/pc64/mmu.c
@@ -164,7 +164,7 @@
 		table, pa, level, index);
 	flags = PTEWRITE|PTEVALID;
 	page = (uintptr*)rampage();
-	DP("mmucreate new page 0x%p PTSZ 0x%x %d BY2PG 0x%x %d\n",
+	DP("mmucreate new page 0x%p PTSZ 0x%x %d BY2PG 0x%zx %zd\n",
 		page, PTSZ, PTSZ, BY2PG, BY2PG);
 	memset(page, 0, PTSZ);
 	table[index] = PADDR(page) | flags;
--- a/os/pc64/screen.c
+++ b/os/pc64/screen.c
@@ -746,8 +746,8 @@
 {
 	VGAscr *scr;
 	int x, y, z, tilt;
-	uvlong pa;
-	ulong chan, sz;
+	uintptr pa;
+	u32 chan, sz;
 	char *s, *p, *err;
 
 	print("bootscreeninit\n");
--- a/os/port/alloc.c
+++ b/os/port/alloc.c
@@ -728,7 +728,7 @@
 	if(b == nil)
 		return;
 
-	print("%.8p %.8p %.8p %c %4d %ud (f %.8p p %.8p)\n",
+	print("%.8p %.8p %.8p %c %4d %zud (f %.8p p %.8p)\n",
 		b, b->left, b->right, c, d, b->size, b->fwd, b->prev);
 	d++;
 	for(t = b->fwd; t != b; t = t->fwd)
@@ -855,7 +855,7 @@
 static void
 corrupted(char *str, char *msg, Pool *p, Bhdr *b, void *v)
 {
-	print("%s(%p): pool %s CORRUPT: %s at %p'%ud(magic=%ux)\n",
+	print("%s(%p): pool %s CORRUPT: %s at %p'%zud(magic=%ux)\n",
 		str, v, p->name, msg, b, b->size, b->magic);
 	dumpvl("bad Bhdr", (uintptr *)((uintptr)b & ~3)-4, 10);
 }
@@ -866,7 +866,7 @@
 	Pool *p;
 	Bhdr *bc, *ec, *b, *nb, *fb = nil;
 	char *fmsg, *msg;
-	ulong fsz;
+	uintptr fsz;
 
 	SET(fsz, fmsg);
 	for (p = &table.pool[0]; p < &table.pool[nelem(table.pool)]; p++) {
@@ -931,11 +931,11 @@
 	}
 badchunk:
 	if (fb != nil) {
-		print("%s: %zux in %s:", str, v, p->name);
+		print("%s: %p in %s:", str, v, p->name);
 		if (fb == v)
-			print(" is %s '%lux\n", fmsg, fsz);
+			print(" is %s '%zux\n", fmsg, fsz);
 		else
-			print(" in %s at %lux'%lux\n", fmsg, fb, fsz);
+			print(" in %s at %p'%zux\n", fmsg, fb, fsz);
 		dumpvl("area", (uintptr *)((uintptr)v & ~3)-4, 20);
 	}
 }
--- a/os/port/allocb.c
+++ b/os/port/allocb.c
@@ -155,5 +155,5 @@
 void
 iallocsummary(void)
 {
-	print("ialloc %ud/%llud\n", ialloc.bytes, conf.ialloc);
+	print("ialloc %ud/%ud\n", ialloc.bytes, conf.ialloc);
 }
--- a/os/port/devdraw.c
+++ b/os/port/devdraw.c
@@ -1176,7 +1176,7 @@
 		m = 0;
 		for(index = 0; index < 256; index++){
 			getcolor(index, &red, &green, &blue);
-			m += sprint((char*)p+m, "%11d %11lud %11lud %11lud\n", index, red>>24, green>>24, blue>>24);
+			m += sprint((char*)p+m, "%11d %11ud %11ud %11ud\n", index, red>>24, green>>24, blue>>24);
 		}
 		n = readstr(offset, a, n, (char*)p);
 		free(p);
--- a/os/port/devsd.c
+++ b/os/port/devsd.c
@@ -1284,13 +1284,13 @@
 		if(unit->sectors){
 			if(unit->dev->ifc->rctl == nil)
 				l += snprint(p+l, m-l,
-					"geometry %llud %lud\n",
+					"geometry %ud %ud\n",
 					unit->sectors, unit->secsize);
 			pp = unit->part;
 			for(i = 0; i < unit->npart; i++){
 				if(pp->valid)
 					l += snprint(p+l, m-l,
-						"part %s %llud %llud\n",
+						"part %s %lud %lud\n",
 						pp->name, pp->start, pp->end);
 				pp++;
 			}
--- a/os/port/iomap.c
+++ b/os/port/iomap.c
@@ -111,8 +111,8 @@
  * Alloc some io port space and remember who it was
  * alloced to. If port == -1, find a free region.
  */
-u32
-ioalloc(u32 port, u32 size, u32 align, char *tag)
+s32
+ioalloc(s32 port, u32 size, u32 align, char *tag)
 {
 	IOMap *m, **l;
 
@@ -141,7 +141,7 @@
 			iomap.free = m;
 			break;
 		}
-		print("ioalloc: %lux - %lux %s: clashes with: %lux - %lux %s\n",
+		print("ioalloc: %ux - %ux %s: clashes with: %lux - %lux %s\n",
 			port, port+size-1, tag,
 			m->start, m->end-1, m->tag);
 		unlock(&iomap);
--- a/os/port/memmap.c
+++ b/os/port/memmap.c
@@ -206,11 +206,11 @@
 }
 
 uvlong
-memmapalloc(uvlong addr, uvlong size, uvlong align, ulong type)
+memmapalloc(uvlong addr, uvlong size, uvlong align, u32 type)
 {
 	Mapent *i, *e;
 
-	print("memmapalloc addr 0x%p size 0x%zx %zd align 0x%x type 0x%x\n",
+	print("memmapalloc addr 0x%p size 0x%zx %zd align 0x%zx type 0x%x\n",
 		addr, size, size, align, type);
 	type &= ~Allocated;
 	lock(&mapalloc);
@@ -225,7 +225,7 @@
 			if(addr - i->addr >= i->size)
 				goto Fail;
 		}
-		print("memmapalloc addr 0x%p i->addr 0x%p size 0x%x %d i->size 0x%x %d\n",
+		print("memmapalloc addr 0x%p i->addr 0x%p size 0x%zx %zd i->size 0x%zx %zd\n",
 			addr, i->addr, size, size, i->size, i->size);
 		if(addr - i->addr + size > i->size)
 			goto Fail;
--- a/os/port/portfns.h
+++ b/os/port/portfns.h
@@ -159,7 +159,7 @@
 uvlong		memmapnext(uvlong, ulong);
 uvlong		memmapsize(uvlong, uvlong);
 void		memmapadd(uvlong, uvlong, ulong);
-uvlong		memmapalloc(uvlong, uvlong, uvlong, ulong);
+uvlong		memmapalloc(uvlong, uvlong, uvlong, u32);
 void		memmapfree(uvlong, uvlong, ulong);
 int			memusehigh(void);
 void		microdelay(int);
--- a/os/port/sd.h
+++ b/os/port/sd.h
@@ -41,11 +41,11 @@
 	SDperm;
 
 	QLock	ctl;
-	ulong	sectors;
-	ulong	secsize;
+	u32	sectors;
+	u32	secsize;
 	SDpart*	part;			/* nil or array of size npart */
 	int	npart;
-	ulong	vers;
+	u32	vers;
 	SDperm	ctlperm;
 
 	QLock	raw;			/* raw read or write in progress */