shithub: riscv

Download patch

ref: f4f19cdf1a8f0d2aa5f9fce10c896201528b5347
parent: 424424fe50c29aa606cea42d176dcac71b968efc
parent: 37d36fdd7f441aa184c4051d02e50e9e770f20f8
author: cinap_lenrek <[email protected]>
date: Thu Apr 11 09:54:03 EDT 2019

merge

--- a/sys/src/9/bcm/arch.c
+++ b/sys/src/9/bcm/arch.c
@@ -24,7 +24,7 @@
 {
 	ureg->pc = p->sched.pc;
 	ureg->sp = p->sched.sp+4;
-	ureg->r14 = PTR2UINT(sched);
+	ureg->r14 = (uintptr)sched;
 }
 
 /*
@@ -95,8 +95,8 @@
 void
 kprocchild(Proc *p, void (*func)(void*), void *arg)
 {
-	p->sched.pc = PTR2UINT(linkproc);
-	p->sched.sp = PTR2UINT(p->kstack+KSTACK);
+	p->sched.pc = (uintptr)linkproc;
+	p->sched.sp = (uintptr)p->kstack+KSTACK;
 
 	p->kpfun = func;
 	p->kparg = arg;
--- a/sys/src/9/bcm/devarch.c
+++ b/sys/src/9/bcm/devarch.c
@@ -172,3 +172,59 @@
 	addarchfile("cputype", 0444, cputyperead, nil);
 	addarchfile("cputemp", 0444, cputempread, nil);
 }
+
+void
+uartconsinit(void)
+{
+	extern PhysUart *physuart[];
+	char *p, *cmd;
+	Uart *uart;
+	int i, n;
+
+	if((p = getconf("console")) == nil)
+		return;
+	i = strtoul(p, &cmd, 0);
+	if(p == cmd)
+		return;
+	/* we only have two possible uarts, the pl011 and aux */
+	for(n = 0; physuart[n] != nil; n++)
+		;
+	if(i < 0 || i >= n)
+		return;
+	uart = physuart[i]->pnp();
+	if(!uart->enabled)
+		(*uart->phys->enable)(uart, 0);
+	uartctl(uart, "l8 pn s1");
+	if(*cmd != '\0')
+		uartctl(uart, cmd);
+	consuart = uart;
+	uart->console = 1;
+}
+
+void
+okay(int on)
+{
+	static int first;
+	static int okled, polarity;
+	char *p;
+
+	if(!first++){
+		p = getconf("bcm2709.disk_led_gpio");
+		if(p == nil)
+			p = getconf("bcm2708.disk_led_gpio");
+		if(p != nil)
+			okled = strtol(p, 0, 0);
+		else
+			okled = 'v';
+		p = getconf("bcm2709.disk_led_active_low");
+		if(p == nil)
+			p = getconf("bcm2708.disk_led_active_low");
+		polarity = (p == nil || *p == '1');
+		if(okled != 'v')
+			gpiosel(okled, Output);
+	}
+	if(okled == 'v')
+		vgpset(0, on);
+	else if(okled != 0)
+		gpioout(okled, on^polarity);
+}
--- a/sys/src/9/bcm/dma.c
+++ b/sys/src/9/bcm/dma.c
@@ -100,13 +100,13 @@
 uintptr
 dmaaddr(void *va)
 {
-	return soc.busdram | (PTR2UINT(va) & ~KSEGM);
+	return soc.busdram | (PADDR(va) - PHYSDRAM);
 }
 
 static uintptr
 dmaioaddr(void *va)
 {
-	return soc.busio | (PTR2UINT(va) & ~VIRTIO);
+	return soc.busio | ((uintptr)va - VIRTIO);
 }
 
 static void
--- a/sys/src/9/bcm/fns.h
+++ b/sys/src/9/bcm/fns.h
@@ -131,14 +131,9 @@
 #define	kmapinval()
 #define countpagerefs(a, b)
 
-#define PTR2UINT(p)	((uintptr)(p))
-#define UINT2PTR(i)	((void*)(i))
-
 #define	waserror()	(up->nerrlab++, setlabel(&up->errlab[up->nerrlab-1]))
 
-#define KADDR(pa)	UINT2PTR(KZERO    | ((uintptr)(pa) & ~KSEGM))
-#define PADDR(va)	PTR2UINT(PHYSDRAM | ((uintptr)(va) & ~KSEGM))
-#define DMAADDR(va)	PTR2UINT(BUSDRAM  | ((uintptr)(va) & ~KSEGM))
-#define DMAIO(va)	PTR2UINT(BUSIO    | ((uintptr)(va) & ~VIRTIO))
+#define KADDR(pa)	((void*)(KZERO | ((uintptr)(pa) & ~KSEGM)))
+#define PADDR(va)	(PHYSDRAM | ((uintptr)(va) & ~KSEGM))
 
 #define MASK(v)	((1UL << (v)) - 1)	/* mask `v' bits wide */
--- a/sys/src/9/bcm/io.h
+++ b/sys/src/9/bcm/io.h
@@ -11,6 +11,7 @@
 	IRQi2c		= 53,
 	IRQspi		= 54,
 	IRQsdhost	= 56,
+	IRQuart		= 57,
 	IRQmmc		= 62,
 
 	IRQbasic	= 64,
--- /dev/null
+++ b/sys/src/9/bcm/irq.c
@@ -1,0 +1,166 @@
+#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"
+
+#define INTREGS		(VIRTIO+0xB200)
+
+enum {
+	Fiqenable = 1<<7,
+
+	Localtimerint	= 0x40,
+	Localmboxint	= 0x50,
+	Localintpending	= 0x60,
+};
+
+/*
+ * interrupt control registers
+ */
+typedef struct Intregs Intregs;
+struct Intregs {
+	u32int	ARMpending;
+	u32int	GPUpending[2];
+	u32int	FIQctl;
+	u32int	GPUenable[2];
+	u32int	ARMenable;
+	u32int	GPUdisable[2];
+	u32int	ARMdisable;
+};
+
+typedef struct Vctl Vctl;
+struct Vctl {
+	Vctl	*next;
+	int	irq;
+	u32int	*reg;
+	u32int	mask;
+	void	(*f)(Ureg*, void*);
+	void	*a;
+};
+
+static Lock vctllock;
+static Vctl *vctl[MAXMACH], *vfiq;
+
+void
+intrcpushutdown(void)
+{
+	u32int *enable;
+
+	if(soc.armlocal == 0)
+		return;
+	enable = (u32int*)(ARMLOCAL + Localtimerint) + m->machno;
+	*enable = 0;
+	if(m->machno){
+		enable = (u32int*)(ARMLOCAL + Localmboxint) + m->machno;
+		*enable = 1;
+	}
+}
+
+void
+intrsoff(void)
+{
+	Intregs *ip;
+	int disable;
+
+	ip = (Intregs*)INTREGS;
+	disable = ~0;
+	ip->GPUdisable[0] = disable;
+	ip->GPUdisable[1] = disable;
+	ip->ARMdisable = disable;
+	ip->FIQctl = 0;
+}
+
+/*
+ *  called by trap to handle irq interrupts.
+ *  returns true iff a clock interrupt, thus maybe reschedule.
+ */
+int
+irq(Ureg* ureg)
+{
+	Vctl *v;
+	int clockintr;
+
+	clockintr = 0;
+	for(v = vctl[m->machno]; v != nil; v = v->next)
+		if((*v->reg & v->mask) != 0){
+			coherence();
+			v->f(ureg, v->a);
+			coherence();
+			if(v->irq == IRQclock || v->irq == IRQcntps || v->irq == IRQcntpns)
+				clockintr = 1;
+		}
+	return clockintr;
+}
+
+/*
+ * called direct from lexception.s to handle fiq interrupt.
+ */
+void
+fiq(Ureg *ureg)
+{
+	Vctl *v;
+
+	v = vfiq;
+	if(v == nil)
+		panic("cpu%d: unexpected item in bagging area", m->machno);
+	m->intr++;
+	ureg->pc -= 4;
+	coherence();
+	v->f(ureg, v->a);
+	coherence();
+}
+
+void
+irqenable(int irq, void (*f)(Ureg*, void*), void* a)
+{
+	Vctl *v;
+	Intregs *ip;
+	u32int *enable;
+	int cpu;
+
+	ip = (Intregs*)INTREGS;
+	if((v = xalloc(sizeof(Vctl))) == nil)
+		panic("irqenable: no mem");
+	cpu = 0;
+	v->irq = irq;
+	if(irq >= IRQlocal){
+		cpu = m->machno;
+		v->reg = (u32int*)(ARMLOCAL + Localintpending) + cpu;
+		if(irq >= IRQmbox0)
+			enable = (u32int*)(ARMLOCAL + Localmboxint) + cpu;
+		else
+			enable = (u32int*)(ARMLOCAL + Localtimerint) + cpu;
+		v->mask = 1 << (irq - IRQlocal);
+	}else if(irq >= IRQbasic){
+		enable = &ip->ARMenable;
+		v->reg = &ip->ARMpending;
+		v->mask = 1 << (irq - IRQbasic);
+	}else{
+		enable = &ip->GPUenable[irq/32];
+		v->reg = &ip->GPUpending[irq/32];
+		v->mask = 1 << (irq % 32);
+	}
+	v->f = f;
+	v->a = a;
+	lock(&vctllock);
+	if(irq == IRQfiq){
+		assert((ip->FIQctl & Fiqenable) == 0);
+		assert((*enable & v->mask) == 0);
+		vfiq = v;
+		ip->FIQctl = Fiqenable | irq;
+	}else{
+		v->next = vctl[cpu];
+		vctl[cpu] = v;
+		if(irq >= IRQmbox0){
+			if(irq <= IRQmbox3)
+				*enable |= 1 << (irq - IRQmbox0);
+		}else if(irq >= IRQlocal)
+			*enable |= 1 << (irq - IRQlocal);
+		else
+			*enable = v->mask;
+	}
+	unlock(&vctllock);
+}
--- a/sys/src/9/bcm/main.c
+++ b/sys/src/9/bcm/main.c
@@ -367,7 +367,7 @@
 	 * of the argument list checked in syscall.
 	 */
 	i = oargblen+1;
-	p = UINT2PTR(STACKALIGN(base + BY2PG - sizeof(Tos) - i));
+	p = (void*)STACKALIGN(base + BY2PG - sizeof(Tos) - i);
 	memmove(p, oargb, i);
 
 	/*
@@ -379,7 +379,7 @@
 	 * not the usual (int argc, char* argv[])
 	 */
 	av = (char**)(p - (oargc+1)*sizeof(char*));
-	ssize = base + BY2PG - PTR2UINT(av);
+	ssize = base + BY2PG - (uintptr)av;
 	for(i = 0; i < oargc; i++)
 		*av++ = (oargv[i] - oargb) + (p - base) + (USTKTOP - BY2PG);
 	*av = nil;
@@ -415,8 +415,8 @@
 	/*
 	 * Kernel Stack
 	 */
-	p->sched.pc = PTR2UINT(init0);
-	p->sched.sp = PTR2UINT(p->kstack+KSTACK-sizeof(up->s.args)-sizeof(uintptr));
+	p->sched.pc = (uintptr)init0;
+	p->sched.sp = (uintptr)p->kstack+KSTACK-sizeof(up->s.args)-sizeof(uintptr);
 	p->sched.sp = STACKALIGN(p->sched.sp);
 
 	/*
@@ -445,7 +445,7 @@
 	pg->txtflush = ~0;
 	segpage(s, pg);
 	k = kmap(s->map[0]->pages[0]);
-	memmove(UINT2PTR(VA(k)), initcode, sizeof initcode);
+	memmove((void*)VA(k), initcode, sizeof initcode);
 	kunmap(k);
 
 	ready(p);
@@ -485,7 +485,7 @@
 		conf.mem[0].limit = conf.mem[0].base + memsize;
 
 	conf.npage = 0;
-	pa = PADDR(PGROUND(PTR2UINT(end)));
+	pa = PADDR(PGROUND((uintptr)end));
 
 	/*
 	 *  we assume that the kernel is at the beginning of one of the
--- a/sys/src/9/bcm/mkfile
+++ b/sys/src/9/bcm/mkfile
@@ -49,6 +49,7 @@
 	fpi.$O\
 	fpiarm.$O\
 	fpimem.$O\
+	irq.$O\
 	main.$O\
 	mmu.$O\
 	random.$O\
--- a/sys/src/9/bcm/mmu.c
+++ b/sys/src/9/bcm/mmu.c
@@ -91,7 +91,7 @@
 	l2 = &proc->mmul2;
 	for(page = *l2; page != nil; page = page->next){
 		if(clear)
-			memset(UINT2PTR(page->va), 0, L2size);
+			memset((void*)page->va, 0, L2size);
 		l1[page->daddr] = Fault;
 		l2 = &page->next;
 	}
@@ -241,7 +241,7 @@
 				m->mmul1hi = L1hi - x;
 		}
 	}
-	pte = UINT2PTR(KADDR(PPN(*l1)));
+	pte = KADDR(PPN(*l1));
 
 	/* protection bits are
 	 *	PTERONLY|PTEVALID;
@@ -283,7 +283,7 @@
 	 * Uncache a Section, must already be
 	 * valid in the MMU.
 	 */
-	va = PTR2UINT(v);
+	va = (uintptr)v;
 	assert(!(va & (1*MiB-1)) && size == 1*MiB);
 
 	x = L1X(va);
--- a/sys/src/9/bcm/trap.c
+++ b/sys/src/9/bcm/trap.c
@@ -12,18 +12,8 @@
 
 #include "arm.h"
 
-#define INTREGS		(VIRTIO+0xB200)
-
-typedef struct Intregs Intregs;
-typedef struct Vctl Vctl;
-
 enum {
 	Nvec = 8,		/* # of vectors at start of lexception.s */
-	Fiqenable = 1<<7,
-
-	Localtimerint	= 0x40,
-	Localmboxint	= 0x50,
-	Localintpending	= 0x60,
 };
 
 /*
@@ -34,31 +24,6 @@
 	u32int	vtable[Nvec];
 } Vpage0;
 
-/*
- * interrupt control registers
- */
-struct Intregs {
-	u32int	ARMpending;
-	u32int	GPUpending[2];
-	u32int	FIQctl;
-	u32int	GPUenable[2];
-	u32int	ARMenable;
-	u32int	GPUdisable[2];
-	u32int	ARMdisable;
-};
-
-struct Vctl {
-	Vctl	*next;
-	int	irq;
-	u32int	*reg;
-	u32int	mask;
-	void	(*f)(Ureg*, void*);
-	void	*a;
-};
-
-static Lock vctllock;
-static Vctl *vctl[MAXMACH], *vfiq;
-
 static char *trapnames[PsrMask+1] = {
 	[ PsrMusr ] "user mode",
 	[ PsrMfiq ] "fiq interrupt",
@@ -70,6 +35,7 @@
 	[ PsrMsys ] "sys trap",
 };
 
+extern int irq(Ureg*);
 extern int notify(Ureg*);
 
 /*
@@ -102,127 +68,6 @@
 	coherence();
 }
 
-void
-intrcpushutdown(void)
-{
-	u32int *enable;
-
-	if(soc.armlocal == 0)
-		return;
-	enable = (u32int*)(ARMLOCAL + Localtimerint) + m->machno;
-	*enable = 0;
-	if(m->machno){
-		enable = (u32int*)(ARMLOCAL + Localmboxint) + m->machno;
-		*enable = 1;
-	}
-}
-
-void
-intrsoff(void)
-{
-	Intregs *ip;
-	int disable;
-
-	ip = (Intregs*)INTREGS;
-	disable = ~0;
-	ip->GPUdisable[0] = disable;
-	ip->GPUdisable[1] = disable;
-	ip->ARMdisable = disable;
-	ip->FIQctl = 0;
-}
-
-/*
- *  called by trap to handle irq interrupts.
- *  returns true iff a clock interrupt, thus maybe reschedule.
- */
-static int
-irq(Ureg* ureg)
-{
-	Vctl *v;
-	int clockintr;
-
-	clockintr = 0;
-	for(v = vctl[m->machno]; v != nil; v = v->next)
-		if((*v->reg & v->mask) != 0){
-			coherence();
-			v->f(ureg, v->a);
-			coherence();
-			if(v->irq == IRQclock || v->irq == IRQcntps || v->irq == IRQcntpns)
-				clockintr = 1;
-		}
-	return clockintr;
-}
-
-/*
- * called direct from lexception.s to handle fiq interrupt.
- */
-void
-fiq(Ureg *ureg)
-{
-	Vctl *v;
-
-	v = vfiq;
-	if(v == nil)
-		panic("cpu%d: unexpected item in bagging area", m->machno);
-	m->intr++;
-	ureg->pc -= 4;
-	coherence();
-	v->f(ureg, v->a);
-	coherence();
-}
-
-void
-irqenable(int irq, void (*f)(Ureg*, void*), void* a)
-{
-	Vctl *v;
-	Intregs *ip;
-	u32int *enable;
-	int cpu;
-
-	ip = (Intregs*)INTREGS;
-	if((v = xalloc(sizeof(Vctl))) == nil)
-		panic("irqenable: no mem");
-	cpu = 0;
-	v->irq = irq;
-	if(irq >= IRQlocal){
-		cpu = m->machno;
-		v->reg = (u32int*)(ARMLOCAL + Localintpending) + cpu;
-		if(irq >= IRQmbox0)
-			enable = (u32int*)(ARMLOCAL + Localmboxint) + cpu;
-		else
-			enable = (u32int*)(ARMLOCAL + Localtimerint) + cpu;
-		v->mask = 1 << (irq - IRQlocal);
-	}else if(irq >= IRQbasic){
-		enable = &ip->ARMenable;
-		v->reg = &ip->ARMpending;
-		v->mask = 1 << (irq - IRQbasic);
-	}else{
-		enable = &ip->GPUenable[irq/32];
-		v->reg = &ip->GPUpending[irq/32];
-		v->mask = 1 << (irq % 32);
-	}
-	v->f = f;
-	v->a = a;
-	lock(&vctllock);
-	if(irq == IRQfiq){
-		assert((ip->FIQctl & Fiqenable) == 0);
-		assert((*enable & v->mask) == 0);
-		vfiq = v;
-		ip->FIQctl = Fiqenable | irq;
-	}else{
-		v->next = vctl[cpu];
-		vctl[cpu] = v;
-		if(irq >= IRQmbox0){
-			if(irq <= IRQmbox3)
-				*enable |= 1 << (irq - IRQmbox0);
-		}else if(irq >= IRQlocal)
-			*enable |= 1 << (irq - IRQlocal);
-		else
-			*enable = v->mask;
-	}
-	unlock(&vctllock);
-}
-
 static char *
 trapname(int psr)
 {
@@ -560,7 +405,7 @@
 	Ureg ureg;
 
 	ureg.pc = getcallerpc(&fn);
-	ureg.sp = PTR2UINT(&fn);
+	ureg.sp = (uintptr)&fn;
 	fn(&ureg);
 }
 
--- a/sys/src/9/bcm/uartmini.c
+++ b/sys/src/9/bcm/uartmini.c
@@ -47,7 +47,7 @@
 
 static Uart miniuart = {
 	.regs	= (u32int*)AUXREGS,
-	.name	= "uart0",
+	.name	= "uart1",
 	.freq	= 250000000,
 	.baud	= 115200,
 	.phys	= &miniphysuart,
@@ -100,7 +100,7 @@
 	ap[MuCntl] = TxEn|RxEn;
 	baud(uart, uart->baud);
 	if(ie){
-		intrenable(IRQaux, interrupt, uart, 0, "uart");
+		intrenable(IRQaux, interrupt, uart, 0, uart->name);
 		ap[MuIer] = RxIen|TxIen;
 	}else
 		ap[MuIer] = 0;
@@ -259,7 +259,7 @@
 {
 }
 
-void
+static void
 putc(Uart*, int c)
 {
 	u32int *ap;
@@ -272,7 +272,7 @@
 		;
 }
 
-int
+static int
 getc(Uart*)
 {
 	u32int *ap;
@@ -283,38 +283,8 @@
 	return ap[MuIo] & 0xFF;
 }
 
-void
-uartconsinit(void)
-{
-	Uart *uart;
-	int n;
-	char *p, *cmd;
-
-	if((p = getconf("console")) == nil)
-		return;
-	n = strtoul(p, &cmd, 0);
-	if(p == cmd)
-		return;
-	switch(n){
-	default:
-		return;
-	case 0:
-		uart = &miniuart;
-		break;
-	}
-
-	if(!uart->enabled)
-		(*uart->phys->enable)(uart, 0);
-	uartctl(uart, "l8 pn s1");
-	if(*cmd != '\0')
-		uartctl(uart, cmd);
-
-	consuart = uart;
-	uart->console = 1;
-}
-
 PhysUart miniphysuart = {
-	.name		= "miniuart",
+	.name		= "mini",
 	.pnp		= pnp,
 	.enable		= enable,
 	.disable	= disable,
@@ -332,31 +302,3 @@
 	.getc		= getc,
 	.putc		= putc,
 };
-
-void
-okay(int on)
-{
-	static int first;
-	static int okled, polarity;
-	char *p;
-
-	if(!first++){
-		p = getconf("bcm2709.disk_led_gpio");
-		if(p == nil)
-			p = getconf("bcm2708.disk_led_gpio");
-		if(p != nil)
-			okled = strtol(p, 0, 0);
-		else
-			okled = 'v';
-		p = getconf("bcm2709.disk_led_active_low");
-		if(p == nil)
-			p = getconf("bcm2708.disk_led_active_low");
-		polarity = (p == nil || *p == '1');
-		if(okled != 'v')
-			gpiosel(okled, Output);
-	}
-	if(okled == 'v')
-		vgpset(0, on);
-	else if(okled != 0)
-		gpioout(okled, on^polarity);
-}
--- /dev/null
+++ b/sys/src/9/bcm/uartpl011.c
@@ -1,0 +1,303 @@
+/*
+ * bcm2835 PL011 uart
+ */
+
+#include "u.h"
+#include "../port/lib.h"
+#include "../port/error.h"
+#include "mem.h"
+#include "dat.h"
+#include "fns.h"
+#include "io.h"
+
+enum {
+	DR	=	0x00>>2,
+	RSRECR	=	0x04>>2,
+	FR	=	0x18>>2,
+		TXFE	= 1<<7,
+		RXFF	= 1<<6,
+		TXFF	= 1<<5,
+		RXFE	= 1<<4,
+		BUSY	= 1<<3,
+
+	ILPR	=	0x20>>2,
+	IBRD	=	0x24>>2,
+	FBRD	=	0x28>>2,
+	LCRH	=	0x2c>>2,
+		WLENM	= 3<<5,
+		WLEN8	= 3<<5,
+		WLEN7	= 2<<5,
+		WLEN6	= 1<<5,
+		WLEN5	= 0<<5,
+		FEN	= 1<<4,	/* fifo enable */
+		STP2	= 1<<3,	/* 2 stop bits */
+		EPS	= 1<<2,	/* even parity select */
+		PEN	= 1<<1,	/* parity enabled */
+		BRK	= 1<<0,	/* send break */
+
+	CR	=	0x30>>2,
+		CTSEN	= 1<<15,
+		RTSEN	= 1<<14,
+		RTS	= 1<<11,
+		RXE	= 1<<9,
+		TXE	= 1<<8,
+		LBE	= 1<<7,
+		UARTEN	= 1<<0,
+		
+	IFLS	=	0x34>>2,
+	IMSC	=	0x38>>2,
+		TXIM	= 1<<5,
+		RXIM	= 1<<4,
+
+	RIS	=	0x3c>>2,
+	MIS	=	0x40>>2,
+	ICR	=	0x44>>2,
+	DMACR	=	0x48>>2,
+	ITCR	=	0x80>>2,
+	ITIP	=	0x84>>2,
+	ITOP	=	0x88>>2,
+	TDR	=	0x8c>>2,
+};
+
+extern PhysUart pl011physuart;
+
+static Uart pl011uart = {
+	.regs	= (u32int*)(VIRTIO+0x201000),
+	.name	= "uart0",
+	.freq	= 250000000,
+	.baud	= 115200,
+	.phys	= &pl011physuart,
+};
+
+static Uart*
+pnp(void)
+{
+	return &pl011uart;
+}
+
+static void
+interrupt(Ureg*, void *arg)
+{
+	Uart *uart = arg;
+	u32int *reg = (u32int*)uart->regs;
+
+	coherence();
+	if((reg[FR] & TXFE) == 0)
+		uartkick(uart);
+	while((reg[FR] & RXFE) == 0)
+		uartrecv(uart, reg[DR] & 0xFF);
+	coherence();
+
+}
+
+static void
+enable(Uart *uart, int ie)
+{
+	u32int *reg = (u32int*)uart->regs;
+
+	reg[CR] = UARTEN | RXE | TXE;
+	if(ie){
+		intrenable(IRQuart, interrupt, uart, 0, uart->name);
+		reg[IMSC] = TXIM|RXIM;
+	} else {
+		reg[IMSC] = 0;
+	}
+}
+
+static void
+disable(Uart *uart)
+{
+	u32int *reg = (u32int*)uart->regs;
+
+	reg[IMSC] = 0;
+	reg[CR] = 0;
+}
+
+static void
+kick(Uart *uart)
+{
+	u32int *reg = (u32int*)uart->regs;
+
+	if(uart->blocked)
+		return;
+	coherence();
+	while((reg[FR] & TXFF) == 0){
+		if(uart->op >= uart->oe && uartstageoutput(uart) == 0)
+			break;
+		reg[DR] = *(uart->op++);
+	}
+	coherence();
+}
+
+static void
+dobreak(Uart *uart, int ms)
+{
+	u32int *reg = (u32int*)uart->regs;
+
+	reg[LCRH] |= BRK;
+	delay(ms);
+	reg[LCRH] &= ~BRK;
+}
+
+static int
+baud(Uart *uart, int n)
+{
+	u32int *reg = (u32int*)uart->regs;
+
+	if(uart->freq <= 0 || n <= 0)
+		return -1;
+
+	reg[IBRD] = (uart->freq >> 4) / n;
+	reg[FBRD] = (uart->freq >> 4) % n;
+	uart->baud = n;
+	return 0;
+}
+
+static int
+bits(Uart *uart, int n)
+{
+	u32int *reg = (u32int*)uart->regs;
+
+	switch(n){
+	case 8:
+		reg[LCRH] = (reg[LCRH] & ~WLENM) | WLEN8;
+		break;
+	case 7:
+		reg[LCRH] = (reg[LCRH] & ~WLENM) | WLEN7;
+		break;
+	case 6:
+		reg[LCRH] = (reg[LCRH] & ~WLENM) | WLEN6;
+		break;
+	case 5:
+		reg[LCRH] = (reg[LCRH] & ~WLENM) | WLEN5;
+		break;
+	default:
+		return -1;
+	}
+	uart->bits = n;
+	return 0;
+}
+
+static int
+stop(Uart *uart, int n)
+{
+	u32int *reg = (u32int*)uart->regs;
+
+	switch(n){
+	case 1:
+		reg[LCRH] &= ~STP2;
+		break;
+	case 2:
+		reg[LCRH] |= STP2;
+		break;
+	default:
+		return -1;
+	}
+	uart->stop = n;
+	return 0;
+}
+
+static int
+parity(Uart *uart, int n)
+{
+	u32int *reg = (u32int*)uart->regs;
+
+	switch(n){
+	case 'n':
+		reg[LCRH] &= ~PEN;
+		break;
+	case 'e':
+		reg[LCRH] |= EPS | PEN;
+		break;
+	case 'o':
+		reg[LCRH] = (reg[LCRH] & ~EPS) | PEN;
+		break;
+	default:
+		return -1;
+	}
+	uart->parity = n;
+	return 0;
+}
+
+static void
+modemctl(Uart *uart, int on)
+{
+	uart->modem = on;
+}
+
+static void
+rts(Uart*, int)
+{
+}
+
+static long
+status(Uart *uart, void *buf, long n, long offset)
+{
+	char *p;
+
+	p = malloc(READSTR);
+	if(p == nil)
+		error(Enomem);
+	snprint(p, READSTR,
+		"b%d\n"
+		"dev(%d) type(%d) framing(%d) overruns(%d) "
+		"berr(%d) serr(%d)\n",
+
+		uart->baud,
+		uart->dev,
+		uart->type,
+		uart->ferr,
+		uart->oerr,
+		uart->berr,
+		uart->serr
+	);
+	n = readstr(offset, buf, n, p);
+	free(p);
+
+	return n;
+}
+
+static void
+donothing(Uart*, int)
+{
+}
+
+static void
+putc(Uart *uart, int c)
+{
+	u32int *reg = (u32int*)uart->regs;
+
+	while((reg[FR] & TXFF) != 0)
+		;
+	reg[DR] = c & 0xFF;
+}
+
+static int
+getc(Uart *uart)
+{
+	u32int *reg = (u32int*)uart->regs;
+
+	while((reg[FR] & RXFE) != 0)
+		;
+	return reg[DR] & 0xFF;
+}
+
+PhysUart pl011physuart = {
+	.name		= "pl011",
+	.pnp		= pnp,
+	.enable		= enable,
+	.disable	= disable,
+	.kick		= kick,
+	.dobreak	= dobreak,
+	.baud		= baud,
+	.bits		= bits,
+	.stop		= stop,
+	.parity		= parity,
+	.modemctl	= donothing,
+	.rts		= rts,
+	.dtr		= donothing,
+	.status		= status,
+	.fifo		= donothing,
+	.getc		= getc,
+	.putc		= putc,
+};
--- a/sys/src/9/bcm/vcore.c
+++ b/sys/src/9/bcm/vcore.c
@@ -149,7 +149,7 @@
 		memmove(prop->data, buf, vallen);
 	cachedwbinvse(prop, prop->len);
 	for(;;){
-		aprop = busaddr? dmaaddr(prop) : PTR2UINT(prop);
+		aprop = busaddr? dmaaddr(prop) : (uintptr)prop;
 		vcwrite(ChanProps, aprop);
 		r = vcread(ChanProps);
 		if(r == aprop)
--- a/sys/src/9/kw/arch.c
+++ b/sys/src/9/kw/arch.c
@@ -24,7 +24,7 @@
 {
 	ureg->pc = p->sched.pc;
 	ureg->sp = p->sched.sp+4;
-	ureg->r14 = PTR2UINT(sched);
+	ureg->r14 = (uintptr)sched;
 }
 
 /*
@@ -95,8 +95,8 @@
 void
 kprocchild(Proc *p, void (*func)(void*), void *arg)
 {
-	p->sched.pc = PTR2UINT(linkproc);
-	p->sched.sp = PTR2UINT(p->kstack+KSTACK);
+	p->sched.pc = (uintptr)linkproc;
+	p->sched.sp = (uintptr)p->kstack+KSTACK;
 
 	p->kpfun = func;
 	p->kparg = arg;
--- a/sys/src/9/kw/fns.h
+++ b/sys/src/9/kw/fns.h
@@ -174,9 +174,6 @@
 #define	getpgcolor(a)	0
 #define	kmapinval()
 
-#define PTR2UINT(p)	((uintptr)(p))
-#define UINT2PTR(i)	((void*)(i))
-
 #define	waserror()	(up->nerrlab++, setlabel(&up->errlab[up->nerrlab-1]))
 
 /*
@@ -195,7 +192,7 @@
 /*
  * These are not good enough.
  */
-#define KADDR(pa)	UINT2PTR(KZERO|((uintptr)(pa)))
-#define PADDR(va)	PTR2UINT(((uintptr)(va)) & ~KSEGM)
+#define KADDR(pa)	((void*)(KZERO|((uintptr)(pa))))
+#define PADDR(va)	(((uintptr)(va)) & ~KSEGM)
 
 #define MASK(v)	((1UL << (v)) - 1)	/* mask `v' bits wide */
--- a/sys/src/9/kw/main.c
+++ b/sys/src/9/kw/main.c
@@ -460,7 +460,7 @@
 	 * of the argument list checked in syscall.
 	 */
 	i = oargblen+1;
-	p = UINT2PTR(STACKALIGN(base + BY2PG - sizeof(up->s.args) - i));
+	p = (void*)(STACKALIGN(base + BY2PG - sizeof(up->s.args) - i));
 	memmove(p, oargb, i);
 
 	/*
@@ -473,7 +473,7 @@
 	 * unused so it doesn't matter (at the moment...).
 	 */
 	av = (char**)(p - (oargc+2)*sizeof(char*));
-	ssize = base + BY2PG - PTR2UINT(av);
+	ssize = base + BY2PG - (uintptr)av;
 	*av++ = (char*)oargc;
 	for(i = 0; i < oargc; i++)
 		*av++ = (oargv[i] - oargb) + (p - base) + (USTKTOP - BY2PG);
@@ -515,8 +515,8 @@
 	/*
 	 * Kernel Stack
 	 */
-	p->sched.pc = PTR2UINT(init0);
-	p->sched.sp = PTR2UINT(p->kstack+KSTACK-sizeof(up->s.args)-sizeof(uintptr));
+	p->sched.pc = (uintptr)init0;
+	p->sched.sp = (uintptr)p->kstack+KSTACK-sizeof(up->s.args)-sizeof(uintptr);
 	p->sched.sp = STACKALIGN(p->sched.sp);
 
 	/*
@@ -545,7 +545,7 @@
 	pg->txtflush = ~0;
 	segpage(s, pg);
 	k = kmap(s->map[0]->pages[0]);
-	memmove(UINT2PTR(VA(k)), initcode, sizeof initcode);
+	memmove((void*)VA(k), initcode, sizeof initcode);
 	kunmap(k);
 
 	ready(p);
@@ -578,7 +578,7 @@
 	memmove(conf.mem, sheevamem, sizeof(sheevamem));
 
 	conf.npage = 0;
-	pa = PADDR(PGROUND(PTR2UINT(end)));
+	pa = PADDR(PGROUND((uintptr)end));
 
 	/*
 	 *  we assume that the kernel is at the beginning of one of the
--- a/sys/src/9/kw/mmu.c
+++ b/sys/src/9/kw/mmu.c
@@ -154,7 +154,7 @@
 	l2 = &proc->mmul2;
 	for(page = *l2; page != nil; page = page->next){
 		if(clear)
-			memset(UINT2PTR(page->va), 0, BY2PG);
+			memset((void*)page->va, 0, BY2PG);
 		l1[page->daddr] = Fault;
 		l2 = &page->next;
 	}
@@ -301,7 +301,7 @@
 		else{
 			pg = up->mmul2cache;
 			up->mmul2cache = pg->next;
-			memset(UINT2PTR(pg->va), 0, BY2PG);
+			memset((void*)pg->va, 0, BY2PG);
 		}
 		pg->daddr = x;
 		pg->next = up->mmul2;
@@ -323,7 +323,7 @@
 				m->mmul1hi = x;
 		}
 	}
-	pte = UINT2PTR(KADDR(PPN(*l1)));
+	pte = (void*)KADDR(PPN(*l1));
 	//print("pte %#p index %ld %#ux\n", pte, L2X(va), *(pte+L2X(va)));
 
 	/* protection bits are
@@ -372,7 +372,7 @@
 	 * Uncache a Section, must already be
 	 * valid in the MMU.
 	 */
-	va = PTR2UINT(v);
+	va = (uintptr)v;
 	assert(!(va & (1*MiB-1)) && size == 1*MiB);
 
 	x = L1X(va);
@@ -459,7 +459,7 @@
 	 * will fail.
 	 */
 	if(pa+size < 4*MiB)
-		return UINT2PTR(kseg0|pa);
+		return (void*)(kseg0|pa);
 
 	osize = size;
 	o = pa & (BY2PG-1);
@@ -473,7 +473,7 @@
 		panic("vmap(%#p, %ld) called from %#p: mmukmap fails %#p",
 			pa+o, osize, getcallerpc(&pa), pae);
 
-	return UINT2PTR(va+o);
+	return (void*)(va+o);
 }
 
 /* from 386 */
--- a/sys/src/9/kw/syscall.c
+++ b/sys/src/9/kw/syscall.c
@@ -41,7 +41,7 @@
 	nf = up->ureg;
 
 	/* sanity clause */
-	if(!okaddr(PTR2UINT(nf), sizeof(NFrame), 0)){
+	if(!okaddr((uintptr)nf, sizeof(NFrame), 0)){
 		qunlock(&up->debug);
 		pprint("bad ureg in noted %#p\n", nf);
 		pexit("Suicide", 0);
@@ -77,8 +77,8 @@
 		nf->arg1 = nf->msg;
 		nf->arg0 = &nf->ureg;
 		nf->ip = 0;
-		cur->sp = PTR2UINT(nf);
-		cur->r0 = PTR2UINT(nf->arg0);
+		cur->sp = (uintptr)nf;
+		cur->r0 = (uintptr)nf->arg0;
 		break;
 	default:
 		up->lastnote.flag = NDebug;
@@ -140,7 +140,7 @@
 		qunlock(&up->debug);
 		pexit(n->msg, n->flag != NDebug);
 	}
-	if(!okaddr(PTR2UINT(up->notify), 1, 0)){
+	if(!okaddr((uintptr)up->notify, 1, 0)){
 		qunlock(&up->debug);
 		pprint("suicide: notify function address %#p\n", up->notify);
 		pexit("Suicide", 0);
@@ -153,7 +153,7 @@
 		pexit("Suicide", 0);
 	}
 
-	nf = UINT2PTR(sp);
+	nf = (void*)sp;
 	memmove(&nf->ureg, ureg, sizeof(Ureg));
 	nf->old = up->ureg;
 	up->ureg = nf;
@@ -163,8 +163,8 @@
 	nf->ip = 0;
 
 	ureg->sp = sp;
-	ureg->pc = PTR2UINT(up->notify);
-	ureg->r0 = PTR2UINT(nf->arg0);
+	ureg->pc = (uintptr)up->notify;
+	ureg->r0 = (uintptr)nf->arg0;
 
 	up->notified = 1;
 	up->nnote--;
--- a/sys/src/9/kw/trap.c
+++ b/sys/src/9/kw/trap.c
@@ -602,7 +602,7 @@
 	Ureg ureg;
 
 	ureg.pc = getcallerpc(&fn);
-	ureg.sp = PTR2UINT(&fn);
+	ureg.sp = (uintptr)&fn;
 	fn(&ureg);
 }
 
--- a/sys/src/9/omap/arch.c
+++ b/sys/src/9/omap/arch.c
@@ -24,7 +24,7 @@
 {
 	ureg->pc = p->sched.pc;
 	ureg->sp = p->sched.sp+4;
-	ureg->r14 = PTR2UINT(sched);
+	ureg->r14 = (uintptr)sched;
 }
 
 /*
@@ -95,8 +95,8 @@
 void
 kprocchild(Proc *p, void (*func)(void*), void *arg)
 {
-	p->sched.pc = PTR2UINT(linkproc);
-	p->sched.sp = PTR2UINT(p->kstack+KSTACK);
+	p->sched.pc = (uintptr)linkproc;
+	p->sched.sp = (uintptr)p->kstack+KSTACK;
 
 	p->kpfun = func;
 	p->kparg = arg;
--- a/sys/src/9/omap/fns.h
+++ b/sys/src/9/omap/fns.h
@@ -165,13 +165,10 @@
 #define	getpgcolor(a)	0
 #define	kmapinval()
 
-#define PTR2UINT(p)	((uintptr)(p))
-#define UINT2PTR(i)	((void*)(i))
-
 #define	waserror()	(up->nerrlab++, setlabel(&up->errlab[up->nerrlab-1]))
 
-#define KADDR(pa)	UINT2PTR(KZERO    | ((uintptr)(pa) & ~KSEGM))
-#define PADDR(va)	PTR2UINT(PHYSDRAM | ((uintptr)(va) & ~KSEGM))
+#define KADDR(pa)	((void*)(KZERO | ((uintptr)(pa) & ~KSEGM)))
+#define PADDR(va)	(PHYSDRAM | ((uintptr)(va) & ~KSEGM))
 
 #define wave(c) *(ulong *)PHYSCONS = (c)
 
--- a/sys/src/9/omap/main.c
+++ b/sys/src/9/omap/main.c
@@ -447,7 +447,7 @@
 	 * of the argument list checked in syscall.
 	 */
 	i = oargblen+1;
-	p = UINT2PTR(STACKALIGN(base + BY2PG - sizeof(up->s.args) - i));
+	p = (void*)(STACKALIGN(base + BY2PG - sizeof(up->s.args) - i));
 	memmove(p, oargb, i);
 
 	/*
@@ -460,7 +460,7 @@
 	 * unused so it doesn't matter (at the moment...).
 	 */
 	av = (char**)(p - (oargc+2)*sizeof(char*));
-	ssize = base + BY2PG - PTR2UINT(av);
+	ssize = base + BY2PG - (uintptr)av;
 	*av++ = (char*)oargc;
 	for(i = 0; i < oargc; i++)
 		*av++ = (oargv[i] - oargb) + (p - base) + (USTKTOP - BY2PG);
@@ -502,8 +502,8 @@
 	/*
 	 * Kernel Stack
 	 */
-	p->sched.pc = PTR2UINT(init0);
-	p->sched.sp = PTR2UINT(p->kstack+KSTACK-sizeof(up->s.args)-sizeof(uintptr));
+	p->sched.pc = (uintptr)init0;
+	p->sched.sp = (uintptr)p->kstack+KSTACK-sizeof(up->s.args)-sizeof(uintptr);
 	p->sched.sp = STACKALIGN(p->sched.sp);
 
 	/*
@@ -532,7 +532,7 @@
 	pg->txtflush = ~0;
 	segpage(s, pg);
 	k = kmap(s->map[0]->pages[0]);
-	memmove(UINT2PTR(VA(k)), initcode, sizeof initcode);
+	memmove((void*)VA(k), initcode, sizeof initcode);
 	kunmap(k);
 
 	ready(p);
@@ -596,7 +596,7 @@
 	memmove(conf.mem, omapmem, sizeof(omapmem));
 
 	conf.npage = 0;
-	pa = PADDR(PGROUND(PTR2UINT(end)));
+	pa = PADDR(PGROUND((uintptr)end));
 
 	/*
 	 *  we assume that the kernel is at the beginning of one of the
--- a/sys/src/9/omap/mmu.c
+++ b/sys/src/9/omap/mmu.c
@@ -138,7 +138,7 @@
 	l2 = &proc->mmul2;
 	for(page = *l2; page != nil; page = page->next){
 		if(clear)
-			memset(UINT2PTR(page->va), 0, BY2PG);
+			memset((void*)page->va, 0, BY2PG);
 		l1[page->daddr] = Fault;
 		l2 = &page->next;
 	}
@@ -282,7 +282,7 @@
 		else{
 			pg = up->mmul2cache;
 			up->mmul2cache = pg->next;
-			memset(UINT2PTR(pg->va), 0, BY2PG);
+			memset((void*)pg->va, 0, BY2PG);
 		}
 		pg->daddr = x;
 		pg->next = up->mmul2;
@@ -302,7 +302,7 @@
 				m->mmul1hi = x;
 		}
 	}
-	pte = UINT2PTR(KADDR(PPN(*l1)));
+	pte = KADDR(PPN(*l1));
 	//print("pte %#p index %ld was %#ux\n", pte, L2X(va), *(pte+L2X(va)));
 
 	/* protection bits are
@@ -349,7 +349,7 @@
 	 * Uncache a Section, must already be
 	 * valid in the MMU.
 	 */
-	va = PTR2UINT(v);
+	va = (uintptr)v;
 	assert(!(va & (1*MiB-1)) && size == 1*MiB);
 
 	x = L1X(va);
@@ -433,7 +433,7 @@
 	 * will fail.
 	 */
 	if(pa+size < 4*MiB)
-		return UINT2PTR(kseg0|pa);
+		return (void*)(kseg0|pa);
 
 	osize = size;
 	o = pa & (BY2PG-1);
@@ -447,7 +447,7 @@
 		panic("vmap(%#p, %ld) called from %#p: mmukmap fails %#p",
 			pa+o, osize, getcallerpc(&pa), pae);
 
-	return UINT2PTR(va+o);
+	return (void*)(va+o);
 }
 
 /* from 386 */
--- a/sys/src/9/omap/syscall.c
+++ b/sys/src/9/omap/syscall.c
@@ -41,7 +41,7 @@
 	nf = up->ureg;
 
 	/* sanity clause */
-	if(!okaddr(PTR2UINT(nf), sizeof(NFrame), 0)){
+	if(!okaddr((uintptr)nf, sizeof(NFrame), 0)){
 		qunlock(&up->debug);
 		pprint("bad ureg in noted %#p\n", nf);
 		pexit("Suicide", 0);
@@ -77,8 +77,8 @@
 		nf->arg1 = nf->msg;
 		nf->arg0 = &nf->ureg;
 		nf->ip = 0;
-		cur->sp = PTR2UINT(nf);
-		cur->r0 = PTR2UINT(nf->arg0);
+		cur->sp = (uintptr)nf;
+		cur->r0 = (uintptr)nf->arg0;
 		break;
 	default:
 		up->lastnote.flag = NDebug;
@@ -140,7 +140,7 @@
 		qunlock(&up->debug);
 		pexit(n->msg, n->flag != NDebug);
 	}
-	if(!okaddr(PTR2UINT(up->notify), 1, 0)){
+	if(!okaddr((uintptr)up->notify, 1, 0)){
 		qunlock(&up->debug);
 		pprint("suicide: notify function address %#p\n", up->notify);
 		pexit("Suicide", 0);
@@ -153,7 +153,7 @@
 		pexit("Suicide", 0);
 	}
 
-	nf = UINT2PTR(sp);
+	nf = (void*)sp;
 	memmove(&nf->ureg, ureg, sizeof(Ureg));
 	nf->old = up->ureg;
 	up->ureg = nf;
@@ -163,8 +163,8 @@
 	nf->ip = 0;
 
 	ureg->sp = sp;
-	ureg->pc = PTR2UINT(up->notify);
-	ureg->r0 = PTR2UINT(nf->arg0);
+	ureg->pc = (uintptr)up->notify;
+	ureg->r0 = (uintptr)nf->arg0;
 
 	up->notified = 1;
 	up->nnote--;
--- a/sys/src/9/omap/trap.c
+++ b/sys/src/9/omap/trap.c
@@ -644,7 +644,7 @@
 	Ureg ureg;
 
 	ureg.pc = getcallerpc(&fn);
-	ureg.sp = PTR2UINT(&fn);
+	ureg.sp = (uintptr)&fn;
 	fn(&ureg);
 }
 
--- a/sys/src/9/port/syscallfmt.c
+++ b/sys/src/9/port/syscallfmt.c
@@ -114,7 +114,7 @@
 		a = va_arg(list, char*);
 		fmtuserstring(&fmt, a, "");
 		argv = va_arg(list, char**);
-		evenaddr(PTR2UINT(argv));
+		evenaddr((uintptr)argv);
 		for(;;){
 			validaddr((uintptr)argv, sizeof(char**), 0);
 			a = *(char **)argv;
--- a/sys/src/9/teg2/arch.c
+++ b/sys/src/9/teg2/arch.c
@@ -24,7 +24,7 @@
 {
 	ureg->pc = p->sched.pc;
 	ureg->sp = p->sched.sp+4;
-	ureg->r14 = PTR2UINT(sched);
+	ureg->r14 = (uintptr)sched;
 }
 
 /*
@@ -95,8 +95,8 @@
 void
 kprocchild(Proc *p, void (*func)(void*), void *arg)
 {
-	p->sched.pc = PTR2UINT(linkproc);
-	p->sched.sp = PTR2UINT(p->kstack+KSTACK);
+	p->sched.pc = (uintptr)linkproc;
+	p->sched.sp = (uintptr)p->kstack+KSTACK;
 
 	p->kpfun = func;
 	p->kparg = arg;
--- a/sys/src/9/teg2/fns.h
+++ b/sys/src/9/teg2/fns.h
@@ -217,12 +217,9 @@
 #define	getpgcolor(a)	0
 #define	kmapinval()
 
-#define PTR2UINT(p)	((uintptr)(p))
-#define UINT2PTR(i)	((void*)(i))
-
 #define	waserror()	(up->nerrlab++, setlabel(&up->errlab[up->nerrlab-1]))
 
-#define KADDR(pa)	UINT2PTR(KZERO    | ((uintptr)(pa) & ~KSEGM))
-#define PADDR(va)	PTR2UINT(PHYSDRAM | ((uintptr)(va) & ~KSEGM))
+#define KADDR(pa)	((void*)(KZERO | ((uintptr)(pa) & ~KSEGM)))
+#define PADDR(va)	(PHYSDRAM | ((uintptr)(va) & ~KSEGM))
 
 #define MASK(v)	((1UL << (v)) - 1)	/* mask `v' bits wide */
--- a/sys/src/9/teg2/main.c
+++ b/sys/src/9/teg2/main.c
@@ -643,7 +643,7 @@
 	 * of the argument list checked in syscall.
 	 */
 	i = oargblen+1;
-	p = UINT2PTR(STACKALIGN(base + BY2PG - sizeof(up->s.args) - i));
+	p = (void*)(STACKALIGN(base + BY2PG - sizeof(up->s.args) - i));
 	memmove(p, oargb, i);
 
 	/*
@@ -656,7 +656,7 @@
 	 * unused so it doesn't matter (at the moment...).
 	 */
 	av = (char**)(p - (oargc+2)*sizeof(char*));
-	ssize = base + BY2PG - PTR2UINT(av);
+	ssize = base + BY2PG - (uintptr)av;
 	*av++ = (char*)oargc;
 	for(i = 0; i < oargc; i++)
 		*av++ = (oargv[i] - oargb) + (p - base) + (USTKTOP - BY2PG);
@@ -698,8 +698,8 @@
 	/*
 	 * Kernel Stack
 	 */
-	p->sched.pc = PTR2UINT(init0);
-	p->sched.sp = PTR2UINT(p->kstack+KSTACK-sizeof(up->s.args)-sizeof(uintptr));
+	p->sched.pc = (uintptr)init0;
+	p->sched.sp = (uintptr)p->kstack+KSTACK-sizeof(up->s.args)-sizeof(uintptr);
 	p->sched.sp = STACKALIGN(p->sched.sp);
 
 	/*
@@ -728,7 +728,7 @@
 	pg->txtflush = ~0;
 	segpage(s, pg);
 	k = kmap(s->map[0]->pages[0]);
-	memmove(UINT2PTR(VA(k)), initcode, sizeof initcode);
+	memmove((void*)VA(k), initcode, sizeof initcode);
 	kunmap(k);
 
 	ready(p);
@@ -797,7 +797,7 @@
 	memmove(conf.mem, tsmem, sizeof(tsmem));
 
 	conf.npage = 0;
-	pa = PADDR(PGROUND(PTR2UINT(end)));
+	pa = PADDR(PGROUND((uintptr)end));
 
 	/*
 	 *  we assume that the kernel is at the beginning of one of the
--- a/sys/src/9/teg2/mmu.c
+++ b/sys/src/9/teg2/mmu.c
@@ -375,7 +375,7 @@
 	l2 = &proc->mmul2;
 	for(page = *l2; page != nil; page = page->next){
 		if(clear)
-			memset(UINT2PTR(page->va), 0, BY2PG);
+			memset((void*)page->va, 0, BY2PG);
 		l1[page->daddr] = Fault;
 		allcache->wbse(l1, sizeof *l1);
 		l2 = &page->next;
@@ -527,7 +527,7 @@
 		else{
 			pg = up->mmul2cache;
 			up->mmul2cache = pg->next;
-			memset(UINT2PTR(pg->va), 0, BY2PG);
+			memset((void*)pg->va, 0, BY2PG);
 		}
 		pg->daddr = x;
 		pg->next = up->mmul2;
@@ -549,7 +549,7 @@
 				m->mmul1hi = x;
 		}
 	}
-	pte = UINT2PTR(KADDR(PPN(*l1)));
+	pte = KADDR(PPN(*l1));
 	if (Debug) {
 		iprint("pte %#p index %ld was %#ux\n", pte, L2X(va), *(pte+L2X(va)));
 		if (*(pte+L2X(va)))
@@ -602,7 +602,7 @@
 	 * Uncache a Section, must already be
 	 * valid in the MMU.
 	 */
-	va = PTR2UINT(v);
+	va = (uintptr)v;
 	assert(!(va & (1*MiB-1)) && size == 1*MiB);
 
 	x = L1X(va);
@@ -687,7 +687,7 @@
 	 * will fail.
 	 */
 	if(pa+size < 4*MiB)
-		return UINT2PTR(kseg0|pa);
+		return (void*)(kseg0|pa);
 
 	osize = size;
 	o = pa & (BY2PG-1);
@@ -701,7 +701,7 @@
 		panic("vmap(%#p, %ld) called from %#p: mmukmap fails %#p",
 			pa+o, osize, getcallerpc(&pa), pae);
 
-	return UINT2PTR(va+o);
+	return (void*)(va+o);
 }
 
 /* from 386 */
--- a/sys/src/9/teg2/syscall.c
+++ b/sys/src/9/teg2/syscall.c
@@ -47,7 +47,7 @@
 	nf = up->ureg;
 
 	/* sanity clause */
-	if(!okaddr(PTR2UINT(nf), sizeof(NFrame), 0)){
+	if(!okaddr((uintptr)nf, sizeof(NFrame), 0)){
 		qunlock(&up->debug);
 		pprint("bad ureg in noted %#p\n", nf);
 		pexit("Suicide", 0);
@@ -83,8 +83,8 @@
 		nf->arg1 = nf->msg;
 		nf->arg0 = &nf->ureg;
 		nf->ip = 0;
-		cur->sp = PTR2UINT(nf);
-		cur->r0 = PTR2UINT(nf->arg0);
+		cur->sp = (uintptr)nf;
+		cur->r0 = (uintptr)nf->arg0;
 		break;
 	default:
 		up->lastnote.flag = NDebug;
@@ -146,7 +146,7 @@
 		qunlock(&up->debug);
 		pexit(n->msg, n->flag != NDebug);
 	}
-	if(!okaddr(PTR2UINT(up->notify), 1, 0)){
+	if(!okaddr((uintptr)up->notify, 1, 0)){
 		qunlock(&up->debug);
 		pprint("suicide: notify function address %#p\n", up->notify);
 		pexit("Suicide", 0);
@@ -159,7 +159,7 @@
 		pexit("Suicide", 0);
 	}
 
-	nf = UINT2PTR(sp);
+	nf = (void*)sp;
 	memmove(&nf->ureg, ureg, sizeof(Ureg));
 	nf->old = up->ureg;
 	up->ureg = nf;
@@ -169,8 +169,8 @@
 	nf->ip = 0;
 
 	ureg->sp = sp;
-	ureg->pc = PTR2UINT(up->notify);
-	ureg->r0 = PTR2UINT(nf->arg0);
+	ureg->pc = (uintptr)up->notify;
+	ureg->r0 = (uintptr)nf->arg0;
 
 	up->notified = 1;
 	up->nnote--;
--- a/sys/src/9/teg2/trap.c
+++ b/sys/src/9/teg2/trap.c
@@ -937,7 +937,7 @@
 
 	memset(&ureg, 0, sizeof ureg);
 	ureg.pc = getcallerpc(&fn);
-	ureg.sp = PTR2UINT(&fn);
+	ureg.sp = (uintptr)&fn;
 	fn(&ureg);
 }