Browse Source

End use of m->externup everywhere.
Declare up at top of function as Proc *up = machp()->externup;
Fix the places it is assigned
Converted the 500 error cases by sed and hand-editing.
Since we're touching everything, decided to clean up some white spaces too.

Change-Id: I62478889af307f4a2695adb5c4972f5c5b579acc
Signed-off-by: Ronald G. Minnich <rminnich@gmail.com>

Ronald G. Minnich 8 years ago
parent
commit
23298ed0ad
100 changed files with 1181 additions and 1143 deletions
  1. 1 1
      sys/src/9/386/aoe.h
  2. 3 3
      sys/src/9/386/devether.c
  3. 12 12
      sys/src/9/386/devrtc.c
  4. 1 1
      sys/src/9/386/ether8169.c
  5. 11 11
      sys/src/9/386/ether82557.c
  6. 2 2
      sys/src/9/386/ether82563.c
  7. 2 2
      sys/src/9/386/etherigbe.c
  8. 11 11
      sys/src/9/386/etherm10g.c
  9. 11 11
      sys/src/9/386/pci.c
  10. 8 8
      sys/src/9/386/random.c
  11. 6 15
      sys/src/9/386/sdiahci.c
  12. 4 4
      sys/src/9/386/uarti8250.c
  13. 20 20
      sys/src/9/amd64pv/acore.c
  14. 3 3
      sys/src/9/amd64pv/acpi.h
  15. 3 3
      sys/src/9/amd64pv/amd64.h
  16. 6 6
      sys/src/9/amd64pv/apic.c
  17. 1 1
      sys/src/9/amd64pv/apic.h
  18. 6 6
      sys/src/9/amd64pv/arch.c
  19. 20 20
      sys/src/9/amd64pv/archk10.c
  20. 5 5
      sys/src/9/amd64pv/asm.c
  21. 1 1
      sys/src/9/amd64pv/backtrace.c
  22. 3 3
      sys/src/9/amd64pv/dat.h
  23. 9 9
      sys/src/9/amd64pv/devacpi.c
  24. 6 6
      sys/src/9/amd64pv/devarch.c
  25. 18 18
      sys/src/9/amd64pv/devusb.c
  26. 10 10
      sys/src/9/amd64pv/entry.S
  27. 1 1
      sys/src/9/amd64pv/ether8139.c
  28. 7 7
      sys/src/9/amd64pv/ether82563.c
  29. 1 1
      sys/src/9/amd64pv/etherif.h
  30. 1 1
      sys/src/9/amd64pv/fns.h
  31. 44 44
      sys/src/9/amd64pv/fpu.c
  32. 1 1
      sys/src/9/amd64pv/io.h
  33. 1 1
      sys/src/9/amd64pv/ioapic.c
  34. 1 1
      sys/src/9/amd64pv/iob.h
  35. 1 1
      sys/src/9/amd64pv/l64acidt.S
  36. 7 7
      sys/src/9/amd64pv/l64idt.S
  37. 5 5
      sys/src/9/amd64pv/l64vsyscall.S
  38. 42 42
      sys/src/9/amd64pv/main.c
  39. 1 1
      sys/src/9/amd64pv/mem.h
  40. 72 72
      sys/src/9/amd64pv/mmu.c
  41. 1 1
      sys/src/9/amd64pv/physalloc.c
  42. 14 14
      sys/src/9/amd64pv/pmcio.c
  43. 5 5
      sys/src/9/amd64pv/qmalloc.c
  44. 99 99
      sys/src/9/amd64pv/syscall.c
  45. 51 51
      sys/src/9/amd64pv/tcore.c
  46. 54 54
      sys/src/9/amd64pv/trap.c
  47. 19 19
      sys/src/9/amd64pv/usbohci.c
  48. 22 22
      sys/src/9/amd64pv/usbuhci.c
  49. 2 2
      sys/src/9/amd64pv/vsvm.c
  50. 1 1
      sys/src/9/boot/boot.c
  51. 1 1
      sys/src/9/boot/boot.h
  52. 3 3
      sys/src/9/ip/arp.c
  53. 1 1
      sys/src/9/ip/chandial.c
  54. 11 11
      sys/src/9/ip/devip.c
  55. 3 3
      sys/src/9/ip/esp.c
  56. 9 9
      sys/src/9/ip/ethermedium.c
  57. 4 4
      sys/src/9/ip/inferno.c
  58. 1 1
      sys/src/9/ip/ip.c
  59. 6 6
      sys/src/9/ip/ipifc.c
  60. 1 1
      sys/src/9/ip/iproute.c
  61. 1 1
      sys/src/9/ip/ipv6.c
  62. 4 4
      sys/src/9/ip/loopbackmedium.c
  63. 4 4
      sys/src/9/ip/netdevmedium.c
  64. 4 4
      sys/src/9/ip/netlog.c
  65. 3 3
      sys/src/9/ip/rudp.c
  66. 8 8
      sys/src/9/ip/tcp.c
  67. 27 27
      sys/src/9/k10/acore.c
  68. 8 8
      sys/src/9/k10/acore.c.old
  69. 3 3
      sys/src/9/k10/acpi.h
  70. 13 13
      sys/src/9/k10/apic.c
  71. 1 1
      sys/src/9/k10/apic.h
  72. 6 6
      sys/src/9/k10/arch.c
  73. 42 42
      sys/src/9/k10/archk10.c
  74. 6 6
      sys/src/9/k10/asm.c
  75. 1 1
      sys/src/9/k10/backtrace.c
  76. 34 0
      sys/src/9/k10/cga.c
  77. 3 3
      sys/src/9/k10/dat.h
  78. 10 9
      sys/src/9/k10/devacpi.c
  79. 13 12
      sys/src/9/k10/devarch.c
  80. 18 18
      sys/src/9/k10/devusb.c
  81. 10 10
      sys/src/9/k10/entry.S
  82. 1 1
      sys/src/9/k10/ether8139.c
  83. 7 7
      sys/src/9/k10/ether82563.c
  84. 1 1
      sys/src/9/k10/etherif.h
  85. 3 1
      sys/src/9/k10/fns.h
  86. 50 50
      sys/src/9/k10/fpu.c
  87. 1 1
      sys/src/9/k10/fpu.c.old
  88. 1 1
      sys/src/9/k10/io.h
  89. 1 1
      sys/src/9/k10/ioapic.c
  90. 1 1
      sys/src/9/k10/iob.h
  91. 1 1
      sys/src/9/k10/l64acidt.S
  92. 7 7
      sys/src/9/k10/l64idt.S
  93. 5 5
      sys/src/9/k10/l64vsyscall.S
  94. 102 93
      sys/src/9/k10/main.c
  95. 1 1
      sys/src/9/k10/mem.h
  96. 75 75
      sys/src/9/k10/mmu.c
  97. 1 1
      sys/src/9/k10/physalloc.c
  98. 14 14
      sys/src/9/k10/pmcio.c
  99. 5 5
      sys/src/9/k10/qmalloc.c
  100. 9 9
      sys/src/9/k10/sdata.c

+ 1 - 1
sys/src/9/386/aoe.h

@@ -1,4 +1,4 @@
-/* 
+/*
  * This file is part of the UCB release of Plan 9. It is subject to the license
  * This file is part of the UCB release of Plan 9. It is subject to the license
  * terms in the LICENSE file found in the top-level directory of this
  * terms in the LICENSE file found in the top-level directory of this
  * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No

+ 3 - 3
sys/src/9/386/devether.c

@@ -23,7 +23,7 @@ static Ether *etherxx[MaxEther];
 Chan*
 Chan*
 etherattach(char* spec)
 etherattach(char* spec)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	uint32_t ctlrno;
 	uint32_t ctlrno;
 	char *p;
 	char *p;
 	Chan *chan;
 	Chan *chan;
@@ -253,7 +253,7 @@ etheroq(Ether* ether, Block* bp)
 static int32_t
 static int32_t
 etherwrite(Chan* chan, void* buf, int32_t n, int64_t mm)
 etherwrite(Chan* chan, void* buf, int32_t n, int64_t mm)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	Ether *ether;
 	Ether *ether;
 	Block *bp;
 	Block *bp;
 	int nn, onoff;
 	int nn, onoff;
@@ -303,7 +303,7 @@ etherwrite(Chan* chan, void* buf, int32_t n, int64_t mm)
 static int32_t
 static int32_t
 etherbwrite(Chan* chan, Block* bp, int64_t mm)
 etherbwrite(Chan* chan, Block* bp, int64_t mm)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	Ether *ether;
 	Ether *ether;
 	int32_t n;
 	int32_t n;
 
 

+ 12 - 12
sys/src/9/386/devrtc.c

@@ -76,13 +76,13 @@ rtcattach(char* spec)
 	return devattach('r', spec);
 	return devattach('r', spec);
 }
 }
 
 
-static Walkqid*	 
+static Walkqid*
 rtcwalk(Chan* c, Chan *nc, char** name, int nname)
 rtcwalk(Chan* c, Chan *nc, char** name, int nname)
 {
 {
 	return devwalk(c, nc, name, nname, rtcdir, nelem(rtcdir), devgen);
 	return devwalk(c, nc, name, nname, rtcdir, nelem(rtcdir), devgen);
 }
 }
 
 
-static int32_t	 
+static int32_t
 rtcstat(Chan* c, uint8_t* dp, int32_t n)
 rtcstat(Chan* c, uint8_t* dp, int32_t n)
 {
 {
 	return devstat(c, dp, n, rtcdir, nelem(rtcdir), devgen);
 	return devstat(c, dp, n, rtcdir, nelem(rtcdir), devgen);
@@ -91,28 +91,28 @@ rtcstat(Chan* c, uint8_t* dp, int32_t n)
 static Chan*
 static Chan*
 rtcopen(Chan* c, int omode)
 rtcopen(Chan* c, int omode)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	omode = openmode(omode);
 	omode = openmode(omode);
 	switch((uint32_t)c->qid.path){
 	switch((uint32_t)c->qid.path){
 	case Qrtc:
 	case Qrtc:
-		if(strcmp(m->externup->user, eve)!=0 && omode!=OREAD)
+		if(strcmp(up->user, eve)!=0 && omode!=OREAD)
 			error(Eperm);
 			error(Eperm);
 		break;
 		break;
 	case Qnvram:
 	case Qnvram:
-		if(strcmp(m->externup->user, eve)!=0)
+		if(strcmp(up->user, eve)!=0)
 			error(Eperm);
 			error(Eperm);
 	}
 	}
 	return devopen(c, omode, rtcdir, nelem(rtcdir), devgen);
 	return devopen(c, omode, rtcdir, nelem(rtcdir), devgen);
 }
 }
 
 
-static void	 
+static void
 rtcclose(Chan* c)
 rtcclose(Chan* c)
 {
 {
 }
 }
 
 
 #define GETBCD(o) ((bcdclock[o]&0xf) + 10*(bcdclock[o]>>4))
 #define GETBCD(o) ((bcdclock[o]&0xf) + 10*(bcdclock[o]>>4))
 
 
-static int32_t	 
+static int32_t
 rtcextract(void)
 rtcextract(void)
 {
 {
 	uint8_t bcdclock[Nbcd];
 	uint8_t bcdclock[Nbcd];
@@ -182,10 +182,10 @@ rtctime(void)
 	return t;
 	return t;
 }
 }
 
 
-static int32_t	 
+static int32_t
 rtcread(Chan* c, void* buf, int32_t n, int64_t off)
 rtcread(Chan* c, void* buf, int32_t n, int64_t off)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	uint32_t t;
 	uint32_t t;
 	char *a, *start;
 	char *a, *start;
 	uint32_t offset = off;
 	uint32_t offset = off;
@@ -230,10 +230,10 @@ rtcread(Chan* c, void* buf, int32_t n, int64_t off)
 
 
 #define PUTBCD(n,o) bcdclock[o] = (n % 10) | (((n / 10) % 10)<<4)
 #define PUTBCD(n,o) bcdclock[o] = (n % 10) | (((n / 10) % 10)<<4)
 
 
-static int32_t	 
+static int32_t
 rtcwrite(Chan* c, void* buf, int32_t n, int64_t off)
 rtcwrite(Chan* c, void* buf, int32_t n, int64_t off)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	int t;
 	int t;
 	char *a, *start;
 	char *a, *start;
 	Rtc rtc;
 	Rtc rtc;
@@ -288,7 +288,7 @@ rtcwrite(Chan* c, void* buf, int32_t n, int64_t off)
 			return 0;
 			return 0;
 		if(n > Nvsize)
 		if(n > Nvsize)
 			n = Nvsize;
 			n = Nvsize;
-	
+
 		start = a = smalloc(n);
 		start = a = smalloc(n);
 		if(waserror()){
 		if(waserror()){
 			free(start);
 			free(start);

+ 1 - 1
sys/src/9/386/ether8169.c

@@ -508,7 +508,7 @@ rtl8169multicast(void* ether, unsigned char *eaddr, int add)
 static int32_t
 static int32_t
 rtl8169ifstat(Ether* edev, void* a, int32_t n, uint32_t offset)
 rtl8169ifstat(Ether* edev, void* a, int32_t n, uint32_t offset)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	char *p, *s, *e;
 	char *p, *s, *e;
 	Ctlr *ctlr;
 	Ctlr *ctlr;
 	Dtcc *dtcc;
 	Dtcc *dtcc;

+ 11 - 11
sys/src/9/386/ether82557.c

@@ -249,15 +249,15 @@ static uint8_t configdata[24] = {
 	0x03,				/* discard short Rx frames */
 	0x03,				/* discard short Rx frames */
 	0x00,				/* 503/MII */
 	0x00,				/* 503/MII */
 
 
-	0x00,	
+	0x00,
 	0x2E,				/* normal operation, NSAI */
 	0x2E,				/* normal operation, NSAI */
 	0x00,				/* linear priority */
 	0x00,				/* linear priority */
 	0x60,				/* inter-frame spacing */
 	0x60,				/* inter-frame spacing */
-	0x00,	
-	0xF2,	
+	0x00,
+	0xF2,
 	0xC8,				/* 503, promiscuous mode off */
 	0xC8,				/* 503, promiscuous mode off */
-	0x00,	
-	0x40,	
+	0x00,
+	0x40,
 	0xF3,				/* transmit padding enable */
 	0xF3,				/* transmit padding enable */
 	0x80,				/* full duplex pin enable */
 	0x80,				/* full duplex pin enable */
 	0x3F,				/* no Multi IA */
 	0x3F,				/* no Multi IA */
@@ -354,14 +354,14 @@ static void txstart(Ether*);
 static void
 static void
 watchdog(void* arg)
 watchdog(void* arg)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	Ether *ether;
 	Ether *ether;
 	Ctlr *ctlr;
 	Ctlr *ctlr;
 	//static void txstart(Ether*);
 	//static void txstart(Ether*);
 
 
 	ether = arg;
 	ether = arg;
 	for(;;){
 	for(;;){
-		tsleep(&m->externup->sleep, return0, 0, 4000);
+		tsleep(&up->sleep, return0, 0, 4000);
 
 
 		/*
 		/*
 		 * Hmmm. This doesn't seem right. Currently
 		 * Hmmm. This doesn't seem right. Currently
@@ -370,7 +370,7 @@ watchdog(void* arg)
 		 */
 		 */
 		ctlr = ether->ctlr;
 		ctlr = ether->ctlr;
 		if(ctlr == nil || ctlr->state == 0){
 		if(ctlr == nil || ctlr->state == 0){
-			print("%s: exiting\n", m->externup->text);
+			print("%s: exiting\n", up->text);
 			pexit("disabled", 0);
 			pexit("disabled", 0);
 		}
 		}
 
 
@@ -634,7 +634,7 @@ receive(Ether* ether)
 	for(rfd = (Rfd*)bp->rp; rfd->field & RfdC; rfd = (Rfd*)bp->rp){
 	for(rfd = (Rfd*)bp->rp; rfd->field & RfdC; rfd = (Rfd*)bp->rp){
 		/*
 		/*
 		 * If it's an OK receive frame
 		 * If it's an OK receive frame
-		 * 1) save the count 
+		 * 1) save the count
 		 * 2) if it's small, try to allocate a block and copy
 		 * 2) if it's small, try to allocate a block and copy
 		 *    the data, then adjust the necessary fields for reuse;
 		 *    the data, then adjust the necessary fields for reuse;
 		 * 3) if it's big, try to allocate a new Rfd and if
 		 * 3) if it's big, try to allocate a new Rfd and if
@@ -1216,7 +1216,7 @@ reset(Ether* ether)
 						break;
 						break;
 				}
 				}
 				miiw(ctlr, phyaddr, 0x1A, 0x2000);
 				miiw(ctlr, phyaddr, 0x1A, 0x2000);
-					
+
 				anar = miir(ctlr, phyaddr, 0x04);
 				anar = miir(ctlr, phyaddr, 0x04);
 				anlpar = miir(ctlr, phyaddr, 0x05) & 0x03E0;
 				anlpar = miir(ctlr, phyaddr, 0x05) & 0x03E0;
 				anar &= anlpar;
 				anar &= anlpar;
@@ -1241,7 +1241,7 @@ reset(Ether* ether)
 					medium = k;
 					medium = k;
 					break;
 					break;
 				}
 				}
-		
+
 				switch(medium){
 				switch(medium){
 				default:
 				default:
 					break;
 					break;

+ 2 - 2
sys/src/9/386/ether82563.c

@@ -696,7 +696,7 @@ static Cmdtab i82563ctlmsg[] = {
 static int32_t
 static int32_t
 i82563ctl(Ether* edev, void* buf, int32_t n)
 i82563ctl(Ether* edev, void* buf, int32_t n)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	uint32_t v;
 	uint32_t v;
 	char *p;
 	char *p;
 	Ctlr *ctlr;
 	Ctlr *ctlr;
@@ -1222,7 +1222,7 @@ i82563tproc(void *v)
 static void
 static void
 i82563attach(Ether* edev)
 i82563attach(Ether* edev)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	Block *bp;
 	Block *bp;
 	Ctlr *ctlr;
 	Ctlr *ctlr;
 	char name[KNAMELEN];
 	char name[KNAMELEN];

+ 2 - 2
sys/src/9/386/etherigbe.c

@@ -707,7 +707,7 @@ static Cmdtab igbectlmsg[] = {
 static int32_t
 static int32_t
 igbectl(Ether* edev, void* buf, int32_t n)
 igbectl(Ether* edev, void* buf, int32_t n)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	int v;
 	int v;
 	char *p;
 	char *p;
 	Ctlr *ctlr;
 	Ctlr *ctlr;
@@ -1235,7 +1235,7 @@ igberproc(void* arg)
 static void
 static void
 igbeattach(Ether* edev)
 igbeattach(Ether* edev)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	Block *bp;
 	Block *bp;
 	Ctlr *ctlr;
 	Ctlr *ctlr;
 	char name[KNAMELEN];
 	char name[KNAMELEN];

+ 11 - 11
sys/src/9/386/etherm10g.c

@@ -485,7 +485,7 @@ prepcmd(uint *cmd, int i)
 uint32_t
 uint32_t
 cmd(Ctlr *c, int type, uint64_t data)
 cmd(Ctlr *c, int type, uint64_t data)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	uint32_t buf[16], i;
 	uint32_t buf[16], i;
 	Cmd *cmd;
 	Cmd *cmd;
 
 
@@ -513,7 +513,7 @@ cmd(Ctlr *c, int type, uint64_t data)
 				dprint("[%ux]", i);
 				dprint("[%ux]", i);
 			return i;
 			return i;
 		}
 		}
-		tsleep(&m->externup->sleep, return0, 0, 1);
+		tsleep(&up->sleep, return0, 0, 1);
 	}
 	}
 	qunlock(&c->cmdl);
 	qunlock(&c->cmdl);
 	iprint("m10g: cmd timeout [%ux %ux] cmd=%d\n",
 	iprint("m10g: cmd timeout [%ux %ux] cmd=%d\n",
@@ -525,7 +525,7 @@ cmd(Ctlr *c, int type, uint64_t data)
 uint32_t
 uint32_t
 maccmd(Ctlr *c, int type, uint8_t *mac)
 maccmd(Ctlr *c, int type, uint8_t *mac)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	uint32_t buf[16], i;
 	uint32_t buf[16], i;
 	Cmd *cmd;
 	Cmd *cmd;
 
 
@@ -553,7 +553,7 @@ maccmd(Ctlr *c, int type, uint8_t *mac)
 				dprint("[%ux]", i);
 				dprint("[%ux]", i);
 			return i;
 			return i;
 		}
 		}
-		tsleep(&m->externup->sleep, return0, 0, 1);
+		tsleep(&up->sleep, return0, 0, 1);
 	}
 	}
 	qunlock(&c->cmdl);
 	qunlock(&c->cmdl);
 	iprint("m10g: maccmd timeout [%ux %ux] cmd=%d\n",
 	iprint("m10g: maccmd timeout [%ux %ux] cmd=%d\n",
@@ -571,7 +571,7 @@ enum {
 uint32_t
 uint32_t
 dmatestcmd(Ctlr *c, int type, uint64_t addr, int len)
 dmatestcmd(Ctlr *c, int type, uint64_t addr, int len)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	uint32_t buf[16], i;
 	uint32_t buf[16], i;
 
 
 	memset(buf, 0, sizeof buf);
 	memset(buf, 0, sizeof buf);
@@ -596,7 +596,7 @@ dmatestcmd(Ctlr *c, int type, uint64_t addr, int len)
 			poperror();
 			poperror();
 			return i;
 			return i;
 		}
 		}
-		tsleep(&m->externup->sleep, return0, 0, 5);
+		tsleep(&up->sleep, return0, 0, 5);
 	}
 	}
 	error(Etimeout);
 	error(Etimeout);
 	return ~0;			/* silence! */
 	return ~0;			/* silence! */
@@ -605,7 +605,7 @@ dmatestcmd(Ctlr *c, int type, uint64_t addr, int len)
 uint32_t
 uint32_t
 rdmacmd(Ctlr *c, int on)
 rdmacmd(Ctlr *c, int on)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	uint32_t buf[16], i;
 	uint32_t buf[16], i;
 
 
 	memset(buf, 0, sizeof buf);
 	memset(buf, 0, sizeof buf);
@@ -627,7 +627,7 @@ rdmacmd(Ctlr *c, int on)
 			poperror();
 			poperror();
 			return gbit32(c->cmd->c);
 			return gbit32(c->cmd->c);
 		}
 		}
-		tsleep(&m->externup->sleep, return0, 0, 1);
+		tsleep(&up->sleep, return0, 0, 1);
 	}
 	}
 	error(Etimeout);
 	error(Etimeout);
 	iprint("m10g: rdmacmd timeout\n");
 	iprint("m10g: rdmacmd timeout\n");
@@ -775,7 +775,7 @@ chkfw(Ctlr *c)
 static int
 static int
 reset(Ether *e, Ctlr *c)
 reset(Ether *e, Ctlr *c)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	uint32_t i, sz;
 	uint32_t i, sz;
 
 
 	if(waserror()){
 	if(waserror()){
@@ -1339,7 +1339,7 @@ m10ginterrupt(Ureg *ureg, void *v)
 static void
 static void
 m10gattach(Ether *e)
 m10gattach(Ether *e)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	Ctlr *c;
 	Ctlr *c;
 	char name[12];
 	char name[12];
 
 
@@ -1499,7 +1499,7 @@ static Cmdtab ctab[] = {
 static int32_t
 static int32_t
 m10gctl(Ether *e, void *v, int32_t n)
 m10gctl(Ether *e, void *v, int32_t n)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	int i;
 	int i;
 	Cmdbuf *c;
 	Cmdbuf *c;
 	Cmdtab *t;
 	Cmdtab *t;

+ 11 - 11
sys/src/9/386/pci.c

@@ -253,7 +253,7 @@ pcilscan(int bno, Pcidev** list)
 	return maxubn;
 	return maxubn;
 }
 }
 
 
-static uint8_t 
+static uint8_t
 pIIxget(Pcidev *router, uint8_t link)
 pIIxget(Pcidev *router, uint8_t link)
 {
 {
 	uint8_t pirq;
 	uint8_t pirq;
@@ -263,13 +263,13 @@ pIIxget(Pcidev *router, uint8_t link)
 	return (pirq < 16)? pirq: 0;
 	return (pirq < 16)? pirq: 0;
 }
 }
 
 
-static void 
+static void
 pIIxset(Pcidev *router, uint8_t link, uint8_t irq)
 pIIxset(Pcidev *router, uint8_t link, uint8_t irq)
 {
 {
 	pcicfgw8(router, link, irq);
 	pcicfgw8(router, link, irq);
 }
 }
 
 
-static uint8_t 
+static uint8_t
 viaget(Pcidev *router, uint8_t link)
 viaget(Pcidev *router, uint8_t link)
 {
 {
 	uint8_t pirq;
 	uint8_t pirq;
@@ -280,7 +280,7 @@ viaget(Pcidev *router, uint8_t link)
 	return (link & 1)? (pirq >> 4): (pirq & 15);
 	return (link & 1)? (pirq >> 4): (pirq & 15);
 }
 }
 
 
-static void 
+static void
 viaset(Pcidev *router, uint8_t link, uint8_t irq)
 viaset(Pcidev *router, uint8_t link, uint8_t irq)
 {
 {
 	uint8_t pirq;
 	uint8_t pirq;
@@ -297,7 +297,7 @@ struct Bridge
 	uint16_t	vid;
 	uint16_t	vid;
 	uint16_t	did;
 	uint16_t	did;
 	uint8_t	(*get)(Pcidev *, uint8_t);
 	uint8_t	(*get)(Pcidev *, uint8_t);
-	void	(*set)(Pcidev *, uint8_t, uint8_t);	
+	void	(*set)(Pcidev *, uint8_t, uint8_t);
 };
 };
 
 
 static Bridge southbridges[] = {
 static Bridge southbridges[] = {
@@ -396,7 +396,7 @@ pcirouting(void)
 			if(pci == nil)
 			if(pci == nil)
 				continue;
 				continue;
 			pin = pcicfgr8(pci, PciINTP);
 			pin = pcicfgr8(pci, PciINTP);
-			if(pin == 0 || pin == 0xff) 
+			if(pin == 0 || pin == 0xff)
 				continue;
 				continue;
 
 
 			map = &e->maps[(pin - 1) * 3];
 			map = &e->maps[(pin - 1) * 3];
@@ -422,7 +422,7 @@ pcireservemem(void)
 {
 {
 	int i;
 	int i;
 	Pcidev *p;
 	Pcidev *p;
-	
+
 	for(p = nil; p = pcimatch(p, 0, 0); )
 	for(p = nil; p = pcimatch(p, 0, 0); )
 		for(i=0; i<nelem(p->mem); i++)
 		for(i=0; i<nelem(p->mem); i++)
 			if(p->mem[i].bar && (p->mem[i].bar&1) == 0)
 			if(p->mem[i].bar && (p->mem[i].bar&1) == 0)
@@ -458,7 +458,7 @@ pcicfginit(void)
 			pcicfgmode = 1;
 			pcicfgmode = 1;
 	}
 	}
 	outl(PciADDR, n);
 	outl(PciADDR, n);
-	
+
 	if(pcicfgmode < 0){
 	if(pcicfgmode < 0){
 		unlock(&pcicfginitlock);
 		unlock(&pcicfginitlock);
 		return;
 		return;
@@ -475,7 +475,7 @@ pcicfginit(void)
 			continue;
 			continue;
 		/*
 		/*
 		 * If we have found a PCI-to-Cardbus bridge, make sure
 		 * If we have found a PCI-to-Cardbus bridge, make sure
-		 * it has no valid mappings anymore.  
+		 * it has no valid mappings anymore.
 		 */
 		 */
 		for(p = pciroot; p != nil; p = p->link){
 		for(p = pciroot; p != nil; p = p->link){
 			if (p->ccrb == 6 && p->ccru == 7) {
 			if (p->ccrb == 6 && p->ccru == 7) {
@@ -486,7 +486,7 @@ pcicfginit(void)
 		}
 		}
 	}
 	}
 
 
-	// no longer. 
+	// no longer.
 	//if(pciroot != nil && getconf("*nopcirouting") == nil)
 	//if(pciroot != nil && getconf("*nopcirouting") == nil)
 	pcirouting();
 	pcirouting();
 	pcireservemem();
 	pcireservemem();
@@ -692,7 +692,7 @@ pcicap(Pcidev *p, int cap)
 
 
 	/* status register bit 4 has capabilities */
 	/* status register bit 4 has capabilities */
 	if((pcicfgr16(p, PciPSR) & 1<<4) == 0)
 	if((pcicfgr16(p, PciPSR) & 1<<4) == 0)
-		return -1;	
+		return -1;
 	switch(pcicfgr8(p, PciHDT) & 0x7f){
 	switch(pcicfgr8(p, PciHDT) & 0x7f){
 	default:
 	default:
 		return -1;
 		return -1;

+ 8 - 8
sys/src/9/386/random.c

@@ -50,9 +50,9 @@ rbnotempty(void* v)
 static void
 static void
 genrandom(void* v)
 genrandom(void* v)
 {
 {
-	Mach *m = machp();
-	m->externup->basepri = PriNormal;
-	m->externup->priority = m->externup->basepri;
+	Proc *up = machp()->externup;
+	up->basepri = PriNormal;
+	up->priority = up->basepri;
 
 
 	for(;;){
 	for(;;){
 		for(;;)
 		for(;;)
@@ -109,7 +109,7 @@ uint32_t
 randomread(void *xp, uint32_t n)
 randomread(void *xp, uint32_t n)
 {
 {
 
 
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	uint8_t *e, *p;
 	uint8_t *e, *p;
 	uint32_t x;
 	uint32_t x;
 
 
@@ -121,7 +121,7 @@ randomread(void *xp, uint32_t n)
 	}
 	}
 
 
 	qlock(&rb);
 	qlock(&rb);
-	
+
 	/** WORKAROUND **/
 	/** WORKAROUND **/
 	for(e = p + n; p < e; ){
 	for(e = p + n; p < e; ){
 		x = (2 * rb.randn +1)%1103515245;
 		x = (2 * rb.randn +1)%1103515245;
@@ -167,19 +167,19 @@ randomread(void *xp, uint32_t n)
 uint32_t
 uint32_t
 urandomread(void *xp, uint32_t n)
 urandomread(void *xp, uint32_t n)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	uint64_t seed[16];
 	uint64_t seed[16];
 	uint8_t *e, *p;
 	uint8_t *e, *p;
 	uint32_t x=0;
 	uint32_t x=0;
 	uint64_t s0;
 	uint64_t s0;
 	uint64_t s1;
 	uint64_t s1;
-	
+
 	if(waserror()){
 	if(waserror()){
 		nexterror();
 		nexterror();
 	}
 	}
 	//The initial seed is from a good random pool.
 	//The initial seed is from a good random pool.
 	randomread(seed, sizeof(seed));
 	randomread(seed, sizeof(seed));
-	
+
 	p = xp;
 	p = xp;
 	for(e = p + n; p < e; ){
 	for(e = p + n; p < e; ){
 		s0 = seed[ x ];
 		s0 = seed[ x ];

+ 6 - 15
sys/src/9/386/sdiahci.c

@@ -267,12 +267,10 @@ dreg(char *s, Aport *p)
 static void
 static void
 esleep(int ms)
 esleep(int ms)
 {
 {
-	Mach *m;
-
-	m = machp();
+	Proc *up = machp()->externup;
 	if(waserror())
 	if(waserror())
 		return;
 		return;
-	tsleep(&m->externup->sleep, return0, 0, ms);
+	tsleep(&up->sleep, return0, 0, ms);
 	poperror();
 	poperror();
 }
 }
 
 
@@ -288,9 +286,6 @@ ahciclear(void *v)
 static void
 static void
 aesleep(Aportm *pm, Asleep *a, int ms)
 aesleep(Aportm *pm, Asleep *a, int ms)
 {
 {
-	Mach *m;
-
-	m = machp();
 	if(waserror())
 	if(waserror())
 		return;
 		return;
 	tsleep(pm, ahciclear, a, ms);
 	tsleep(pm, ahciclear, a, ms);
@@ -385,10 +380,8 @@ setudmamode(Aportc *pc, unsigned char f)
 static void
 static void
 asleep(int ms)
 asleep(int ms)
 {
 {
-	Mach *m;
-
-	m = machp();
-	if(m->externup == nil)
+	Proc *up = machp()->externup;
+	if(up == nil)
 		delay(ms);
 		delay(ms);
 	else
 	else
 		esleep(ms);
 		esleep(ms);
@@ -1307,12 +1300,10 @@ portreset:
 static void
 static void
 satakproc(void *v)
 satakproc(void *v)
 {
 {
-	Mach *m;
+	Proc *up = machp()->externup;
 	int i;
 	int i;
-
-	m = machp();
 	for(;;){
 	for(;;){
-		tsleep(&m->externup->sleep, return0, 0, Nms);
+		tsleep(&up->sleep, return0, 0, Nms);
 		for(i = 0; i < niadrive; i++)
 		for(i = 0; i < niadrive; i++)
 			if(iadrive[i] != nil)
 			if(iadrive[i] != nil)
 				checkdrive(iadrive[i], i);
 				checkdrive(iadrive[i], i);

+ 4 - 4
sys/src/9/386/uarti8250.c

@@ -185,7 +185,7 @@ i8250status(Uart* uart, void* buf, int32_t n, int32_t offset)
 		(msr & Dsr) != 0,
 		(msr & Dsr) != 0,
 		uart->hup_dsr,
 		uart->hup_dsr,
 		(lcr & WlsMASK) + 5,
 		(lcr & WlsMASK) + 5,
-		(ier & Ems) != 0, 
+		(ier & Ems) != 0,
 		(lcr & Pen) ? ((lcr & Eps) ? 'e': 'o'): 'n',
 		(lcr & Pen) ? ((lcr & Eps) ? 'e': 'o'): 'n',
 		(mcr & Rts) != 0,
 		(mcr & Rts) != 0,
 		(lcr & Stb) ? 2: 1,
 		(lcr & Stb) ? 2: 1,
@@ -430,7 +430,7 @@ i8250baud(Uart* uart, int baud)
 static void
 static void
 i8250break(Uart* uart, int ms)
 i8250break(Uart* uart, int ms)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	Ctlr *ctlr;
 	Ctlr *ctlr;
 
 
 	/*
 	/*
@@ -441,7 +441,7 @@ i8250break(Uart* uart, int ms)
 
 
 	ctlr = uart->regs;
 	ctlr = uart->regs;
 	csr8w(ctlr, Lcr, Brk);
 	csr8w(ctlr, Lcr, Brk);
-	tsleep(&m->externup->sleep, return0, 0, ms);
+	tsleep(&up->sleep, return0, 0, ms);
 	csr8w(ctlr, Lcr, 0);
 	csr8w(ctlr, Lcr, 0);
 }
 }
 
 
@@ -782,7 +782,7 @@ i8250console(char* cfg)
 		break;
 		break;
 	case 1:
 	case 1:
 		uart = &i8250uart[1];
 		uart = &i8250uart[1];
-		break;	
+		break;
 	}
 	}
 
 
 	/*
 	/*

+ 20 - 20
sys/src/9/amd64pv/acore.c

@@ -50,14 +50,14 @@ extern void _actrapret(void);
 
 
 ACVctl *acvctl[256];
 ACVctl *acvctl[256];
 
 
-/* 
+/*
  * Test inter core calls by calling a cores to print something, and then
  * Test inter core calls by calling a cores to print something, and then
  * waiting for it to complete.
  * waiting for it to complete.
  */
  */
 static void
 static void
 testiccfn(void)
 testiccfn(void)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	print("called: %s\n", ( char *)m->icc->data);
 	print("called: %s\n", ( char *)m->icc->data);
 }
 }
 
 
@@ -87,13 +87,13 @@ testicc(int i)
 static void
 static void
 acstackok(void)
 acstackok(void)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	char dummy;
 	char dummy;
 	char *sstart;
 	char *sstart;
 
 
 	sstart = (char *)m - PGSZ - 4*PTSZ - MACHSTKSZ;
 	sstart = (char *)m - PGSZ - 4*PTSZ - MACHSTKSZ;
 	if(&dummy < sstart + 4*KiB){
 	if(&dummy < sstart + 4*KiB){
-		print("ac kernel stack overflow, cpu%d stopped\n", m->machno);
+		print("ac kernel stack overflow, cpu%d stopped\n", machp()->machno);
 		DONE();
 		DONE();
 	}
 	}
 }
 }
@@ -109,16 +109,16 @@ acstackok(void)
 void
 void
 acsched(void)
 acsched(void)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	acmmuswitch();
 	acmmuswitch();
 	for(;;){
 	for(;;){
 		acstackok();
 		acstackok();
 		mwait(&m->icc->fn);
 		mwait(&m->icc->fn);
 		if(m->icc->flushtlb)
 		if(m->icc->flushtlb)
 			acmmuswitch();
 			acmmuswitch();
-		DBG("acsched: cpu%d: fn %#p\n", m->machno, m->icc->fn);
+		DBG("acsched: cpu%d: fn %#p\n", machp()->machno, m->icc->fn);
 		m->icc->fn();
 		m->icc->fn();
-		DBG("acsched: cpu%d: idle\n", m->machno);
+		DBG("acsched: cpu%d: idle\n", machp()->machno);
 		mfence();
 		mfence();
 		m->icc->fn = nil;
 		m->icc->fn = nil;
 	}
 	}
@@ -127,13 +127,13 @@ acsched(void)
 void
 void
 acmmuswitch(void)
 acmmuswitch(void)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	extern Page mach0pml4;
 	extern Page mach0pml4;
 
 
-	DBG("acmmuswitch mpl4 %#p mach0pml4 %#p m0pml4 %#p\n", m->pml4->pa, mach0pml4.pa, sys->machptr[0]->pml4->pa);
+	DBG("acmmuswitch mpl4 %#p mach0pml4 %#p m0pml4 %#p\n", machp()->pml4->pa, mach0pml4.pa, sys->machptr[0]->pml4->pa);
 
 
 
 
-	cr3put(m->pml4->pa);
+	cr3put(machp()->pml4->pa);
 }
 }
 
 
 /*
 /*
@@ -149,7 +149,7 @@ actouser(void)
 	acfpusysprocsetup(m->proc);
 	acfpusysprocsetup(m->proc);
 
 
 	u = m->proc->dbgreg;
 	u = m->proc->dbgreg;
-	DBG("cpu%d: touser usp = %#p entry %#p\n", m->machno, u->sp, u->ip);
+	DBG("cpu%d: touser usp = %#p entry %#p\n", machp()->machno, u->sp, u->ip);
 	xactouser(u->sp);
 	xactouser(u->sp);
 #endif
 #endif
 	panic("actouser");
 	panic("actouser");
@@ -163,12 +163,12 @@ actrapret(void)
 
 
 /*
 /*
  * Entered in AP core context, upon traps (system calls go through acsyscall)
  * Entered in AP core context, upon traps (system calls go through acsyscall)
- * using m->externup->dbgreg means cores MUST be homogeneous.
+ * using up->dbgreg means cores MUST be homogeneous.
  *
  *
  * BUG: We should setup some trapenable() mechanism for the AC,
  * BUG: We should setup some trapenable() mechanism for the AC,
  * so that code like fpu.c could arrange for handlers specific for
  * so that code like fpu.c could arrange for handlers specific for
  * the AC, instead of doint that by hand here.
  * the AC, instead of doint that by hand here.
- * 
+ *
  * All interrupts are masked while in the "kernel"
  * All interrupts are masked while in the "kernel"
  */
  */
 void
 void
@@ -189,7 +189,7 @@ actrap(Ureg *u)
 	if(u->type < nelem(acvctl)){
 	if(u->type < nelem(acvctl)){
 		v = acvctl[u->type];
 		v = acvctl[u->type];
 		if(v != nil){
 		if(v != nil){
-			DBG("actrap: cpu%d: %ulld\n", m->machno, u->type);
+			DBG("actrap: cpu%d: %ulld\n", machp()->machno, u->type);
 			n = v->f(u, v->a);
 			n = v->f(u, v->a);
 			if(n != nil)
 			if(n != nil)
 				goto Post;
 				goto Post;
@@ -203,7 +203,7 @@ actrap(Ureg *u)
 		ndnr();
 		ndnr();
 	case IdtIPI:
 	case IdtIPI:
 		m->intr++;
 		m->intr++;
-		DBG("actrap: cpu%d: IPI\n", m->machno);
+		DBG("actrap: cpu%d: IPI\n", machp()->machno);
 		apiceoi(IdtIPI);
 		apiceoi(IdtIPI);
 		break;
 		break;
 	case IdtTIMER:
 	case IdtTIMER:
@@ -213,10 +213,10 @@ actrap(Ureg *u)
 	case IdtPF:
 	case IdtPF:
 		/* this case is here for debug only */
 		/* this case is here for debug only */
 		m->pfault++;
 		m->pfault++;
-		DBG("actrap: cpu%d: PF cr2 %#ullx\n", m->machno, cr2get());
+		DBG("actrap: cpu%d: PF cr2 %#ullx\n", machp()->machno, cr2get());
 		break;
 		break;
 	default:
 	default:
-		print("actrap: cpu%d: %ulld\n", m->machno, u->type);
+		print("actrap: cpu%d: %ulld\n", machp()->machno, u->type);
 	}
 	}
 Post:
 Post:
 	m->icc->rc = ICCTRAP;
 	m->icc->rc = ICCTRAP;
@@ -254,7 +254,7 @@ acsyscall(void)
 	 * There's nothing else we have to do.
 	 * There's nothing else we have to do.
 	 * Otherwise, we should m->proc->dbgregs = u;
 	 * Otherwise, we should m->proc->dbgregs = u;
 	 */
 	 */
-	DBG("acsyscall: cpu%d\n", m->machno);
+	DBG("acsyscall: cpu%d\n", machp()->machno);
 
 
 	_pmcupdate(m);
 	_pmcupdate(m);
 	p = m->proc;
 	p = m->proc;
@@ -299,7 +299,7 @@ dumpreg(void *u)
 	ndnr();
 	ndnr();
 }
 }
 
 
-char *rolename[] = 
+char *rolename[] =
 {
 {
 	[NIXAC]	"AC",
 	[NIXAC]	"AC",
 	[NIXTC]	"TC",
 	[NIXTC]	"TC",
@@ -310,7 +310,7 @@ char *rolename[] =
 void
 void
 acmodeset(int mode)
 acmodeset(int mode)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	switch(mode){
 	switch(mode){
 	case NIXAC:
 	case NIXAC:
 	case NIXKC:
 	case NIXKC:

+ 3 - 3
sys/src/9/amd64pv/acpi.h

@@ -1,4 +1,4 @@
-/* 
+/*
  * This file is part of the UCB release of Plan 9. It is subject to the license
  * This file is part of the UCB release of Plan 9. It is subject to the license
  * terms in the LICENSE file found in the top-level directory of this
  * terms in the LICENSE file found in the top-level directory of this
  * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
@@ -151,7 +151,7 @@ struct Reg
 	int	accsz;		/* access size */
 	int	accsz;		/* access size */
 };
 };
 
 
-/* Generic address structure. 
+/* Generic address structure.
  */
  */
 struct Gas
 struct Gas
 {
 {
@@ -321,7 +321,7 @@ struct Srat
 			uint64_t	addr;	/* base address */
 			uint64_t	addr;	/* base address */
 			uint64_t	len;
 			uint64_t	len;
 			int	hplug;	/* hot pluggable */
 			int	hplug;	/* hot pluggable */
-			int	nvram;	/* non volatile */	
+			int	nvram;	/* non volatile */
 		} mem;
 		} mem;
 		struct{
 		struct{
 			int	dom;	/* proximity domain */
 			int	dom;	/* proximity domain */

+ 3 - 3
sys/src/9/amd64pv/amd64.h

@@ -1,4 +1,4 @@
-/* 
+/*
  * This file is part of the UCB release of Plan 9. It is subject to the license
  * This file is part of the UCB release of Plan 9. It is subject to the license
  * terms in the LICENSE file found in the top-level directory of this
  * terms in the LICENSE file found in the top-level directory of this
  * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
@@ -156,7 +156,7 @@ enum {						/* Segment Descriptor */
  * Performance Counter Configuration
  * Performance Counter Configuration
  */
  */
 enum {						/* Performance Event Selector */
 enum {						/* Performance Event Selector */
-    				 
+
 	PeHo		= 0x0000020000000000ull,/* Host only */
 	PeHo		= 0x0000020000000000ull,/* Host only */
 	PeGo		= 0x0000010000000000ull,/* Guest only */
 	PeGo		= 0x0000010000000000ull,/* Guest only */
 	PeEvMskH	= 0x0000000f00000000ull,/* Event mask H */
 	PeEvMskH	= 0x0000000f00000000ull,/* Event mask H */
@@ -202,4 +202,4 @@ enum {
  * Extern registers.
  * Extern registers.
  */
  */
 #define RMACH		R15			/* m-> */
 #define RMACH		R15			/* m-> */
-#define RUSER		R14			/* m->externup-> */
+#define RUSER		R14			/* up-> */

+ 6 - 6
sys/src/9/amd64pv/apic.c

@@ -118,7 +118,7 @@ apicisr(int vecno)
 void
 void
 apicinit(int apicno, uintmem pa, int isbp)
 apicinit(int apicno, uintmem pa, int isbp)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	Apic *apic;
 	Apic *apic;
 
 
 	/*
 	/*
@@ -198,7 +198,7 @@ apictimer(Ureg* ureg, void* v)
 int
 int
 apiconline(void)
 apiconline(void)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	Apic *apic;
 	Apic *apic;
 	uint64_t tsc;
 	uint64_t tsc;
 	uint32_t dfr, ver;
 	uint32_t dfr, ver;
@@ -275,7 +275,7 @@ apiconline(void)
 	apic->min = apic->hz/(100*HZ);
 	apic->min = apic->hz/(100*HZ);
 	apic->div = ((m->cpuhz/apic->max)+HZ/2)/HZ;
 	apic->div = ((m->cpuhz/apic->max)+HZ/2)/HZ;
 
 
-	if(m->machno == 0 || DBGFLG){
+	if(machp()->machno == 0 || DBGFLG){
 		print("apic%d: hz %lld max %lld min %lld div %lld\n", apicno,
 		print("apic%d: hz %lld max %lld min %lld div %lld\n", apicno,
 			apic->hz, apic->max, apic->min, apic->div);
 			apic->hz, apic->max, apic->min, apic->div);
 	}
 	}
@@ -319,7 +319,7 @@ apiconline(void)
 	 * then lower the task priority to allow interrupts to be
 	 * then lower the task priority to allow interrupts to be
 	 * accepted by the APIC.
 	 * accepted by the APIC.
 	 */
 	 */
-	microdelay((TK2MS(1)*1000/apmachno) * m->machno);
+	microdelay((TK2MS(1)*1000/apmachno) * machp()->machno);
 
 
 	if(apic->machno == 0){
 	if(apic->machno == 0){
 		apicrput(Tic, apic->max);
 		apicrput(Tic, apic->max);
@@ -327,7 +327,7 @@ apiconline(void)
 		apicrput(Tlvt, Periodic|IrqTIMER);
 		apicrput(Tlvt, Periodic|IrqTIMER);
 	}
 	}
 
 
-	if(m->machno == 0)
+	if(machp()->machno == 0)
 		apicrput(Tp, 0);
 		apicrput(Tp, 0);
 
 
 	xlapicmachptr[apicno] = m;
 	xlapicmachptr[apicno] = m;
@@ -352,7 +352,7 @@ apictimerenab(void)
 void
 void
 apictimerset(uint64_t next)
 apictimerset(uint64_t next)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	Mpl pl;
 	Mpl pl;
 	Apic *apic;
 	Apic *apic;
 	int64_t period;
 	int64_t period;

+ 1 - 1
sys/src/9/amd64pv/apic.h

@@ -1,4 +1,4 @@
-/* 
+/*
  * This file is part of the UCB release of Plan 9. It is subject to the license
  * This file is part of the UCB release of Plan 9. It is subject to the license
  * terms in the LICENSE file found in the top-level directory of this
  * terms in the LICENSE file found in the top-level directory of this
  * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No

+ 6 - 6
sys/src/9/amd64pv/arch.c

@@ -21,11 +21,11 @@
 #include "../port/error.h"
 #include "../port/error.h"
 
 
 /* the rules are different for different compilers. We need to define up. */
 /* the rules are different for different compilers. We need to define up. */
-// Initialize it to force it into data. 
+// Initialize it to force it into data.
 // That way, if we set them in assembly, they won't get zero'd by the bss init in main
 // That way, if we set them in assembly, they won't get zero'd by the bss init in main
 // N.B. There was an interesting hack in plan 9 c. You could grab up to two registers for your
 // N.B. There was an interesting hack in plan 9 c. You could grab up to two registers for your
 // program. In the case of Plan 9, m was r15, and up was r14. Very slick, and if there is a way to do
 // program. In the case of Plan 9, m was r15, and up was r14. Very slick, and if there is a way to do
-// this in gcc or clang I don't know it. This also nicely handled per cpu info; R15/14 were always right for 
+// this in gcc or clang I don't know it. This also nicely handled per cpu info; R15/14 were always right for
 // your core and context.
 // your core and context.
 //Mach *m = (void *)0;
 //Mach *m = (void *)0;
 
 
@@ -87,9 +87,9 @@ procsave(Proc *p)
 static void
 static void
 linkproc(void)
 linkproc(void)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	spllo();
 	spllo();
-	m->externup->kpfun(m->externup->kparg);
+	up->kpfun(up->kparg);
 	pexit("kproc dying", 0);
 	pexit("kproc dying", 0);
 }
 }
 
 
@@ -119,12 +119,12 @@ kprocchild(Proc* p, void (*func)(void*), void* arg)
 void
 void
 idlehands(void)
 idlehands(void)
 {
 {
-Mach *m = machp();
+Proc *up = machp()->externup;
 if(sys->nmach <= 1)
 if(sys->nmach <= 1)
 {
 {
 	halt();
 	halt();
 }
 }
 if(0)
 if(0)
-	if(m->machno != 0)
+	if(machp()->machno != 0)
 		halt();
 		halt();
 }
 }

+ 20 - 20
sys/src/9/amd64pv/archk10.c

@@ -19,7 +19,7 @@
 static int
 static int
 cpuidinit(void)
 cpuidinit(void)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	uint32_t eax, info[4];
 	uint32_t eax, info[4];
 
 
 	/*
 	/*
@@ -43,7 +43,7 @@ cpuidinit(void)
 
 
 	/* is mnonitor supported? */
 	/* is mnonitor supported? */
 	if (m->cpuinfo[1][2] & 8) {
 	if (m->cpuinfo[1][2] & 8) {
-		cpuid(5, 0, m->cpuinfo[2]);	
+		cpuid(5, 0, m->cpuinfo[2]);
 		mwait = k10mwait;
 		mwait = k10mwait;
 	}
 	}
 
 
@@ -53,7 +53,7 @@ cpuidinit(void)
 static int
 static int
 cpuidinfo(uint32_t eax, uint32_t ecx, uint32_t info[4])
 cpuidinfo(uint32_t eax, uint32_t ecx, uint32_t info[4])
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	if(m->ncpuinfos == 0 && cpuidinit() == 0)
 	if(m->ncpuinfos == 0 && cpuidinit() == 0)
 		return 0;
 		return 0;
 
 
@@ -214,7 +214,7 @@ print("\n");*/
 void
 void
 cpuiddump(void)
 cpuiddump(void)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	int i;
 	int i;
 	uint32_t info[4];
 	uint32_t info[4];
 
 
@@ -239,7 +239,7 @@ cpuiddump(void)
 int64_t
 int64_t
 archhz(void)
 archhz(void)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	int64_t hz;
 	int64_t hz;
 	uint32_t info0[4], info1[4];
 	uint32_t info0[4], info1[4];
 
 
@@ -254,7 +254,7 @@ archhz(void)
 	}
 	}
 
 
 	hz = cpuidhz(info0, info1);
 	hz = cpuidhz(info0, info1);
-	if(hz != 0 || m->machno != 0)
+	if(hz != 0 || machp()->machno != 0)
 		return hz;
 		return hz;
 
 
 	iprint("arch hz, cpuidhz failed, going to i8254hz\n");
 	iprint("arch hz, cpuidhz failed, going to i8254hz\n");
@@ -264,11 +264,11 @@ archhz(void)
 int
 int
 archmmu(void)
 archmmu(void)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	uint32_t info[4];
 	uint32_t info[4];
 
 
 	/*
 	/*
-	 * Should the check for m->machno != 0 be here
+	 * Should the check for machp()->machno != 0 be here
 	 * or in the caller (mmuinit)?
 	 * or in the caller (mmuinit)?
 	 *
 	 *
 	 * To do here:
 	 * To do here:
@@ -283,9 +283,9 @@ archmmu(void)
 	 */
 	 */
 	assert(PGSZ == 4*KiB);
 	assert(PGSZ == 4*KiB);
 
 
-	m->pgszlg2[0] = 12;
-	m->pgszmask[0] = (1<<12)-1;
-	m->pgsz[0] = 1<<12;
+	machp()->pgszlg2[0] = 12;
+	machp()->pgszmask[0] = (1<<12)-1;
+	machp()->pgsz[0] = 1<<12;
 	m->npgsz = 1;
 	m->npgsz = 1;
 	if(m->ncpuinfos == 0 && cpuidinit() == 0)
 	if(m->ncpuinfos == 0 && cpuidinit() == 0)
 		return 1;
 		return 1;
@@ -296,18 +296,18 @@ archmmu(void)
 	 */
 	 */
 	if(!(m->cpuinfo[1][3] & 0x00000008))
 	if(!(m->cpuinfo[1][3] & 0x00000008))
 		return 1;
 		return 1;
-	m->pgszlg2[1] = 21;
-	m->pgszmask[1] = (1<<21)-1;
-	m->pgsz[1] = 1<<21;
+	machp()->pgszlg2[1] = 21;
+	machp()->pgszmask[1] = (1<<21)-1;
+	machp()->pgsz[1] = 1<<21;
 	m->npgsz = 2;
 	m->npgsz = 2;
 
 
 	/*
 	/*
 	 * Check the Page1GB bit in function 0x80000001 DX for 1*GiB support.
 	 * Check the Page1GB bit in function 0x80000001 DX for 1*GiB support.
 	 */
 	 */
 	if(cpuidinfo(0x80000001, 0, info) && (info[3] & 0x04000000)){
 	if(cpuidinfo(0x80000001, 0, info) && (info[3] & 0x04000000)){
-		m->pgszlg2[2] = 30;
-		m->pgszmask[2] = (1<<30)-1;
-		m->pgsz[2] = 1<<30;
+		machp()->pgszlg2[2] = 30;
+		machp()->pgszmask[2] = (1<<30)-1;
+		machp()->pgsz[2] = 1<<30;
 		m->npgsz = 3;
 		m->npgsz = 3;
 	}
 	}
 
 
@@ -357,7 +357,7 @@ fmtW(Fmt *f)
 	return fmtprint(f, "%#ullx=0x[%ullx][%ullx][%ullx][%ullx][%ullx]", va,
 	return fmtprint(f, "%#ullx=0x[%ullx][%ullx][%ullx][%ullx][%ullx]", va,
 		PTLX(va, 3), PTLX(va, 2), PTLX(va, 1), PTLX(va, 0),
 		PTLX(va, 3), PTLX(va, 2), PTLX(va, 1), PTLX(va, 0),
 		va & ((1<<PGSHFT)-1));
 		va & ((1<<PGSHFT)-1));
-		
+
 }
 }
 
 
 void
 void
@@ -389,7 +389,7 @@ archidle(void)
 void
 void
 microdelay(int microsecs)
 microdelay(int microsecs)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	uint64_t r, t;
 	uint64_t r, t;
 
 
 	r = rdtsc();
 	r = rdtsc();
@@ -400,7 +400,7 @@ microdelay(int microsecs)
 void
 void
 millidelay(int millisecs)
 millidelay(int millisecs)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	uint64_t r, t;
 	uint64_t r, t;
 
 
 	r = rdtsc();
 	r = rdtsc();

+ 5 - 5
sys/src/9/amd64pv/asm.c

@@ -317,7 +317,7 @@ asmwalkalloc(usize size)
 void
 void
 asmmeminit(void)
 asmmeminit(void)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	int i, l;
 	int i, l;
 	Asm* assem;
 	Asm* assem;
 	PTE *pte, *pml4;
 	PTE *pte, *pml4;
@@ -327,7 +327,7 @@ asmmeminit(void)
 	int cx;
 	int cx;
 #endif /* ConfCrap */
 #endif /* ConfCrap */
 
 
-	assert(!((sys->vmunmapped|sys->vmend) & m->pgszmask[1]));
+	assert(!((sys->vmunmapped|sys->vmend) & machp()->pgszmask[1]));
 
 
 	if((pa = mmuphysaddr(sys->vmunused)) == ~0)
 	if((pa = mmuphysaddr(sys->vmunused)) == ~0)
 		panic("asmmeminit 1");
 		panic("asmmeminit 1");
@@ -339,7 +339,7 @@ asmmeminit(void)
 
 
 	/* assume already 2MiB aligned*/
 	/* assume already 2MiB aligned*/
 	assert(ALIGNED(sys->vmunmapped, 2*MiB));
 	assert(ALIGNED(sys->vmunmapped, 2*MiB));
-	pml4 = UINT2PTR(m->pml4->va);
+	pml4 = UINT2PTR(machp()->pml4->va);
 	while(sys->vmunmapped < sys->vmend){
 	while(sys->vmunmapped < sys->vmend){
 		l = mmuwalk(pml4, sys->vmunmapped, 1, &pte, asmwalkalloc);
 		l = mmuwalk(pml4, sys->vmunmapped, 1, &pte, asmwalkalloc);
 		DBG("%#p l %d\n", sys->vmunmapped, l);
 		DBG("%#p l %d\n", sys->vmunmapped, l);
@@ -363,11 +363,11 @@ asmmeminit(void)
 		hi = assem->addr+assem->size;
 		hi = assem->addr+assem->size;
 		/* Convert a range into pages */
 		/* Convert a range into pages */
 		for(mem = lo; mem < hi; mem = nextmem){
 		for(mem = lo; mem < hi; mem = nextmem){
-			nextmem = (mem + PGLSZ(0)) & ~m->pgszmask[0];
+			nextmem = (mem + PGLSZ(0)) & ~machp()->pgszmask[0];
 
 
 			/* Try large pages first */
 			/* Try large pages first */
 			for(i = m->npgsz - 1; i >= 0; i--){
 			for(i = m->npgsz - 1; i >= 0; i--){
-				if((mem & m->pgszmask[i]) != 0)
+				if((mem & machp()->pgszmask[i]) != 0)
 					continue;
 					continue;
 				if(mem + PGLSZ(i) > hi)
 				if(mem + PGLSZ(i) > hi)
 					continue;
 					continue;

+ 1 - 1
sys/src/9/amd64pv/backtrace.c

@@ -29,7 +29,7 @@ int backtrace_list(uintptr_t pc, uintptr_t fp, uintptr_t *pcs, size_t nr_slots)
 
 
 #if 0
 #if 0
 void backtrace_frame(uintptr_t eip, uintptr_t ebp)
 void backtrace_frame(uintptr_t eip, uintptr_t ebp)
-{ 
+{
 	char *func_name;
 	char *func_name;
 	#define MAX_BT_DEPTH 20
 	#define MAX_BT_DEPTH 20
 	uintptr_t pcs[MAX_BT_DEPTH];
 	uintptr_t pcs[MAX_BT_DEPTH];

+ 3 - 3
sys/src/9/amd64pv/dat.h

@@ -1,4 +1,4 @@
-/* 
+/*
  * This file is part of the UCB release of Plan 9. It is subject to the license
  * This file is part of the UCB release of Plan 9. It is subject to the license
  * terms in the LICENSE file found in the top-level directory of this
  * terms in the LICENSE file found in the top-level directory of this
  * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
@@ -162,7 +162,7 @@ struct MFPU
 struct NIX
 struct NIX
 {
 {
 	ICC*	icc;			/* inter-core call */
 	ICC*	icc;			/* inter-core call */
-	int	nixtype;	
+	int	nixtype;
 };
 };
 
 
 /*
 /*
@@ -422,7 +422,7 @@ extern char*rolename[];
 /*
 /*
  * Horrid.
  * Horrid.
  */
  */
-// HARVEY: TODO: bring this back, it's actually nice. Or do something better. 
+// HARVEY: TODO: bring this back, it's actually nice. Or do something better.
 // Talk to Ron before you condemn it.
 // Talk to Ron before you condemn it.
 
 
 #ifdef _DBGC_
 #ifdef _DBGC_

+ 9 - 9
sys/src/9/amd64pv/devacpi.c

@@ -273,21 +273,21 @@ cfgset32(uintptr_t p, uint32_t v, void* r)
 	pcicfgw32(&d, p, v);
 	pcicfgw32(&d, p, v);
 }
 }
 
 
-static Regio memio = 
+static Regio memio =
 {
 {
 	nil,
 	nil,
 	mget8, mset8, mget16, mset16,
 	mget8, mset8, mget16, mset16,
 	mget32, mset32, mget64, mset64
 	mget32, mset32, mget64, mset64
 };
 };
 
 
-static Regio ioio = 
+static Regio ioio =
 {
 {
 	nil,
 	nil,
 	ioget8, ioset8, ioget16, ioset16,
 	ioget8, ioset8, ioget16, ioset16,
 	ioget32, ioset32, nil, nil
 	ioget32, ioset32, nil, nil
 };
 };
 
 
-static Regio cfgio = 
+static Regio cfgio =
 {
 {
 	nil,
 	nil,
 	cfgget8, cfgset8, cfgget16, cfgset16,
 	cfgget8, cfgset8, cfgget16, cfgset16,
@@ -777,7 +777,7 @@ static void
 dumpslit(Slit *sl)
 dumpslit(Slit *sl)
 {
 {
 	int i;
 	int i;
-	
+
 	DBG("acpi slit:\n");
 	DBG("acpi slit:\n");
 	for(i = 0; i < sl->rowlen*sl->rowlen; i++){
 	for(i = 0; i < sl->rowlen*sl->rowlen; i++){
 		DBG("slit: %ux\n", sl->e[i/sl->rowlen][i%sl->rowlen].dist);
 		DBG("slit: %ux\n", sl->e[i/sl->rowlen][i%sl->rowlen].dist);
@@ -819,7 +819,7 @@ acpislit(uint8_t *p, int len)
 	dumpslit(slit);
 	dumpslit(slit);
 	for(i = 0; i < slit->rowlen; i++)
 	for(i = 0; i < slit->rowlen; i++)
 		qsort(slit->e[i], slit->rowlen, sizeof(slit->e[0][0]), cmpslitent);
 		qsort(slit->e[i], slit->rowlen, sizeof(slit->e[0][0]), cmpslitent);
-	
+
 	dumpslit(slit);
 	dumpslit(slit);
 	return nil;	/* can be unmapped once parsed */
 	return nil;	/* can be unmapped once parsed */
 }
 }
@@ -846,7 +846,7 @@ acpimblocksize(uintmem addr, int *dom)
 int
 int
 corecolor(int core)
 corecolor(int core)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	Srat *sl;
 	Srat *sl;
 	static int colors[32];
 	static int colors[32];
 
 
@@ -1455,7 +1455,7 @@ acpiintr(Ureg* ureg, void *j)
 	if(sts&1)
 	if(sts&1)
 		print("power button\n");
 		print("power button\n");
 	// XXX serve other interrupts here.
 	// XXX serve other interrupts here.
-	setpm1sts(sts);	
+	setpm1sts(sts);
 }
 }
 
 
 static void
 static void
@@ -1615,7 +1615,7 @@ acpiread(Chan *c, void *a, int32_t n, int64_t off)
 				}
 				}
 				s = ns;
 				s = ns;
 			}
 			}
-					
+
 		}
 		}
 		return readstr(off, a, n, ttext);
 		return readstr(off, a, n, ttext);
 	case Qio:
 	case Qio:
@@ -1630,7 +1630,7 @@ acpiread(Chan *c, void *a, int32_t n, int64_t off)
 static int32_t
 static int32_t
 acpiwrite(Chan *c, void *a, int32_t n, int64_t off)
 acpiwrite(Chan *c, void *a, int32_t n, int64_t off)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	Cmdtab *ct;
 	Cmdtab *ct;
 	Cmdbuf *cb;
 	Cmdbuf *cb;
 	Reg *r;
 	Reg *r;

+ 6 - 6
sys/src/9/amd64pv/devarch.c

@@ -296,7 +296,7 @@ iounused(int start, int end)
 	for(map = iomap.map; map; map = map->next){
 	for(map = iomap.map; map; map = map->next){
 		if(start >= map->start && start < map->end
 		if(start >= map->start && start < map->end
 		|| start <= map->start && end > map->start)
 		|| start <= map->start && end > map->start)
-			return 0; 
+			return 0;
 	}
 	}
 	return 1;
 	return 1;
 }
 }
@@ -436,7 +436,7 @@ archread(Chan *c, void *a, int32_t n, int64_t offset)
 			}
 			}
 #endif
 #endif
 		error("Not yet");
 		error("Not yet");
-	
+
 		break;
 		break;
 	}
 	}
 
 
@@ -525,7 +525,7 @@ void (*coherence)(void) = mfence;
 static int32_t
 static int32_t
 cputyperead(Chan* c, void *a, int32_t n, int64_t off)
 cputyperead(Chan* c, void *a, int32_t n, int64_t off)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	char buf[512], *s, *e;
 	char buf[512], *s, *e;
 	int i, k;
 	int i, k;
 
 
@@ -576,7 +576,7 @@ archreset(void)
 uint64_t
 uint64_t
 fastticks(uint64_t* hz)
 fastticks(uint64_t* hz)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	if(hz != nil)
 	if(hz != nil)
 		*hz = m->cpuhz;
 		*hz = m->cpuhz;
 	return rdtsc();
 	return rdtsc();
@@ -608,7 +608,7 @@ cycles(uint64_t* t)
 void
 void
 delay(int millisecs)
 delay(int millisecs)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	uint64_t r, t;
 	uint64_t r, t;
 
 
 	if(millisecs <= 0)
 	if(millisecs <= 0)
@@ -618,7 +618,7 @@ delay(int millisecs)
 		;
 		;
 }
 }
 
 
-/*  
+/*
  *  performance measurement ticks.  must be low overhead.
  *  performance measurement ticks.  must be low overhead.
  *  doesn't have to count over a second.
  *  doesn't have to count over a second.
  */
  */

+ 18 - 18
sys/src/9/amd64pv/devusb.c

@@ -276,7 +276,7 @@ addhcitype(char* t, int (*r)(Hci*))
 static char*
 static char*
 seprintep(char *s, char *se, Ep *ep, int all)
 seprintep(char *s, char *se, Ep *ep, int all)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	static char* dsnames[] = { "config", "enabled", "detached", "reset" };
 	static char* dsnames[] = { "config", "enabled", "detached", "reset" };
 	Udev *d;
 	Udev *d;
 	int i;
 	int i;
@@ -410,7 +410,7 @@ putep(Ep *ep)
 static void
 static void
 dumpeps(void)
 dumpeps(void)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	int i;
 	int i;
 	static char buf[512];
 	static char buf[512];
 	char *s;
 	char *s;
@@ -547,7 +547,7 @@ epdataperm(int mode)
 static int
 static int
 usbgen(Chan *c, char *l, Dirtab *d, int n, int s, Dir *dp)
 usbgen(Chan *c, char *l, Dirtab *d, int n, int s, Dir *dp)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	Qid q;
 	Qid q;
 	Dirtab *dir;
 	Dirtab *dir;
 	int perm;
 	int perm;
@@ -619,12 +619,12 @@ usbgen(Chan *c, char *l, Dirtab *d, int n, int s, Dir *dp)
 			putep(ep);
 			putep(ep);
 			nexterror();
 			nexterror();
 		}
 		}
-		se = m->externup->genbuf+sizeof(m->externup->genbuf);
-		seprint(m->externup->genbuf, se, "ep%d.%d", ep->dev->nb, ep->nb);
+		se = up->genbuf+sizeof(up->genbuf);
+		seprint(up->genbuf, se, "ep%d.%d", ep->dev->nb, ep->nb);
 		mkqid(&q, Qep0dir+4*s, 0, QTDIR);
 		mkqid(&q, Qep0dir+4*s, 0, QTDIR);
 		putep(ep);
 		putep(ep);
 		poperror();
 		poperror();
-		devdir(c, q, m->externup->genbuf, 0, eve, 0755, dp);
+		devdir(c, q, up->genbuf, 0, eve, 0755, dp);
 		if(0)ddprint("ok\n");
 		if(0)ddprint("ok\n");
 		return 1;
 		return 1;
 
 
@@ -835,7 +835,7 @@ usbload(int speed, int maxpkt)
 static Chan*
 static Chan*
 usbopen(Chan *c, int omode)
 usbopen(Chan *c, int omode)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	int q;
 	int q;
 	Ep *ep;
 	Ep *ep;
 	int mode;
 	int mode;
@@ -892,7 +892,7 @@ usbopen(Chan *c, int omode)
 static void
 static void
 epclose(Ep *ep)
 epclose(Ep *ep)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	qlock(ep);
 	qlock(ep);
 	if(waserror()){
 	if(waserror()){
 		qunlock(ep);
 		qunlock(ep);
@@ -909,7 +909,7 @@ epclose(Ep *ep)
 static void
 static void
 usbclose(Chan *c)
 usbclose(Chan *c)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	int q;
 	int q;
 	Ep *ep;
 	Ep *ep;
 
 
@@ -939,7 +939,7 @@ usbclose(Chan *c)
 static int32_t
 static int32_t
 ctlread(Chan *c, void *a, int32_t n, int64_t offset)
 ctlread(Chan *c, void *a, int32_t n, int64_t offset)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	int q;
 	int q;
 	char *s;
 	char *s;
 	char *us;
 	char *us;
@@ -1056,7 +1056,7 @@ rhubwrite(Ep *ep, void *a, int32_t n)
 static int32_t
 static int32_t
 usbread(Chan *c, void *a, int32_t n, int64_t offset)
 usbread(Chan *c, void *a, int32_t n, int64_t offset)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	int q;
 	int q;
 	Ep *ep;
 	Ep *ep;
 	int nr;
 	int nr;
@@ -1134,7 +1134,7 @@ setmaxpkt(Ep *ep, char* s)
 static int32_t
 static int32_t
 epctl(Ep *ep, Chan *c, void *a, int32_t n)
 epctl(Ep *ep, Chan *c, void *a, int32_t n)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	int i, l, mode, nb, tt;
 	int i, l, mode, nb, tt;
 	char *b, *s;
 	char *b, *s;
 	Cmdbuf *cb;
 	Cmdbuf *cb;
@@ -1190,9 +1190,9 @@ epctl(Ep *ep, Chan *c, void *a, int32_t n)
 		/* next read request will read
 		/* next read request will read
 		 * the name for the new endpoint
 		 * the name for the new endpoint
 		 */
 		 */
-		l = sizeof(m->externup->genbuf);
-		snprint(m->externup->genbuf, l, "ep%d.%d", nep->dev->nb, nep->nb);
-		kstrdup((char**)&c->aux, m->externup->genbuf);
+		l = sizeof(up->genbuf);
+		snprint(up->genbuf, l, "ep%d.%d", nep->dev->nb, nep->nb);
+		kstrdup((char**)&c->aux, up->genbuf);
 		break;
 		break;
 	case CMhub:
 	case CMhub:
 		deprint("usb epctl %s\n", cb->f[0]);
 		deprint("usb epctl %s\n", cb->f[0]);
@@ -1348,7 +1348,7 @@ epctl(Ep *ep, Chan *c, void *a, int32_t n)
 static int32_t
 static int32_t
 usbctl(void *a, int32_t n)
 usbctl(void *a, int32_t n)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	Cmdtab *ct;
 	Cmdtab *ct;
 	Cmdbuf *cb;
 	Cmdbuf *cb;
 	Ep *ep;
 	Ep *ep;
@@ -1388,7 +1388,7 @@ usbctl(void *a, int32_t n)
 static int32_t
 static int32_t
 ctlwrite(Chan *c, void *a, int32_t n)
 ctlwrite(Chan *c, void *a, int32_t n)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	int q;
 	int q;
 	Ep *ep;
 	Ep *ep;
 
 
@@ -1420,7 +1420,7 @@ ctlwrite(Chan *c, void *a, int32_t n)
 static int32_t
 static int32_t
 usbwrite(Chan *c, void *a, int32_t n, int64_t off)
 usbwrite(Chan *c, void *a, int32_t n, int64_t off)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	int nr, q;
 	int nr, q;
 	Ep *ep;
 	Ep *ep;
 
 

+ 10 - 10
sys/src/9/amd64pv/entry.S

@@ -6,7 +6,7 @@
 
 
 // It gets REALLY ugly to try  to link this at some low address and then have the rest of the
 // It gets REALLY ugly to try  to link this at some low address and then have the rest of the
 // kernel linked high. Really, really ugly. And that defines any attempt to load at a randome
 // kernel linked high. Really, really ugly. And that defines any attempt to load at a randome
-// address. So, you have to learn to write position independent code here. 
+// address. So, you have to learn to write position independent code here.
 // It will make you stronger. Assuming you survive the training.
 // It will make you stronger. Assuming you survive the training.
 .code32
 .code32
 
 
@@ -90,7 +90,7 @@ gdt_end:
  *	cache will be reloaded.
  *	cache will be reloaded.
  */
  */
 	.align	4
 	.align	4
-1: 
+1:
 //	jmp 1b
 //	jmp 1b
 .globl protected_start
 .globl protected_start
 protected_start:
 protected_start:
@@ -316,7 +316,7 @@ _start64v:
 // Don't undo this until all APs are started. Then we don't need to bother
 // Don't undo this until all APs are started. Then we don't need to bother
 // having the APs remap it. Save work.
 // having the APs remap it. Save work.
 	// OK, this part is called "we climbed up the tree on a ladder, now pull
 	// OK, this part is called "we climbed up the tree on a ladder, now pull
-	// the ladder up after us.". We remove the identity mapping. 
+	// the ladder up after us.". We remove the identity mapping.
 _zap0pml4:
 _zap0pml4:
 	cmpq	$PML4O(KZERO), %rdx		/* KZER0 & 0x0000ff8000000000 */
 	cmpq	$PML4O(KZERO), %rdx		/* KZER0 & 0x0000ff8000000000 */
 	JE	_zap0pdp
 	JE	_zap0pdp
@@ -340,7 +340,7 @@ _zap0done:
 
 
 	addq	$(2*PTSZ+4*KiB), %rax		/* PD+PT+vsvm */
 	addq	$(2*PTSZ+4*KiB), %rax		/* PD+PT+vsvm */
 	movq	%rax, entrym
 	movq	%rax, entrym
-	movq	$0, (%rax) 				/* m->machno = 0 */
+	movq	$0, (%rax) 				/* machp()->machno = 0 */
 
 
 	PUSHQ	%rdx				/* clear flags */
 	PUSHQ	%rdx				/* clear flags */
 	POPFQ
 	POPFQ
@@ -437,7 +437,7 @@ gdtptr78:
 	.quad	0x0020980000000000		/* Long mode CS */
 	.quad	0x0020980000000000		/* Long mode CS */
 gdt78_end:
 gdt78_end:
 .global e1978
 .global e1978
-e1978:	
+e1978:
 
 
 /*
 /*
  * Protected mode. Welcome to 1982.
  * Protected mode. Welcome to 1982.
@@ -467,7 +467,7 @@ e1978:
 #define PDO(v)		((PTLX((v), 1))<<3)
 #define PDO(v)		((PTLX((v), 1))<<3)
 #define PTO(v)		((PTLX((v), 0))<<3)
 #define PTO(v)		((PTLX((v), 0))<<3)
 
 
-_approtected:	
+_approtected:
 	MOVL	$0xfee00000, %ebp	/* apicbase */
 	MOVL	$0xfee00000, %ebp	/* apicbase */
 	MOVL	0x20(%eBP), %eBP	/* Id */
 	MOVL	0x20(%eBP), %eBP	/* Id */
 	SHRL	$24, %eBP		/* becomes RARG later */
 	SHRL	$24, %eBP		/* becomes RARG later */
@@ -504,7 +504,7 @@ _approtected:
  *	make an inter-segment jump to the Long Mode code.
  *	make an inter-segment jump to the Long Mode code.
  * It's all in 32-bit mode until the jump is made.
  * It's all in 32-bit mode until the jump is made.
  */
  */
-aplme:	
+aplme:
 	MOVL	%CR4, %eAX
 	MOVL	%CR4, %eAX
 	ANDL	$~Pse, %eAX			/* Page Size */
 	ANDL	$~Pse, %eAX			/* Page Size */
 	ORL	$(Pge|Pae), %eAX			/* Page Global, Phys. Address */
 	ORL	$(Pge|Pae), %eAX			/* Page Global, Phys. Address */
@@ -532,12 +532,12 @@ aplme:
  */
  */
 .code64
 .code64
 
 
-_apidentity:	
+_apidentity:
 	MOVQ	$_apstart64v, %rAX
 	MOVQ	$_apstart64v, %rAX
 	JMP	*%rAX
 	JMP	*%rAX
 
 
 .section .text
 .section .text
-_apstart64v:	
+_apstart64v:
 	MOVQ	$_gdtptr64v, %rAX
 	MOVQ	$_gdtptr64v, %rAX
 
 
 	lgdt	(%rax)
 	lgdt	(%rax)
@@ -554,7 +554,7 @@ _apstart64v:
 
 
 	MOVQ	%rAX, %rSP			/* set stack */
 	MOVQ	%rAX, %rSP			/* set stack */
 
 
-	// DON'T ZAP. 
+	// DON'T ZAP.
 	// DO IT LATER.
 	// DO IT LATER.
 	//MOVQ	%rDX, PML4O(0)(%rAX)		/* zap identity map */
 	//MOVQ	%rDX, PML4O(0)(%rAX)		/* zap identity map */
 
 

+ 1 - 1
sys/src/9/amd64pv/ether8139.c

@@ -754,7 +754,7 @@ rtl8139match(Ether* edev, int id)
 
 
 		if(pcigetpms(p) > 0){
 		if(pcigetpms(p) > 0){
 			pcisetpms(p, 0);
 			pcisetpms(p, 0);
-	
+
 			for(i = 0; i < 6; i++)
 			for(i = 0; i < 6; i++)
 				pcicfgw32(p, PciBAR0+i*4, p->mem[i].bar);
 				pcicfgw32(p, PciBAR0+i*4, p->mem[i].bar);
 			pcicfgw8(p, PciINTL, p->intl);
 			pcicfgw8(p, PciINTL, p->intl);

+ 7 - 7
sys/src/9/amd64pv/ether82563.c

@@ -8,7 +8,7 @@
  */
  */
 
 
  /*
  /*
- * Intel 8256[367], 8257[1-9], 82573[ev], 
+ * Intel 8256[367], 8257[1-9], 82573[ev],
  * 82575eb, 82576, 82577, 82579, 8258[03]
  * 82575eb, 82576, 82577, 82579, 8258[03]
  *	Gigabit Ethernet PCI-Express Controllers
  *	Gigabit Ethernet PCI-Express Controllers
  * Coraid EtherDrive® hba
  * Coraid EtherDrive® hba
@@ -488,7 +488,7 @@ enum {
 	i82575,
 	i82575,
 	i82576,
 	i82576,
 	i82577,
 	i82577,
-	i82577m,	
+	i82577m,
 	i82578,
 	i82578,
 	i82578m,
 	i82578m,
 	i82579,
 	i82579,
@@ -879,7 +879,7 @@ i82563txinit(Ctlr* ctlr)
 	csr32w(ctlr, Tdt, 0);
 	csr32w(ctlr, Tdt, 0);
 	for(i = 0; i < ctlr->ntd; i++){
 	for(i = 0; i < ctlr->ntd; i++){
 		if((bp = ctlr->tb[i]) != nil){
 		if((bp = ctlr->tb[i]) != nil){
-			ctlr->tb[i] = nil;	
+			ctlr->tb[i] = nil;
 			freeb(bp);
 			freeb(bp);
 		}
 		}
 		memset(&ctlr->tdba[i], 0, sizeof(Td));
 		memset(&ctlr->tdba[i], 0, sizeof(Td));
@@ -1423,7 +1423,7 @@ i82563tproc(void *v)
 static void
 static void
 i82563attach(Ether* edev)
 i82563attach(Ether* edev)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	char name[KNAMELEN];
 	char name[KNAMELEN];
 	Block *bp;
 	Block *bp;
 	Ctlr *ctlr;
 	Ctlr *ctlr;
@@ -1809,7 +1809,7 @@ static Cmdtab i82563ctlmsg[] = {
 static int32_t
 static int32_t
 i82563ctl(Ether *edev, void *buf, int32_t n)
 i82563ctl(Ether *edev, void *buf, int32_t n)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	char *p;
 	char *p;
 	uint32_t v;
 	uint32_t v;
 	Ctlr *ctlr;
 	Ctlr *ctlr;
@@ -1923,7 +1923,7 @@ didtype(int d)
 	case 0x150f:		/* fiber */
 	case 0x150f:		/* fiber */
 	case 0x1510:		/* backplane */
 	case 0x1510:		/* backplane */
 	case 0x1511:		/* sfp */
 	case 0x1511:		/* sfp */
-	case 0x1516:		
+	case 0x1516:
 		return i82580;
 		return i82580;
 	case 0x1506:		/* v */
 	case 0x1506:		/* v */
 		return i82583;
 		return i82583;
@@ -1974,7 +1974,7 @@ i82563pci(void)
 		if((type = didtype(p->did)) == -1)
 		if((type = didtype(p->did)) == -1)
 			continue;
 			continue;
 		ctlr = malloc(sizeof(Ctlr));
 		ctlr = malloc(sizeof(Ctlr));
-		if(ctlr == nil) 
+		if(ctlr == nil)
 			error(Enomem);
 			error(Enomem);
 		ctlr->type = type;
 		ctlr->type = type;
 		ctlr->pcidev = p;
 		ctlr->pcidev = p;

+ 1 - 1
sys/src/9/amd64pv/etherif.h

@@ -1,4 +1,4 @@
-/* 
+/*
  * This file is part of the UCB release of Plan 9. It is subject to the license
  * This file is part of the UCB release of Plan 9. It is subject to the license
  * terms in the LICENSE file found in the top-level directory of this
  * terms in the LICENSE file found in the top-level directory of this
  * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No

+ 1 - 1
sys/src/9/amd64pv/fns.h

@@ -205,7 +205,7 @@ void	acsyscallentry(void);
 void	syscallreturn(void);
 void	syscallreturn(void);
 void	sysrforkret(void);
 void	sysrforkret(void);
 
 
-#define	waserror()	(m->externup->nerrlab++, setlabel(&m->externup->errlab[m->externup->nerrlab-1]))
+#define	waserror()	(up->nerrlab++, setlabel(&up->errlab[up->nerrlab-1]))
 
 
 #define	dcflush(a, b)
 #define	dcflush(a, b)
 
 

+ 44 - 44
sys/src/9/amd64pv/fpu.c

@@ -120,7 +120,7 @@ fpudevprocio(Proc* proc, void* a, int32_t n, uintptr_t offset, int write)
 void
 void
 fpunotify(Ureg* u)
 fpunotify(Ureg* u)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	/*
 	/*
 	 * Called when a note is about to be delivered to a
 	 * Called when a note is about to be delivered to a
 	 * user process, usually at the end of a system call.
 	 * user process, usually at the end of a system call.
@@ -128,55 +128,55 @@ fpunotify(Ureg* u)
 	 * the state is marked (after saving if necessary) and
 	 * the state is marked (after saving if necessary) and
 	 * checked in the Device Not Available handler.
 	 * checked in the Device Not Available handler.
 	 */
 	 */
-	if(m->externup->fpustate == Busy){
-		_fxsave(m->externup->fpusave);
+	if(up->fpustate == Busy){
+		_fxsave(up->fpusave);
 		_stts();
 		_stts();
-		m->externup->fpustate = Idle;
+		up->fpustate = Idle;
 	}
 	}
-	m->externup->fpustate |= Hold;
+	up->fpustate |= Hold;
 }
 }
 
 
 void
 void
 fpunoted(void)
 fpunoted(void)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	/*
 	/*
 	 * Called from sysnoted() via the machine-dependent
 	 * Called from sysnoted() via the machine-dependent
 	 * noted() routine.
 	 * noted() routine.
 	 * Clear the flag set above in fpunotify().
 	 * Clear the flag set above in fpunotify().
 	 */
 	 */
-	m->externup->fpustate &= ~Hold;
+	up->fpustate &= ~Hold;
 }
 }
 
 
 void
 void
 fpusysrfork(Ureg* u)
 fpusysrfork(Ureg* u)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	/*
 	/*
 	 * Called early in the non-interruptible path of
 	 * Called early in the non-interruptible path of
 	 * sysrfork() via the machine-dependent syscall() routine.
 	 * sysrfork() via the machine-dependent syscall() routine.
 	 * Save the state so that it can be easily copied
 	 * Save the state so that it can be easily copied
 	 * to the child process later.
 	 * to the child process later.
 	 */
 	 */
-	if(m->externup->fpustate != Busy)
+	if(up->fpustate != Busy)
 		return;
 		return;
 
 
-	_fxsave(m->externup->fpusave);
+	_fxsave(up->fpusave);
 	_stts();
 	_stts();
-	m->externup->fpustate = Idle;
+	up->fpustate = Idle;
 }
 }
 
 
 void
 void
 fpusysrforkchild(Proc* child, Proc* parent)
 fpusysrforkchild(Proc* child, Proc* parent)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	/*
 	/*
 	 * Called later in sysrfork() via the machine-dependent
 	 * Called later in sysrfork() via the machine-dependent
 	 * sysrforkchild() routine.
 	 * sysrforkchild() routine.
 	 * Copy the parent FPU state to the child.
 	 * Copy the parent FPU state to the child.
 	 */
 	 */
 	child->fpustate = parent->fpustate;
 	child->fpustate = parent->fpustate;
-	child->fpusave = (void*)((PTR2UINT(m->externup->fxsave) + 15) & ~15);
+	child->fpusave = (void*)((PTR2UINT(up->fxsave) + 15) & ~15);
 	if(child->fpustate == Init)
 	if(child->fpustate == Init)
 		return;
 		return;
 
 
@@ -212,7 +212,7 @@ fpuprocsave(Proc* p)
 	/*
 	/*
 	 * Save the FPU state without handling pending
 	 * Save the FPU state without handling pending
 	 * unmasked exceptions and disable. Postnote() can't
 	 * unmasked exceptions and disable. Postnote() can't
-	 * be called here as sleep() already has m->externup->rlock,
+	 * be called here as sleep() already has up->rlock,
 	 * so the handling of pending exceptions is delayed
 	 * so the handling of pending exceptions is delayed
 	 * until the process runs again and generates a
 	 * until the process runs again and generates a
 	 * Device Not Available exception fault to activate
 	 * Device Not Available exception fault to activate
@@ -266,7 +266,7 @@ acfpusysprocsetup(Proc *p)
 static char*
 static char*
 fpunote(void)
 fpunote(void)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	uint16_t fsw;
 	uint16_t fsw;
 	Fxsave *fpusave;
 	Fxsave *fpusave;
 	char *cm;
 	char *cm;
@@ -276,7 +276,7 @@ fpunote(void)
 	 * cleared or there's no way to tell if the exception was an
 	 * cleared or there's no way to tell if the exception was an
 	 * invalid operation or a stack fault.
 	 * invalid operation or a stack fault.
 	 */
 	 */
-	fpusave = m->externup->fpusave;
+	fpusave = up->fpusave;
 	fsw = (fpusave->fsw & ~fpusave->fcw) & (Sff|P|U|O|Z|D|I);
 	fsw = (fpusave->fsw & ~fpusave->fcw) & (Sff|P|U|O|Z|D|I);
 	if(fsw & I){
 	if(fsw & I){
 		if(fsw & Sff){
 		if(fsw & Sff){
@@ -301,16 +301,16 @@ fpunote(void)
 	else
 	else
 		cm =  "Unknown";
 		cm =  "Unknown";
 
 
-	snprint(m->externup->genbuf, sizeof(m->externup->genbuf),
+	snprint(up->genbuf, sizeof(up->genbuf),
 		"sys: fp: %s Exception ipo=%#llux fsw=%#ux",
 		"sys: fp: %s Exception ipo=%#llux fsw=%#ux",
 		cm, fpusave->rip, fsw);
 		cm, fpusave->rip, fsw);
-	return m->externup->genbuf;
+	return up->genbuf;
 }
 }
 
 
 char*
 char*
 xfpuxf(Ureg* ureg, void* v)
 xfpuxf(Ureg* ureg, void* v)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	uint32_t mxcsr;
 	uint32_t mxcsr;
 	Fxsave *fpusave;
 	Fxsave *fpusave;
 	char *cm;
 	char *cm;
@@ -322,10 +322,10 @@ xfpuxf(Ureg* ureg, void* v)
 	/*
 	/*
 	 * Save FPU state to check out the error.
 	 * Save FPU state to check out the error.
 	 */
 	 */
-	fpusave = m->externup->fpusave;
+	fpusave = up->fpusave;
 	_fxsave(fpusave);
 	_fxsave(fpusave);
 	_stts();
 	_stts();
-	m->externup->fpustate = Idle;
+	up->fpustate = Idle;
 
 
 	if(ureg->ip & KZERO)
 	if(ureg->ip & KZERO)
 		panic("#MF: ip=%#p", ureg->ip);
 		panic("#MF: ip=%#p", ureg->ip);
@@ -352,20 +352,20 @@ xfpuxf(Ureg* ureg, void* v)
 	else
 	else
 		cm =  "Unknown";
 		cm =  "Unknown";
 
 
-	snprint(m->externup->genbuf, sizeof(m->externup->genbuf),
+	snprint(up->genbuf, sizeof(up->genbuf),
 		"sys: fp: %s Exception mxcsr=%#ux", cm, mxcsr);
 		"sys: fp: %s Exception mxcsr=%#ux", cm, mxcsr);
-	return m->externup->genbuf;
+	return up->genbuf;
 }
 }
 
 
 void
 void
 fpuxf(Ureg *ureg, void *p)
 fpuxf(Ureg *ureg, void *p)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	char *n;
 	char *n;
 
 
 	n = xfpuxf(ureg, p);
 	n = xfpuxf(ureg, p);
 	if(n != nil)
 	if(n != nil)
-		postnote(m->externup, 1, n, NDebug);
+		postnote(up, 1, n, NDebug);
 }
 }
 
 
 char*
 char*
@@ -377,7 +377,7 @@ acfpuxf(Ureg *ureg, void *p)
 static char*
 static char*
 xfpumf(Ureg* ureg, void* v)
 xfpumf(Ureg* ureg, void* v)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	Fxsave *fpusave;
 	Fxsave *fpusave;
 
 
 	/*
 	/*
@@ -387,10 +387,10 @@ xfpumf(Ureg* ureg, void* v)
 	/*
 	/*
 	 * Save FPU state to check out the error.
 	 * Save FPU state to check out the error.
 	 */
 	 */
-	fpusave = m->externup->fpusave;
+	fpusave = up->fpusave;
 	_fxsave(fpusave);
 	_fxsave(fpusave);
 	_stts();
 	_stts();
-	m->externup->fpustate = Idle;
+	up->fpustate = Idle;
 
 
 	if(ureg->ip & KZERO)
 	if(ureg->ip & KZERO)
 		panic("#MF: ip=%#p rip=%#p", ureg->ip, fpusave->rip);
 		panic("#MF: ip=%#p rip=%#p", ureg->ip, fpusave->rip);
@@ -414,12 +414,12 @@ xfpumf(Ureg* ureg, void* v)
 void
 void
 fpumf(Ureg *ureg, void *p)
 fpumf(Ureg *ureg, void *p)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	char *n;
 	char *n;
 
 
 	n = xfpumf(ureg, p);
 	n = xfpumf(ureg, p);
 	if(n != nil)
 	if(n != nil)
-		postnote(m->externup, 1, n, NDebug);
+		postnote(up, 1, n, NDebug);
 }
 }
 
 
 char*
 char*
@@ -431,30 +431,30 @@ acfpumf(Ureg *ureg, void *p)
 static char*
 static char*
 xfpunm(Ureg* ureg, void* v)
 xfpunm(Ureg* ureg, void* v)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	Fxsave *fpusave;
 	Fxsave *fpusave;
 
 
 	/*
 	/*
 	 * #NM - Device Not Available (Vector 7).
 	 * #NM - Device Not Available (Vector 7).
 	 */
 	 */
-	if(m->externup == nil)
+	if(up == nil)
 		panic("#NM: fpu in kernel: ip %#p\n", ureg->ip);
 		panic("#NM: fpu in kernel: ip %#p\n", ureg->ip);
 
 
 	/*
 	/*
 	 * Someone tried to use the FPU in a note handler.
 	 * Someone tried to use the FPU in a note handler.
 	 * That's a no-no.
 	 * That's a no-no.
 	 */
 	 */
-	if(m->externup->fpustate & Hold)
+	if(up->fpustate & Hold)
 		return "sys: floating point in note handler";
 		return "sys: floating point in note handler";
 
 
 	if(ureg->ip & KZERO)
 	if(ureg->ip & KZERO)
 		panic("#NM: proc %d %s state %d ip %#p\n",
 		panic("#NM: proc %d %s state %d ip %#p\n",
-			m->externup->pid, m->externup->text, m->externup->fpustate, ureg->ip);
+			up->pid, up->text, up->fpustate, ureg->ip);
 
 
-	switch(m->externup->fpustate){
+	switch(up->fpustate){
 	case Busy:
 	case Busy:
 	default:
 	default:
-		panic("#NM: state %d ip %#p\n", m->externup->fpustate, ureg->ip);
+		panic("#NM: state %d ip %#p\n", up->fpustate, ureg->ip);
 		break;
 		break;
 	case Init:
 	case Init:
 		/*
 		/*
@@ -470,8 +470,8 @@ xfpunm(Ureg* ureg, void* v)
 		_fwait();
 		_fwait();
 		_fldcw(m->fcw);
 		_fldcw(m->fcw);
 		_ldmxcsr(m->mxcsr);
 		_ldmxcsr(m->mxcsr);
-		m->externup->fpusave = (void*)((PTR2UINT(m->externup->fxsave) + 15) & ~15);
-		m->externup->fpustate = Busy;
+		up->fpusave = (void*)((PTR2UINT(up->fxsave) + 15) & ~15);
+		up->fpustate = Busy;
 		break;
 		break;
 	case Idle:
 	case Idle:
 		/*
 		/*
@@ -479,7 +479,7 @@ xfpunm(Ureg* ureg, void* v)
 		 * exceptions, there's no way to restore the state without
 		 * exceptions, there's no way to restore the state without
 		 * generating an unmasked exception.
 		 * generating an unmasked exception.
 		 */
 		 */
-		fpusave = m->externup->fpusave;
+		fpusave = up->fpusave;
 		if((fpusave->fsw & ~fpusave->fcw) & (Sff|P|U|O|Z|D|I))
 		if((fpusave->fsw & ~fpusave->fcw) & (Sff|P|U|O|Z|D|I))
 			return fpunote();
 			return fpunote();
 
 
@@ -489,7 +489,7 @@ xfpunm(Ureg* ureg, void* v)
 		fpusave->fcw &= ~Sff;
 		fpusave->fcw &= ~Sff;
 		_clts();
 		_clts();
 		_fxrstor(fpusave);
 		_fxrstor(fpusave);
-		m->externup->fpustate = Busy;
+		up->fpustate = Busy;
 		break;
 		break;
 	}
 	}
 	return nil;
 	return nil;
@@ -498,12 +498,12 @@ xfpunm(Ureg* ureg, void* v)
 void
 void
 fpunm(Ureg *ureg, void *p)
 fpunm(Ureg *ureg, void *p)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	char *n;
 	char *n;
 
 
 	n = xfpunm(ureg, p);
 	n = xfpunm(ureg, p);
 	if(n != nil)
 	if(n != nil)
-		postnote(m->externup, 1, n, NDebug);
+		postnote(up, 1, n, NDebug);
 }
 }
 
 
 char*
 char*
@@ -515,7 +515,7 @@ acfpunm(Ureg *ureg, void *p)
 void
 void
 fpuinit(void)
 fpuinit(void)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	uint64_t r;
 	uint64_t r;
 	Fxsave *fxsave;
 	Fxsave *fxsave;
 	uint8_t buf[sizeof(Fxsave)+15];
 	uint8_t buf[sizeof(Fxsave)+15];
@@ -544,7 +544,7 @@ fpuinit(void)
 	m->mxcsr = (Rn|Pm|Um|Dm) & m->mxcsrmask;
 	m->mxcsr = (Rn|Pm|Um|Dm) & m->mxcsrmask;
 	_stts();
 	_stts();
 
 
-	if(m->machno != 0)
+	if(machp()->machno != 0)
 		return;
 		return;
 
 
 	/*
 	/*

+ 1 - 1
sys/src/9/amd64pv/io.h

@@ -1,4 +1,4 @@
-/* 
+/*
  * This file is part of the UCB release of Plan 9. It is subject to the license
  * This file is part of the UCB release of Plan 9. It is subject to the license
  * terms in the LICENSE file found in the top-level directory of this
  * terms in the LICENSE file found in the top-level directory of this
  * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No

+ 1 - 1
sys/src/9/amd64pv/ioapic.c

@@ -266,7 +266,7 @@ ioapicintrdd(uint32_t* hi, uint32_t* lo)
 				break;
 				break;
 		}
 		}
 		unlock(&dflock);
 		unlock(&dflock);
-	
+
 		*hi = i<<24;
 		*hi = i<<24;
 		break;
 		break;
 	}
 	}

+ 1 - 1
sys/src/9/amd64pv/iob.h

@@ -1,4 +1,4 @@
-/* 
+/*
  * This file is part of the UCB release of Plan 9. It is subject to the license
  * This file is part of the UCB release of Plan 9. It is subject to the license
  * terms in the LICENSE file found in the top-level directory of this
  * terms in the LICENSE file found in the top-level directory of this
  * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No

+ 1 - 1
sys/src/9/amd64pv/l64acidt.S

@@ -83,7 +83,7 @@ _aciretnested:
 	iretq
 	iretq
 
 
 .globl acidthandlers
 .globl acidthandlers
-acidthandlers:	
+acidthandlers:
 	CALL _acintrp; .byte IdtDE		/* #DE Divide-by-Zero Error */
 	CALL _acintrp; .byte IdtDE		/* #DE Divide-by-Zero Error */
 	CALL _acintrp; .byte IdtDB		/* #DB Debug */
 	CALL _acintrp; .byte IdtDB		/* #DB Debug */
 	CALL _acintrp; .byte IdtNMI		/* #NMI Borked */
 	CALL _acintrp; .byte IdtNMI		/* #NMI Borked */

+ 7 - 7
sys/src/9/amd64pv/l64idt.S

@@ -20,7 +20,7 @@
 	* EIP of interrupted code 8(%rsp)
 	* EIP of interrupted code 8(%rsp)
 	* EIP from the call from the idthandlers. (%rsp)
 	* EIP from the call from the idthandlers. (%rsp)
 	* We, finally, need to push the error code and type.,
 	* We, finally, need to push the error code and type.,
-	* then the registers. 
+	* then the registers.
 	* Why the call from IDThandlers? So we can get a way to point
 	* Why the call from IDThandlers? So we can get a way to point
 	* to the type. We don't need to save 0(%rsp), we just need
 	* to the type. We don't need to save 0(%rsp), we just need
 	* it to get the type. We can pop it and throw it away when
 	* it to get the type. We can pop it and throw it away when
@@ -37,14 +37,14 @@
 	* is on the stack. For others, it's not. To make the stacks
 	* is on the stack. For others, it's not. To make the stacks
 	* look identical for the common code and exit we save %rax and line things up.
 	* look identical for the common code and exit we save %rax and line things up.
 	*/
 	*/
-	
+
 .globl ire
 .globl ire
 .globl irx
 .globl irx
 .globl irxe
 .globl irxe
-// When we enter: 
+// When we enter:
 // registers are NOT saved. We need to save them all.
 // registers are NOT saved. We need to save them all.
 // return PC is on the stat8(%rsp). It should be left there.
 // return PC is on the stat8(%rsp). It should be left there.
-// @ (%rsp) is the PC from the vector table. 
+// @ (%rsp) is the PC from the vector table.
 // So indirecting on that will get us the interrupt #.
 // So indirecting on that will get us the interrupt #.
 // We need to get what the return PC is pointing to into %rdi.
 // We need to get what the return PC is pointing to into %rdi.
 // We no longer need to make the stack look the same as in Plan 9
 // We no longer need to make the stack look the same as in Plan 9
@@ -58,8 +58,8 @@ _intrp:
 	// Now %rax points to the vector number.
 	// Now %rax points to the vector number.
 	JMP	_intrcommon
 	JMP	_intrcommon
 
 
-// For intre, error is at top of stack on trap. But then we call here 
-// from the interrupt vectors so error is at 8(%rsp). 
+// For intre, error is at top of stack on trap. But then we call here
+// from the interrupt vectors so error is at 8(%rsp).
 // I just realized I think intre means interrupt exception, e.g. page fault.
 // I just realized I think intre means interrupt exception, e.g. page fault.
 .globl _intre
 .globl _intre
 _intre:
 _intre:
@@ -69,7 +69,7 @@ _intre:
 	XCHGQ	%rax, (%rsp)
 	XCHGQ	%rax, (%rsp)
 	// Now %rax points to the vector number.
 	// Now %rax points to the vector number.
 
 
-// When we get here: 
+// When we get here:
 // %RAX points to our vector number, i.e. "return" pc from calls below.
 // %RAX points to our vector number, i.e. "return" pc from calls below.
 // For intrp, (%rsp) is bogus code, 8(%rsp) is pointer to vno
 // For intrp, (%rsp) is bogus code, 8(%rsp) is pointer to vno
 // for intre, (%rsp) is pointer to vno, 8(%rsp) is error code.
 // for intre, (%rsp) is pointer to vno, 8(%rsp) is error code.

+ 5 - 5
sys/src/9/amd64pv/l64vsyscall.S

@@ -10,7 +10,7 @@
  * starting the user program up. First time.
  * starting the user program up. First time.
  */
  */
 	.globl touser
 	.globl touser
-touser:	
+touser:
 	CLI
 	CLI
 	SWAPGS
 	SWAPGS
 	// we should be able to skip this step. We'll see.
 	// we should be able to skip this step. We'll see.
@@ -34,7 +34,7 @@ touser:
 .global syscallentry
 .global syscallentry
 syscallentry:
 syscallentry:
 	incq	sce
 	incq	sce
-	SWAPGS	
+	SWAPGS
 	movq	%gs:0, %r15
 	movq	%gs:0, %r15
 	movq	16(%r15), %r15			/* m->proc */
 	movq	16(%r15), %r15			/* m->proc */
 	// NOTE! This assumes sizeof(Label) == 16!
 	// NOTE! This assumes sizeof(Label) == 16!
@@ -76,7 +76,7 @@ syscallentry:
 	CALL	syscall
 	CALL	syscall
 
 
 	.globl	syscallreturn
 	.globl	syscallreturn
-syscallreturn:	
+syscallreturn:
 #ifdef NOTNOW
 #ifdef NOTNOW
 	/* we do the TLS setup in linuxsyscall.c.
 	/* we do the TLS setup in linuxsyscall.c.
 	 * Leave this here in case we ever think it should be done
 	 * Leave this here in case we ever think it should be done
@@ -125,7 +125,7 @@ _linuxsyscallreturn:
 	MOVW	4(%rsp), FS
 	MOVW	4(%rsp), FS
 	*/
 	*/
 	MOVW	6(%rsp), GS
 	MOVW	6(%rsp), GS
-#endif	
+#endif
 
 
 	MOVQ	0(%rsp), %rCX			/* ip */
 	MOVQ	0(%rsp), %rCX			/* ip */
 	MOVQ	16(%rsp), %r11			/* flags */
 	MOVQ	16(%rsp), %r11			/* flags */
@@ -137,7 +137,7 @@ _linuxsyscallreturn:
 //	BYTE $0x48; SYSRET			/* SYSRETQ */
 //	BYTE $0x48; SYSRET			/* SYSRETQ */
 
 
 	.globl sysrforkret
 	.globl sysrforkret
-sysrforkret:	
+sysrforkret:
 //	CALL	linuxclonefinish(SB)
 //	CALL	linuxclonefinish(SB)
 	// DEBUG
 	// DEBUG
 	MOVQ	$0, %rAX
 	MOVQ	$0, %rAX

+ 42 - 42
sys/src/9/amd64pv/main.c

@@ -106,7 +106,7 @@ squidboy(int apicno, Mach *m)
 {
 {
 	// FIX QEMU. extern int64_t hz;
 	// FIX QEMU. extern int64_t hz;
 	int64_t hz;
 	int64_t hz;
-	sys->machptr[m->machno] = m;
+	sys->machptr[machp()->machno] = m;
 	/*
 	/*
 	 * Need something for initial delays
 	 * Need something for initial delays
 	 * until a timebase is worked out.
 	 * until a timebase is worked out.
@@ -123,7 +123,7 @@ squidboy(int apicno, Mach *m)
 	// PRINT WILL PANIC. So wait.
 	// PRINT WILL PANIC. So wait.
 	vsvminit(MACHSTKSZ, m->nixtype, m);
 	vsvminit(MACHSTKSZ, m->nixtype, m);
 
 
-	DBG("Hello Squidboy %d %d\n", apicno, m->machno);
+	DBG("Hello Squidboy %d %d\n", apicno, machp()->machno);
 
 
 
 
 	/*
 	/*
@@ -156,7 +156,7 @@ squidboy(int apicno, Mach *m)
 	m->rdtsc = rdtsc();
 	m->rdtsc = rdtsc();
 
 
 	print("cpu%d color %d role %s tsc %lld\n",
 	print("cpu%d color %d role %s tsc %lld\n",
-		m->machno, corecolor(m->machno), rolename[m->nixtype], m->rdtsc);
+		machp()->machno, corecolor(machp()->machno), rolename[m->nixtype], m->rdtsc);
 	switch(m->nixtype){
 	switch(m->nixtype){
 	case NIXAC:
 	case NIXAC:
 		acmmuswitch();
 		acmmuswitch();
@@ -214,7 +214,7 @@ testiccs(void)
 static void
 static void
 nixsquids(void)
 nixsquids(void)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	Mach *mp;
 	Mach *mp;
 	int i;
 	int i;
 	uint64_t now, start;
 	uint64_t now, start;
@@ -275,7 +275,7 @@ void wave(int c)
 	outb(0x3f8, c);
 	outb(0x3f8, c);
 }
 }
 
 
-void hi(char *s) 
+void hi(char *s)
 {
 {
 	if (! s)
 	if (! s)
 		s = "<NULL>";
 		s = "<NULL>";
@@ -284,14 +284,14 @@ void hi(char *s)
 }
 }
 
 
 /*
 /*
- * for gdb: 
- * call this anywhere in your code. 
+ * for gdb:
+ * call this anywhere in your code.
  *   die("yourturn with gdb\n");
  *   die("yourturn with gdb\n");
  *   gdb 9k
  *   gdb 9k
  *   target remote localhost:1234
  *   target remote localhost:1234
  *   display/i $pc
  *   display/i $pc
  *   set staydead = 0
  *   set staydead = 0
- *   stepi, and debug. 
+ *   stepi, and debug.
  * note, you can always resume after a die. Just set staydead = 0
  * note, you can always resume after a die. Just set staydead = 0
  */
  */
 
 
@@ -341,14 +341,14 @@ void put64(uint64_t v)
 
 
 void debugtouser(void *va)
 void debugtouser(void *va)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	uintptr_t uva = (uintptr_t) va;
 	uintptr_t uva = (uintptr_t) va;
 	PTE *pte, *pml4;
 	PTE *pte, *pml4;
 
 
-	pml4 = UINT2PTR(m->pml4->va);
+	pml4 = UINT2PTR(machp()->pml4->va);
 	mmuwalk(pml4, uva, 0, &pte, nil);
 	mmuwalk(pml4, uva, 0, &pte, nil);
-	iprint("va %p m %p m>pml4 %p m->pml4->va %p pml4 %p PTE 0x%lx\n", va,
-			m, m->pml4, m->pml4->va, (void *)pml4, *pte);
+	iprint("va %p m %p m>pml4 %p machp()->pml4->va %p pml4 %p PTE 0x%lx\n", va,
+			m, machp()->pml4, machp()->pml4->va, (void *)pml4, *pte);
 }
 }
 
 
 /*
 /*
@@ -381,7 +381,7 @@ teardownidmap(Mach *m)
 	 * report if there were that many, as that is odd.
 	 * report if there were that many, as that is odd.
 	 */
 	 */
 	for(i = 0; i < 512; i++, va += BIGPGSZ) {
 	for(i = 0; i < 512; i++, va += BIGPGSZ) {
-		if (mmuwalk(UINT2PTR(m->pml4->va), va, 1, &p, nil) != 1)
+		if (mmuwalk(UINT2PTR(machp()->pml4->va), va, 1, &p, nil) != 1)
 			break;
 			break;
 		if (! *p)
 		if (! *p)
 			break;
 			break;
@@ -391,7 +391,7 @@ teardownidmap(Mach *m)
 	iprint("Teardown: zapped %d PML1 entries\n", i);
 	iprint("Teardown: zapped %d PML1 entries\n", i);
 
 
 	for(i = 2; i < 4; i++) {
 	for(i = 2; i < 4; i++) {
-		if (mmuwalk(UINT2PTR(m->pml4->va), 0, i, &p, nil) != i) {
+		if (mmuwalk(UINT2PTR(machp()->pml4->va), 0, i, &p, nil) != i) {
 			iprint("weird; 0 not mapped at %d\n", i);
 			iprint("weird; 0 not mapped at %d\n", i);
 			continue;
 			continue;
 		}
 		}
@@ -407,10 +407,10 @@ main(uint32_t mbmagic, uint32_t mbaddress)
 {
 {
 	Mach *m = entrym;
 	Mach *m = entrym;
 	/* when we get here, entrym is set to core0 mach. */
 	/* when we get here, entrym is set to core0 mach. */
-	sys->machptr[m->machno] = m;
+	sys->machptr[machp()->machno] = m;
 	// Very special case for BSP only. Too many things
 	// Very special case for BSP only. Too many things
 	// assume this is set.
 	// assume this is set.
-	wrmsr(GSbase, PTR2UINT(&sys->machptr[m->machno]));
+	wrmsr(GSbase, PTR2UINT(&sys->machptr[machp()->machno]));
 	if (machp() != m)
 	if (machp() != m)
 		panic("m and machp() are different!!\n");
 		panic("m and machp() are different!!\n");
 	assert(sizeof(Mach) <= PGSZ);
 	assert(sizeof(Mach) <= PGSZ);
@@ -419,7 +419,7 @@ main(uint32_t mbmagic, uint32_t mbaddress)
 	 * Check that our data is on the right boundaries.
 	 * Check that our data is on the right boundaries.
 	 * This works because the immediate value is in code.
 	 * This works because the immediate value is in code.
 	 */
 	 */
-	if (x != 0x123456) 
+	if (x != 0x123456)
 		panic("Data is not set up correctly\n");
 		panic("Data is not set up correctly\n");
 	memset(edata, 0, end - edata);
 	memset(edata, 0, end - edata);
 
 
@@ -428,19 +428,19 @@ main(uint32_t mbmagic, uint32_t mbaddress)
 
 
 	/*
 	/*
 	 * ilock via i8250enable via i8250console
 	 * ilock via i8250enable via i8250console
-	 * needs m->machno, sys->machptr[] set, and
+	 * needs machp()->machno, sys->machptr[] set, and
 	 * also 'up' set to nil.
 	 * also 'up' set to nil.
 	 */
 	 */
 	cgapost(sizeof(uintptr_t)*8);
 	cgapost(sizeof(uintptr_t)*8);
 	memset(m, 0, sizeof(Mach));
 	memset(m, 0, sizeof(Mach));
 
 
-	m->machno = 0;
+	machp()->machno = 0;
 	m->online = 1;
 	m->online = 1;
 	m->nixtype = NIXTC;
 	m->nixtype = NIXTC;
-	sys->machptr[m->machno] = &sys->mach;
+	sys->machptr[machp()->machno] = &sys->mach;
 	m->stack = PTR2UINT(sys->machstk);
 	m->stack = PTR2UINT(sys->machstk);
 	m->vsvm = sys->vsvmpage;
 	m->vsvm = sys->vsvmpage;
-	m->externup = (void *)0;
+	up = (void *)0;
 	active.nonline = 1;
 	active.nonline = 1;
 	active.exiting = 0;
 	active.exiting = 0;
 	active.nbooting = 0;
 	active.nbooting = 0;
@@ -458,7 +458,7 @@ main(uint32_t mbmagic, uint32_t mbaddress)
 
 
 	cgainit();
 	cgainit();
 	i8250console("0");
 	i8250console("0");
-	
+
 	consputs = cgaconsputs;
 	consputs = cgaconsputs;
 
 
 	/* It all ends here. */
 	/* It all ends here. */
@@ -466,9 +466,9 @@ main(uint32_t mbmagic, uint32_t mbaddress)
 	if (machp() != m)
 	if (machp() != m)
 		panic("After vsvminit, m and machp() are different");
 		panic("After vsvminit, m and machp() are different");
 	fmtinit();
 	fmtinit();
-	
+
 	print("\nHarvey\n");
 	print("\nHarvey\n");
-	sys->nmach = 1;			
+	sys->nmach = 1;
 
 
 	if(1){
 	if(1){
 		multiboot(mbmagic, mbaddress, 1);
 		multiboot(mbmagic, mbaddress, 1);
@@ -484,7 +484,7 @@ main(uint32_t mbmagic, uint32_t mbaddress)
 
 
 	/*
 	/*
 	 * Mmuinit before meminit because it
 	 * Mmuinit before meminit because it
-	 * flushes the TLB via m->pml4->pa.
+	 * flushes the TLB via machp()->pml4->pa.
 	 */
 	 */
 	mmuinit();
 	mmuinit();
 	ioinit();
 	ioinit();
@@ -494,9 +494,9 @@ main(uint32_t mbmagic, uint32_t mbaddress)
 	archinit();
 	archinit();
 	mallocinit();
 	mallocinit();
 
 
-	/* test malloc. It's easier to find out it's broken here, 
+	/* test malloc. It's easier to find out it's broken here,
 	 * not deep in some call chain.
 	 * not deep in some call chain.
-	 * See next note. 
+	 * See next note.
 	 *
 	 *
 	void *v = malloc(1234);
 	void *v = malloc(1234);
 	hi("v "); put64((uint64_t)v); hi("\n");
 	hi("v "); put64((uint64_t)v); hi("\n");
@@ -514,7 +514,7 @@ main(uint32_t mbmagic, uint32_t mbaddress)
 	 * things like that completely broken).
 	 * things like that completely broken).
 	 */
 	 */
 if (0){	acpiinit(); hi("	acpiinit();\n");}
 if (0){	acpiinit(); hi("	acpiinit();\n");}
-	
+
 	umeminit();
 	umeminit();
 	trapinit();
 	trapinit();
 	printinit();
 	printinit();
@@ -558,10 +558,10 @@ if (0){	acpiinit(); hi("	acpiinit();\n");}
 void
 void
 init0(void)
 init0(void)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	char buf[2*KNAMELEN];
 	char buf[2*KNAMELEN];
 
 
-	m->externup->nerrlab = 0;
+	up->nerrlab = 0;
 
 
 	/*
 	/*
 	 * if(consuart == nil)
 	 * if(consuart == nil)
@@ -573,10 +573,10 @@ init0(void)
 	 * These are o.k. because rootinit is null.
 	 * These are o.k. because rootinit is null.
 	 * Then early kproc's will have a root and dot.
 	 * Then early kproc's will have a root and dot.
 	 */
 	 */
-	m->externup->slash = namec("#/", Atodir, 0, 0);
-	pathclose(m->externup->slash->path);
-	m->externup->slash->path = newpath("/");
-	m->externup->dot = cclone(m->externup->slash);
+	up->slash = namec("#/", Atodir, 0, 0);
+	pathclose(up->slash->path);
+	up->slash->path = newpath("/");
+	up->dot = cclone(up->slash);
 
 
 	devtabinit();
 	devtabinit();
 
 
@@ -608,10 +608,10 @@ bootargs(uintptr_t base)
 	 * Push the boot args onto the stack.
 	 * Push the boot args onto the stack.
 	 * Make sure the validaddr check in syscall won't fail
 	 * Make sure the validaddr check in syscall won't fail
 	 * because there are fewer than the maximum number of
 	 * because there are fewer than the maximum number of
-	 * args by subtracting sizeof(m->externup->arg).
+	 * args by subtracting sizeof(up->arg).
 	 */
 	 */
 	i = oargblen+1;
 	i = oargblen+1;
-	p = UINT2PTR(STACKALIGN(base + BIGPGSZ - sizeof(entrym->externup->arg) - i));
+	p = UINT2PTR(STACKALIGN(base + BIGPGSZ - sizeof(entryup->arg) - i));
 	memmove(p, oargb, i);
 	memmove(p, oargb, i);
 
 
 	/*
 	/*
@@ -636,7 +636,7 @@ bootargs(uintptr_t base)
 void
 void
 userinit(void)
 userinit(void)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	Proc *p;
 	Proc *p;
 	Segment *s;
 	Segment *s;
 	KMap *k;
 	KMap *k;
@@ -663,7 +663,7 @@ userinit(void)
 	 * AMD64 stack must be quad-aligned.
 	 * AMD64 stack must be quad-aligned.
 	 */
 	 */
 	p->sched.pc = PTR2UINT(init0);
 	p->sched.pc = PTR2UINT(init0);
-	p->sched.sp = PTR2UINT(p->kstack+KSTACK-sizeof(m->externup->arg)-sizeof(uintptr_t));
+	p->sched.sp = PTR2UINT(p->kstack+KSTACK-sizeof(up->arg)-sizeof(uintptr_t));
 	p->sched.sp = STACKALIGN(p->sched.sp);
 	p->sched.sp = STACKALIGN(p->sched.sp);
 
 
 	/*
 	/*
@@ -727,13 +727,13 @@ confinit(void)
 static void
 static void
 shutdown(int ispanic)
 shutdown(int ispanic)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	int ms, once;
 	int ms, once;
 
 
 	lock(&active);
 	lock(&active);
 	if(ispanic)
 	if(ispanic)
 		active.ispanic = ispanic;
 		active.ispanic = ispanic;
-	else if(m->machno == 0 && m->online == 0)
+	else if(machp()->machno == 0 && m->online == 0)
 		active.ispanic = 0;
 		active.ispanic = 0;
 	once = m->online;
 	once = m->online;
 	m->online = 0;
 	m->online = 0;
@@ -742,7 +742,7 @@ shutdown(int ispanic)
 	unlock(&active);
 	unlock(&active);
 
 
 	if(once)
 	if(once)
-		iprint("cpu%d: exiting\n", m->machno);
+		iprint("cpu%d: exiting\n", machp()->machno);
 
 
 	spllo();
 	spllo();
 	for(ms = 5*1000; ms > 0; ms -= TK2MS(2)){
 	for(ms = 5*1000; ms > 0; ms -= TK2MS(2)){
@@ -751,7 +751,7 @@ shutdown(int ispanic)
 			break;
 			break;
 	}
 	}
 
 
-	if(active.ispanic && m->machno == 0){
+	if(active.ispanic && machp()->machno == 0){
 		if(cpuserver)
 		if(cpuserver)
 			delay(30000);
 			delay(30000);
 		else
 		else

+ 1 - 1
sys/src/9/amd64pv/mem.h

@@ -1,4 +1,4 @@
-/* 
+/*
  * This file is part of the UCB release of Plan 9. It is subject to the license
  * This file is part of the UCB release of Plan 9. It is subject to the license
  * terms in the LICENSE file found in the top-level directory of this
  * terms in the LICENSE file found in the top-level directory of this
  * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No

+ 72 - 72
sys/src/9/amd64pv/mmu.c

@@ -31,32 +31,32 @@
 void
 void
 mmuflushtlb(uint64_t u)
 mmuflushtlb(uint64_t u)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 
 
 	m->tlbpurge++;
 	m->tlbpurge++;
-	if(m->pml4->daddr){
-		memset(UINT2PTR(m->pml4->va), 0, m->pml4->daddr*sizeof(PTE));
-		m->pml4->daddr = 0;
+	if(machp()->pml4->daddr){
+		memset(UINT2PTR(machp()->pml4->va), 0, machp()->pml4->daddr*sizeof(PTE));
+		machp()->pml4->daddr = 0;
 	}
 	}
-	cr3put(m->pml4->pa);
+	cr3put(machp()->pml4->pa);
 }
 }
 
 
 void
 void
 mmuflush(void)
 mmuflush(void)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	Mpl pl;
 	Mpl pl;
 
 
 	pl = splhi();
 	pl = splhi();
-	m->externup->newtlb = 1;
-	mmuswitch(m->externup);
+	up->newtlb = 1;
+	mmuswitch(up);
 	splx(pl);
 	splx(pl);
 }
 }
 
 
 static void
 static void
 mmuptpfree(Proc* proc, int clear)
 mmuptpfree(Proc* proc, int clear)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	int l;
 	int l;
 	PTE *pte;
 	PTE *pte;
 	Page **last, *page;
 	Page **last, *page;
@@ -78,7 +78,7 @@ mmuptpfree(Proc* proc, int clear)
 		proc->mmuptp[l] = nil;
 		proc->mmuptp[l] = nil;
 	}
 	}
 
 
-	m->pml4->daddr = 0;
+	machp()->pml4->daddr = 0;
 }
 }
 
 
 static void
 static void
@@ -117,7 +117,7 @@ dumpptepg(int lvl, uintptr_t pa)
 void
 void
 dumpmmu(Proc *p)
 dumpmmu(Proc *p)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	int i;
 	int i;
 	Page *pg;
 	Page *pg;
 
 
@@ -129,26 +129,26 @@ dumpmmu(Proc *p)
 				" daddr %#ulx next %#p prev %#p\n",
 				" daddr %#ulx next %#p prev %#p\n",
 				pg, pg->va, pg->pa, pg->daddr, pg->next, pg->prev);
 				pg, pg->va, pg->pa, pg->daddr, pg->next, pg->prev);
 	}
 	}
-	print("pml4 %#ullx\n", m->pml4->pa);
-	if(0)dumpptepg(4, m->pml4->pa);
+	print("pml4 %#ullx\n", machp()->pml4->pa);
+	if(0)dumpptepg(4, machp()->pml4->pa);
 }
 }
 
 
 void
 void
 dumpmmuwalk(uint64_t addr)
 dumpmmuwalk(uint64_t addr)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	int l;
 	int l;
 	PTE *pte, *pml4;
 	PTE *pte, *pml4;
 
 
-	pml4 = UINT2PTR(m->pml4->va);
+	pml4 = UINT2PTR(machp()->pml4->va);
 	if((l = mmuwalk(pml4, addr, 3, &pte, nil)) >= 0)
 	if((l = mmuwalk(pml4, addr, 3, &pte, nil)) >= 0)
-		print("cpu%d: mmu l%d pte %#p = %llux\n", m->machno, l, pte, *pte);
+		print("cpu%d: mmu l%d pte %#p = %llux\n", machp()->machno, l, pte, *pte);
 	if((l = mmuwalk(pml4, addr, 2, &pte, nil)) >= 0)
 	if((l = mmuwalk(pml4, addr, 2, &pte, nil)) >= 0)
-		print("cpu%d: mmu l%d pte %#p = %llux\n", m->machno, l, pte, *pte);
+		print("cpu%d: mmu l%d pte %#p = %llux\n", machp()->machno, l, pte, *pte);
 	if((l = mmuwalk(pml4, addr, 1, &pte, nil)) >= 0)
 	if((l = mmuwalk(pml4, addr, 1, &pte, nil)) >= 0)
-		print("cpu%d: mmu l%d pte %#p = %llux\n", m->machno, l, pte, *pte);
+		print("cpu%d: mmu l%d pte %#p = %llux\n", machp()->machno, l, pte, *pte);
 	if((l = mmuwalk(pml4, addr, 0, &pte, nil)) >= 0)
 	if((l = mmuwalk(pml4, addr, 0, &pte, nil)) >= 0)
-		print("cpu%d: mmu l%d pte %#p = %llux\n", m->machno, l, pte, *pte);
+		print("cpu%d: mmu l%d pte %#p = %llux\n", machp()->machno, l, pte, *pte);
 }
 }
 
 
 static Page mmuptpfreelist;
 static Page mmuptpfreelist;
@@ -206,7 +206,7 @@ mmuptpalloc(void)
 void
 void
 mmuswitch(Proc* proc)
 mmuswitch(Proc* proc)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	PTE *pte;
 	PTE *pte;
 	Page *page;
 	Page *page;
 	Mpl pl;
 	Mpl pl;
@@ -222,28 +222,28 @@ mmuswitch(Proc* proc)
 		proc->newtlb = 0;
 		proc->newtlb = 0;
 	}
 	}
 
 
-	if(m->pml4->daddr){
-		memset(UINT2PTR(m->pml4->va), 0, m->pml4->daddr*sizeof(PTE));
-		m->pml4->daddr = 0;
+	if(machp()->pml4->daddr){
+		memset(UINT2PTR(machp()->pml4->va), 0, machp()->pml4->daddr*sizeof(PTE));
+		machp()->pml4->daddr = 0;
 	}
 	}
 
 
-	pte = UINT2PTR(m->pml4->va);
+	pte = UINT2PTR(machp()->pml4->va);
 	for(page = proc->mmuptp[3]; page != nil; page = page->next){
 	for(page = proc->mmuptp[3]; page != nil; page = page->next){
 		pte[page->daddr] = PPN(page->pa)|PteU|PteRW|PteP;
 		pte[page->daddr] = PPN(page->pa)|PteU|PteRW|PteP;
-		if(page->daddr >= m->pml4->daddr)
-			m->pml4->daddr = page->daddr+1;
-		page->prev = m->pml4;
+		if(page->daddr >= machp()->pml4->daddr)
+			machp()->pml4->daddr = page->daddr+1;
+		page->prev = machp()->pml4;
 	}
 	}
 
 
 	tssrsp0(machp(), STACKALIGN(PTR2UINT(proc->kstack+KSTACK)));
 	tssrsp0(machp(), STACKALIGN(PTR2UINT(proc->kstack+KSTACK)));
-	cr3put(m->pml4->pa);
+	cr3put(machp()->pml4->pa);
 	splx(pl);
 	splx(pl);
 }
 }
 
 
 void
 void
 mmurelease(Proc* proc)
 mmurelease(Proc* proc)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	Page *page, *next;
 	Page *page, *next;
 
 
 	mmuptpfree(proc, 0);
 	mmuptpfree(proc, 0);
@@ -264,20 +264,20 @@ mmurelease(Proc* proc)
 	proc->mmuptp[0] = nil;
 	proc->mmuptp[0] = nil;
 
 
 	tssrsp0(m, STACKALIGN(m->stack+MACHSTKSZ));
 	tssrsp0(m, STACKALIGN(m->stack+MACHSTKSZ));
-	cr3put(m->pml4->pa);
+	cr3put(machp()->pml4->pa);
 }
 }
 
 
 static void
 static void
 checkpte(uintmem ppn, void *a)
 checkpte(uintmem ppn, void *a)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	int l;
 	int l;
 	PTE *pte, *pml4;
 	PTE *pte, *pml4;
 	uint64_t addr;
 	uint64_t addr;
 	char buf[240], *s;
 	char buf[240], *s;
 
 
 	addr = PTR2UINT(a);
 	addr = PTR2UINT(a);
-	pml4 = UINT2PTR(m->pml4->va);
+	pml4 = UINT2PTR(machp()->pml4->va);
 	pte = 0;
 	pte = 0;
 	s = buf;
 	s = buf;
 	*s = 0;
 	*s = 0;
@@ -300,7 +300,7 @@ checkpte(uintmem ppn, void *a)
 		l, pte, pte?*pte:~0);
 		l, pte, pte?*pte:~0);
 	return;
 	return;
 Panic:
 Panic:
-	
+
 	seprint(s, buf+sizeof buf,
 	seprint(s, buf+sizeof buf,
 		"checkpte: l%d addr %#p ppn %#ullx kaddr %#p pte %#p = %llux",
 		"checkpte: l%d addr %#p ppn %#ullx kaddr %#p pte %#p = %llux",
 		l, a, ppn, KADDR(ppn), pte, pte?*pte:~0);
 		l, a, ppn, KADDR(ppn), pte, pte?*pte:~0);
@@ -315,14 +315,14 @@ Panic:
 static void
 static void
 mmuptpcheck(Proc *proc)
 mmuptpcheck(Proc *proc)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	int lvl, npgs, i;
 	int lvl, npgs, i;
 	Page *lp, *p, *pgs[16], *fp;
 	Page *lp, *p, *pgs[16], *fp;
 	uint idx[16];
 	uint idx[16];
 
 
 	if(proc == nil)
 	if(proc == nil)
 		return;
 		return;
-	lp = m->pml4;
+	lp = machp()->pml4;
 	for(lvl = 3; lvl >= 2; lvl--){
 	for(lvl = 3; lvl >= 2; lvl--){
 		npgs = 0;
 		npgs = 0;
 		for(p = proc->mmuptp[lvl]; p != nil; p = p->next){
 		for(p = proc->mmuptp[lvl]; p != nil; p = p->next){
@@ -350,7 +350,7 @@ mmuptpcheck(Proc *proc)
 				panic("ptpcheck: wrong prev");
 				panic("ptpcheck: wrong prev");
 			}
 			}
 		}
 		}
-		
+
 	}
 	}
 	npgs = 0;
 	npgs = 0;
 	for(fp = proc->mmuptp[0]; fp != nil; fp = fp->next){
 	for(fp = proc->mmuptp[0]; fp != nil; fp = fp->next){
@@ -381,7 +381,7 @@ pteflags(uint attr)
 }
 }
 
 
 /*
 /*
- * pg->pgszi indicates the page size in m->pgsz[] used for the mapping.
+ * pg->pgszi indicates the page size in machp()->pgsz[] used for the mapping.
  * For the user, it can be either 2*MiB or 1*GiB pages.
  * For the user, it can be either 2*MiB or 1*GiB pages.
  * For 2*MiB pages, we use three levels, not four.
  * For 2*MiB pages, we use three levels, not four.
  * For 1*GiB pages, we use two levels.
  * For 1*GiB pages, we use two levels.
@@ -389,7 +389,7 @@ pteflags(uint attr)
 void
 void
 mmuput(uintptr_t va, Page *pg, uint attr)
 mmuput(uintptr_t va, Page *pg, uint attr)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	int lvl, user, x, pgsz;
 	int lvl, user, x, pgsz;
 	PTE *pte;
 	PTE *pte;
 	Page *page, *prev;
 	Page *page, *prev;
@@ -403,25 +403,25 @@ mmuput(uintptr_t va, Page *pg, uint attr)
 		panic("mmuput: zero pa");
 		panic("mmuput: zero pa");
 
 
 	if(DBGFLG){
 	if(DBGFLG){
-		snprint(buf, sizeof buf, "cpu%d: up %#p mmuput %#p %#P %#ux\n", 
-			m->machno, m->externup, va, pa, attr);
+		snprint(buf, sizeof buf, "cpu%d: up %#p mmuput %#p %#P %#ux\n",
+			machp()->machno, up, va, pa, attr);
 		print("%s", buf);
 		print("%s", buf);
 	}
 	}
 	assert(pg->pgszi >= 0);
 	assert(pg->pgszi >= 0);
-	pgsz = m->pgsz[pg->pgszi];
+	pgsz = machp()->pgsz[pg->pgszi];
 	if(pa & (pgsz-1))
 	if(pa & (pgsz-1))
 		panic("mmuput: pa offset non zero: %#ullx\n", pa);
 		panic("mmuput: pa offset non zero: %#ullx\n", pa);
 	pa |= pteflags(attr);
 	pa |= pteflags(attr);
 
 
 	pl = splhi();
 	pl = splhi();
 	if(DBGFLG)
 	if(DBGFLG)
-		mmuptpcheck(m->externup);
+		mmuptpcheck(up);
 	user = (va < KZERO);
 	user = (va < KZERO);
 	x = PTLX(va, 3);
 	x = PTLX(va, 3);
 
 
-	pte = UINT2PTR(m->pml4->va);
+	pte = UINT2PTR(machp()->pml4->va);
 	pte += x;
 	pte += x;
-	prev = m->pml4;
+	prev = machp()->pml4;
 
 
 	for(lvl = 3; lvl >= 0; lvl--){
 	for(lvl = 3; lvl >= 0; lvl--){
 		if(user){
 		if(user){
@@ -430,7 +430,7 @@ mmuput(uintptr_t va, Page *pg, uint attr)
 			if(pgsz == 1ull*GiB && lvl == 2)	/* use 1G */
 			if(pgsz == 1ull*GiB && lvl == 2)	/* use 1G */
 				break;
 				break;
 		}
 		}
-		for(page = m->externup->mmuptp[lvl]; page != nil; page = page->next)
+		for(page = up->mmuptp[lvl]; page != nil; page = page->next)
 			if(page->prev == prev && page->daddr == x){
 			if(page->prev == prev && page->daddr == x){
 				if(*pte == 0){
 				if(*pte == 0){
 					print("mmu: jmk and nemo had fun\n");
 					print("mmu: jmk and nemo had fun\n");
@@ -440,19 +440,19 @@ mmuput(uintptr_t va, Page *pg, uint attr)
 			}
 			}
 
 
 		if(page == nil){
 		if(page == nil){
-			if(m->externup->mmuptp[0] == nil)
+			if(up->mmuptp[0] == nil)
 				page = mmuptpalloc();
 				page = mmuptpalloc();
 			else {
 			else {
-				page = m->externup->mmuptp[0];
-				m->externup->mmuptp[0] = page->next;
+				page = up->mmuptp[0];
+				up->mmuptp[0] = page->next;
 			}
 			}
 			page->daddr = x;
 			page->daddr = x;
-			page->next = m->externup->mmuptp[lvl];
-			m->externup->mmuptp[lvl] = page;
+			page->next = up->mmuptp[lvl];
+			up->mmuptp[lvl] = page;
 			page->prev = prev;
 			page->prev = prev;
 			*pte = PPN(page->pa)|PteU|PteRW|PteP;
 			*pte = PPN(page->pa)|PteU|PteRW|PteP;
-			if(lvl == 3 && x >= m->pml4->daddr)
-				m->pml4->daddr = x+1;
+			if(lvl == 3 && x >= machp()->pml4->daddr)
+				machp()->pml4->daddr = x+1;
 		}
 		}
 		x = PTLX(va, lvl-1);
 		x = PTLX(va, lvl-1);
 
 
@@ -481,8 +481,8 @@ mmuput(uintptr_t va, Page *pg, uint attr)
 	splx(pl);
 	splx(pl);
 
 
 	if(DBGFLG){
 	if(DBGFLG){
-		snprint(buf, sizeof buf, "cpu%d: up %#p new pte %#p = %#llux\n", 
-			m->machno, m->externup, pte, pte?*pte:~0);
+		snprint(buf, sizeof buf, "cpu%d: up %#p new pte %#p = %#llux\n",
+			machp()->machno, up, pte, pte?*pte:~0);
 		print("%s", buf);
 		print("%s", buf);
 	}
 	}
 
 
@@ -649,13 +649,13 @@ vmapalloc(usize size)
 void*
 void*
 vmap(uintptr_t pa, usize size)
 vmap(uintptr_t pa, usize size)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	uintptr_t va;
 	uintptr_t va;
 	usize o, sz;
 	usize o, sz;
 
 
 	DBG("vmap(%#p, %lud) pc=%#p\n", pa, size, getcallerpc(&pa));
 	DBG("vmap(%#p, %lud) pc=%#p\n", pa, size, getcallerpc(&pa));
 
 
-	if(m->machno != 0)
+	if(machp()->machno != 0)
 		panic("vmap");
 		panic("vmap");
 
 
 	/*
 	/*
@@ -702,12 +702,12 @@ vmap(uintptr_t pa, usize size)
 void
 void
 vunmap(void* v, usize size)
 vunmap(void* v, usize size)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	uintptr_t va;
 	uintptr_t va;
 
 
 	DBG("vunmap(%#p, %lud)\n", v, size);
 	DBG("vunmap(%#p, %lud)\n", v, size);
 
 
-	if(m->machno != 0)
+	if(machp()->machno != 0)
 		panic("vunmap");
 		panic("vunmap");
 
 
 	/*
 	/*
@@ -729,7 +729,7 @@ int
 mmuwalk(PTE* pml4, uintptr_t va, int level, PTE** ret,
 mmuwalk(PTE* pml4, uintptr_t va, int level, PTE** ret,
 	uint64_t (*alloc)(usize))
 	uint64_t (*alloc)(usize))
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	int l;
 	int l;
 	uintmem pa;
 	uintmem pa;
 	PTE *pte;
 	PTE *pte;
@@ -738,7 +738,7 @@ mmuwalk(PTE* pml4, uintptr_t va, int level, PTE** ret,
 
 
 	pl = splhi();
 	pl = splhi();
 	if(DBGFLG > 1)
 	if(DBGFLG > 1)
-		DBG("mmuwalk%d: va %#p level %d\n", m->machno, va, level);
+		DBG("mmuwalk%d: va %#p level %d\n", machp()->machno, va, level);
 	pte = &pml4[PTLX(va, 3)];
 	pte = &pml4[PTLX(va, 3)];
 	for(l = 3; l >= 0; l--){
 	for(l = 3; l >= 0; l--){
 		if(l == level)
 		if(l == level)
@@ -765,7 +765,7 @@ mmuwalk(PTE* pml4, uintptr_t va, int level, PTE** ret,
 uintmem
 uintmem
 mmuphysaddr(uintptr_t va)
 mmuphysaddr(uintptr_t va)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	int l;
 	int l;
 	PTE *pte;
 	PTE *pte;
 	uintmem mask, pa;
 	uintmem mask, pa;
@@ -776,7 +776,7 @@ mmuphysaddr(uintptr_t va)
 	 * but will do as an experiment. Usual
 	 * but will do as an experiment. Usual
 	 * question, should va be void* or uintptr?
 	 * question, should va be void* or uintptr?
 	 */
 	 */
-	l = mmuwalk(UINT2PTR(m->pml4->va), va, 0, &pte, nil);
+	l = mmuwalk(UINT2PTR(machp()->pml4->va), va, 0, &pte, nil);
 	DBG("physaddr: va %#p l %d\n", va, l);
 	DBG("physaddr: va %#p l %d\n", va, l);
 	if(l < 0)
 	if(l < 0)
 		return ~0;
 		return ~0;
@@ -794,15 +794,15 @@ Page mach0pml4;
 void
 void
 mmuinit(void)
 mmuinit(void)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	uint8_t *p;
 	uint8_t *p;
 	Page *page;
 	Page *page;
 	uint64_t o, pa, r, sz;
 	uint64_t o, pa, r, sz;
 
 
 	archmmu();
 	archmmu();
-	DBG("mach%d: %#p pml4 %#p npgsz %d\n", m->machno, m, m->pml4, m->npgsz);
+	DBG("mach%d: %#p pml4 %#p npgsz %d\n", machp()->machno, m, machp()->pml4, m->npgsz);
 
 
-	if(m->machno != 0){
+	if(machp()->machno != 0){
 		/* NIX: KLUDGE: Has to go when each mach is using
 		/* NIX: KLUDGE: Has to go when each mach is using
 		 * its own page table
 		 * its own page table
 		 */
 		 */
@@ -810,16 +810,16 @@ mmuinit(void)
 		p += MACHSTKSZ;
 		p += MACHSTKSZ;
 
 
 		memmove(p, UINT2PTR(mach0pml4.va), PTSZ);
 		memmove(p, UINT2PTR(mach0pml4.va), PTSZ);
-		m->pml4 = &m->pml4kludge;
-		m->pml4->va = PTR2UINT(p);
-		m->pml4->pa = PADDR(p);
-		m->pml4->daddr = mach0pml4.daddr;	/* # of user mappings in pml4 */
+		machp()->pml4 = &machp()->pml4kludge;
+		machp()->pml4->va = PTR2UINT(p);
+		machp()->pml4->pa = PADDR(p);
+		machp()->pml4->daddr = mach0pml4.daddr;	/* # of user mappings in pml4 */
 
 
 		r = rdmsr(Efer);
 		r = rdmsr(Efer);
 		r |= Nxe;
 		r |= Nxe;
 		wrmsr(Efer, r);
 		wrmsr(Efer, r);
-		cr3put(m->pml4->pa);
-		DBG("m %#p pml4 %#p\n", m, m->pml4);
+		cr3put(machp()->pml4->pa);
+		DBG("m %#p pml4 %#p\n", m, machp()->pml4);
 		return;
 		return;
 	}
 	}
 
 
@@ -827,7 +827,7 @@ mmuinit(void)
 	page->pa = cr3get();
 	page->pa = cr3get();
 	page->va = PTR2UINT(KADDR(page->pa));
 	page->va = PTR2UINT(KADDR(page->pa));
 
 
-	m->pml4 = page;
+	machp()->pml4 = page;
 
 
 	r = rdmsr(Efer);
 	r = rdmsr(Efer);
 	r |= Nxe;
 	r |= Nxe;

+ 1 - 1
sys/src/9/amd64pv/physalloc.c

@@ -530,7 +530,7 @@ physinit(uintmem a, uint64_t size)
 				b->size = (addr-b->base) + len;
 				b->size = (addr-b->base) + len;
 			for(i = 0; i < Ndoms; i++)
 			for(i = 0; i < Ndoms; i++)
 				if(bal[i].kmin && &bal[i] != b)
 				if(bal[i].kmin && &bal[i] != b)
-				if(bal[i].base < b->base + b->size && 
+				if(bal[i].base < b->base + b->size &&
 				   bal[i].base + bal[i].size > b->base + b->size)
 				   bal[i].base + bal[i].size > b->base + b->size)
 					panic("physinit: doms overlap");
 					panic("physinit: doms overlap");
 		}
 		}

+ 14 - 14
sys/src/9/amd64pv/pmcio.c

@@ -21,7 +21,7 @@
 #include	"../port/pmc.h"
 #include	"../port/pmc.h"
 
 
 
 
-/* non portable, for intel will be CPUID.0AH.EDX 
+/* non portable, for intel will be CPUID.0AH.EDX
  */
  */
 
 
 enum {
 enum {
@@ -38,7 +38,7 @@ pmcnregs(void)
 }
 }
 
 
 //PeHo|PeGo
 //PeHo|PeGo
-#define PeAll	(PeOS|PeUsr)	
+#define PeAll	(PeOS|PeUsr)
 #define SetEvMsk(v, e) ((v)|(((e)&PeEvMskL)|(((e)<<(PeEvMsksh-8))&PeEvMskH)))
 #define SetEvMsk(v, e) ((v)|(((e)&PeEvMskL)|(((e)<<(PeEvMsksh-8))&PeEvMskH)))
 #define SetUMsk(v, u) ((v)|(((u)<<8ull)&PeUnMsk))
 #define SetUMsk(v, u) ((v)|(((u)<<8ull)&PeUnMsk))
 
 
@@ -203,16 +203,16 @@ pmcctlstr(char *str, int nstr, PmcCtl *p)
 		ns += snprint(str + ns, nstr - ns, "enable\n");
 		ns += snprint(str + ns, nstr - ns, "enable\n");
 	else
 	else
 		ns += snprint(str + ns, nstr - ns, "disable\n");
 		ns += snprint(str + ns, nstr - ns, "disable\n");
-		
+
 	if (p->user && p->user != PmcCtlNullval)
 	if (p->user && p->user != PmcCtlNullval)
 		ns += snprint(str + ns, nstr - ns, "user\n");
 		ns += snprint(str + ns, nstr - ns, "user\n");
 	if (p->os && p->user != PmcCtlNullval)
 	if (p->os && p->user != PmcCtlNullval)
 		ns += snprint(str + ns, nstr - ns, "os\n");
 		ns += snprint(str + ns, nstr - ns, "os\n");
-	
+
 	//TODO, inverse pmctrans?
 	//TODO, inverse pmctrans?
 	if(!p->nodesc)
 	if(!p->nodesc)
 		ns += snprint(str + ns, nstr - ns, "%s\n", p->descstr);
 		ns += snprint(str + ns, nstr - ns, "%s\n", p->descstr);
-	else 
+	else
 		ns += snprint(str + ns, nstr - ns, "no desc\n");
 		ns += snprint(str + ns, nstr - ns, "no desc\n");
 	return ns;
 	return ns;
 }
 }
@@ -281,7 +281,7 @@ pmcwclose(PmcWait *w)
 static void
 static void
 waitnotstale(Mach *mp, PmcCtr *p)
 waitnotstale(Mach *mp, PmcCtr *p)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	PmcWait *w;
 	PmcWait *w;
 
 
 	p->stale = 1;
 	p->stale = 1;
@@ -329,12 +329,12 @@ shouldipi(Mach *mp)
 uint64_t
 uint64_t
 pmcgetctr(uint32_t coreno, uint32_t regno)
 pmcgetctr(uint32_t coreno, uint32_t regno)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	PmcCtr *p;
 	PmcCtr *p;
 	Mach *mp;
 	Mach *mp;
 	uint64_t v;
 	uint64_t v;
 
 
-	if(coreno == m->machno){
+	if(coreno == machp()->machno){
 		v = getctr(regno);
 		v = getctr(regno);
 		if (pmcdebug) {
 		if (pmcdebug) {
 			print("int getctr[%#ux, %#ux] = %#llux\n", regno, coreno, v);
 			print("int getctr[%#ux, %#ux] = %#llux\n", regno, coreno, v);
@@ -361,11 +361,11 @@ pmcgetctr(uint32_t coreno, uint32_t regno)
 int
 int
 pmcsetctr(uint32_t coreno, uint64_t v, uint32_t regno)
 pmcsetctr(uint32_t coreno, uint64_t v, uint32_t regno)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	PmcCtr *p;
 	PmcCtr *p;
 	Mach *mp;
 	Mach *mp;
 
 
-	if(coreno == m->machno){
+	if(coreno == machp()->machno){
 		if (pmcdebug) {
 		if (pmcdebug) {
 			print("int getctr[%#ux, %#ux] = %#llux\n", regno, coreno, v);
 			print("int getctr[%#ux, %#ux] = %#llux\n", regno, coreno, v);
 		}
 		}
@@ -405,11 +405,11 @@ ctl2ctl(PmcCtl *dctl, PmcCtl *sctl)
 int
 int
 pmcsetctl(uint32_t coreno, PmcCtl *pctl, uint32_t regno)
 pmcsetctl(uint32_t coreno, PmcCtl *pctl, uint32_t regno)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	PmcCtr *p;
 	PmcCtr *p;
 	Mach *mp;
 	Mach *mp;
 
 
-	if(coreno == m->machno)
+	if(coreno == machp()->machno)
 		return setctl(pctl, regno);
 		return setctl(pctl, regno);
 
 
 	mp = sys->machptr[coreno];
 	mp = sys->machptr[coreno];
@@ -427,11 +427,11 @@ pmcsetctl(uint32_t coreno, PmcCtl *pctl, uint32_t regno)
 int
 int
 pmcgetctl(uint32_t coreno, PmcCtl *pctl, uint32_t regno)
 pmcgetctl(uint32_t coreno, PmcCtl *pctl, uint32_t regno)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	PmcCtr *p;
 	PmcCtr *p;
 	Mach *mp;
 	Mach *mp;
 
 
-	if(coreno == m->machno)
+	if(coreno == machp()->machno)
 		return getctl(pctl, regno);
 		return getctl(pctl, regno);
 
 
 	mp = sys->machptr[coreno];
 	mp = sys->machptr[coreno];

+ 5 - 5
sys/src/9/amd64pv/qmalloc.c

@@ -115,10 +115,10 @@ static	Lock		mainlock;
  * Experiment: per-core quick lists.
  * Experiment: per-core quick lists.
  * change quicklist to be
  * change quicklist to be
  * static	Qlist	quicklist[MACHMAX][NQUICK+1];
  * static	Qlist	quicklist[MACHMAX][NQUICK+1];
- * and define QLIST to be quicklist[m->machno]
+ * and define QLIST to be quicklist[machp()->machno]
  *
  *
- * using quicklist[m->machno] runs out of memory soon.
- * using quicklist[m->machno%4] yields times worse than using quicklist!
+ * using quicklist[machp()->machno] runs out of memory soon.
+ * using quicklist[machp()->machno%4] yields times worse than using quicklist!
  */
  */
 #define QLIST	quicklist
 #define QLIST	quicklist
 
 
@@ -549,11 +549,11 @@ mallocalign(uint32_t nbytes, uint32_t align, int32_t offset, uint32_t span)
 void*
 void*
 smalloc(uint32_t size)
 smalloc(uint32_t size)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	void *v;
 	void *v;
 
 
 	while((v = malloc(size)) == nil)
 	while((v = malloc(size)) == nil)
-		tsleep(&m->externup->sleep, return0, 0, 100);
+		tsleep(&up->sleep, return0, 0, 100);
 	memset(v, 0, size);
 	memset(v, 0, size);
 
 
 	return v;
 	return v;

+ 99 - 99
sys/src/9/amd64pv/syscall.c

@@ -39,25 +39,25 @@ typedef struct {
 void
 void
 noted(Ureg* cur, uintptr_t arg0)
 noted(Ureg* cur, uintptr_t arg0)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	NFrame *nf;
 	NFrame *nf;
 	Note note;
 	Note note;
 	Ureg *nur;
 	Ureg *nur;
 
 
-	qlock(&m->externup->debug);
-	if(arg0 != NRSTR && !m->externup->notified){
-		qunlock(&m->externup->debug);
+	qlock(&up->debug);
+	if(arg0 != NRSTR && !up->notified){
+		qunlock(&up->debug);
 		pprint("suicide: call to noted when not notified\n");
 		pprint("suicide: call to noted when not notified\n");
 		pexit("Suicide", 0);
 		pexit("Suicide", 0);
 	}
 	}
-	m->externup->notified = 0;
+	up->notified = 0;
 	fpunoted();
 	fpunoted();
 
 
-	nf = m->externup->ureg;
+	nf = up->ureg;
 
 
 	/* sanity clause */
 	/* sanity clause */
 	if(!okaddr(PTR2UINT(nf), sizeof(NFrame), 0)){
 	if(!okaddr(PTR2UINT(nf), sizeof(NFrame), 0)){
-		qunlock(&m->externup->debug);
+		qunlock(&up->debug);
 		pprint("suicide: bad ureg %#p in noted\n", nf);
 		pprint("suicide: bad ureg %#p in noted\n", nf);
 		pexit("Suicide", 0);
 		pexit("Suicide", 0);
 	}
 	}
@@ -67,7 +67,7 @@ noted(Ureg* cur, uintptr_t arg0)
 	 */
 	 */
 	nur = &nf->ureg;
 	nur = &nf->ureg;
 	if(nur->cs != SSEL(SiUCS, SsRPL3) || nur->ss != SSEL(SiUDS, SsRPL3)) {
 	if(nur->cs != SSEL(SiUCS, SsRPL3) || nur->ss != SSEL(SiUDS, SsRPL3)) {
-		qunlock(&m->externup->debug);
+		qunlock(&up->debug);
 		pprint("suicide: bad segment selector in noted\n");
 		pprint("suicide: bad segment selector in noted\n");
 		pexit("Suicide", 0);
 		pexit("Suicide", 0);
 	}
 	}
@@ -82,22 +82,22 @@ noted(Ureg* cur, uintptr_t arg0)
 	case NCONT:
 	case NCONT:
 	case NRSTR:
 	case NRSTR:
 		if(!okaddr(nur->ip, BY2SE, 0) || !okaddr(nur->sp, BY2SE, 0)){
 		if(!okaddr(nur->ip, BY2SE, 0) || !okaddr(nur->sp, BY2SE, 0)){
-			qunlock(&m->externup->debug);
+			qunlock(&up->debug);
 			pprint("suicide: trap in noted pc=%#p sp=%#p\n",
 			pprint("suicide: trap in noted pc=%#p sp=%#p\n",
 				nur->ip, nur->sp);
 				nur->ip, nur->sp);
 			pexit("Suicide", 0);
 			pexit("Suicide", 0);
 		}
 		}
-		m->externup->ureg = nf->old;
-		qunlock(&m->externup->debug);
+		up->ureg = nf->old;
+		qunlock(&up->debug);
 		break;
 		break;
 	case NSAVE:
 	case NSAVE:
 		if(!okaddr(nur->ip, BY2SE, 0) || !okaddr(nur->sp, BY2SE, 0)){
 		if(!okaddr(nur->ip, BY2SE, 0) || !okaddr(nur->sp, BY2SE, 0)){
-			qunlock(&m->externup->debug);
+			qunlock(&up->debug);
 			pprint("suicide: trap in noted pc=%#p sp=%#p\n",
 			pprint("suicide: trap in noted pc=%#p sp=%#p\n",
 				nur->ip, nur->sp);
 				nur->ip, nur->sp);
 			pexit("Suicide", 0);
 			pexit("Suicide", 0);
 		}
 		}
-		qunlock(&m->externup->debug);
+		qunlock(&up->debug);
 
 
 		splhi();
 		splhi();
 		nf->arg1 = nf->msg;
 		nf->arg1 = nf->msg;
@@ -107,14 +107,14 @@ noted(Ureg* cur, uintptr_t arg0)
 		cur->sp = PTR2UINT(nf);
 		cur->sp = PTR2UINT(nf);
 		break;
 		break;
 	default:
 	default:
-		memmove(&note, &m->externup->lastnote, sizeof(Note));
-		qunlock(&m->externup->debug);
+		memmove(&note, &up->lastnote, sizeof(Note));
+		qunlock(&up->debug);
 		pprint("suicide: bad arg %#p in noted: %s\n", arg0, note.msg);
 		pprint("suicide: bad arg %#p in noted: %s\n", arg0, note.msg);
 		pexit(note.msg, 0);
 		pexit(note.msg, 0);
 		break;
 		break;
 	case NDFLT:
 	case NDFLT:
-		memmove(&note, &m->externup->lastnote, sizeof(Note));
-		qunlock(&m->externup->debug);
+		memmove(&note, &up->lastnote, sizeof(Note));
+		qunlock(&up->debug);
 		if(note.flag == NDebug)
 		if(note.flag == NDebug)
 			pprint("suicide: %s\n", note.msg);
 			pprint("suicide: %s\n", note.msg);
 		pexit(note.msg, note.flag != NDebug);
 		pexit(note.msg, note.flag != NDebug);
@@ -129,7 +129,7 @@ noted(Ureg* cur, uintptr_t arg0)
 int
 int
 notify(Ureg* ureg)
 notify(Ureg* ureg)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	int l;
 	int l;
 	Mpl pl;
 	Mpl pl;
 	Note note;
 	Note note;
@@ -139,18 +139,18 @@ notify(Ureg* ureg)
 	/*
 	/*
 	 * Calls procctl splhi, see comment in procctl for the reasoning.
 	 * Calls procctl splhi, see comment in procctl for the reasoning.
 	 */
 	 */
-	if(m->externup->procctl)
-		procctl(m->externup);
-	if(m->externup->nnote == 0)
+	if(up->procctl)
+		procctl(up);
+	if(up->nnote == 0)
 		return 0;
 		return 0;
 
 
 	fpunotify(ureg);
 	fpunotify(ureg);
 
 
 	pl = spllo();
 	pl = spllo();
-	qlock(&m->externup->debug);
+	qlock(&up->debug);
 
 
-	m->externup->notepending = 0;
-	memmove(&note, &m->externup->note[0], sizeof(Note));
+	up->notepending = 0;
+	memmove(&note, &up->note[0], sizeof(Note));
 	if(strncmp(note.msg, "sys:", 4) == 0){
 	if(strncmp(note.msg, "sys:", 4) == 0){
 		l = strlen(note.msg);
 		l = strlen(note.msg);
 		if(l > ERRMAX-sizeof(" pc=0x0123456789abcdef"))
 		if(l > ERRMAX-sizeof(" pc=0x0123456789abcdef"))
@@ -158,41 +158,41 @@ notify(Ureg* ureg)
 		sprint(note.msg+l, " pc=%#p", ureg->ip);
 		sprint(note.msg+l, " pc=%#p", ureg->ip);
 	}
 	}
 
 
-	if(note.flag != NUser && (m->externup->notified || m->externup->notify == nil)){
-		qunlock(&m->externup->debug);
+	if(note.flag != NUser && (up->notified || up->notify == nil)){
+		qunlock(&up->debug);
 		if(note.flag == NDebug)
 		if(note.flag == NDebug)
 			pprint("suicide: %s\n", note.msg);
 			pprint("suicide: %s\n", note.msg);
 		pexit(note.msg, note.flag != NDebug);
 		pexit(note.msg, note.flag != NDebug);
 	}
 	}
 
 
-	if(m->externup->notified){
-		qunlock(&m->externup->debug);
+	if(up->notified){
+		qunlock(&up->debug);
 		splhi();
 		splhi();
 		return 0;
 		return 0;
 	}
 	}
 
 
-	if(m->externup->notify == nil){
-		qunlock(&m->externup->debug);
+	if(up->notify == nil){
+		qunlock(&up->debug);
 		pexit(note.msg, note.flag != NDebug);
 		pexit(note.msg, note.flag != NDebug);
 	}
 	}
-	if(!okaddr(PTR2UINT(m->externup->notify), sizeof(ureg->ip), 0)){
-		qunlock(&m->externup->debug);
+	if(!okaddr(PTR2UINT(up->notify), sizeof(ureg->ip), 0)){
+		qunlock(&up->debug);
 		pprint("suicide: bad function address %#p in notify\n",
 		pprint("suicide: bad function address %#p in notify\n",
-			m->externup->notify);
+			up->notify);
 		pexit("Suicide", 0);
 		pexit("Suicide", 0);
 	}
 	}
 
 
 	sp = ureg->sp - sizeof(NFrame);
 	sp = ureg->sp - sizeof(NFrame);
 	if(!okaddr(sp, sizeof(NFrame), 1)){
 	if(!okaddr(sp, sizeof(NFrame), 1)){
-		qunlock(&m->externup->debug);
+		qunlock(&up->debug);
 		pprint("suicide: bad stack address %#p in notify\n", sp);
 		pprint("suicide: bad stack address %#p in notify\n", sp);
 		pexit("Suicide", 0);
 		pexit("Suicide", 0);
 	}
 	}
 
 
 	nf = UINT2PTR(sp);
 	nf = UINT2PTR(sp);
 	memmove(&nf->ureg, ureg, sizeof(Ureg));
 	memmove(&nf->ureg, ureg, sizeof(Ureg));
-	nf->old = m->externup->ureg;
-	m->externup->ureg = nf;	/* actually the NFrame, for noted */
+	nf->old = up->ureg;
+	up->ureg = nf;	/* actually the NFrame, for noted */
 	memmove(nf->msg, note.msg, ERRMAX);
 	memmove(nf->msg, note.msg, ERRMAX);
 	nf->arg1 = nf->msg;
 	nf->arg1 = nf->msg;
 	nf->arg0 = &nf->ureg;
 	nf->arg0 = &nf->ureg;
@@ -203,13 +203,13 @@ notify(Ureg* ureg)
 	nf->ip = 0;
 	nf->ip = 0;
 
 
 	ureg->sp = sp;
 	ureg->sp = sp;
-	ureg->ip = PTR2UINT(m->externup->notify);
-	m->externup->notified = 1;
-	m->externup->nnote--;
-	memmove(&m->externup->lastnote, &note, sizeof(Note));
-	memmove(&m->externup->note[0], &m->externup->note[1], m->externup->nnote*sizeof(Note));
+	ureg->ip = PTR2UINT(up->notify);
+	up->notified = 1;
+	up->nnote--;
+	memmove(&up->lastnote, &note, sizeof(Note));
+	memmove(&up->note[0], &up->note[1], up->nnote*sizeof(Note));
 
 
-	qunlock(&m->externup->debug);
+	qunlock(&up->debug);
 	splx(pl);
 	splx(pl);
 
 
 	return 1;
 	return 1;
@@ -218,18 +218,18 @@ notify(Ureg* ureg)
 void
 void
 noerrorsleft(void)
 noerrorsleft(void)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	int i;
 	int i;
 
 
-	if(m->externup->nerrlab){
+	if(up->nerrlab){
 		/* NIX processes will have a waserror in their handler */
 		/* NIX processes will have a waserror in their handler */
-		if(m->externup->ac != nil && m->externup->nerrlab == 1)
+		if(up->ac != nil && up->nerrlab == 1)
 			return;
 			return;
 
 
-		print("bad errstack: %d extra\n", m->externup->nerrlab);
+		print("bad errstack: %d extra\n", up->nerrlab);
 		for(i = 0; i < NERR; i++)
 		for(i = 0; i < NERR; i++)
 			print("sp=%#p pc=%#p\n",
 			print("sp=%#p pc=%#p\n",
-				m->externup->errlab[i].sp, m->externup->errlab[i].pc);
+				up->errlab[i].sp, up->errlab[i].pc);
 		panic("error stack");
 		panic("error stack");
 	}
 	}
 }
 }
@@ -239,7 +239,7 @@ void
 syscall(int badscallnr, Ureg *ureg)
 syscall(int badscallnr, Ureg *ureg)
 {
 {
 	// can only handle 4 args right now.
 	// can only handle 4 args right now.
-	uintptr_t a0, a1, a2, a3; 
+	uintptr_t a0, a1, a2, a3;
 	uintptr_t a4, a5 = 0;
 	uintptr_t a4, a5 = 0;
 
 
 	a0 = ureg->di;
 	a0 = ureg->di;
@@ -247,7 +247,7 @@ syscall(int badscallnr, Ureg *ureg)
 	a2 = ureg->dx;
 	a2 = ureg->dx;
 	a3 = ureg->r10;
 	a3 = ureg->r10;
 	a4 = ureg->r8;
 	a4 = ureg->r8;
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	unsigned int scallnr = (unsigned int) badscallnr;
 	unsigned int scallnr = (unsigned int) badscallnr;
 	if (0) iprint("Syscall %d, %lx, %lx, %lx %lx %lx\n", scallnr, a0, a1, a2, a3, a4);
 	if (0) iprint("Syscall %d, %lx, %lx, %lx %lx %lx\n", scallnr, a0, a1, a2, a3, a4);
 	char *e;
 	char *e;
@@ -266,27 +266,27 @@ syscall(int badscallnr, Ureg *ureg)
 	if(!userureg(ureg))
 	if(!userureg(ureg))
 		panic("syscall: cs %#llux\n", ureg->cs);
 		panic("syscall: cs %#llux\n", ureg->cs);
 
 
-	cycles(&m->externup->kentry);
+	cycles(&up->kentry);
 
 
 	m->syscall++;
 	m->syscall++;
-	m->externup->nsyscall++;
-	m->externup->nqsyscall++;
-	m->externup->insyscall = 1;
-	m->externup->pc = ureg->ip;
-	m->externup->dbgreg = ureg;
+	up->nsyscall++;
+	up->nqsyscall++;
+	up->insyscall = 1;
+	up->pc = ureg->ip;
+	up->dbgreg = ureg;
 	sp = ureg->sp;
 	sp = ureg->sp;
 	startns = 0;
 	startns = 0;
 	if (0) hi("so far syscall!\n");
 	if (0) hi("so far syscall!\n");
 	if (printallsyscalls) {
 	if (printallsyscalls) {
 		syscallfmt(scallnr, a0, a1, a2, a3, a4, a5);
 		syscallfmt(scallnr, a0, a1, a2, a3, a4, a5);
-		if(m->externup->syscalltrace) {
-			if(1) iprint("E %s\n", m->externup->syscalltrace);
-			free(m->externup->syscalltrace);
-			m->externup->syscalltrace = nil;
+		if(up->syscalltrace) {
+			if(1) iprint("E %s\n", up->syscalltrace);
+			free(up->syscalltrace);
+			up->syscalltrace = nil;
 		}
 		}
 	}
 	}
 
 
-	if(m->externup->procctl == Proc_tracesyscall){
+	if(up->procctl == Proc_tracesyscall){
 		/*
 		/*
 		 * Redundant validaddr.  Do we care?
 		 * Redundant validaddr.  Do we care?
 		 * Tracing syscalls is not exactly a fast path...
 		 * Tracing syscalls is not exactly a fast path...
@@ -294,39 +294,39 @@ syscall(int badscallnr, Ureg *ureg)
 		 * than an error if there's a problem; that might
 		 * than an error if there's a problem; that might
 		 * change in the future.
 		 * change in the future.
 		 */
 		 */
-		if(sp < (USTKTOP-BIGPGSZ) || sp > (USTKTOP-sizeof(m->externup->arg)-BY2SE))
-			validaddr(UINT2PTR(sp), sizeof(m->externup->arg)+BY2SE, 0);
+		if(sp < (USTKTOP-BIGPGSZ) || sp > (USTKTOP-sizeof(up->arg)-BY2SE))
+			validaddr(UINT2PTR(sp), sizeof(up->arg)+BY2SE, 0);
 
 
 		syscallfmt(scallnr, a0, a1, a2, a3, a4, a5);
 		syscallfmt(scallnr, a0, a1, a2, a3, a4, a5);
-		m->externup->procctl = Proc_stopme;
-		procctl(m->externup);
-		if(m->externup->syscalltrace)
-			free(m->externup->syscalltrace);
-		m->externup->syscalltrace = nil;
+		up->procctl = Proc_stopme;
+		procctl(up);
+		if(up->syscalltrace)
+			free(up->syscalltrace);
+		up->syscalltrace = nil;
 		startns = todget(nil);
 		startns = todget(nil);
 	}
 	}
 	if (0) hi("more syscall!\n");
 	if (0) hi("more syscall!\n");
-	m->externup->scallnr = scallnr;
+	up->scallnr = scallnr;
 	if(scallnr == RFORK)
 	if(scallnr == RFORK)
 		fpusysrfork(ureg);
 		fpusysrfork(ureg);
 	spllo();
 	spllo();
 
 
 	sp = ureg->sp;
 	sp = ureg->sp;
-	m->externup->nerrlab = 0;
+	up->nerrlab = 0;
 	ar0 = zar0;
 	ar0 = zar0;
 	if(!waserror()){
 	if(!waserror()){
 		if(scallnr >= nsyscall || systab[scallnr].f == nil){
 		if(scallnr >= nsyscall || systab[scallnr].f == nil){
 			pprint("bad sys call number %d pc %#llux\n",
 			pprint("bad sys call number %d pc %#llux\n",
 				scallnr, ureg->ip);
 				scallnr, ureg->ip);
-			postnote(m->externup, 1, "sys: bad sys call", NDebug);
+			postnote(up, 1, "sys: bad sys call", NDebug);
 			error(Ebadarg);
 			error(Ebadarg);
 		}
 		}
 
 
-		if(sp < (USTKTOP-BIGPGSZ) || sp > (USTKTOP-sizeof(m->externup->arg)-BY2SE))
-			validaddr(UINT2PTR(sp), sizeof(m->externup->arg)+BY2SE, 0);
+		if(sp < (USTKTOP-BIGPGSZ) || sp > (USTKTOP-sizeof(up->arg)-BY2SE))
+			validaddr(UINT2PTR(sp), sizeof(up->arg)+BY2SE, 0);
 
 
-		memmove(m->externup->arg, UINT2PTR(sp+BY2SE), sizeof(m->externup->arg));
-		m->externup->psstate = systab[scallnr].n;
+		memmove(up->arg, UINT2PTR(sp+BY2SE), sizeof(up->arg));
+		up->psstate = systab[scallnr].n;
 	if (0) hi("call syscall!\n");
 	if (0) hi("call syscall!\n");
 		systab[scallnr].f(&ar0, a0, a1, a2, a3, a4, a5);
 		systab[scallnr].f(&ar0, a0, a1, a2, a3, a4, a5);
 	if (0) hi("it returned!\n");
 	if (0) hi("it returned!\n");
@@ -339,7 +339,7 @@ syscall(int badscallnr, Ureg *ureg)
 			 * already return from the system call, when dispatching
 			 * already return from the system call, when dispatching
 			 * the user code to the AC. The only thing left is to
 			 * the user code to the AC. The only thing left is to
 			 * return. The user registers should be ok, because
 			 * return. The user registers should be ok, because
-			 * m->externup->dbgreg has been the user context for the process.
+			 * up->dbgreg has been the user context for the process.
 			 */
 			 */
 			return;
 			return;
 		}
 		}
@@ -347,12 +347,12 @@ syscall(int badscallnr, Ureg *ureg)
 	}
 	}
 	else{
 	else{
 		/* failure: save the error buffer for errstr */
 		/* failure: save the error buffer for errstr */
-		e = m->externup->syserrstr;
-		m->externup->syserrstr = m->externup->errstr;
-		m->externup->errstr = e;
-		if(DBGFLG && m->externup->pid == 1)
+		e = up->syserrstr;
+		up->syserrstr = up->errstr;
+		up->errstr = e;
+		if(DBGFLG && up->pid == 1)
 			iprint("%s: syscall %s error %s\n",
 			iprint("%s: syscall %s error %s\n",
-				m->externup->text, systab[scallnr].n, m->externup->syserrstr);
+				up->text, systab[scallnr].n, up->syserrstr);
 		ar0 = systab[scallnr].r;
 		ar0 = systab[scallnr].r;
 	}
 	}
 
 
@@ -372,40 +372,40 @@ syscall(int badscallnr, Ureg *ureg)
 	if (printallsyscalls) {
 	if (printallsyscalls) {
 		stopns = todget(nil);
 		stopns = todget(nil);
 		sysretfmt(scallnr, &ar0, startns, stopns, a0, a1, a2, a3, a4, a5);
 		sysretfmt(scallnr, &ar0, startns, stopns, a0, a1, a2, a3, a4, a5);
-		if(m->externup->syscalltrace) {
-			if (1) iprint("X %s\n", m->externup->syscalltrace);
-			free(m->externup->syscalltrace);
-			m->externup->syscalltrace = nil;
+		if(up->syscalltrace) {
+			if (1) iprint("X %s\n", up->syscalltrace);
+			free(up->syscalltrace);
+			up->syscalltrace = nil;
 		}
 		}
 	}
 	}
 
 
-	if(m->externup->procctl == Proc_tracesyscall){
+	if(up->procctl == Proc_tracesyscall){
 		stopns = todget(nil);
 		stopns = todget(nil);
-		m->externup->procctl = Proc_stopme;
+		up->procctl = Proc_stopme;
 		sysretfmt(scallnr, &ar0, startns, stopns, a0, a1, a2, a3, a4, a5);
 		sysretfmt(scallnr, &ar0, startns, stopns, a0, a1, a2, a3, a4, a5);
 		s = splhi();
 		s = splhi();
-		procctl(m->externup);
+		procctl(up);
 		splx(s);
 		splx(s);
-		if(m->externup->syscalltrace)
-			free(m->externup->syscalltrace);
-		m->externup->syscalltrace = nil;
-	}else if(m->externup->procctl == Proc_totc || m->externup->procctl == Proc_toac)
-		procctl(m->externup);
+		if(up->syscalltrace)
+			free(up->syscalltrace);
+		up->syscalltrace = nil;
+	}else if(up->procctl == Proc_totc || up->procctl == Proc_toac)
+		procctl(up);
 
 
 	if (0) hi("past sysretfmt\n");
 	if (0) hi("past sysretfmt\n");
-	m->externup->insyscall = 0;
-	m->externup->psstate = 0;
+	up->insyscall = 0;
+	up->psstate = 0;
 
 
 	if(scallnr == NOTED)
 	if(scallnr == NOTED)
 		noted(ureg, a0);
 		noted(ureg, a0);
 
 
 	if (0) hi("now to splihi\n");
 	if (0) hi("now to splihi\n");
 	splhi();
 	splhi();
-	if(scallnr != RFORK && (m->externup->procctl || m->externup->nnote))
+	if(scallnr != RFORK && (up->procctl || up->nnote))
 		notify(ureg);
 		notify(ureg);
 
 
 	/* if we delayed sched because we held a lock, sched now */
 	/* if we delayed sched because we held a lock, sched now */
-	if(m->externup->delaysched){
+	if(up->delaysched){
 		sched();
 		sched();
 		splhi();
 		splhi();
 	}
 	}
@@ -436,13 +436,13 @@ sysexecstack(uintptr_t stack, int argc)
 void*
 void*
 sysexecregs(uintptr_t entry, uint32_t ssize, void *argv, uint32_t nargs, void *tos)
 sysexecregs(uintptr_t entry, uint32_t ssize, void *argv, uint32_t nargs, void *tos)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	uintptr_t *sp;
 	uintptr_t *sp;
 	Ureg *ureg;
 	Ureg *ureg;
 
 
 	sp = (uintptr_t*)(USTKTOP - ssize);
 	sp = (uintptr_t*)(USTKTOP - ssize);
 
 
-	ureg = m->externup->dbgreg;
+	ureg = up->dbgreg;
 	ureg->sp = PTR2UINT(sp);
 	ureg->sp = PTR2UINT(sp);
 	ureg->ip = entry;
 	ureg->ip = entry;
 	ureg->type = 64;			/* fiction for acid */
 	ureg->type = 64;			/* fiction for acid */
@@ -467,7 +467,7 @@ void
 sysrforkchild(Proc* child, Proc* parent)
 sysrforkchild(Proc* child, Proc* parent)
 {
 {
 	Ureg *cureg;
 	Ureg *cureg;
-// If STACKPAD is 1 things go very bad very quickly. 
+// If STACKPAD is 1 things go very bad very quickly.
 // But it is the right value ...
 // But it is the right value ...
 #define STACKPAD 1 /* for return PC? */
 #define STACKPAD 1 /* for return PC? */
 	/*
 	/*

+ 51 - 51
sys/src/9/amd64pv/tcore.c

@@ -31,7 +31,7 @@ extern void acsysret(void);
 Mach*
 Mach*
 getac(Proc *p, int core)
 getac(Proc *p, int core)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	int i;
 	int i;
 	Mach *mp;
 	Mach *mp;
 
 
@@ -72,7 +72,7 @@ getac(Proc *p, int core)
  * This is important for note handling, because postnote()
  * This is important for note handling, because postnote()
  * assumes that it's ok to send an IPI to an AC, no matter its
  * assumes that it's ok to send an IPI to an AC, no matter its
  * state. The /proc interface also assumes that.
  * state. The /proc interface also assumes that.
- * 
+ *
  */
  */
 void
 void
 intrac(Proc *p)
 intrac(Proc *p)
@@ -101,22 +101,22 @@ putac(Mach *m)
 void
 void
 stopac(void)
 stopac(void)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	Mach *mp;
 	Mach *mp;
 
 
-	mp = m->externup->ac;
+	mp = up->ac;
 	if(mp == nil)
 	if(mp == nil)
 		return;
 		return;
-	if(mp->proc != m->externup)
+	if(mp->proc != up)
 		panic("stopac");
 		panic("stopac");
 
 
 	lock(&nixaclock);
 	lock(&nixaclock);
-	m->externup->ac = nil;
+	up->ac = nil;
 	mp->proc = nil;
 	mp->proc = nil;
 	unlock(&nixaclock);
 	unlock(&nixaclock);
 
 
 	/* TODO:
 	/* TODO:
-	 * send sipi to m->externup->ac, it would rerun squidboy(), and
+	 * send sipi to up->ac, it would rerun squidboy(), and
 	 * wait for us to give it a function to run.
 	 * wait for us to give it a function to run.
 	 */
 	 */
 }
 }
@@ -140,7 +140,7 @@ extern int notify(Ureg*);
 int
 int
 runac(Mach *mp, APfunc func, int flushtlb, void *a, int32_t n)
 runac(Mach *mp, APfunc func, int flushtlb, void *a, int32_t n)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	uint8_t *dpg, *spg;
 	uint8_t *dpg, *spg;
 
 
 	if (n > sizeof(mp->icc->data))
 	if (n > sizeof(mp->icc->data))
@@ -148,21 +148,21 @@ runac(Mach *mp, APfunc func, int flushtlb, void *a, int32_t n)
 
 
 	if(mp->online == 0)
 	if(mp->online == 0)
 		panic("Bad core");
 		panic("Bad core");
-	if(mp->proc != nil && mp->proc != m->externup)
+	if(mp->proc != nil && mp->proc != up)
 		panic("runapfunc: mach is busy with another proc?");
 		panic("runapfunc: mach is busy with another proc?");
 
 
 	memmove(mp->icc->data, a, n);
 	memmove(mp->icc->data, a, n);
 	if(flushtlb){
 	if(flushtlb){
-		DBG("runac flushtlb: cppml4 %#p %#p\n", mp->pml4->pa, m->pml4->pa);
+		DBG("runac flushtlb: cppml4 %#p %#p\n", mp->pml4->pa, machp()->pml4->pa);
 		dpg = UINT2PTR(mp->pml4->va);
 		dpg = UINT2PTR(mp->pml4->va);
-		spg = UINT2PTR(m->pml4->va);
+		spg = UINT2PTR(machp()->pml4->va);
 		/* We should copy less:
 		/* We should copy less:
-		 *	memmove(dgp, spg, m->pml4->daddr * sizeof(PTE));
+		 *	memmove(dgp, spg, machp()->pml4->daddr * sizeof(PTE));
 		 */
 		 */
 		memmove(dpg, spg, PTSZ);
 		memmove(dpg, spg, PTSZ);
 		if(0){
 		if(0){
-			print("runac: upac pml4 %#p\n", m->externup->ac->pml4->pa);
-			dumpptepg(4, m->externup->ac->pml4->pa);
+			print("runac: upac pml4 %#p\n", up->ac->pml4->pa);
+			dumpptepg(4, up->ac->pml4->pa);
 		}
 		}
 	}
 	}
 	mp->icc->flushtlb = flushtlb;
 	mp->icc->flushtlb = flushtlb;
@@ -170,14 +170,14 @@ runac(Mach *mp, APfunc func, int flushtlb, void *a, int32_t n)
 
 
 	DBG("runac: exotic proc on cpu%d\n", mp->machno);
 	DBG("runac: exotic proc on cpu%d\n", mp->machno);
 	if(waserror()){
 	if(waserror()){
-		qunlock(&m->externup->debug);
+		qunlock(&up->debug);
 		nexterror();
 		nexterror();
 	}
 	}
-	qlock(&m->externup->debug);
-	m->externup->nicc++;
-	m->externup->state = Exotic;
-	m->externup->psstate = 0;
-	qunlock(&m->externup->debug);
+	qlock(&up->debug);
+	up->nicc++;
+	up->state = Exotic;
+	up->psstate = 0;
+	qunlock(&up->debug);
 	poperror();
 	poperror();
 	mfence();
 	mfence();
 	mp->icc->fn = func;
 	mp->icc->fn = func;
@@ -193,20 +193,20 @@ runac(Mach *mp, APfunc func, int flushtlb, void *a, int32_t n)
 static void
 static void
 fakeretfromsyscall(Ureg *ureg)
 fakeretfromsyscall(Ureg *ureg)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	int s;
 	int s;
 
 
 	poperror();	/* as syscall() would do if we would return */
 	poperror();	/* as syscall() would do if we would return */
-	if(m->externup->procctl == Proc_tracesyscall){	/* Would this work? */
-		m->externup->procctl = Proc_stopme;
+	if(up->procctl == Proc_tracesyscall){	/* Would this work? */
+		up->procctl = Proc_stopme;
 		s = splhi();
 		s = splhi();
-		procctl(m->externup);
+		procctl(up);
 		splx(s);
 		splx(s);
 	}
 	}
 
 
-	m->externup->insyscall = 0;
+	up->insyscall = 0;
 	/* if we delayed sched because we held a lock, sched now */
 	/* if we delayed sched because we held a lock, sched now */
-	if(m->externup->delaysched){
+	if(up->delaysched){
 		sched();
 		sched();
 		splhi();
 		splhi();
 	}
 	}
@@ -236,7 +236,7 @@ fakeretfromsyscall(Ureg *ureg)
 void
 void
 runacore(void)
 runacore(void)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	Ureg *ureg;
 	Ureg *ureg;
 	void (*fn)(void);
 	void (*fn)(void);
 	int rc, flush, s;
 	int rc, flush, s;
@@ -244,14 +244,14 @@ runacore(void)
 	uint64_t t1;
 	uint64_t t1;
 
 
 	if(waserror())
 	if(waserror())
-		panic("runacore: error: %s\n", m->externup->errstr);
-	ureg = m->externup->dbgreg;
+		panic("runacore: error: %s\n", up->errstr);
+	ureg = up->dbgreg;
 	fakeretfromsyscall(ureg);
 	fakeretfromsyscall(ureg);
 	fpusysrfork(ureg);
 	fpusysrfork(ureg);
 
 
-	procpriority(m->externup, PriKproc, 1);
-	rc = runac(m->externup->ac, actouser, 1, nil, 0);
-	procpriority(m->externup, PriNormal, 0);
+	procpriority(up, PriKproc, 1);
+	rc = runac(up->ac, actouser, 1, nil, 0);
+	procpriority(up, PriNormal, 0);
 	for(;;){
 	for(;;){
 		t1 = fastticks(nil);
 		t1 = fastticks(nil);
 		flush = 0;
 		flush = 0;
@@ -259,16 +259,16 @@ runacore(void)
 		switch(rc){
 		switch(rc){
 		case ICCTRAP:
 		case ICCTRAP:
 			s = splhi();
 			s = splhi();
-			m->cr2 = m->externup->ac->cr2;
+			m->cr2 = up->ac->cr2;
 			DBG("runacore: trap %ulld cr2 %#ullx ureg %#p\n",
 			DBG("runacore: trap %ulld cr2 %#ullx ureg %#p\n",
 				ureg->type, m->cr2, ureg);
 				ureg->type, m->cr2, ureg);
 			switch(ureg->type){
 			switch(ureg->type){
 			case IdtIPI:
 			case IdtIPI:
-				if(m->externup->procctl || m->externup->nnote)
-					notify(m->externup->dbgreg);
-				if(m->externup->ac == nil)
+				if(up->procctl || up->nnote)
+					notify(up->dbgreg);
+				if(up->ac == nil)
 					goto ToTC;
 					goto ToTC;
-				kexit(m->externup->dbgreg);
+				kexit(up->dbgreg);
 				break;
 				break;
 			case IdtNM:
 			case IdtNM:
 			case IdtMF:
 			case IdtMF:
@@ -278,19 +278,19 @@ runacore(void)
 				 * a note to be posted to the process.
 				 * a note to be posted to the process.
 				 * Post it, and make the vector a NOP.
 				 * Post it, and make the vector a NOP.
 				 */
 				 */
-				n = m->externup->ac->icc->note;
+				n = up->ac->icc->note;
 				if(n != nil)
 				if(n != nil)
-					postnote(m->externup, 1, n, NDebug);
+					postnote(up, 1, n, NDebug);
 				ureg->type = IdtIPI;		/* NOP */
 				ureg->type = IdtIPI;		/* NOP */
 				break;
 				break;
 			default:
 			default:
-				cr3put(m->pml4->pa);
+				cr3put(machp()->pml4->pa);
 				if(0 && ureg->type == IdtPF){
 				if(0 && ureg->type == IdtPF){
 					print("before PF:\n");
 					print("before PF:\n");
 					print("AC:\n");
 					print("AC:\n");
-					dumpptepg(4, m->externup->ac->pml4->pa);
+					dumpptepg(4, up->ac->pml4->pa);
 					print("\n%s:\n", rolename[NIXTC]);
 					print("\n%s:\n", rolename[NIXTC]);
-					dumpptepg(4, m->pml4->pa);
+					dumpptepg(4, machp()->pml4->pa);
 				}
 				}
 				trap(ureg);
 				trap(ureg);
 			}
 			}
@@ -301,30 +301,30 @@ runacore(void)
 		case ICCSYSCALL:
 		case ICCSYSCALL:
 			DBG("runacore: syscall ax %#ullx ureg %#p\n",
 			DBG("runacore: syscall ax %#ullx ureg %#p\n",
 				ureg->ax, ureg);
 				ureg->ax, ureg);
-			cr3put(m->pml4->pa);
+			cr3put(machp()->pml4->pa);
 			//syscall(ureg->ax, ureg);
 			//syscall(ureg->ax, ureg);
 			flush = 1;
 			flush = 1;
 			fn = acsysret;
 			fn = acsysret;
 			if(0)
 			if(0)
-			if(m->externup->nqtrap > 2 || m->externup->nsyscall > 1)
+			if(up->nqtrap > 2 || up->nsyscall > 1)
 				goto ToTC;
 				goto ToTC;
-			if(m->externup->ac == nil)
+			if(up->ac == nil)
 				goto ToTC;
 				goto ToTC;
 			break;
 			break;
 		default:
 		default:
 			panic("runacore: unexpected rc = %d", rc);
 			panic("runacore: unexpected rc = %d", rc);
 		}
 		}
-		m->externup->tctime += fastticks2us(fastticks(nil) - t1);
-		procpriority(m->externup, PriExtra, 1);
-		rc = runac(m->externup->ac, fn, flush, nil, 0);
-		procpriority(m->externup, PriNormal, 0);
+		up->tctime += fastticks2us(fastticks(nil) - t1);
+		procpriority(up, PriExtra, 1);
+		rc = runac(up->ac, fn, flush, nil, 0);
+		procpriority(up, PriNormal, 0);
 	}
 	}
 ToTC:
 ToTC:
 	/*
 	/*
-	 *  to procctl, then syscall,  to 
+	 *  to procctl, then syscall,  to
 	 *  be back in the TC
 	 *  be back in the TC
 	 */
 	 */
-	DBG("runacore: up %#p: return\n", m->externup);
+	DBG("runacore: up %#p: return\n", up);
 }
 }
 
 
 extern ACVctl *acvctl[];
 extern ACVctl *acvctl[];

+ 54 - 54
sys/src/9/amd64pv/trap.c

@@ -266,7 +266,7 @@ static char* excname[32] = {
 void
 void
 intrtime(int vno)
 intrtime(int vno)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	uint32_t diff, x;		/* should be uint64_t */
 	uint32_t diff, x;		/* should be uint64_t */
 
 
 	x = perfticks();
 	x = perfticks();
@@ -274,7 +274,7 @@ intrtime(int vno)
 	m->perf.intrts = x;
 	m->perf.intrts = x;
 
 
 	m->perf.inintr += diff;
 	m->perf.inintr += diff;
-	if(m->externup == nil && m->perf.inidle > diff)
+	if(up == nil && m->perf.inidle > diff)
 		m->perf.inidle -= diff;
 		m->perf.inidle -= diff;
 
 
 	intrtimes[vno].cycles += diff;
 	intrtimes[vno].cycles += diff;
@@ -292,7 +292,7 @@ void (*_pmcupdate)(Mach *m) = pmcnop;
 void
 void
 kexit(Ureg* u)
 kexit(Ureg* u)
 {
 {
- 	Mach *m = machp();
+ 	Proc *up = machp()->externup;
  	uint64_t t;
  	uint64_t t;
 	Tos *tos;
 	Tos *tos;
 	Mach *mp;
 	Mach *mp;
@@ -303,16 +303,16 @@ kexit(Ureg* u)
 	 */
 	 */
 	tos = (Tos*)(USTKTOP-sizeof(Tos));
 	tos = (Tos*)(USTKTOP-sizeof(Tos));
 	cycles(&t);
 	cycles(&t);
-	tos->kcycles += t - m->externup->kentry;
-	tos->pcycles = m->externup->pcycles;
-	tos->pid = m->externup->pid;
-	if (m->externup->ac != nil)
-		mp = m->externup->ac;
+	tos->kcycles += t - up->kentry;
+	tos->pcycles = up->pcycles;
+	tos->pid = up->pid;
+	if (up->ac != nil)
+		mp = up->ac;
 	else
 	else
 		mp = m;
 		mp = m;
-	tos->core = mp->machno;	
+	tos->core = mp->machno;
 	tos->nixtype = mp->nixtype;
 	tos->nixtype = mp->nixtype;
-	//_pmcupdate(m);	
+	//_pmcupdate(m);
 	/*
 	/*
 	 * The process may change its core.
 	 * The process may change its core.
 	 * Be sure it has the right cyclefreq.
 	 * Be sure it has the right cyclefreq.
@@ -323,7 +323,7 @@ kexit(Ureg* u)
 void
 void
 _trap(Ureg *ureg)
 _trap(Ureg *ureg)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	/*
 	/*
 	 * If it's a real trap in this core, then we want to
 	 * If it's a real trap in this core, then we want to
 	 * use the hardware cr2 register.
 	 * use the hardware cr2 register.
@@ -357,7 +357,7 @@ trap(Ureg* ureg)
 	if (vno == 8) {
 	if (vno == 8) {
 		iprint("Lstar is %p\n", (void *)rdmsr(Lstar));
 		iprint("Lstar is %p\n", (void *)rdmsr(Lstar));
 		iprint("GSbase is %p\n", (void *)gsbase);
 		iprint("GSbase is %p\n", (void *)gsbase);
-		iprint("ire %d irx %d sce %d scx %d lastvno %d\n", 
+		iprint("ire %d irx %d sce %d scx %d lastvno %d\n",
 			ire, irx, sce, scx, lastvno);
 			ire, irx, sce, scx, lastvno);
 		iprint("irxe %d \n",
 		iprint("irxe %d \n",
 			irxe);
 			irxe);
@@ -366,11 +366,11 @@ trap(Ureg* ureg)
 	lastvno = vno;
 	lastvno = vno;
 	if (gsbase < 1ULL<<63)
 	if (gsbase < 1ULL<<63)
 		die("bogus gsbase");
 		die("bogus gsbase");
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	char buf[ERRMAX];
 	char buf[ERRMAX];
 	Vctl *ctl, *v;
 	Vctl *ctl, *v;
 
 
-	if (0 && m && m->externup && m->externup->pid == 6) {
+	if (0 && m && up && up->pid == 6) {
 		//iprint("type %x\n", ureg->type);
 		//iprint("type %x\n", ureg->type);
 		if (ureg->type != 0x49)
 		if (ureg->type != 0x49)
 			die("6\n");
 			die("6\n");
@@ -378,8 +378,8 @@ trap(Ureg* ureg)
 	m->perf.intrts = perfticks();
 	m->perf.intrts = perfticks();
 	user = userureg(ureg);
 	user = userureg(ureg);
 	if(user && (m->nixtype == NIXTC)){
 	if(user && (m->nixtype == NIXTC)){
-		m->externup->dbgreg = ureg;
-		cycles(&m->externup->kentry);
+		up->dbgreg = ureg;
+		cycles(&up->kentry);
 	}
 	}
 
 
 	clockintr = 0;
 	clockintr = 0;
@@ -392,8 +392,8 @@ trap(Ureg* ureg)
 			if(vno >= VectorPIC && vno != VectorSYSCALL)
 			if(vno >= VectorPIC && vno != VectorSYSCALL)
 				m->lastintr = ctl->irq;
 				m->lastintr = ctl->irq;
 		}else
 		}else
-			if(m->externup)
-				m->externup->nqtrap++;
+			if(up)
+				up->nqtrap++;
 
 
 		if(ctl->isr)
 		if(ctl->isr)
 			ctl->isr(vno);
 			ctl->isr(vno);
@@ -408,14 +408,14 @@ trap(Ureg* ureg)
 			if(ctl->irq == IrqCLOCK || ctl->irq == IrqTIMER)
 			if(ctl->irq == IrqCLOCK || ctl->irq == IrqTIMER)
 				clockintr = 1;
 				clockintr = 1;
 
 
-			if(m->externup && !clockintr)
+			if(up && !clockintr)
 				preempted();
 				preempted();
 		}
 		}
 	}
 	}
 	else if(vno < nelem(excname) && user){
 	else if(vno < nelem(excname) && user){
 		spllo();
 		spllo();
 		snprint(buf, sizeof buf, "sys: trap: %s", excname[vno]);
 		snprint(buf, sizeof buf, "sys: trap: %s", excname[vno]);
-		postnote(m->externup, 1, buf, NDebug);
+		postnote(up, 1, buf, NDebug);
 	}
 	}
 	else if(vno >= VectorPIC && vno != VectorSYSCALL){
 	else if(vno >= VectorPIC && vno != VectorSYSCALL){
 		/*
 		/*
@@ -431,7 +431,7 @@ trap(Ureg* ureg)
 		i8259isr(vno);
 		i8259isr(vno);
 
 
 		iprint("cpu%d: spurious interrupt %d, last %d\n",
 		iprint("cpu%d: spurious interrupt %d, last %d\n",
-			m->machno, vno, m->lastintr);
+			machp()->machno, vno, m->lastintr);
 		intrtime(vno);
 		intrtime(vno);
 		if(user)
 		if(user)
 			kexit(ureg);
 			kexit(ureg);
@@ -440,9 +440,9 @@ trap(Ureg* ureg)
 	else{
 	else{
 		if(vno == VectorNMI){
 		if(vno == VectorNMI){
 			nmienable();
 			nmienable();
-			if(m->machno != 0){
+			if(machp()->machno != 0){
 				iprint("cpu%d: PC %#llux\n",
 				iprint("cpu%d: PC %#llux\n",
-					m->machno, ureg->ip);
+					machp()->machno, ureg->ip);
 				for(;;);
 				for(;;);
 			}
 			}
 		}
 		}
@@ -458,11 +458,11 @@ trap(Ureg* ureg)
 	splhi();
 	splhi();
 
 
 	/* delaysched set because we held a lock or because our quantum ended */
 	/* delaysched set because we held a lock or because our quantum ended */
-	if(m->externup && m->externup->delaysched && clockintr){
+	if(up && up->delaysched && clockintr){
 		if(0)
 		if(0)
-		if(user && m->externup->ac == nil && m->externup->nqtrap == 0 && m->externup->nqsyscall == 0){
+		if(user && up->ac == nil && up->nqtrap == 0 && up->nqsyscall == 0){
 			if(!waserror()){
 			if(!waserror()){
-				m->externup->ac = getac(m->externup, -1);
+				up->ac = getac(up, -1);
 				poperror();
 				poperror();
 				runacore();
 				runacore();
 				return;
 				return;
@@ -474,7 +474,7 @@ trap(Ureg* ureg)
 
 
 
 
 	if(user){
 	if(user){
-		if(m->externup && m->externup->procctl || m->externup->nnote)
+		if(up && up->procctl || up->nnote)
 			notify(ureg);
 			notify(ureg);
 		kexit(ureg);
 		kexit(ureg);
 	}
 	}
@@ -486,12 +486,12 @@ trap(Ureg* ureg)
 void
 void
 dumpgpr(Ureg* ureg)
 dumpgpr(Ureg* ureg)
 {
 {
-	Mach *m = machp();
-	if(m->externup != nil)
+	Proc *up = machp()->externup;
+	if(up != nil)
 		iprint("cpu%d: registers for %s %d\n",
 		iprint("cpu%d: registers for %s %d\n",
-			m->machno, m->externup->text, m->externup->pid);
+			machp()->machno, up->text, up->pid);
 	else
 	else
-		iprint("cpu%d: registers for kernel\n", m->machno);
+		iprint("cpu%d: registers for kernel\n", machp()->machno);
 
 
 	iprint("ax\t%#16.16llux\n", ureg->ax);
 	iprint("ax\t%#16.16llux\n", ureg->ax);
 	iprint("bx\t%#16.16llux\n", ureg->bx);
 	iprint("bx\t%#16.16llux\n", ureg->bx);
@@ -519,13 +519,13 @@ dumpgpr(Ureg* ureg)
 	iprint("FS\t%#llux\n", rdmsr(FSbase));
 	iprint("FS\t%#llux\n", rdmsr(FSbase));
 	iprint("GS\t%#llux\n", rdmsr(GSbase));
 	iprint("GS\t%#llux\n", rdmsr(GSbase));
 
 
-	iprint("m\t%#16.16p\nup\t%#16.16p\n", m, m->externup);
+	iprint("m\t%#16.16p\nup\t%#16.16p\n", m, up);
 }
 }
 
 
 void
 void
 dumpregs(Ureg* ureg)
 dumpregs(Ureg* ureg)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 
 
 	dumpgpr(ureg);
 	dumpgpr(ureg);
 
 
@@ -559,7 +559,7 @@ callwithureg(void (*fn)(Ureg*))
 static void
 static void
 dumpstackwithureg(Ureg* ureg)
 dumpstackwithureg(Ureg* ureg)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	uintptr_t l, v, i, estack;
 	uintptr_t l, v, i, estack;
 //	extern char etext;
 //	extern char etext;
 	int x;
 	int x;
@@ -573,15 +573,15 @@ dumpstackwithureg(Ureg* ureg)
 	x = 0;
 	x = 0;
 	x += iprint("ktrace 9%s %#p %#p\n", strrchr(conffile, '/')+1, ureg->ip, ureg->sp);
 	x += iprint("ktrace 9%s %#p %#p\n", strrchr(conffile, '/')+1, ureg->ip, ureg->sp);
 	i = 0;
 	i = 0;
-	if(m->externup != nil
-//	&& (uintptr)&l >= (uintptr)m->externup->kstack
-	&& (uintptr_t)&l <= (uintptr_t)m->externup->kstack+KSTACK)
-		estack = (uintptr_t)m->externup->kstack+KSTACK;
+	if(up != nil
+//	&& (uintptr)&l >= (uintptr)up->kstack
+	&& (uintptr_t)&l <= (uintptr_t)up->kstack+KSTACK)
+		estack = (uintptr_t)up->kstack+KSTACK;
 	else if((uintptr_t)&l >= m->stack && (uintptr_t)&l <= m->stack+MACHSTKSZ)
 	else if((uintptr_t)&l >= m->stack && (uintptr_t)&l <= m->stack+MACHSTKSZ)
 		estack = m->stack+MACHSTKSZ;
 		estack = m->stack+MACHSTKSZ;
 	else{
 	else{
-		if(m->externup != nil)
-			iprint("&m->externup->kstack %#p &l %#p\n", m->externup->kstack, &l);
+		if(up != nil)
+			iprint("&up->kstack %#p &l %#p\n", up->kstack, &l);
 		else
 		else
 			iprint("&m %#p &l %#p\n", m, &l);
 			iprint("&m %#p &l %#p\n", m, &l);
 		return;
 		return;
@@ -613,15 +613,15 @@ dumpstack(void)
 static void
 static void
 debugbpt(Ureg* ureg, void* v)
 debugbpt(Ureg* ureg, void* v)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	char buf[ERRMAX];
 	char buf[ERRMAX];
 
 
-	if(m->externup == 0)
+	if(up == 0)
 		panic("kernel bpt");
 		panic("kernel bpt");
 	/* restore pc to instruction that caused the trap */
 	/* restore pc to instruction that caused the trap */
 	ureg->ip--;
 	ureg->ip--;
 	sprint(buf, "sys: breakpoint");
 	sprint(buf, "sys: breakpoint");
-	postnote(m->externup, 1, buf, NDebug);
+	postnote(up, 1, buf, NDebug);
 }
 }
 
 
 static void
 static void
@@ -645,7 +645,7 @@ expected(Ureg* ureg, void* v)
 static void
 static void
 faultamd64(Ureg* ureg, void* v)
 faultamd64(Ureg* ureg, void* v)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	uint64_t addr;
 	uint64_t addr;
 	int read, user, insyscall;
 	int read, user, insyscall;
 	char buf[ERRMAX];
 	char buf[ERRMAX];
@@ -660,7 +660,7 @@ faultamd64(Ureg* ureg, void* v)
 	 * If not, the usual problem is causing a fault during
 	 * If not, the usual problem is causing a fault during
 	 * initialisation before the system is fully up.
 	 * initialisation before the system is fully up.
 	 */
 	 */
-	if(m->externup == nil){
+	if(up == nil){
 		panic("fault with up == nil; pc %#llux addr %#llux\n",
 		panic("fault with up == nil; pc %#llux addr %#llux\n",
 			ureg->ip, addr);
 			ureg->ip, addr);
 	}
 	}
@@ -670,8 +670,8 @@ if (read) hi("read fault\n"); else hi("write fault\n");
 hi("addr "); put64(addr); hi("\n");
 hi("addr "); put64(addr); hi("\n");
  */
  */
 
 
-	insyscall = m->externup->insyscall;
-	m->externup->insyscall = 1;
+	insyscall = up->insyscall;
+	up->insyscall = 1;
 	if (0)hi("call fault\n");
 	if (0)hi("call fault\n");
 
 
 	if(fault(addr, read) < 0){
 	if(fault(addr, read) < 0){
@@ -688,18 +688,18 @@ iprint("could not fault %p\n", addr);
 		 * process resumes it may fault while in kernel mode.
 		 * process resumes it may fault while in kernel mode.
 		 * No need to panic this case, post a note to the process
 		 * No need to panic this case, post a note to the process
 		 * and unwind the error stack. There must be an error stack
 		 * and unwind the error stack. There must be an error stack
-		 * (m->externup->nerrlab != 0) if this is a system call, if not then
+		 * (up->nerrlab != 0) if this is a system call, if not then
 		 * the game's a bogey.
 		 * the game's a bogey.
 		 */
 		 */
-		if(!user && (!insyscall || m->externup->nerrlab == 0))
+		if(!user && (!insyscall || up->nerrlab == 0))
 			panic("fault: %#llux\n", addr);
 			panic("fault: %#llux\n", addr);
 		sprint(buf, "sys: trap: fault %s addr=%#llux",
 		sprint(buf, "sys: trap: fault %s addr=%#llux",
 			read? "read": "write", addr);
 			read? "read": "write", addr);
-		postnote(m->externup, 1, buf, NDebug);
+		postnote(up, 1, buf, NDebug);
 		if(insyscall)
 		if(insyscall)
 			error(buf);
 			error(buf);
 	}
 	}
-	m->externup->insyscall = insyscall;
+	up->insyscall = insyscall;
 }
 }
 
 
 /*
 /*
@@ -708,15 +708,15 @@ iprint("could not fault %p\n", addr);
 uintptr_t
 uintptr_t
 userpc(Ureg* ureg)
 userpc(Ureg* ureg)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	if(ureg == nil)
 	if(ureg == nil)
-		ureg = m->externup->dbgreg;
+		ureg = up->dbgreg;
 	return ureg->ip;
 	return ureg->ip;
 }
 }
 
 
 /* This routine must save the values of registers the user is not permitted
 /* This routine must save the values of registers the user is not permitted
  * to write from devproc and then restore the saved values before returning.
  * to write from devproc and then restore the saved values before returning.
- * TODO: fix this because the segment registers are wrong for 64-bit mode. 
+ * TODO: fix this because the segment registers are wrong for 64-bit mode.
  */
  */
 void
 void
 setregisters(Ureg* ureg, char* pureg, char* uva, int n)
 setregisters(Ureg* ureg, char* pureg, char* uva, int n)

+ 19 - 19
sys/src/9/amd64pv/usbohci.c

@@ -1410,7 +1410,7 @@ epiodone(void *a)
 static void
 static void
 epiowait(Ctlr *ctlr, Qio *io, int tmout, uint32_t n)
 epiowait(Ctlr *ctlr, Qio *io, int tmout, uint32_t n)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	Ed *ed;
 	Ed *ed;
 	int timedout;
 	int timedout;
 
 
@@ -1438,7 +1438,7 @@ epiowait(Ctlr *ctlr, Qio *io, int tmout, uint32_t n)
 		io->err = "request timed out";
 		io->err = "request timed out";
 		iunlock(ctlr);
 		iunlock(ctlr);
 		if(!waserror()){
 		if(!waserror()){
-			tsleep(&m->externup->sleep, return0, 0, Abortdelay);
+			tsleep(&up->sleep, return0, 0, Abortdelay);
 			poperror();
 			poperror();
 		}
 		}
 		ilock(ctlr);
 		ilock(ctlr);
@@ -1456,7 +1456,7 @@ epiowait(Ctlr *ctlr, Qio *io, int tmout, uint32_t n)
 static int32_t
 static int32_t
 epio(Ep *ep, Qio *io, void *a, int32_t count, int mustlock)
 epio(Ep *ep, Qio *io, void *a, int32_t count, int mustlock)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	Ed *ed;
 	Ed *ed;
 	Ctlr *ctlr;
 	Ctlr *ctlr;
 	char buf[80];
 	char buf[80];
@@ -1518,7 +1518,7 @@ epio(Ep *ep, Qio *io, void *a, int32_t count, int mustlock)
 
 
 	ilock(ctlr);
 	ilock(ctlr);
 	if(io->state != Qclose){
 	if(io->state != Qclose){
-		io->iotime = TK2MS(m->ticks);
+		io->iotime = TK2MS(machp()->ticks);
 		io->state = Qrun;
 		io->state = Qrun;
 		ed->tail = ptr2pa(ltd);
 		ed->tail = ptr2pa(ltd);
 		if(ep->ttype == Tctl)
 		if(ep->ttype == Tctl)
@@ -1608,7 +1608,7 @@ clrhalt(Ep *ep)
 static int32_t
 static int32_t
 epread(Ep *ep, void *a, int32_t count)
 epread(Ep *ep, void *a, int32_t count)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	Ctlio *cio;
 	Ctlio *cio;
 	Qio *io;
 	Qio *io;
 	char buf[80];
 	char buf[80];
@@ -1655,9 +1655,9 @@ epread(Ep *ep, void *a, int32_t count)
 		return epio(ep, &io[OREAD], a, count, 1);
 		return epio(ep, &io[OREAD], a, count, 1);
 	case Tintr:
 	case Tintr:
 		io = ep->aux;
 		io = ep->aux;
-		delta = TK2MS(m->ticks) - io[OREAD].iotime + 1;
+		delta = TK2MS(machp()->ticks) - io[OREAD].iotime + 1;
 		if(delta < ep->pollival / 2)
 		if(delta < ep->pollival / 2)
-			tsleep(&m->externup->sleep, return0, 0, ep->pollival/2 - delta);
+			tsleep(&up->sleep, return0, 0, ep->pollival/2 - delta);
 		if(ep->clrhalt)
 		if(ep->clrhalt)
 			clrhalt(ep);
 			clrhalt(ep);
 		return epio(ep, &io[OREAD], a, count, 1);
 		return epio(ep, &io[OREAD], a, count, 1);
@@ -1686,7 +1686,7 @@ epread(Ep *ep, void *a, int32_t count)
 static int32_t
 static int32_t
 epctlio(Ep *ep, Ctlio *cio, void *a, int32_t count)
 epctlio(Ep *ep, Ctlio *cio, void *a, int32_t count)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	unsigned char *c;
 	unsigned char *c;
 	int32_t len;
 	int32_t len;
 
 
@@ -1791,7 +1791,7 @@ putsamples(Ctlr *ctlr, Ep *ep, Isoio *iso, unsigned char *b, int32_t count)
 static int32_t
 static int32_t
 episowrite(Ep *ep, void *a, int32_t count)
 episowrite(Ep *ep, void *a, int32_t count)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	int32_t tot, nw;
 	int32_t tot, nw;
 	char *err;
 	char *err;
 	unsigned char *b;
 	unsigned char *b;
@@ -1857,7 +1857,7 @@ episowrite(Ep *ep, void *a, int32_t count)
 static int32_t
 static int32_t
 epwrite(Ep *ep, void *a, int32_t count)
 epwrite(Ep *ep, void *a, int32_t count)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	Qio *io;
 	Qio *io;
 	Ctlio *cio;
 	Ctlio *cio;
 	uint32_t delta;
 	uint32_t delta;
@@ -1889,9 +1889,9 @@ epwrite(Ep *ep, void *a, int32_t count)
 		return tot;
 		return tot;
 	case Tintr:
 	case Tintr:
 		io = ep->aux;
 		io = ep->aux;
-		delta = TK2MS(m->ticks) - io[OWRITE].iotime + 1;
+		delta = TK2MS(machp()->ticks) - io[OWRITE].iotime + 1;
 		if(delta < ep->pollival)
 		if(delta < ep->pollival)
-			tsleep(&m->externup->sleep, return0, 0, ep->pollival - delta);
+			tsleep(&up->sleep, return0, 0, ep->pollival - delta);
 		if(ep->clrhalt)
 		if(ep->clrhalt)
 			clrhalt(ep);
 			clrhalt(ep);
 		return epio(ep, &io[OWRITE], a, count, 1);
 		return epio(ep, &io[OWRITE], a, count, 1);
@@ -1906,7 +1906,7 @@ epwrite(Ep *ep, void *a, int32_t count)
 static Ed*
 static Ed*
 newed(Ctlr *ctlr, Ep *ep, Qio *io, char *c)
 newed(Ctlr *ctlr, Ep *ep, Qio *io, char *c)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	Ed *ed;
 	Ed *ed;
 	Td *td;
 	Td *td;
 
 
@@ -2021,7 +2021,7 @@ isoopen(Ctlr *ctlr, Ep *ep)
 static void
 static void
 epopen(Ep *ep)
 epopen(Ep *ep)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	Ctlr *ctlr;
 	Ctlr *ctlr;
 	Qio *io;
 	Qio *io;
 	Ctlio *cio;
 	Ctlio *cio;
@@ -2091,7 +2091,7 @@ epopen(Ep *ep)
 static void
 static void
 cancelio(Ep *ep, Qio *io)
 cancelio(Ep *ep, Qio *io)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	Ed *ed;
 	Ed *ed;
 	Ctlr *ctlr;
 	Ctlr *ctlr;
 
 
@@ -2109,7 +2109,7 @@ cancelio(Ep *ep, Qio *io)
 	aborttds(io);
 	aborttds(io);
 	iunlock(ctlr);
 	iunlock(ctlr);
 	if(!waserror()){
 	if(!waserror()){
-		tsleep(&m->externup->sleep, return0, 0, Abortdelay);
+		tsleep(&up->sleep, return0, 0, Abortdelay);
 		poperror();
 		poperror();
 	}
 	}
 
 
@@ -2185,7 +2185,7 @@ epclose(Ep *ep)
 static int
 static int
 portreset(Hci *hp, int port, int on)
 portreset(Hci *hp, int port, int on)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	Ctlr *ctlr;
 	Ctlr *ctlr;
 	Ohci *ohci;
 	Ohci *ohci;
 
 
@@ -2221,7 +2221,7 @@ portreset(Hci *hp, int port, int on)
 static int
 static int
 portenable(Hci *hp, int port, int on)
 portenable(Hci *hp, int port, int on)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	Ctlr *ctlr;
 	Ctlr *ctlr;
 
 
 	ctlr = hp->aux;
 	ctlr = hp->aux;
@@ -2237,7 +2237,7 @@ portenable(Hci *hp, int port, int on)
 	else
 	else
 		ctlr->ohci->rhportsts[port - 1] = Cpe;
 		ctlr->ohci->rhportsts[port - 1] = Cpe;
 	iunlock(ctlr);
 	iunlock(ctlr);
-	tsleep(&m->externup->sleep, return0, 0, Enabledelay);
+	tsleep(&up->sleep, return0, 0, Enabledelay);
 	poperror();
 	poperror();
 	qunlock(&ctlr->resetl);
 	qunlock(&ctlr->resetl);
 	return 0;
 	return 0;

+ 22 - 22
sys/src/9/amd64pv/usbuhci.c

@@ -1007,7 +1007,7 @@ putsamples(Isoio *iso, unsigned char *b, int32_t count)
 static int32_t
 static int32_t
 episowrite(Ep *ep, Isoio *iso, void *a, int32_t count)
 episowrite(Ep *ep, Isoio *iso, void *a, int32_t count)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	Ctlr *ctlr;
 	Ctlr *ctlr;
 	unsigned char *b;
 	unsigned char *b;
 	int tot;
 	int tot;
@@ -1075,7 +1075,7 @@ episowrite(Ep *ep, Isoio *iso, void *a, int32_t count)
 static int32_t
 static int32_t
 episoread(Ep *ep, Isoio *iso, void *a, int count)
 episoread(Ep *ep, Isoio *iso, void *a, int count)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	Ctlr *ctlr;
 	Ctlr *ctlr;
 	unsigned char *b;
 	unsigned char *b;
 	int nr;
 	int nr;
@@ -1219,7 +1219,7 @@ epiodone(void *a)
 static void
 static void
 epiowait(Ctlr *ctlr, Qio *io, int tmout, uint32_t load)
 epiowait(Ctlr *ctlr, Qio *io, int tmout, uint32_t load)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	Qh *qh;
 	Qh *qh;
 	int timedout;
 	int timedout;
 
 
@@ -1246,7 +1246,7 @@ epiowait(Ctlr *ctlr, Qio *io, int tmout, uint32_t load)
 		io->err = "request timed out";
 		io->err = "request timed out";
 		iunlock(ctlr);
 		iunlock(ctlr);
 		if(!waserror()){
 		if(!waserror()){
-			tsleep(&m->externup->sleep, return0, 0, Abortdelay);
+			tsleep(&up->sleep, return0, 0, Abortdelay);
 			poperror();
 			poperror();
 		}
 		}
 		ilock(ctlr);
 		ilock(ctlr);
@@ -1266,7 +1266,7 @@ epiowait(Ctlr *ctlr, Qio *io, int tmout, uint32_t load)
 static int32_t
 static int32_t
 epio(Ep *ep, Qio *io, void *a, int32_t count, int mustlock)
 epio(Ep *ep, Qio *io, void *a, int32_t count, int mustlock)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	Td *td, *ltd, *td0, *ntd;
 	Td *td, *ltd, *td0, *ntd;
 	Ctlr *ctlr;
 	Ctlr *ctlr;
 	Qh* qh;
 	Qh* qh;
@@ -1332,7 +1332,7 @@ epio(Ep *ep, Qio *io, void *a, int32_t count, int mustlock)
 	ddeprint("uhci: load %uld ctlr load %uld\n", load, ctlr->load);
 	ddeprint("uhci: load %uld ctlr load %uld\n", load, ctlr->load);
 	ilock(ctlr);
 	ilock(ctlr);
 	if(qh->state != Qclose){
 	if(qh->state != Qclose){
-		io->iotime = TK2MS(m->ticks);
+		io->iotime = TK2MS(machp()->ticks);
 		qh->state = Qrun;
 		qh->state = Qrun;
 		coherence();
 		coherence();
 		qhlinktd(qh, td0);
 		qhlinktd(qh, td0);
@@ -1415,7 +1415,7 @@ clrhalt(Ep *ep)
 static int32_t
 static int32_t
 epread(Ep *ep, void *a, int32_t count)
 epread(Ep *ep, void *a, int32_t count)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	Ctlio *cio;
 	Ctlio *cio;
 	Qio *io;
 	Qio *io;
 	Isoio *iso;
 	Isoio *iso;
@@ -1464,9 +1464,9 @@ epread(Ep *ep, void *a, int32_t count)
 		return epio(ep, &io[OREAD], a, count, 1);
 		return epio(ep, &io[OREAD], a, count, 1);
 	case Tintr:
 	case Tintr:
 		io = ep->aux;
 		io = ep->aux;
-		delta = TK2MS(m->ticks) - io[OREAD].iotime + 1;
+		delta = TK2MS(machp()->ticks) - io[OREAD].iotime + 1;
 		if(delta < ep->pollival / 2)
 		if(delta < ep->pollival / 2)
-			tsleep(&m->externup->sleep, return0, 0, ep->pollival/2 - delta);
+			tsleep(&up->sleep, return0, 0, ep->pollival/2 - delta);
 		if(ep->clrhalt)
 		if(ep->clrhalt)
 			clrhalt(ep);
 			clrhalt(ep);
 		return epio(ep, &io[OREAD], a, count, 1);
 		return epio(ep, &io[OREAD], a, count, 1);
@@ -1495,7 +1495,7 @@ epread(Ep *ep, void *a, int32_t count)
 static int32_t
 static int32_t
 epctlio(Ep *ep, Ctlio *cio, void *a, int32_t count)
 epctlio(Ep *ep, Ctlio *cio, void *a, int32_t count)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	unsigned char *c;
 	unsigned char *c;
 	int32_t len;
 	int32_t len;
 
 
@@ -1569,7 +1569,7 @@ epctlio(Ep *ep, Ctlio *cio, void *a, int32_t count)
 static int32_t
 static int32_t
 epwrite(Ep *ep, void *a, int32_t count)
 epwrite(Ep *ep, void *a, int32_t count)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	Ctlio *cio;
 	Ctlio *cio;
 	Isoio *iso;
 	Isoio *iso;
 	Qio *io;
 	Qio *io;
@@ -1603,9 +1603,9 @@ epwrite(Ep *ep, void *a, int32_t count)
 		return tot;
 		return tot;
 	case Tintr:
 	case Tintr:
 		io = ep->aux;
 		io = ep->aux;
-		delta = TK2MS(m->ticks) - io[OWRITE].iotime + 1;
+		delta = TK2MS(machp()->ticks) - io[OWRITE].iotime + 1;
 		if(delta < ep->pollival)
 		if(delta < ep->pollival)
-			tsleep(&m->externup->sleep, return0, 0, ep->pollival - delta);
+			tsleep(&up->sleep, return0, 0, ep->pollival - delta);
 		if(ep->clrhalt)
 		if(ep->clrhalt)
 			clrhalt(ep);
 			clrhalt(ep);
 		return epio(ep, &io[OWRITE], a, count, 1);
 		return epio(ep, &io[OWRITE], a, count, 1);
@@ -1726,7 +1726,7 @@ isoopen(Ep *ep)
 static void
 static void
 epopen(Ep *ep)
 epopen(Ep *ep)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	Ctlr *ctlr;
 	Ctlr *ctlr;
 	Qh *cqh;
 	Qh *cqh;
 	Qio *io;
 	Qio *io;
@@ -1797,7 +1797,7 @@ epopen(Ep *ep)
 static void
 static void
 cancelio(Ctlr *ctlr, Qio *io)
 cancelio(Ctlr *ctlr, Qio *io)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	Qh *qh;
 	Qh *qh;
 
 
 	ilock(ctlr);
 	ilock(ctlr);
@@ -1812,7 +1812,7 @@ cancelio(Ctlr *ctlr, Qio *io)
 	qh->state = Qclose;
 	qh->state = Qclose;
 	iunlock(ctlr);
 	iunlock(ctlr);
 	if(!waserror()){
 	if(!waserror()){
-		tsleep(&m->externup->sleep, return0, 0, Abortdelay);
+		tsleep(&up->sleep, return0, 0, Abortdelay);
 		poperror();
 		poperror();
 	}
 	}
 
 
@@ -1828,7 +1828,7 @@ cancelio(Ctlr *ctlr, Qio *io)
 static void
 static void
 cancelisoio(Ctlr *ctlr, Isoio *iso, int pollival, uint32_t load)
 cancelisoio(Ctlr *ctlr, Isoio *iso, int pollival, uint32_t load)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	Isoio **il;
 	Isoio **il;
 	uint32_t *lp;
 	uint32_t *lp;
 	int i;
 	int i;
@@ -1875,7 +1875,7 @@ cancelisoio(Ctlr *ctlr, Isoio *iso, int pollival, uint32_t load)
 	 */
 	 */
 	wakeup(iso);
 	wakeup(iso);
 	diprint("cancelisoio iso %#p waiting for I/O to cease\n", iso);
 	diprint("cancelisoio iso %#p waiting for I/O to cease\n", iso);
-	tsleep(&m->externup->sleep, return0, 0, 5);
+	tsleep(&up->sleep, return0, 0, 5);
 	qlock(iso);
 	qlock(iso);
 	qunlock(iso);
 	qunlock(iso);
 	diprint("cancelisoio iso %#p releasing iso\n", iso);
 	diprint("cancelisoio iso %#p releasing iso\n", iso);
@@ -1986,7 +1986,7 @@ seprintep(char *s, char *e, Ep *ep)
 static int
 static int
 portenable(Hci *hp, int port, int on)
 portenable(Hci *hp, int port, int on)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	int s;
 	int s;
 	int ioport;
 	int ioport;
 	Ctlr *ctlr;
 	Ctlr *ctlr;
@@ -2007,7 +2007,7 @@ portenable(Hci *hp, int port, int on)
 		OUTS(ioport, s & ~PSenable);
 		OUTS(ioport, s & ~PSenable);
 	microdelay(64);
 	microdelay(64);
 	iunlock(ctlr);
 	iunlock(ctlr);
-	tsleep(&m->externup->sleep, return0, 0, Enabledelay);
+	tsleep(&up->sleep, return0, 0, Enabledelay);
 	dprint("uhci %#ux port %d enable=%d: sts %#x\n",
 	dprint("uhci %#ux port %d enable=%d: sts %#x\n",
 		ctlr->port, port, on, INS(ioport));
 		ctlr->port, port, on, INS(ioport));
 	qunlock(&ctlr->portlck);
 	qunlock(&ctlr->portlck);
@@ -2044,7 +2044,7 @@ portreset(Hci *hp, int port, int on)
 static int
 static int
 portstatus(Hci *hp, int port)
 portstatus(Hci *hp, int port)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	int s;
 	int s;
 	int r;
 	int r;
 	int ioport;
 	int ioport;
@@ -2282,7 +2282,7 @@ reset(Hci *hp)
 	if(getconf("*nousbuhci"))
 	if(getconf("*nousbuhci"))
 		return -1;
 		return -1;
 	*/
 	*/
-	
+
 	ilock(&resetlck);
 	ilock(&resetlck);
 	scanpci();
 	scanpci();
 
 

+ 2 - 2
sys/src/9/amd64pv/vsvm.c

@@ -164,7 +164,7 @@ vsvminit(int size, int nixtype, Mach *m)
 {
 {
 	Sd *sd;
 	Sd *sd;
 	uint64_t r;
 	uint64_t r;
-	if(m->machno == 0){
+	if(machp()->machno == 0){
 		idtinit(idt64, PTR2UINT(idthandlers));
 		idtinit(idt64, PTR2UINT(idthandlers));
 		idtinit(acidt64, PTR2UINT(acidthandlers));
 		idtinit(acidt64, PTR2UINT(acidthandlers));
 	}
 	}
@@ -190,7 +190,7 @@ vsvminit(int size, int nixtype, Mach *m)
 	asm volatile("ltr %w0"::"q" (SSEL(SiTSS, SsTIGDT|SsRPL0)));
 	asm volatile("ltr %w0"::"q" (SSEL(SiTSS, SsTIGDT|SsRPL0)));
 
 
 	wrmsr(FSbase, 0ull);
 	wrmsr(FSbase, 0ull);
-	wrmsr(GSbase, PTR2UINT(&sys->machptr[m->machno]));
+	wrmsr(GSbase, PTR2UINT(&sys->machptr[machp()->machno]));
 	wrmsr(KernelGSbase, 0ull);
 	wrmsr(KernelGSbase, 0ull);
 
 
 	r = rdmsr(Efer);
 	r = rdmsr(Efer);

+ 1 - 1
sys/src/9/boot/boot.c

@@ -129,7 +129,7 @@ print("\n");
 	rp = getenv("rootspec");
 	rp = getenv("rootspec");
 	if(rp == nil)
 	if(rp == nil)
 		rp = "";
 		rp = "";
-	
+
 	afd = fauth(fd, rp);
 	afd = fauth(fd, rp);
 	if(afd >= 0){
 	if(afd >= 0){
 		ai = auth_proxy(afd, auth_getkey, "proto=p9any role=client");
 		ai = auth_proxy(afd, auth_getkey, "proto=p9any role=client");

+ 1 - 1
sys/src/9/boot/boot.h

@@ -1,4 +1,4 @@
-/* 
+/*
  * This file is part of the UCB release of Plan 9. It is subject to the license
  * This file is part of the UCB release of Plan 9. It is subject to the license
  * terms in the LICENSE file found in the top-level directory of this
  * terms in the LICENSE file found in the top-level directory of this
  * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No

+ 3 - 3
sys/src/9/ip/arp.c

@@ -306,7 +306,7 @@ arpresolve(Arp *arp, Arpent *a, Medium *type, uint8_t *mac)
 void
 void
 arpenter(Fs *fs, int version, uint8_t *ip, uint8_t *mac, int n, int refresh)
 arpenter(Fs *fs, int version, uint8_t *ip, uint8_t *mac, int n, int refresh)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	Arp *arp;
 	Arp *arp;
 	Route *r;
 	Route *r;
 	Arpent *a, *f, **l;
 	Arpent *a, *f, **l;
@@ -676,11 +676,11 @@ rxready(void *v)
 static void
 static void
 rxmitproc(void *v)
 rxmitproc(void *v)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	Arp *arp = v;
 	Arp *arp = v;
 	int32_t wakeupat;
 	int32_t wakeupat;
 
 
-	arp->rxmitp = m->externup;
+	arp->rxmitp = up;
 	//print("arp rxmitproc started\n");
 	//print("arp rxmitproc started\n");
 	if(waserror()){
 	if(waserror()){
 		arp->rxmitp = 0;
 		arp->rxmitp = 0;

+ 1 - 1
sys/src/9/ip/chandial.c

@@ -60,7 +60,7 @@ chandial(char *dest, char *local, char *dir, Chan **ctlp)
 static Chan*
 static Chan*
 call(char *clone, char *dest, DS *ds)
 call(char *clone, char *dest, DS *ds)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	int n;
 	int n;
 	Chan *dchan, *cchan;
 	Chan *dchan, *cchan;
 	char name[Maxpath], data[Maxpath], *p;
 	char name[Maxpath], data[Maxpath], *p;

+ 11 - 11
sys/src/9/ip/devip.c

@@ -183,7 +183,7 @@ static int
 ipgen(Chan *c, char* j, Dirtab* dir, int mm, int s, Dir *dp)
 ipgen(Chan *c, char* j, Dirtab* dir, int mm, int s, Dir *dp)
 
 
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	Qid q;
 	Qid q;
 	Conv *cv;
 	Conv *cv;
 	Fs *f;
 	Fs *f;
@@ -194,8 +194,8 @@ ipgen(Chan *c, char* j, Dirtab* dir, int mm, int s, Dir *dp)
 	case Qtopdir:
 	case Qtopdir:
 		if(s == DEVDOTDOT){
 		if(s == DEVDOTDOT){
 			mkqid(&q, QID(0, 0, Qtopdir), 0, QTDIR);
 			mkqid(&q, QID(0, 0, Qtopdir), 0, QTDIR);
-			snprint(m->externup->genbuf, sizeof m->externup->genbuf, "#I%lud", c->dev);
-			devdir(c, q, m->externup->genbuf, 0, network, 0555, dp);
+			snprint(up->genbuf, sizeof up->genbuf, "#I%lud", c->dev);
+			devdir(c, q, up->genbuf, 0, network, 0555, dp);
 			return 1;
 			return 1;
 		}
 		}
 		if(s < f->np) {
 		if(s < f->np) {
@@ -217,15 +217,15 @@ ipgen(Chan *c, char* j, Dirtab* dir, int mm, int s, Dir *dp)
 	case Qprotodir:
 	case Qprotodir:
 		if(s == DEVDOTDOT){
 		if(s == DEVDOTDOT){
 			mkqid(&q, QID(0, 0, Qtopdir), 0, QTDIR);
 			mkqid(&q, QID(0, 0, Qtopdir), 0, QTDIR);
-			snprint(m->externup->genbuf, sizeof m->externup->genbuf, "#I%lud", c->dev);
-			devdir(c, q, m->externup->genbuf, 0, network, 0555, dp);
+			snprint(up->genbuf, sizeof up->genbuf, "#I%lud", c->dev);
+			devdir(c, q, up->genbuf, 0, network, 0555, dp);
 			return 1;
 			return 1;
 		}
 		}
 		if(s < f->p[PROTO(c->qid)]->ac) {
 		if(s < f->p[PROTO(c->qid)]->ac) {
 			cv = f->p[PROTO(c->qid)]->conv[s];
 			cv = f->p[PROTO(c->qid)]->conv[s];
-			snprint(m->externup->genbuf, sizeof m->externup->genbuf, "%d", s);
+			snprint(up->genbuf, sizeof up->genbuf, "%d", s);
 			mkqid(&q, QID(PROTO(c->qid), s, Qconvdir), 0, QTDIR);
 			mkqid(&q, QID(PROTO(c->qid), s, Qconvdir), 0, QTDIR);
-			devdir(c, q, m->externup->genbuf, 0, cv->owner, 0555, dp);
+			devdir(c, q, up->genbuf, 0, cv->owner, 0555, dp);
 			return 1;
 			return 1;
 		}
 		}
 		s -= f->p[PROTO(c->qid)]->ac;
 		s -= f->p[PROTO(c->qid)]->ac;
@@ -368,7 +368,7 @@ static int m2p[] = {
 static Chan*
 static Chan*
 ipopen(Chan* c, int omode)
 ipopen(Chan* c, int omode)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	Conv *cv, *nc;
 	Conv *cv, *nc;
 	Proto *p;
 	Proto *p;
 	int perm;
 	int perm;
@@ -971,7 +971,7 @@ connected(void* a)
 static void
 static void
 connectctlmsg(Proto *x, Conv *c, Cmdbuf *cb)
 connectctlmsg(Proto *x, Conv *c, Cmdbuf *cb)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	char *p;
 	char *p;
 
 
 	if(c->state != 0)
 	if(c->state != 0)
@@ -1025,7 +1025,7 @@ announced(void* a)
 static void
 static void
 announcectlmsg(Proto *x, Conv *c, Cmdbuf *cb)
 announcectlmsg(Proto *x, Conv *c, Cmdbuf *cb)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	char *p;
 	char *p;
 
 
 	if(c->state != 0)
 	if(c->state != 0)
@@ -1100,7 +1100,7 @@ ttlctlmsg(Conv *c, Cmdbuf *cb)
 static int32_t
 static int32_t
 ipwrite(Chan* ch, void *v, int32_t n, int64_t off)
 ipwrite(Chan* ch, void *v, int32_t n, int64_t off)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	Conv *c;
 	Conv *c;
 	Proto *x;
 	Proto *x;
 	char *p;
 	char *p;

+ 3 - 3
sys/src/9/ip/esp.c

@@ -459,7 +459,7 @@ espkick(void *x)
 void
 void
 espiput(Proto *esp, Ipifc *ipifc, Block *bp)
 espiput(Proto *esp, Ipifc *ipifc, Block *bp)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	int payload, nexthdr;
 	int payload, nexthdr;
 	uint8_t *auth, *espspi;
 	uint8_t *auth, *espspi;
 	Conv *c;
 	Conv *c;
@@ -534,9 +534,9 @@ print("esp: bad auth %I -> %I!%ld\n", vers.raddr, vers.laddr, vers.spi);
 	/* decrypt payload */
 	/* decrypt payload */
 	if(!ecb->cipher(ecb, bp->rp + vers.hdrlen, payload)) {
 	if(!ecb->cipher(ecb, bp->rp + vers.hdrlen, payload)) {
 		qunlock(c);
 		qunlock(c);
-print("esp: cipher failed %I -> %I!%ld: %s\n", vers.raddr, vers.laddr, vers.spi, m->externup->errstr);
+print("esp: cipher failed %I -> %I!%ld: %s\n", vers.raddr, vers.laddr, vers.spi, up->errstr);
 		netlog(f, Logesp, "esp: cipher failed %I -> %I!%lud: %s\n",
 		netlog(f, Logesp, "esp: cipher failed %I -> %I!%lud: %s\n",
-			vers.raddr, vers.laddr, vers.spi, m->externup->errstr);
+			vers.raddr, vers.laddr, vers.spi, up->errstr);
 		freeb(bp);
 		freeb(bp);
 		return;
 		return;
 	}
 	}

+ 9 - 9
sys/src/9/ip/ethermedium.c

@@ -133,7 +133,7 @@ static char *nbmsg = "nonblocking";
 static void
 static void
 etherbind(Ipifc *ifc, int argc, char **argv)
 etherbind(Ipifc *ifc, int argc, char **argv)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	Chan *mchan4, *cchan4, *achan, *mchan6, *cchan6, *schan;
 	Chan *mchan4, *cchan4, *achan, *mchan6, *cchan6, *schan;
 	char addr[Maxpath];	//char addr[2*KNAMELEN];
 	char addr[Maxpath];	//char addr[2*KNAMELEN];
 	char dir[Maxpath];	//char dir[2*KNAMELEN];
 	char dir[Maxpath];	//char dir[2*KNAMELEN];
@@ -248,7 +248,7 @@ etherbind(Ipifc *ifc, int argc, char **argv)
 static void
 static void
 etherunbind(Ipifc *ifc)
 etherunbind(Ipifc *ifc)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	Etherrock *er = ifc->arg;
 	Etherrock *er = ifc->arg;
 
 
 	if(er->read4p)
 	if(er->read4p)
@@ -260,7 +260,7 @@ etherunbind(Ipifc *ifc)
 
 
 	/* wait for readers to die */
 	/* wait for readers to die */
 	while(er->arpp != 0 || er->read4p != 0 || er->read6p != 0)
 	while(er->arpp != 0 || er->read4p != 0 || er->read6p != 0)
-		tsleep(&m->externup->sleep, return0, 0, 300);
+		tsleep(&up->sleep, return0, 0, 300);
 
 
 	if(er->mchan4 != nil)
 	if(er->mchan4 != nil)
 		cclose(er->mchan4);
 		cclose(er->mchan4);
@@ -343,14 +343,14 @@ etherbwrite(Ipifc *ifc, Block *bp, int version, uint8_t *ip)
 static void
 static void
 etherread4(void *a)
 etherread4(void *a)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	Ipifc *ifc;
 	Ipifc *ifc;
 	Block *bp;
 	Block *bp;
 	Etherrock *er;
 	Etherrock *er;
 
 
 	ifc = a;
 	ifc = a;
 	er = ifc->arg;
 	er = ifc->arg;
-	er->read4p = m->externup;	/* hide identity under a rock for unbind */
+	er->read4p = up;	/* hide identity under a rock for unbind */
 	if(waserror()){
 	if(waserror()){
 		er->read4p = 0;
 		er->read4p = 0;
 		pexit("hangup", 1);
 		pexit("hangup", 1);
@@ -383,14 +383,14 @@ etherread4(void *a)
 static void
 static void
 etherread6(void *a)
 etherread6(void *a)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	Ipifc *ifc;
 	Ipifc *ifc;
 	Block *bp;
 	Block *bp;
 	Etherrock *er;
 	Etherrock *er;
 
 
 	ifc = a;
 	ifc = a;
 	er = ifc->arg;
 	er = ifc->arg;
-	er->read6p = m->externup;	/* hide identity under a rock for unbind */
+	er->read6p = up;	/* hide identity under a rock for unbind */
 	if(waserror()){
 	if(waserror()){
 		er->read6p = 0;
 		er->read6p = 0;
 		pexit("hangup", 1);
 		pexit("hangup", 1);
@@ -688,11 +688,11 @@ recvarp(Ipifc *ifc)
 static void
 static void
 recvarpproc(void *v)
 recvarpproc(void *v)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	Ipifc *ifc = v;
 	Ipifc *ifc = v;
 	Etherrock *er = ifc->arg;
 	Etherrock *er = ifc->arg;
 
 
-	er->arpp = m->externup;
+	er->arpp = up;
 	if(waserror()){
 	if(waserror()){
 		er->arpp = 0;
 		er->arpp = 0;
 		pexit("hangup", 1);
 		pexit("hangup", 1);

+ 4 - 4
sys/src/9/ip/inferno.c

@@ -21,15 +21,15 @@
 char*
 char*
 commonuser(void)
 commonuser(void)
 {
 {
-	Mach *m = machp();
-	return m->externup->user;
+	Proc *up = machp()->externup;
+	return up->user;
 }
 }
 
 
 char*
 char*
 commonerror(void)
 commonerror(void)
 {
 {
-	Mach *m = machp();
-	return m->externup->errstr;
+	Proc *up = machp()->externup;
+	return up->errstr;
 }
 }
 
 
 int
 int

+ 1 - 1
sys/src/9/ip/ip.c

@@ -129,7 +129,7 @@ iprouting(Fs *f, int on)
 int
 int
 ipoput4(Fs *f, Block *bp, int gating, int ttl, int tos, Conv *c)
 ipoput4(Fs *f, Block *bp, int gating, int ttl, int tos, Conv *c)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	Ipifc *ifc;
 	Ipifc *ifc;
 	uint8_t *gate;
 	uint8_t *gate;
 	uint32_t fragoff;
 	uint32_t fragoff;

+ 6 - 6
sys/src/9/ip/ipifc.c

@@ -112,7 +112,7 @@ ipfindmedium(char *name)
 static char*
 static char*
 ipifcbind(Conv *c, char **argv, int argc)
 ipifcbind(Conv *c, char **argv, int argc)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	Ipifc *ifc;
 	Ipifc *ifc;
 	Medium *medium;
 	Medium *medium;
 
 
@@ -183,7 +183,7 @@ ipifcbind(Conv *c, char **argv, int argc)
 static char*
 static char*
 ipifcunbind(Ipifc *ifc)
 ipifcunbind(Ipifc *ifc)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	char *err;
 	char *err;
 
 
 	if(waserror()){
 	if(waserror()){
@@ -294,7 +294,7 @@ ipifcinuse(Conv *c)
 static void
 static void
 ipifckick(void *x)
 ipifckick(void *x)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	Conv *c = x;
 	Conv *c = x;
 	Block *bp;
 	Block *bp;
 	Ipifc *ifc;
 	Ipifc *ifc;
@@ -681,7 +681,7 @@ ipifcremroute(Fs *f, int vers, uint8_t *addr, uint8_t *mask)
 static char*
 static char*
 ipifcconnect(Conv* c, char **argv, int argc)
 ipifcconnect(Conv* c, char **argv, int argc)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	char *err;
 	char *err;
 	Ipifc *ifc;
 	Ipifc *ifc;
 
 
@@ -1439,7 +1439,7 @@ ipisbm(uint8_t *ip)
 void
 void
 ipifcaddmulti(Conv *c, uint8_t *ma, uint8_t *ia)
 ipifcaddmulti(Conv *c, uint8_t *ma, uint8_t *ia)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	Ipifc *ifc;
 	Ipifc *ifc;
 	Iplifc *lifc;
 	Iplifc *lifc;
 	Conv **p;
 	Conv **p;
@@ -1481,7 +1481,7 @@ ipifcaddmulti(Conv *c, uint8_t *ma, uint8_t *ia)
 void
 void
 ipifcremmulti(Conv *c, uint8_t *ma, uint8_t *ia)
 ipifcremmulti(Conv *c, uint8_t *ma, uint8_t *ia)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	Ipmulti *multi, **l;
 	Ipmulti *multi, **l;
 	Iplifc *lifc;
 	Iplifc *lifc;
 	Conv **p;
 	Conv **p;

+ 1 - 1
sys/src/9/ip/iproute.c

@@ -818,7 +818,7 @@ printroute(Route *r)
 int32_t
 int32_t
 routewrite(Fs *f, Chan *c, char *p, int n)
 routewrite(Fs *f, Chan *c, char *p, int n)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	int h, changed;
 	int h, changed;
 	char *tag;
 	char *tag;
 	Cmdbuf *cb;
 	Cmdbuf *cb;

+ 1 - 1
sys/src/9/ip/ipv6.c

@@ -39,7 +39,7 @@ int		unfraglen(Block *bp, uint8_t *nexthdr, int setfh);
 int
 int
 ipoput6(Fs *f, Block *bp, int gating, int ttl, int tos, Conv *c)
 ipoput6(Fs *f, Block *bp, int gating, int ttl, int tos, Conv *c)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	int medialen, len, chunk, uflen, flen, seglen, lid, offset, fragoff;
 	int medialen, len, chunk, uflen, flen, seglen, lid, offset, fragoff;
 	int morefrags, blklen, rv = 0, tentative;
 	int morefrags, blklen, rv = 0, tentative;
 	uint8_t *gate, nexthdr;
 	uint8_t *gate, nexthdr;

+ 4 - 4
sys/src/9/ip/loopbackmedium.c

@@ -49,7 +49,7 @@ loopbackbind(Ipifc *ifc, int i, char**argv)
 static void
 static void
 loopbackunbind(Ipifc *ifc)
 loopbackunbind(Ipifc *ifc)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	LB *lb = ifc->arg;
 	LB *lb = ifc->arg;
 
 
 	if(lb->readp)
 	if(lb->readp)
@@ -57,7 +57,7 @@ loopbackunbind(Ipifc *ifc)
 
 
 	/* wait for reader to die */
 	/* wait for reader to die */
 	while(lb->readp != 0)
 	while(lb->readp != 0)
-		tsleep(&m->externup->sleep, return0, 0, 300);
+		tsleep(&up->sleep, return0, 0, 300);
 
 
 	/* clean up */
 	/* clean up */
 	qfree(lb->q);
 	qfree(lb->q);
@@ -78,14 +78,14 @@ loopbackbwrite(Ipifc *ifc, Block *bp, int i, uint8_t *c)
 static void
 static void
 loopbackread(void *a)
 loopbackread(void *a)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	Ipifc *ifc;
 	Ipifc *ifc;
 	Block *bp;
 	Block *bp;
 	LB *lb;
 	LB *lb;
 
 
 	ifc = a;
 	ifc = a;
 	lb = ifc->arg;
 	lb = ifc->arg;
-	lb->readp = m->externup;	/* hide identity under a rock for unbind */
+	lb->readp = up;	/* hide identity under a rock for unbind */
 	if(waserror()){
 	if(waserror()){
 		lb->readp = 0;
 		lb->readp = 0;
 		pexit("hangup", 1);
 		pexit("hangup", 1);

+ 4 - 4
sys/src/9/ip/netdevmedium.c

@@ -72,7 +72,7 @@ netdevbind(Ipifc *ifc, int argc, char **argv)
 static void
 static void
 netdevunbind(Ipifc *ifc)
 netdevunbind(Ipifc *ifc)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	Netdevrock *er = ifc->arg;
 	Netdevrock *er = ifc->arg;
 
 
 	if(er->readp != nil)
 	if(er->readp != nil)
@@ -80,7 +80,7 @@ netdevunbind(Ipifc *ifc)
 
 
 	/* wait for readers to die */
 	/* wait for readers to die */
 	while(er->readp != nil)
 	while(er->readp != nil)
-		tsleep(&m->externup->sleep, return0, 0, 300);
+		tsleep(&up->sleep, return0, 0, 300);
 
 
 	if(er->mchan != nil)
 	if(er->mchan != nil)
 		cclose(er->mchan);
 		cclose(er->mchan);
@@ -111,7 +111,7 @@ netdevbwrite(Ipifc *ifc, Block *bp, int i, uint8_t *c)
 static void
 static void
 netdevread(void *a)
 netdevread(void *a)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	Ipifc *ifc;
 	Ipifc *ifc;
 	Block *bp;
 	Block *bp;
 	Netdevrock *er;
 	Netdevrock *er;
@@ -119,7 +119,7 @@ netdevread(void *a)
 
 
 	ifc = a;
 	ifc = a;
 	er = ifc->arg;
 	er = ifc->arg;
-	er->readp = m->externup;	/* hide identity under a rock for unbind */
+	er->readp = up;	/* hide identity under a rock for unbind */
 	if(waserror()){
 	if(waserror()){
 		er->readp = nil;
 		er->readp = nil;
 		pexit("hangup", 1);
 		pexit("hangup", 1);

+ 4 - 4
sys/src/9/ip/netlog.c

@@ -86,7 +86,7 @@ netloginit(Fs *f)
 void
 void
 netlogopen(Fs *f)
 netlogopen(Fs *f)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	lock(f->alog);
 	lock(f->alog);
 	if(waserror()){
 	if(waserror()){
 		unlock(f->alog);
 		unlock(f->alog);
@@ -108,7 +108,7 @@ netlogopen(Fs *f)
 void
 void
 netlogclose(Fs *f)
 netlogclose(Fs *f)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	lock(f->alog);
 	lock(f->alog);
 	if(waserror()){
 	if(waserror()){
 		unlock(f->alog);
 		unlock(f->alog);
@@ -134,7 +134,7 @@ netlogready(void *a)
 int32_t
 int32_t
 netlogread(Fs *f, void *a, uint32_t u, int32_t n)
 netlogread(Fs *f, void *a, uint32_t u, int32_t n)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	int i, d;
 	int i, d;
 	char *p, *rptr;
 	char *p, *rptr;
 
 
@@ -180,7 +180,7 @@ netlogread(Fs *f, void *a, uint32_t u, int32_t n)
 void
 void
 netlogctl(Fs *f, char* s, int n)
 netlogctl(Fs *f, char* s, int n)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	int i, set;
 	int i, set;
 	Netlogflag *fp;
 	Netlogflag *fp;
 	Cmdbuf *cb;
 	Cmdbuf *cb;

+ 3 - 3
sys/src/9/ip/rudp.c

@@ -345,7 +345,7 @@ flow(void *v)
 void
 void
 rudpkick(void *x)
 rudpkick(void *x)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	Conv *c = x;
 	Conv *c = x;
 	Udphdr *uh;
 	Udphdr *uh;
 	uint16_t rport;
 	uint16_t rport;
@@ -737,7 +737,7 @@ relackq(Reliable *r, Block *bp)
 void
 void
 relackproc(void *a)
 relackproc(void *a)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	Rudpcb *ucb;
 	Rudpcb *ucb;
 	Proto *rudp;
 	Proto *rudp;
 	Reliable *r;
 	Reliable *r;
@@ -746,7 +746,7 @@ relackproc(void *a)
 	rudp = (Proto *)a;
 	rudp = (Proto *)a;
 
 
 loop:
 loop:
-	tsleep(&m->externup->sleep, return0, 0, Rudptickms);
+	tsleep(&up->sleep, return0, 0, Rudptickms);
 
 
 	for(s = rudp->conv; *s; s++) {
 	for(s = rudp->conv; *s; s++) {
 		c = *s;
 		c = *s;

+ 8 - 8
sys/src/9/ip/tcp.c

@@ -595,7 +595,7 @@ tcpclose(Conv *c)
 static void
 static void
 tcpkick(void *x)
 tcpkick(void *x)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	Conv *s = x;
 	Conv *s = x;
 	Tcpctl *tcb;
 	Tcpctl *tcb;
 
 
@@ -654,7 +654,7 @@ tcprcvwin(Conv *s)				/* Call with tcb locked */
 static void
 static void
 tcpacktimer(void *v)
 tcpacktimer(void *v)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	Tcpctl *tcb;
 	Tcpctl *tcb;
 	Conv *s;
 	Conv *s;
 
 
@@ -757,7 +757,7 @@ timerstate(Tcppriv *priv, Tcptimer *t, int newstate)
 static void
 static void
 tcpackproc(void *a)
 tcpackproc(void *a)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	Tcptimer *t, *tp, *timeo;
 	Tcptimer *t, *tp, *timeo;
 	Proto *tcp;
 	Proto *tcp;
 	Tcppriv *priv;
 	Tcppriv *priv;
@@ -767,7 +767,7 @@ tcpackproc(void *a)
 	priv = tcp->priv;
 	priv = tcp->priv;
 
 
 	for(;;) {
 	for(;;) {
-		tsleep(&m->externup->sleep, return0, 0, MSPTICK);
+		tsleep(&up->sleep, return0, 0, MSPTICK);
 
 
 		qlock(&priv->tl);
 		qlock(&priv->tl);
 		timeo = nil;
 		timeo = nil;
@@ -1430,7 +1430,7 @@ sndrst(Proto *tcp, uint8_t *source, uint8_t *dest, uint16_t length, Tcp *seg, ui
 static char*
 static char*
 tcphangup(Conv *s)
 tcphangup(Conv *s)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	Tcp seg;
 	Tcp seg;
 	Tcpctl *tcb;
 	Tcpctl *tcb;
 	Block *hbp;
 	Block *hbp;
@@ -2084,7 +2084,7 @@ done:
 static void
 static void
 tcpiput(Proto *tcp, Ipifc *ipifc, Block *bp)
 tcpiput(Proto *tcp, Ipifc *ipifc, Block *bp)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	Tcp seg;
 	Tcp seg;
 	Tcp4hdr *h4;
 	Tcp4hdr *h4;
 	Tcp6hdr *h6;
 	Tcp6hdr *h6;
@@ -2872,7 +2872,7 @@ tcpsetkacounter(Tcpctl *tcb)
 static void
 static void
 tcpkeepalive(void *v)
 tcpkeepalive(void *v)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	Tcpctl *tcb;
 	Tcpctl *tcb;
 	Conv *s;
 	Conv *s;
 
 
@@ -2966,7 +2966,7 @@ tcprxmit(Conv *s)
 static void
 static void
 tcptimeout(void *arg)
 tcptimeout(void *arg)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	Conv *s;
 	Conv *s;
 	Tcpctl *tcb;
 	Tcpctl *tcb;
 	int maxback;
 	int maxback;

+ 27 - 27
sys/src/9/k10/acore.c

@@ -50,15 +50,15 @@ extern void _actrapret(void);
 
 
 ACVctl *acvctl[256];
 ACVctl *acvctl[256];
 
 
-/* 
+/*
  * Test inter core calls by calling a cores to print something, and then
  * Test inter core calls by calling a cores to print something, and then
  * waiting for it to complete.
  * waiting for it to complete.
  */
  */
 static void
 static void
 testiccfn(void)
 testiccfn(void)
 {
 {
-	Mach *m = machp();
-	print("called: %s\n", ( char *)m->icc->data);
+	Proc *up = machp()->externup;
+	print("called: %s\n", ( char *)machp()->icc->data);
 }
 }
 
 
 void
 void
@@ -87,13 +87,13 @@ testicc(int i)
 static void
 static void
 acstackok(void)
 acstackok(void)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	char dummy;
 	char dummy;
 	char *sstart;
 	char *sstart;
 
 
-	sstart = (char *)m - PGSZ - 4*PTSZ - MACHSTKSZ;
+	sstart = (char *)machp() - PGSZ - 4*PTSZ - MACHSTKSZ;
 	if(&dummy < sstart + 4*KiB){
 	if(&dummy < sstart + 4*KiB){
-		print("ac kernel stack overflow, cpu%d stopped\n", m->machno);
+		print("ac kernel stack overflow, cpu%d stopped\n", machp()->machno);
 		DONE();
 		DONE();
 	}
 	}
 }
 }
@@ -109,31 +109,31 @@ acstackok(void)
 void
 void
 acsched(void)
 acsched(void)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	acmmuswitch();
 	acmmuswitch();
 	for(;;){
 	for(;;){
 		acstackok();
 		acstackok();
-		mwait(&m->icc->fn);
-		if(m->icc->flushtlb)
+		mwait(&machp()->icc->fn);
+		if(machp()->icc->flushtlb)
 			acmmuswitch();
 			acmmuswitch();
-		DBG("acsched: cpu%d: fn %#p\n", m->machno, m->icc->fn);
-		m->icc->fn();
-		DBG("acsched: cpu%d: idle\n", m->machno);
+		DBG("acsched: cpu%d: fn %#p\n", machp()->machno, machp()->icc->fn);
+		machp()->icc->fn();
+		DBG("acsched: cpu%d: idle\n", machp()->machno);
 		mfence();
 		mfence();
-		m->icc->fn = nil;
+		machp()->icc->fn = nil;
 	}
 	}
 }
 }
 
 
 void
 void
 acmmuswitch(void)
 acmmuswitch(void)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	extern Page mach0pml4;
 	extern Page mach0pml4;
 
 
-	DBG("acmmuswitch mpl4 %#p mach0pml4 %#p m0pml4 %#p\n", m->pml4->pa, mach0pml4.pa, sys->machptr[0]->pml4->pa);
+	DBG("acmmuswitch mpl4 %#p mach0pml4 %#p m0pml4 %#p\n", machp()->pml4->pa, mach0pml4.pa, sys->machptr[0]->pml4->pa);
 
 
 
 
-	cr3put(m->pml4->pa);
+	cr3put(machp()->pml4->pa);
 }
 }
 
 
 /*
 /*
@@ -149,7 +149,7 @@ actouser(void)
 	acfpusysprocsetup(m->proc);
 	acfpusysprocsetup(m->proc);
 
 
 	u = m->proc->dbgreg;
 	u = m->proc->dbgreg;
-	DBG("cpu%d: touser usp = %#p entry %#p\n", m->machno, u->sp, u->ip);
+	DBG("cpu%d: touser usp = %#p entry %#p\n", machp()->machno, u->sp, u->ip);
 	xactouser(u->sp);
 	xactouser(u->sp);
 #endif
 #endif
 	panic("actouser");
 	panic("actouser");
@@ -163,12 +163,12 @@ actrapret(void)
 
 
 /*
 /*
  * Entered in AP core context, upon traps (system calls go through acsyscall)
  * Entered in AP core context, upon traps (system calls go through acsyscall)
- * using m->externup->dbgreg means cores MUST be homogeneous.
+ * using up->dbgreg means cores MUST be homogeneous.
  *
  *
  * BUG: We should setup some trapenable() mechanism for the AC,
  * BUG: We should setup some trapenable() mechanism for the AC,
  * so that code like fpu.c could arrange for handlers specific for
  * so that code like fpu.c could arrange for handlers specific for
  * the AC, instead of doint that by hand here.
  * the AC, instead of doint that by hand here.
- * 
+ *
  * All interrupts are masked while in the "kernel"
  * All interrupts are masked while in the "kernel"
  */
  */
 void
 void
@@ -189,7 +189,7 @@ actrap(Ureg *u)
 	if(u->type < nelem(acvctl)){
 	if(u->type < nelem(acvctl)){
 		v = acvctl[u->type];
 		v = acvctl[u->type];
 		if(v != nil){
 		if(v != nil){
-			DBG("actrap: cpu%d: %ulld\n", m->machno, u->type);
+			DBG("actrap: cpu%d: %ulld\n", machp()->machno, u->type);
 			n = v->f(u, v->a);
 			n = v->f(u, v->a);
 			if(n != nil)
 			if(n != nil)
 				goto Post;
 				goto Post;
@@ -203,7 +203,7 @@ actrap(Ureg *u)
 		ndnr();
 		ndnr();
 	case IdtIPI:
 	case IdtIPI:
 		m->intr++;
 		m->intr++;
-		DBG("actrap: cpu%d: IPI\n", m->machno);
+		DBG("actrap: cpu%d: IPI\n", machp()->machno);
 		apiceoi(IdtIPI);
 		apiceoi(IdtIPI);
 		break;
 		break;
 	case IdtTIMER:
 	case IdtTIMER:
@@ -213,10 +213,10 @@ actrap(Ureg *u)
 	case IdtPF:
 	case IdtPF:
 		/* this case is here for debug only */
 		/* this case is here for debug only */
 		m->pfault++;
 		m->pfault++;
-		DBG("actrap: cpu%d: PF cr2 %#ullx\n", m->machno, cr2get());
+		DBG("actrap: cpu%d: PF cr2 %#ullx\n", machp()->machno, cr2get());
 		break;
 		break;
 	default:
 	default:
-		print("actrap: cpu%d: %ulld\n", m->machno, u->type);
+		print("actrap: cpu%d: %ulld\n", machp()->machno, u->type);
 	}
 	}
 Post:
 Post:
 	m->icc->rc = ICCTRAP;
 	m->icc->rc = ICCTRAP;
@@ -254,7 +254,7 @@ acsyscall(void)
 	 * There's nothing else we have to do.
 	 * There's nothing else we have to do.
 	 * Otherwise, we should m->proc->dbgregs = u;
 	 * Otherwise, we should m->proc->dbgregs = u;
 	 */
 	 */
-	DBG("acsyscall: cpu%d\n", m->machno);
+	DBG("acsyscall: cpu%d\n", machp()->machno);
 
 
 	_pmcupdate(m);
 	_pmcupdate(m);
 	p = m->proc;
 	p = m->proc;
@@ -299,7 +299,7 @@ dumpreg(void *u)
 	ndnr();
 	ndnr();
 }
 }
 
 
-char *rolename[] = 
+char *rolename[] =
 {
 {
 	[NIXAC]	"AC",
 	[NIXAC]	"AC",
 	[NIXTC]	"TC",
 	[NIXTC]	"TC",
@@ -310,7 +310,7 @@ char *rolename[] =
 void
 void
 acmodeset(int mode)
 acmodeset(int mode)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	switch(mode){
 	switch(mode){
 	case NIXAC:
 	case NIXAC:
 	case NIXKC:
 	case NIXKC:
@@ -320,7 +320,7 @@ acmodeset(int mode)
 	default:
 	default:
 		panic("acmodeset: bad mode %d", mode);
 		panic("acmodeset: bad mode %d", mode);
 	}
 	}
-	m->nixtype = mode;
+	machp()->nixtype = mode;
 }
 }
 
 
 void
 void

+ 8 - 8
sys/src/9/k10/acore.c.old

@@ -52,7 +52,7 @@ static char *acnames[] = { "Ok", "Trap", "Syscall"};
 void
 void
 acmmuswitch(void)
 acmmuswitch(void)
 {
 {
-	cr3put(m->pml4->pa);
+	cr3put(machp()->pml4->pa);
 }
 }
 void xactouser(u64int);
 void xactouser(u64int);
 void
 void
@@ -63,7 +63,7 @@ actouser(void)
 
 
 	memmove(&sp, m->icc->data, sizeof(sp));
 	memmove(&sp, m->icc->data, sizeof(sp));
 	u = m->proc->dbgreg;
 	u = m->proc->dbgreg;
-	DBG("cpu%d: touser usp = %#p entry %#p\n", m->machno, sp, u->ip);
+	DBG("cpu%d: touser usp = %#p entry %#p\n", machp()->machno, sp, u->ip);
 
 
 
 
 	/*
 	/*
@@ -96,7 +96,7 @@ actrap(Ureg *u)
 	switch(u->type){
 	switch(u->type){
 	case IdtIPI:
 	case IdtIPI:
 		m->intr++;
 		m->intr++;
-		print("actrap: cpu%d: IPI\n", m->machno);
+		print("actrap: cpu%d: IPI\n", machp()->machno);
 		/*
 		/*
 		 * Beware: BUG: we can get now IPIs while in kernel mode,
 		 * Beware: BUG: we can get now IPIs while in kernel mode,
 		 * after declaring the end of the interrupt.
 		 * after declaring the end of the interrupt.
@@ -106,10 +106,10 @@ actrap(Ureg *u)
 		break;
 		break;
 	case IdtPF:
 	case IdtPF:
 		m->pfault++;
 		m->pfault++;
-		print("actrap: cpu%d: PF\n", m->machno);
+		print("actrap: cpu%d: PF\n", machp()->machno);
 		break;
 		break;
 	default:
 	default:
-		print("actrap: cpu%d: %ulld\n", m->machno, u->type);
+		print("actrap: cpu%d: %ulld\n", machp()->machno, u->type);
 	}
 	}
 	m->icc->rc = ICCTRAP;
 	m->icc->rc = ICCTRAP;
 	m->cr2 = cr2get();
 	m->cr2 = cr2get();
@@ -137,7 +137,7 @@ acsyscall(void)
 	 * There's nothing else we have to do.
 	 * There's nothing else we have to do.
 	 * Otherwise, we should m->proc->dbgregs = u;
 	 * Otherwise, we should m->proc->dbgregs = u;
 	 */
 	 */
-	DBG("acsyscall: cpu%d\n", m->machno);
+	DBG("acsyscall: cpu%d\n", machp()->machno);
 	m->syscall++;	/* would also count it in the TS core */
 	m->syscall++;	/* would also count it in the TS core */
 	m->icc->rc = ICCSYSCALL;
 	m->icc->rc = ICCSYSCALL;
 	m->cr2 = cr2get();
 	m->cr2 = cr2get();
@@ -196,9 +196,9 @@ runac(int core, APfunc func, int flushtlb, void *a, long n)
 	memmove(mp->icc->data, a, n);
 	memmove(mp->icc->data, a, n);
 	if(flushtlb){
 	if(flushtlb){
 		dpg = UINT2PTR(mp->pml4->va);
 		dpg = UINT2PTR(mp->pml4->va);
-		spg = UINT2PTR(m->pml4->va);
+		spg = UINT2PTR(machp()->pml4->va);
 		/* We should copy only user space mappings:
 		/* We should copy only user space mappings:
-		 *	memmove(dgp, spg, m->pml4->daddr * sizeof(PTE));
+		 *	memmove(dgp, spg, machp()->pml4->daddr * sizeof(PTE));
 		 */
 		 */
 		memmove(dpg, spg, PTPGSZ);
 		memmove(dpg, spg, PTPGSZ);
 	}
 	}

+ 3 - 3
sys/src/9/k10/acpi.h

@@ -1,4 +1,4 @@
-/* 
+/*
  * This file is part of the UCB release of Plan 9. It is subject to the license
  * This file is part of the UCB release of Plan 9. It is subject to the license
  * terms in the LICENSE file found in the top-level directory of this
  * terms in the LICENSE file found in the top-level directory of this
  * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
@@ -151,7 +151,7 @@ struct Reg
 	int	accsz;		/* access size */
 	int	accsz;		/* access size */
 };
 };
 
 
-/* Generic address structure. 
+/* Generic address structure.
  */
  */
 struct Gas
 struct Gas
 {
 {
@@ -321,7 +321,7 @@ struct Srat
 			uint64_t	addr;	/* base address */
 			uint64_t	addr;	/* base address */
 			uint64_t	len;
 			uint64_t	len;
 			int	hplug;	/* hot pluggable */
 			int	hplug;	/* hot pluggable */
-			int	nvram;	/* non volatile */	
+			int	nvram;	/* non volatile */
 		} mem;
 		} mem;
 		struct{
 		struct{
 			int	dom;	/* proximity domain */
 			int	dom;	/* proximity domain */

+ 13 - 13
sys/src/9/k10/apic.c

@@ -118,7 +118,7 @@ apicisr(int vecno)
 void
 void
 apicinit(int apicno, uintmem pa, int isbp)
 apicinit(int apicno, uintmem pa, int isbp)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	Apic *apic;
 	Apic *apic;
 
 
 	/*
 	/*
@@ -154,7 +154,7 @@ apicinit(int apicno, uintmem pa, int isbp)
 	 */
 	 */
 	if(isbp){
 	if(isbp){
 		apic->machno = 0;
 		apic->machno = 0;
-		m->apicno = apicno;
+		machp()->apicno = apicno;
 	}
 	}
 	else
 	else
 		apic->machno = apmachno++;
 		apic->machno = apmachno++;
@@ -198,7 +198,7 @@ apictimer(Ureg* ureg, void* v)
 int
 int
 apiconline(void)
 apiconline(void)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	Apic *apic;
 	Apic *apic;
 	uint64_t tsc;
 	uint64_t tsc;
 	uint32_t dfr, ver;
 	uint32_t dfr, ver;
@@ -231,7 +231,7 @@ apiconline(void)
 	 * These don't really matter in Physical mode;
 	 * These don't really matter in Physical mode;
 	 * set the defaults anyway.
 	 * set the defaults anyway.
 	 */
 	 */
-	if(memcmp(m->cpuinfo, "AuthenticAMD", 12) == 0)
+	if(memcmp(machp()->cpuinfo, "AuthenticAMD", 12) == 0)
 		dfr = 0xf0000000;
 		dfr = 0xf0000000;
 	else
 	else
 		dfr = 0xffffffff;
 		dfr = 0xffffffff;
@@ -264,7 +264,7 @@ apiconline(void)
 	 */
 	 */
 	apicrput(Tdc, DivX1);
 	apicrput(Tdc, DivX1);
 	apicrput(Tlvt, Im);
 	apicrput(Tlvt, Im);
-	tsc = rdtsc() + m->cpuhz/10;
+	tsc = rdtsc() + machp()->cpuhz/10;
 	apicrput(Tic, 0xffffffff);
 	apicrput(Tic, 0xffffffff);
 
 
 	while(rdtsc() < tsc)
 	while(rdtsc() < tsc)
@@ -273,9 +273,9 @@ apiconline(void)
 	apic->hz = (0xffffffff-apicrget(Tcc))*10;
 	apic->hz = (0xffffffff-apicrget(Tcc))*10;
 	apic->max = apic->hz/HZ;
 	apic->max = apic->hz/HZ;
 	apic->min = apic->hz/(100*HZ);
 	apic->min = apic->hz/(100*HZ);
-	apic->div = ((m->cpuhz/apic->max)+HZ/2)/HZ;
+	apic->div = ((machp()->cpuhz/apic->max)+HZ/2)/HZ;
 
 
-	if(m->machno == 0 || DBGFLG){
+	if(machp()->machno == 0 || DBGFLG){
 		print("apic%d: hz %lld max %lld min %lld div %lld\n", apicno,
 		print("apic%d: hz %lld max %lld min %lld div %lld\n", apicno,
 			apic->hz, apic->max, apic->min, apic->div);
 			apic->hz, apic->max, apic->min, apic->div);
 	}
 	}
@@ -319,7 +319,7 @@ apiconline(void)
 	 * then lower the task priority to allow interrupts to be
 	 * then lower the task priority to allow interrupts to be
 	 * accepted by the APIC.
 	 * accepted by the APIC.
 	 */
 	 */
-	microdelay((TK2MS(1)*1000/apmachno) * m->machno);
+	microdelay((TK2MS(1)*1000/apmachno) * machp()->machno);
 
 
 	if(apic->machno == 0){
 	if(apic->machno == 0){
 		apicrput(Tic, apic->max);
 		apicrput(Tic, apic->max);
@@ -327,10 +327,10 @@ apiconline(void)
 		apicrput(Tlvt, Periodic|IrqTIMER);
 		apicrput(Tlvt, Periodic|IrqTIMER);
 	}
 	}
 
 
-	if(m->machno == 0)
+	if(machp()->machno == 0)
 		apicrput(Tp, 0);
 		apicrput(Tp, 0);
 
 
-	xlapicmachptr[apicno] = m;
+	xlapicmachptr[apicno] = machp();
 
 
 	return 1;
 	return 1;
 }
 }
@@ -352,7 +352,7 @@ apictimerenab(void)
 void
 void
 apictimerset(uint64_t next)
 apictimerset(uint64_t next)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	Mpl pl;
 	Mpl pl;
 	Apic *apic;
 	Apic *apic;
 	int64_t period;
 	int64_t period;
@@ -360,7 +360,7 @@ apictimerset(uint64_t next)
 	apic = &xlapic[(apicrget(Id)>>24) & 0xff];
 	apic = &xlapic[(apicrget(Id)>>24) & 0xff];
 
 
 	pl = splhi();
 	pl = splhi();
-	lock(&m->apictimerlock);
+	lock(&machp()->apictimerlock);
 
 
 	period = apic->max;
 	period = apic->max;
 	if(next != 0){
 	if(next != 0){
@@ -374,7 +374,7 @@ apictimerset(uint64_t next)
 	}
 	}
 	apicrput(Tic, period);
 	apicrput(Tic, period);
 
 
-	unlock(&m->apictimerlock);
+	unlock(&machp()->apictimerlock);
 	splx(pl);
 	splx(pl);
 }
 }
 
 

+ 1 - 1
sys/src/9/k10/apic.h

@@ -1,4 +1,4 @@
-/* 
+/*
  * This file is part of the UCB release of Plan 9. It is subject to the license
  * This file is part of the UCB release of Plan 9. It is subject to the license
  * terms in the LICENSE file found in the top-level directory of this
  * terms in the LICENSE file found in the top-level directory of this
  * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No

+ 6 - 6
sys/src/9/k10/arch.c

@@ -21,11 +21,11 @@
 #include "../port/error.h"
 #include "../port/error.h"
 
 
 /* the rules are different for different compilers. We need to define up. */
 /* the rules are different for different compilers. We need to define up. */
-// Initialize it to force it into data. 
+// Initialize it to force it into data.
 // That way, if we set them in assembly, they won't get zero'd by the bss init in main
 // That way, if we set them in assembly, they won't get zero'd by the bss init in main
 // N.B. There was an interesting hack in plan 9 c. You could grab up to two registers for your
 // N.B. There was an interesting hack in plan 9 c. You could grab up to two registers for your
 // program. In the case of Plan 9, m was r15, and up was r14. Very slick, and if there is a way to do
 // program. In the case of Plan 9, m was r15, and up was r14. Very slick, and if there is a way to do
-// this in gcc or clang I don't know it. This also nicely handled per cpu info; R15/14 were always right for 
+// this in gcc or clang I don't know it. This also nicely handled per cpu info; R15/14 were always right for
 // your core and context.
 // your core and context.
 //Mach *m = (void *)0;
 //Mach *m = (void *)0;
 
 
@@ -87,9 +87,9 @@ procsave(Proc *p)
 static void
 static void
 linkproc(void)
 linkproc(void)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	spllo();
 	spllo();
-	m->externup->kpfun(m->externup->kparg);
+	up->kpfun(up->kparg);
 	pexit("kproc dying", 0);
 	pexit("kproc dying", 0);
 }
 }
 
 
@@ -119,7 +119,7 @@ kprocchild(Proc* p, void (*func)(void*), void* arg)
 void
 void
 idlehands(void)
 idlehands(void)
 {
 {
-	Mach *m = machp();
-	if(m->nixtype != NIXAC)
+	Proc *up = machp()->externup;
+	if(machp()->nixtype != NIXAC)
  		halt();
  		halt();
 }
 }

+ 42 - 42
sys/src/9/k10/archk10.c

@@ -19,7 +19,7 @@
 static int
 static int
 cpuidinit(void)
 cpuidinit(void)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	uint32_t eax, info[4];
 	uint32_t eax, info[4];
 
 
 	/*
 	/*
@@ -27,23 +27,23 @@ cpuidinit(void)
 	 * Functions 0 and 1 will be needed multiple times
 	 * Functions 0 and 1 will be needed multiple times
 	 * so cache the info now.
 	 * so cache the info now.
 	 */
 	 */
-	if((m->ncpuinfos = cpuid(0, 0, m->cpuinfo[0])) == 0)
+	if((machp()->ncpuinfos = cpuid(0, 0, machp()->cpuinfo[0])) == 0)
 		return 0;
 		return 0;
-	m->ncpuinfos++;
+	machp()->ncpuinfos++;
 
 
-	if(memcmp(&m->cpuinfo[0][1], "GenuntelineI", 12) == 0)
-		m->isintelcpu = 1;
-	cpuid(1, 0, m->cpuinfo[1]);
+	if(memcmp(&machp()->cpuinfo[0][1], "GenuntelineI", 12) == 0)
+		machp()->isintelcpu = 1;
+	cpuid(1, 0, machp()->cpuinfo[1]);
 
 
 	/*
 	/*
 	 * Extended CPUID functions.
 	 * Extended CPUID functions.
 	 */
 	 */
 	if((eax = cpuid(0x80000000, 0, info)) >= 0x80000000)
 	if((eax = cpuid(0x80000000, 0, info)) >= 0x80000000)
-		m->ncpuinfoe = (eax & ~0x80000000) + 1;
+		machp()->ncpuinfoe = (eax & ~0x80000000) + 1;
 
 
 	/* is mnonitor supported? */
 	/* is mnonitor supported? */
-	if (m->cpuinfo[1][2] & 8) {
-		cpuid(5, 0, m->cpuinfo[2]);	
+	if (machp()->cpuinfo[1][2] & 8) {
+		cpuid(5, 0, machp()->cpuinfo[2]);
 		mwait = k10mwait;
 		mwait = k10mwait;
 	}
 	}
 
 
@@ -53,15 +53,15 @@ cpuidinit(void)
 static int
 static int
 cpuidinfo(uint32_t eax, uint32_t ecx, uint32_t info[4])
 cpuidinfo(uint32_t eax, uint32_t ecx, uint32_t info[4])
 {
 {
-	Mach *m = machp();
-	if(m->ncpuinfos == 0 && cpuidinit() == 0)
+	Proc *up = machp()->externup;
+	if(machp()->ncpuinfos == 0 && cpuidinit() == 0)
 		return 0;
 		return 0;
 
 
 	if(!(eax & 0x80000000)){
 	if(!(eax & 0x80000000)){
-		if(eax >= m->ncpuinfos)
+		if(eax >= machp()->ncpuinfos)
 			return 0;
 			return 0;
 	}
 	}
-	else if(eax >= (0x80000000|m->ncpuinfoe))
+	else if(eax >= (0x80000000|machp()->ncpuinfoe))
 		return 0;
 		return 0;
 
 
 	cpuid(eax, ecx, info);
 	cpuid(eax, ecx, info);
@@ -145,7 +145,7 @@ cpuidhz(uint32_t *info0, uint32_t *info1)
 				r = rdmsr(0x2a) & 0x1f;
 				r = rdmsr(0x2a) & 0x1f;
 			}
 			}
 			f = rdmsr(0xcd) & 0x07;
 			f = rdmsr(0xcd) & 0x07;
-//iprint("rdmsr Intel: %d\n", rdmsr(0x2a));	
+//iprint("rdmsr Intel: %d\n", rdmsr(0x2a));
 //iprint("Intel msr.lo %d\n", r);
 //iprint("Intel msr.lo %d\n", r);
 //iprint("Intel msr.hi %d\n", f);
 //iprint("Intel msr.hi %d\n", f);
 			switch(f){
 			switch(f){
@@ -231,22 +231,22 @@ cpuidhz(uint32_t *info0, uint32_t *info1)
 void
 void
 cpuiddump(void)
 cpuiddump(void)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	int i;
 	int i;
 	uint32_t info[4];
 	uint32_t info[4];
 
 
 	if(!DBGFLG)
 	if(!DBGFLG)
 		return;
 		return;
 
 
-	if(m->ncpuinfos == 0 && cpuidinit() == 0)
+	if(machp()->ncpuinfos == 0 && cpuidinit() == 0)
 		return;
 		return;
 
 
-	for(i = 0; i < m->ncpuinfos; i++){
+	for(i = 0; i < machp()->ncpuinfos; i++){
 		cpuid(i, 0, info);
 		cpuid(i, 0, info);
 		DBG("eax = %#8.8ux: %8.8ux %8.8ux %8.8ux %8.8ux\n",
 		DBG("eax = %#8.8ux: %8.8ux %8.8ux %8.8ux %8.8ux\n",
 			i, info[0], info[1], info[2], info[3]);
 			i, info[0], info[1], info[2], info[3]);
 	}
 	}
-	for(i = 0; i < m->ncpuinfoe; i++){
+	for(i = 0; i < machp()->ncpuinfoe; i++){
 		cpuid(0x80000000|i, 0, info);
 		cpuid(0x80000000|i, 0, info);
 		DBG("eax = %#8.8ux: %8.8ux %8.8ux %8.8ux %8.8ux\n",
 		DBG("eax = %#8.8ux: %8.8ux %8.8ux %8.8ux %8.8ux\n",
 			0x80000000|i, info[0], info[1], info[2], info[3]);
 			0x80000000|i, info[0], info[1], info[2], info[3]);
@@ -256,7 +256,7 @@ cpuiddump(void)
 int64_t
 int64_t
 archhz(void)
 archhz(void)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	int64_t hz;
 	int64_t hz;
 	uint32_t info0[4], info1[4];
 	uint32_t info0[4], info1[4];
 
 
@@ -271,7 +271,7 @@ archhz(void)
 	}
 	}
 
 
 	hz = cpuidhz(info0, info1);
 	hz = cpuidhz(info0, info1);
-	if(hz != 0 || m->machno != 0)
+	if(hz != 0 || machp()->machno != 0)
 		return hz;
 		return hz;
 
 
 	iprint("archhz, cpuidhz failed, going to i8254hz\n");
 	iprint("archhz, cpuidhz failed, going to i8254hz\n");
@@ -281,11 +281,11 @@ archhz(void)
 int
 int
 archmmu(void)
 archmmu(void)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	uint32_t info[4];
 	uint32_t info[4];
 
 
 	/*
 	/*
-	 * Should the check for m->machno != 0 be here
+	 * Should the check for machp()->machno != 0 be here
 	 * or in the caller (mmuinit)?
 	 * or in the caller (mmuinit)?
 	 *
 	 *
 	 * To do here:
 	 * To do here:
@@ -300,35 +300,35 @@ archmmu(void)
 	 */
 	 */
 	assert(PGSZ == 4*KiB);
 	assert(PGSZ == 4*KiB);
 
 
-	m->pgszlg2[0] = 12;
-	m->pgszmask[0] = (1<<12)-1;
-	m->pgsz[0] = 1<<12;
-	m->npgsz = 1;
-	if(m->ncpuinfos == 0 && cpuidinit() == 0)
+	machp()->pgszlg2[0] = 12;
+	machp()->pgszmask[0] = (1<<12)-1;
+	machp()->pgsz[0] = 1<<12;
+	machp()->npgsz = 1;
+	if(machp()->ncpuinfos == 0 && cpuidinit() == 0)
 		return 1;
 		return 1;
 
 
 	/*
 	/*
 	 * Check the Pse bit in function 1 DX for 2*MiB support;
 	 * Check the Pse bit in function 1 DX for 2*MiB support;
 	 * if false, only 4*KiB is available.
 	 * if false, only 4*KiB is available.
 	 */
 	 */
-	if(!(m->cpuinfo[1][3] & 0x00000008))
+	if(!(machp()->cpuinfo[1][3] & 0x00000008))
 		return 1;
 		return 1;
-	m->pgszlg2[1] = 21;
-	m->pgszmask[1] = (1<<21)-1;
-	m->pgsz[1] = 1<<21;
-	m->npgsz = 2;
+	machp()->pgszlg2[1] = 21;
+	machp()->pgszmask[1] = (1<<21)-1;
+	machp()->pgsz[1] = 1<<21;
+	machp()->npgsz = 2;
 
 
 	/*
 	/*
 	 * Check the Page1GB bit in function 0x80000001 DX for 1*GiB support.
 	 * Check the Page1GB bit in function 0x80000001 DX for 1*GiB support.
 	 */
 	 */
 	if(cpuidinfo(0x80000001, 0, info) && (info[3] & 0x04000000)){
 	if(cpuidinfo(0x80000001, 0, info) && (info[3] & 0x04000000)){
-		m->pgszlg2[2] = 30;
-		m->pgszmask[2] = (1<<30)-1;
-		m->pgsz[2] = 1<<30;
-		m->npgsz = 3;
+		machp()->pgszlg2[2] = 30;
+		machp()->pgszmask[2] = (1<<30)-1;
+		machp()->pgsz[2] = 1<<30;
+		machp()->npgsz = 3;
 	}
 	}
 
 
-	return m->npgsz;
+	return machp()->npgsz;
 }
 }
 
 
 static int
 static int
@@ -374,7 +374,7 @@ fmtW(Fmt *f)
 	return fmtprint(f, "%#ullx=0x[%ullx][%ullx][%ullx][%ullx][%ullx]", va,
 	return fmtprint(f, "%#ullx=0x[%ullx][%ullx][%ullx][%ullx][%ullx]", va,
 		PTLX(va, 3), PTLX(va, 2), PTLX(va, 1), PTLX(va, 0),
 		PTLX(va, 3), PTLX(va, 2), PTLX(va, 1), PTLX(va, 0),
 		va & ((1<<PGSHFT)-1));
 		va & ((1<<PGSHFT)-1));
-		
+
 }
 }
 
 
 void
 void
@@ -406,21 +406,21 @@ archidle(void)
 void
 void
 microdelay(int microsecs)
 microdelay(int microsecs)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	uint64_t r, t;
 	uint64_t r, t;
 
 
 	r = rdtsc();
 	r = rdtsc();
-	for(t = r + m->cpumhz*microsecs; r < t; r = rdtsc())
+	for(t = r + machp()->cpumhz*microsecs; r < t; r = rdtsc())
 		;
 		;
 }
 }
 
 
 void
 void
 millidelay(int millisecs)
 millidelay(int millisecs)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	uint64_t r, t;
 	uint64_t r, t;
 
 
 	r = rdtsc();
 	r = rdtsc();
-	for(t = r + m->cpumhz*1000ull*millisecs; r < t; r = rdtsc())
+	for(t = r + machp()->cpumhz*1000ull*millisecs; r < t; r = rdtsc())
 		;
 		;
 }
 }

+ 6 - 6
sys/src/9/k10/asm.c

@@ -317,7 +317,7 @@ asmwalkalloc(usize size)
 void
 void
 asmmeminit(void)
 asmmeminit(void)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	int i, l;
 	int i, l;
 	Asm* assem;
 	Asm* assem;
 	PTE *pte, *pml4;
 	PTE *pte, *pml4;
@@ -327,7 +327,7 @@ asmmeminit(void)
 	int cx;
 	int cx;
 #endif /* ConfCrap */
 #endif /* ConfCrap */
 
 
-	assert(!((sys->vmunmapped|sys->vmend) & m->pgszmask[1]));
+	assert(!((sys->vmunmapped|sys->vmend) & machp()->pgszmask[1]));
 
 
 	if((pa = mmuphysaddr(sys->vmunused)) == ~0)
 	if((pa = mmuphysaddr(sys->vmunused)) == ~0)
 		panic("asmmeminit 1");
 		panic("asmmeminit 1");
@@ -339,7 +339,7 @@ asmmeminit(void)
 
 
 	/* assume already 2MiB aligned*/
 	/* assume already 2MiB aligned*/
 	assert(ALIGNED(sys->vmunmapped, 2*MiB));
 	assert(ALIGNED(sys->vmunmapped, 2*MiB));
-	pml4 = UINT2PTR(m->pml4->va);
+	pml4 = UINT2PTR(machp()->pml4->va);
 	while(sys->vmunmapped < sys->vmend){
 	while(sys->vmunmapped < sys->vmend){
 		l = mmuwalk(pml4, sys->vmunmapped, 1, &pte, asmwalkalloc);
 		l = mmuwalk(pml4, sys->vmunmapped, 1, &pte, asmwalkalloc);
 		DBG("%#p l %d\n", sys->vmunmapped, l);
 		DBG("%#p l %d\n", sys->vmunmapped, l);
@@ -363,11 +363,11 @@ asmmeminit(void)
 		hi = assem->addr+assem->size;
 		hi = assem->addr+assem->size;
 		/* Convert a range into pages */
 		/* Convert a range into pages */
 		for(mem = lo; mem < hi; mem = nextmem){
 		for(mem = lo; mem < hi; mem = nextmem){
-			nextmem = (mem + PGLSZ(0)) & ~m->pgszmask[0];
+			nextmem = (mem + PGLSZ(0)) & ~machp()->pgszmask[0];
 
 
 			/* Try large pages first */
 			/* Try large pages first */
-			for(i = m->npgsz - 1; i >= 0; i--){
-				if((mem & m->pgszmask[i]) != 0)
+			for(i = machp()->npgsz - 1; i >= 0; i--){
+				if((mem & machp()->pgszmask[i]) != 0)
 					continue;
 					continue;
 				if(mem + PGLSZ(i) > hi)
 				if(mem + PGLSZ(i) > hi)
 					continue;
 					continue;

+ 1 - 1
sys/src/9/k10/backtrace.c

@@ -29,7 +29,7 @@ int backtrace_list(uintptr_t pc, uintptr_t fp, uintptr_t *pcs, size_t nr_slots)
 
 
 #if 0
 #if 0
 void backtrace_frame(uintptr_t eip, uintptr_t ebp)
 void backtrace_frame(uintptr_t eip, uintptr_t ebp)
-{ 
+{
 	char *func_name;
 	char *func_name;
 	#define MAX_BT_DEPTH 20
 	#define MAX_BT_DEPTH 20
 	uintptr_t pcs[MAX_BT_DEPTH];
 	uintptr_t pcs[MAX_BT_DEPTH];

+ 34 - 0
sys/src/9/k10/cga.c

@@ -124,6 +124,40 @@ cgaputc(int c)
 	cgacursor();
 	cgacursor();
 }
 }
 
 
+int
+cgaprint(int off, char *fmt, ...)
+{
+	va_list va;
+	char buf[128];
+	uint8_t *cga;
+	int i, n;
+
+	va_start(va, fmt);
+	n = vsnprint(buf, sizeof buf, fmt, va);
+	va_end(va);
+
+	cga = CGA;
+	for(i = 0; (2*(i+off))+1 < Cgasize && i < n; i++){
+		cga[2*(i+off)+0] = buf[i];
+		cga[2*(i+off)+1] = Attr;
+	}
+	return n;
+}
+
+int
+cgaclearln(int off, int c)
+{
+	uint8_t  *cga;
+	int i;
+
+	cga = CGA;
+	for(i = off; (2*i)+1 < Cgasize && i%80 != 0; i++){
+		cga[2*i+0] = c;
+		cga[2*i+1] = Attr;
+	}
+	return i-off;
+}
+
 /*
 /*
  * debug
  * debug
  */
  */

+ 3 - 3
sys/src/9/k10/dat.h

@@ -1,4 +1,4 @@
-/* 
+/*
  * This file is part of the UCB release of Plan 9. It is subject to the license
  * This file is part of the UCB release of Plan 9. It is subject to the license
  * terms in the LICENSE file found in the top-level directory of this
  * terms in the LICENSE file found in the top-level directory of this
  * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
@@ -162,7 +162,7 @@ struct MFPU
 struct NIX
 struct NIX
 {
 {
 	ICC*	icc;			/* inter-core call */
 	ICC*	icc;			/* inter-core call */
-	int	nixtype;	
+	int	nixtype;
 };
 };
 
 
 /*
 /*
@@ -422,7 +422,7 @@ extern char*rolename[];
 /*
 /*
  * Horrid.
  * Horrid.
  */
  */
-// HARVEY: TODO: bring this back, it's actually nice. Or do something better. 
+// HARVEY: TODO: bring this back, it's actually nice. Or do something better.
 // Talk to Ron before you condemn it.
 // Talk to Ron before you condemn it.
 
 
 #ifdef _DBGC_
 #ifdef _DBGC_

+ 10 - 9
sys/src/9/k10/devacpi.c

@@ -273,21 +273,21 @@ cfgset32(uintptr_t p, uint32_t v, void* r)
 	pcicfgw32(&d, p, v);
 	pcicfgw32(&d, p, v);
 }
 }
 
 
-static Regio memio = 
+static Regio memio =
 {
 {
 	nil,
 	nil,
 	mget8, mset8, mget16, mset16,
 	mget8, mset8, mget16, mset16,
 	mget32, mset32, mget64, mset64
 	mget32, mset32, mget64, mset64
 };
 };
 
 
-static Regio ioio = 
+static Regio ioio =
 {
 {
 	nil,
 	nil,
 	ioget8, ioset8, ioget16, ioset16,
 	ioget8, ioset8, ioget16, ioset16,
 	ioget32, ioset32, nil, nil
 	ioget32, ioset32, nil, nil
 };
 };
 
 
-static Regio cfgio = 
+static Regio cfgio =
 {
 {
 	nil,
 	nil,
 	cfgget8, cfgset8, cfgget16, cfgset16,
 	cfgget8, cfgset8, cfgget16, cfgset16,
@@ -777,7 +777,7 @@ static void
 dumpslit(Slit *sl)
 dumpslit(Slit *sl)
 {
 {
 	int i;
 	int i;
-	
+
 	DBG("acpi slit:\n");
 	DBG("acpi slit:\n");
 	for(i = 0; i < sl->rowlen*sl->rowlen; i++){
 	for(i = 0; i < sl->rowlen*sl->rowlen; i++){
 		DBG("slit: %ux\n", sl->e[i/sl->rowlen][i%sl->rowlen].dist);
 		DBG("slit: %ux\n", sl->e[i/sl->rowlen][i%sl->rowlen].dist);
@@ -819,7 +819,7 @@ acpislit(uint8_t *p, int len)
 	dumpslit(slit);
 	dumpslit(slit);
 	for(i = 0; i < slit->rowlen; i++)
 	for(i = 0; i < slit->rowlen; i++)
 		qsort(slit->e[i], slit->rowlen, sizeof(slit->e[0][0]), cmpslitent);
 		qsort(slit->e[i], slit->rowlen, sizeof(slit->e[0][0]), cmpslitent);
-	
+
 	dumpslit(slit);
 	dumpslit(slit);
 	return nil;	/* can be unmapped once parsed */
 	return nil;	/* can be unmapped once parsed */
 }
 }
@@ -846,7 +846,8 @@ acpimblocksize(uintmem addr, int *dom)
 int
 int
 corecolor(int core)
 corecolor(int core)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
+	Mach *m;
 	Srat *sl;
 	Srat *sl;
 	static int colors[32];
 	static int colors[32];
 
 
@@ -1455,7 +1456,7 @@ acpiintr(Ureg* ureg, void *j)
 	if(sts&1)
 	if(sts&1)
 		print("power button\n");
 		print("power button\n");
 	// XXX serve other interrupts here.
 	// XXX serve other interrupts here.
-	setpm1sts(sts);	
+	setpm1sts(sts);
 }
 }
 
 
 static void
 static void
@@ -1615,7 +1616,7 @@ acpiread(Chan *c, void *a, int32_t n, int64_t off)
 				}
 				}
 				s = ns;
 				s = ns;
 			}
 			}
-					
+
 		}
 		}
 		return readstr(off, a, n, ttext);
 		return readstr(off, a, n, ttext);
 	case Qio:
 	case Qio:
@@ -1630,7 +1631,7 @@ acpiread(Chan *c, void *a, int32_t n, int64_t off)
 static int32_t
 static int32_t
 acpiwrite(Chan *c, void *a, int32_t n, int64_t off)
 acpiwrite(Chan *c, void *a, int32_t n, int64_t off)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	Cmdtab *ct;
 	Cmdtab *ct;
 	Cmdbuf *cb;
 	Cmdbuf *cb;
 	Reg *r;
 	Reg *r;

+ 13 - 12
sys/src/9/k10/devarch.c

@@ -297,7 +297,7 @@ iounused(int start, int end)
 	for(map = iomap.map; map; map = map->next){
 	for(map = iomap.map; map; map = map->next){
 		if(start >= map->start && start < map->end
 		if(start >= map->start && start < map->end
 		|| start <= map->start && end > map->start)
 		|| start <= map->start && end > map->start)
-			return 0; 
+			return 0;
 	}
 	}
 	return 1;
 	return 1;
 }
 }
@@ -435,9 +435,10 @@ archread(Chan *c, void *a, int32_t n, int64_t offset)
 				pa = mp->addr;
 				pa = mp->addr;
 				size = mp->size;
 				size = mp->size;
 			}
 			}
+		}
 #endif
 #endif
 		error("Not yet");
 		error("Not yet");
-	
+
 		break;
 		break;
 	}
 	}
 
 
@@ -526,19 +527,19 @@ void (*coherence)(void) = mfence;
 static int32_t
 static int32_t
 cputyperead(Chan* c, void *a, int32_t n, int64_t off)
 cputyperead(Chan* c, void *a, int32_t n, int64_t off)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	char buf[512], *s, *e;
 	char buf[512], *s, *e;
 	int i, k;
 	int i, k;
 
 
 	e = buf+sizeof buf;
 	e = buf+sizeof buf;
-	s = seprint(buf, e, "%s %ud\n", "AMD64", m->cpumhz);
-	k = m->ncpuinfoe - m->ncpuinfos;
+	s = seprint(buf, e, "%s %ud\n", "AMD64", machp()->cpumhz);
+	k = machp()->ncpuinfoe - machp()->ncpuinfos;
 	if(k > 4)
 	if(k > 4)
 		k = 4;
 		k = 4;
 	for(i = 0; i < k; i++)
 	for(i = 0; i < k; i++)
 		s = seprint(s, e, "%#8.8ux %#8.8ux %#8.8ux %#8.8ux\n",
 		s = seprint(s, e, "%#8.8ux %#8.8ux %#8.8ux %#8.8ux\n",
-			m->cpuinfo[i][0], m->cpuinfo[i][1],
-			m->cpuinfo[i][2], m->cpuinfo[i][3]);
+			machp()->cpuinfo[i][0], machp()->cpuinfo[i][1],
+			machp()->cpuinfo[i][2], machp()->cpuinfo[i][3]);
 	return readstr(off, a, n, buf);
 	return readstr(off, a, n, buf);
 }
 }
 
 
@@ -577,9 +578,9 @@ archreset(void)
 uint64_t
 uint64_t
 fastticks(uint64_t* hz)
 fastticks(uint64_t* hz)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	if(hz != nil)
 	if(hz != nil)
-		*hz = m->cpuhz;
+		*hz = machp()->cpuhz;
 	return rdtsc();
 	return rdtsc();
 }
 }
 
 
@@ -609,17 +610,17 @@ cycles(uint64_t* t)
 void
 void
 delay(int millisecs)
 delay(int millisecs)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	uint64_t r, t;
 	uint64_t r, t;
 
 
 	if(millisecs <= 0)
 	if(millisecs <= 0)
 		millisecs = 1;
 		millisecs = 1;
 	r = rdtsc();
 	r = rdtsc();
-	for(t = r + m->cpumhz*1000ull*millisecs; r < t; r = rdtsc())
+	for(t = r + machp()->cpumhz*1000ull*millisecs; r < t; r = rdtsc())
 		;
 		;
 }
 }
 
 
-/*  
+/*
  *  performance measurement ticks.  must be low overhead.
  *  performance measurement ticks.  must be low overhead.
  *  doesn't have to count over a second.
  *  doesn't have to count over a second.
  */
  */

+ 18 - 18
sys/src/9/k10/devusb.c

@@ -276,7 +276,7 @@ addhcitype(char* t, int (*r)(Hci*))
 static char*
 static char*
 seprintep(char *s, char *se, Ep *ep, int all)
 seprintep(char *s, char *se, Ep *ep, int all)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	static char* dsnames[] = { "config", "enabled", "detached", "reset" };
 	static char* dsnames[] = { "config", "enabled", "detached", "reset" };
 	Udev *d;
 	Udev *d;
 	int i;
 	int i;
@@ -410,7 +410,7 @@ putep(Ep *ep)
 static void
 static void
 dumpeps(void)
 dumpeps(void)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	int i;
 	int i;
 	static char buf[512];
 	static char buf[512];
 	char *s;
 	char *s;
@@ -547,7 +547,7 @@ epdataperm(int mode)
 static int
 static int
 usbgen(Chan *c, char *l, Dirtab *d, int n, int s, Dir *dp)
 usbgen(Chan *c, char *l, Dirtab *d, int n, int s, Dir *dp)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	Qid q;
 	Qid q;
 	Dirtab *dir;
 	Dirtab *dir;
 	int perm;
 	int perm;
@@ -619,12 +619,12 @@ usbgen(Chan *c, char *l, Dirtab *d, int n, int s, Dir *dp)
 			putep(ep);
 			putep(ep);
 			nexterror();
 			nexterror();
 		}
 		}
-		se = m->externup->genbuf+sizeof(m->externup->genbuf);
-		seprint(m->externup->genbuf, se, "ep%d.%d", ep->dev->nb, ep->nb);
+		se = up->genbuf+sizeof(up->genbuf);
+		seprint(up->genbuf, se, "ep%d.%d", ep->dev->nb, ep->nb);
 		mkqid(&q, Qep0dir+4*s, 0, QTDIR);
 		mkqid(&q, Qep0dir+4*s, 0, QTDIR);
 		putep(ep);
 		putep(ep);
 		poperror();
 		poperror();
-		devdir(c, q, m->externup->genbuf, 0, eve, 0755, dp);
+		devdir(c, q, up->genbuf, 0, eve, 0755, dp);
 		if(0)ddprint("ok\n");
 		if(0)ddprint("ok\n");
 		return 1;
 		return 1;
 
 
@@ -835,7 +835,7 @@ usbload(int speed, int maxpkt)
 static Chan*
 static Chan*
 usbopen(Chan *c, int omode)
 usbopen(Chan *c, int omode)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	int q;
 	int q;
 	Ep *ep;
 	Ep *ep;
 	int mode;
 	int mode;
@@ -892,7 +892,7 @@ usbopen(Chan *c, int omode)
 static void
 static void
 epclose(Ep *ep)
 epclose(Ep *ep)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	qlock(ep);
 	qlock(ep);
 	if(waserror()){
 	if(waserror()){
 		qunlock(ep);
 		qunlock(ep);
@@ -909,7 +909,7 @@ epclose(Ep *ep)
 static void
 static void
 usbclose(Chan *c)
 usbclose(Chan *c)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	int q;
 	int q;
 	Ep *ep;
 	Ep *ep;
 
 
@@ -939,7 +939,7 @@ usbclose(Chan *c)
 static int32_t
 static int32_t
 ctlread(Chan *c, void *a, int32_t n, int64_t offset)
 ctlread(Chan *c, void *a, int32_t n, int64_t offset)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	int q;
 	int q;
 	char *s;
 	char *s;
 	char *us;
 	char *us;
@@ -1056,7 +1056,7 @@ rhubwrite(Ep *ep, void *a, int32_t n)
 static int32_t
 static int32_t
 usbread(Chan *c, void *a, int32_t n, int64_t offset)
 usbread(Chan *c, void *a, int32_t n, int64_t offset)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	int q;
 	int q;
 	Ep *ep;
 	Ep *ep;
 	int nr;
 	int nr;
@@ -1134,7 +1134,7 @@ setmaxpkt(Ep *ep, char* s)
 static int32_t
 static int32_t
 epctl(Ep *ep, Chan *c, void *a, int32_t n)
 epctl(Ep *ep, Chan *c, void *a, int32_t n)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	int i, l, mode, nb, tt;
 	int i, l, mode, nb, tt;
 	char *b, *s;
 	char *b, *s;
 	Cmdbuf *cb;
 	Cmdbuf *cb;
@@ -1190,9 +1190,9 @@ epctl(Ep *ep, Chan *c, void *a, int32_t n)
 		/* next read request will read
 		/* next read request will read
 		 * the name for the new endpoint
 		 * the name for the new endpoint
 		 */
 		 */
-		l = sizeof(m->externup->genbuf);
-		snprint(m->externup->genbuf, l, "ep%d.%d", nep->dev->nb, nep->nb);
-		kstrdup((char**)&c->aux, m->externup->genbuf);
+		l = sizeof(up->genbuf);
+		snprint(up->genbuf, l, "ep%d.%d", nep->dev->nb, nep->nb);
+		kstrdup((char**)&c->aux, up->genbuf);
 		break;
 		break;
 	case CMhub:
 	case CMhub:
 		deprint("usb epctl %s\n", cb->f[0]);
 		deprint("usb epctl %s\n", cb->f[0]);
@@ -1348,7 +1348,7 @@ epctl(Ep *ep, Chan *c, void *a, int32_t n)
 static int32_t
 static int32_t
 usbctl(void *a, int32_t n)
 usbctl(void *a, int32_t n)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	Cmdtab *ct;
 	Cmdtab *ct;
 	Cmdbuf *cb;
 	Cmdbuf *cb;
 	Ep *ep;
 	Ep *ep;
@@ -1388,7 +1388,7 @@ usbctl(void *a, int32_t n)
 static int32_t
 static int32_t
 ctlwrite(Chan *c, void *a, int32_t n)
 ctlwrite(Chan *c, void *a, int32_t n)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	int q;
 	int q;
 	Ep *ep;
 	Ep *ep;
 
 
@@ -1420,7 +1420,7 @@ ctlwrite(Chan *c, void *a, int32_t n)
 static int32_t
 static int32_t
 usbwrite(Chan *c, void *a, int32_t n, int64_t off)
 usbwrite(Chan *c, void *a, int32_t n, int64_t off)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	int nr, q;
 	int nr, q;
 	Ep *ep;
 	Ep *ep;
 
 

+ 10 - 10
sys/src/9/k10/entry.S

@@ -6,7 +6,7 @@
 
 
 // It gets REALLY ugly to try  to link this at some low address and then have the rest of the
 // It gets REALLY ugly to try  to link this at some low address and then have the rest of the
 // kernel linked high. Really, really ugly. And that defines any attempt to load at a randome
 // kernel linked high. Really, really ugly. And that defines any attempt to load at a randome
-// address. So, you have to learn to write position independent code here. 
+// address. So, you have to learn to write position independent code here.
 // It will make you stronger. Assuming you survive the training.
 // It will make you stronger. Assuming you survive the training.
 .code32
 .code32
 
 
@@ -90,7 +90,7 @@ gdt_end:
  *	cache will be reloaded.
  *	cache will be reloaded.
  */
  */
 	.align	4
 	.align	4
-1: 
+1:
 //	jmp 1b
 //	jmp 1b
 .globl protected_start
 .globl protected_start
 protected_start:
 protected_start:
@@ -316,7 +316,7 @@ _start64v:
 // Don't undo this until all APs are started. Then we don't need to bother
 // Don't undo this until all APs are started. Then we don't need to bother
 // having the APs remap it. Save work.
 // having the APs remap it. Save work.
 	// OK, this part is called "we climbed up the tree on a ladder, now pull
 	// OK, this part is called "we climbed up the tree on a ladder, now pull
-	// the ladder up after us.". We remove the identity mapping. 
+	// the ladder up after us.". We remove the identity mapping.
 _zap0pml4:
 _zap0pml4:
 	cmpq	$PML4O(KZERO), %rdx		/* KZER0 & 0x0000ff8000000000 */
 	cmpq	$PML4O(KZERO), %rdx		/* KZER0 & 0x0000ff8000000000 */
 	JE	_zap0pdp
 	JE	_zap0pdp
@@ -340,7 +340,7 @@ _zap0done:
 
 
 	addq	$(2*PTSZ+4*KiB), %rax		/* PD+PT+vsvm */
 	addq	$(2*PTSZ+4*KiB), %rax		/* PD+PT+vsvm */
 	movq	%rax, entrym
 	movq	%rax, entrym
-	movq	$0, (%rax) 				/* m->machno = 0 */
+	movq	$0, (%rax) 				/* machp()->machno = 0 */
 
 
 	PUSHQ	%rdx				/* clear flags */
 	PUSHQ	%rdx				/* clear flags */
 	POPFQ
 	POPFQ
@@ -437,7 +437,7 @@ gdtptr78:
 	.quad	0x0020980000000000		/* Long mode CS */
 	.quad	0x0020980000000000		/* Long mode CS */
 gdt78_end:
 gdt78_end:
 .global e1978
 .global e1978
-e1978:	
+e1978:
 
 
 /*
 /*
  * Protected mode. Welcome to 1982.
  * Protected mode. Welcome to 1982.
@@ -467,7 +467,7 @@ e1978:
 #define PDO(v)		((PTLX((v), 1))<<3)
 #define PDO(v)		((PTLX((v), 1))<<3)
 #define PTO(v)		((PTLX((v), 0))<<3)
 #define PTO(v)		((PTLX((v), 0))<<3)
 
 
-_approtected:	
+_approtected:
 	MOVL	$0xfee00000, %ebp	/* apicbase */
 	MOVL	$0xfee00000, %ebp	/* apicbase */
 	MOVL	0x20(%eBP), %eBP	/* Id */
 	MOVL	0x20(%eBP), %eBP	/* Id */
 	SHRL	$24, %eBP		/* becomes RARG later */
 	SHRL	$24, %eBP		/* becomes RARG later */
@@ -504,7 +504,7 @@ _approtected:
  *	make an inter-segment jump to the Long Mode code.
  *	make an inter-segment jump to the Long Mode code.
  * It's all in 32-bit mode until the jump is made.
  * It's all in 32-bit mode until the jump is made.
  */
  */
-aplme:	
+aplme:
 	MOVL	%CR4, %eAX
 	MOVL	%CR4, %eAX
 	ANDL	$~Pse, %eAX			/* Page Size */
 	ANDL	$~Pse, %eAX			/* Page Size */
 	ORL	$(Pge|Pae), %eAX			/* Page Global, Phys. Address */
 	ORL	$(Pge|Pae), %eAX			/* Page Global, Phys. Address */
@@ -532,12 +532,12 @@ aplme:
  */
  */
 .code64
 .code64
 
 
-_apidentity:	
+_apidentity:
 	MOVQ	$_apstart64v, %rAX
 	MOVQ	$_apstart64v, %rAX
 	JMP	*%rAX
 	JMP	*%rAX
 
 
 .section .text
 .section .text
-_apstart64v:	
+_apstart64v:
 	MOVQ	$_gdtptr64v, %rAX
 	MOVQ	$_gdtptr64v, %rAX
 
 
 	lgdt	(%rax)
 	lgdt	(%rax)
@@ -554,7 +554,7 @@ _apstart64v:
 
 
 	MOVQ	%rAX, %rSP			/* set stack */
 	MOVQ	%rAX, %rSP			/* set stack */
 
 
-	// DON'T ZAP. 
+	// DON'T ZAP.
 	// DO IT LATER.
 	// DO IT LATER.
 	//MOVQ	%rDX, PML4O(0)(%rAX)		/* zap identity map */
 	//MOVQ	%rDX, PML4O(0)(%rAX)		/* zap identity map */
 
 

+ 1 - 1
sys/src/9/k10/ether8139.c

@@ -754,7 +754,7 @@ rtl8139match(Ether* edev, int id)
 
 
 		if(pcigetpms(p) > 0){
 		if(pcigetpms(p) > 0){
 			pcisetpms(p, 0);
 			pcisetpms(p, 0);
-	
+
 			for(i = 0; i < 6; i++)
 			for(i = 0; i < 6; i++)
 				pcicfgw32(p, PciBAR0+i*4, p->mem[i].bar);
 				pcicfgw32(p, PciBAR0+i*4, p->mem[i].bar);
 			pcicfgw8(p, PciINTL, p->intl);
 			pcicfgw8(p, PciINTL, p->intl);

+ 7 - 7
sys/src/9/k10/ether82563.c

@@ -8,7 +8,7 @@
  */
  */
 
 
  /*
  /*
- * Intel 8256[367], 8257[1-9], 82573[ev], 
+ * Intel 8256[367], 8257[1-9], 82573[ev],
  * 82575eb, 82576, 82577, 82579, 8258[03]
  * 82575eb, 82576, 82577, 82579, 8258[03]
  *	Gigabit Ethernet PCI-Express Controllers
  *	Gigabit Ethernet PCI-Express Controllers
  * Coraid EtherDrive® hba
  * Coraid EtherDrive® hba
@@ -488,7 +488,7 @@ enum {
 	i82575,
 	i82575,
 	i82576,
 	i82576,
 	i82577,
 	i82577,
-	i82577m,	
+	i82577m,
 	i82578,
 	i82578,
 	i82578m,
 	i82578m,
 	i82579,
 	i82579,
@@ -879,7 +879,7 @@ i82563txinit(Ctlr* ctlr)
 	csr32w(ctlr, Tdt, 0);
 	csr32w(ctlr, Tdt, 0);
 	for(i = 0; i < ctlr->ntd; i++){
 	for(i = 0; i < ctlr->ntd; i++){
 		if((bp = ctlr->tb[i]) != nil){
 		if((bp = ctlr->tb[i]) != nil){
-			ctlr->tb[i] = nil;	
+			ctlr->tb[i] = nil;
 			freeb(bp);
 			freeb(bp);
 		}
 		}
 		memset(&ctlr->tdba[i], 0, sizeof(Td));
 		memset(&ctlr->tdba[i], 0, sizeof(Td));
@@ -1423,7 +1423,7 @@ i82563tproc(void *v)
 static void
 static void
 i82563attach(Ether* edev)
 i82563attach(Ether* edev)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	char name[KNAMELEN];
 	char name[KNAMELEN];
 	Block *bp;
 	Block *bp;
 	Ctlr *ctlr;
 	Ctlr *ctlr;
@@ -1809,7 +1809,7 @@ static Cmdtab i82563ctlmsg[] = {
 static int32_t
 static int32_t
 i82563ctl(Ether *edev, void *buf, int32_t n)
 i82563ctl(Ether *edev, void *buf, int32_t n)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	char *p;
 	char *p;
 	uint32_t v;
 	uint32_t v;
 	Ctlr *ctlr;
 	Ctlr *ctlr;
@@ -1923,7 +1923,7 @@ didtype(int d)
 	case 0x150f:		/* fiber */
 	case 0x150f:		/* fiber */
 	case 0x1510:		/* backplane */
 	case 0x1510:		/* backplane */
 	case 0x1511:		/* sfp */
 	case 0x1511:		/* sfp */
-	case 0x1516:		
+	case 0x1516:
 		return i82580;
 		return i82580;
 	case 0x1506:		/* v */
 	case 0x1506:		/* v */
 		return i82583;
 		return i82583;
@@ -1974,7 +1974,7 @@ i82563pci(void)
 		if((type = didtype(p->did)) == -1)
 		if((type = didtype(p->did)) == -1)
 			continue;
 			continue;
 		ctlr = malloc(sizeof(Ctlr));
 		ctlr = malloc(sizeof(Ctlr));
-		if(ctlr == nil) 
+		if(ctlr == nil)
 			error(Enomem);
 			error(Enomem);
 		ctlr->type = type;
 		ctlr->type = type;
 		ctlr->pcidev = p;
 		ctlr->pcidev = p;

+ 1 - 1
sys/src/9/k10/etherif.h

@@ -1,4 +1,4 @@
-/* 
+/*
  * This file is part of the UCB release of Plan 9. It is subject to the license
  * This file is part of the UCB release of Plan 9. It is subject to the license
  * terms in the LICENSE file found in the top-level directory of this
  * terms in the LICENSE file found in the top-level directory of this
  * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No

+ 3 - 1
sys/src/9/k10/fns.h

@@ -35,6 +35,8 @@ void	noerrorsleft(void);
 void	archinit(void);
 void	archinit(void);
 void	archreset(void);
 void	archreset(void);
 int64_t	archhz(void);
 int64_t	archhz(void);
+int	cgaprint(int off, char *fmt, ...);
+int	cgaclearln(int off, int c);
 void	cgaconsputs(char*, int);
 void	cgaconsputs(char*, int);
 void	cgainit(void);
 void	cgainit(void);
 void	cgapost(int);
 void	cgapost(int);
@@ -204,7 +206,7 @@ void	acsyscallentry(void);
 void	syscallreturn(void);
 void	syscallreturn(void);
 void	sysrforkret(void);
 void	sysrforkret(void);
 
 
-#define	waserror()	(m->externup->nerrlab++, setlabel(&m->externup->errlab[m->externup->nerrlab-1]))
+#define	waserror()	(machp()->externup->nerrlab++, setlabel(&machp()->externup->errlab[machp()->externup->nerrlab-1]))
 
 
 #define	dcflush(a, b)
 #define	dcflush(a, b)
 
 

+ 50 - 50
sys/src/9/k10/fpu.c

@@ -120,7 +120,7 @@ fpudevprocio(Proc* proc, void* a, int32_t n, uintptr_t offset, int write)
 void
 void
 fpunotify(Ureg* u)
 fpunotify(Ureg* u)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	/*
 	/*
 	 * Called when a note is about to be delivered to a
 	 * Called when a note is about to be delivered to a
 	 * user process, usually at the end of a system call.
 	 * user process, usually at the end of a system call.
@@ -128,55 +128,55 @@ fpunotify(Ureg* u)
 	 * the state is marked (after saving if necessary) and
 	 * the state is marked (after saving if necessary) and
 	 * checked in the Device Not Available handler.
 	 * checked in the Device Not Available handler.
 	 */
 	 */
-	if(m->externup->fpustate == Busy){
-		_fxsave(m->externup->fpusave);
+	if(up->fpustate == Busy){
+		_fxsave(up->fpusave);
 		_stts();
 		_stts();
-		m->externup->fpustate = Idle;
+		up->fpustate = Idle;
 	}
 	}
-	m->externup->fpustate |= Hold;
+	up->fpustate |= Hold;
 }
 }
 
 
 void
 void
 fpunoted(void)
 fpunoted(void)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	/*
 	/*
 	 * Called from sysnoted() via the machine-dependent
 	 * Called from sysnoted() via the machine-dependent
 	 * noted() routine.
 	 * noted() routine.
 	 * Clear the flag set above in fpunotify().
 	 * Clear the flag set above in fpunotify().
 	 */
 	 */
-	m->externup->fpustate &= ~Hold;
+	up->fpustate &= ~Hold;
 }
 }
 
 
 void
 void
 fpusysrfork(Ureg* u)
 fpusysrfork(Ureg* u)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	/*
 	/*
 	 * Called early in the non-interruptible path of
 	 * Called early in the non-interruptible path of
 	 * sysrfork() via the machine-dependent syscall() routine.
 	 * sysrfork() via the machine-dependent syscall() routine.
 	 * Save the state so that it can be easily copied
 	 * Save the state so that it can be easily copied
 	 * to the child process later.
 	 * to the child process later.
 	 */
 	 */
-	if(m->externup->fpustate != Busy)
+	if(up->fpustate != Busy)
 		return;
 		return;
 
 
-	_fxsave(m->externup->fpusave);
+	_fxsave(up->fpusave);
 	_stts();
 	_stts();
-	m->externup->fpustate = Idle;
+	up->fpustate = Idle;
 }
 }
 
 
 void
 void
 fpusysrforkchild(Proc* child, Proc* parent)
 fpusysrforkchild(Proc* child, Proc* parent)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	/*
 	/*
 	 * Called later in sysrfork() via the machine-dependent
 	 * Called later in sysrfork() via the machine-dependent
 	 * sysrforkchild() routine.
 	 * sysrforkchild() routine.
 	 * Copy the parent FPU state to the child.
 	 * Copy the parent FPU state to the child.
 	 */
 	 */
 	child->fpustate = parent->fpustate;
 	child->fpustate = parent->fpustate;
-	child->fpusave = (void*)((PTR2UINT(m->externup->fxsave) + 15) & ~15);
+	child->fpusave = (void*)((PTR2UINT(up->fxsave) + 15) & ~15);
 	if(child->fpustate == Init)
 	if(child->fpustate == Init)
 		return;
 		return;
 
 
@@ -212,7 +212,7 @@ fpuprocsave(Proc* p)
 	/*
 	/*
 	 * Save the FPU state without handling pending
 	 * Save the FPU state without handling pending
 	 * unmasked exceptions and disable. Postnote() can't
 	 * unmasked exceptions and disable. Postnote() can't
-	 * be called here as sleep() already has m->externup->rlock,
+	 * be called here as sleep() already has up->rlock,
 	 * so the handling of pending exceptions is delayed
 	 * so the handling of pending exceptions is delayed
 	 * until the process runs again and generates a
 	 * until the process runs again and generates a
 	 * Device Not Available exception fault to activate
 	 * Device Not Available exception fault to activate
@@ -266,7 +266,7 @@ acfpusysprocsetup(Proc *p)
 static char*
 static char*
 fpunote(void)
 fpunote(void)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	uint16_t fsw;
 	uint16_t fsw;
 	Fxsave *fpusave;
 	Fxsave *fpusave;
 	char *cm;
 	char *cm;
@@ -276,7 +276,7 @@ fpunote(void)
 	 * cleared or there's no way to tell if the exception was an
 	 * cleared or there's no way to tell if the exception was an
 	 * invalid operation or a stack fault.
 	 * invalid operation or a stack fault.
 	 */
 	 */
-	fpusave = m->externup->fpusave;
+	fpusave = up->fpusave;
 	fsw = (fpusave->fsw & ~fpusave->fcw) & (Sff|P|U|O|Z|D|I);
 	fsw = (fpusave->fsw & ~fpusave->fcw) & (Sff|P|U|O|Z|D|I);
 	if(fsw & I){
 	if(fsw & I){
 		if(fsw & Sff){
 		if(fsw & Sff){
@@ -301,16 +301,16 @@ fpunote(void)
 	else
 	else
 		cm =  "Unknown";
 		cm =  "Unknown";
 
 
-	snprint(m->externup->genbuf, sizeof(m->externup->genbuf),
+	snprint(up->genbuf, sizeof(up->genbuf),
 		"sys: fp: %s Exception ipo=%#llux fsw=%#ux",
 		"sys: fp: %s Exception ipo=%#llux fsw=%#ux",
 		cm, fpusave->rip, fsw);
 		cm, fpusave->rip, fsw);
-	return m->externup->genbuf;
+	return up->genbuf;
 }
 }
 
 
 char*
 char*
 xfpuxf(Ureg* ureg, void* v)
 xfpuxf(Ureg* ureg, void* v)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	uint32_t mxcsr;
 	uint32_t mxcsr;
 	Fxsave *fpusave;
 	Fxsave *fpusave;
 	char *cm;
 	char *cm;
@@ -322,10 +322,10 @@ xfpuxf(Ureg* ureg, void* v)
 	/*
 	/*
 	 * Save FPU state to check out the error.
 	 * Save FPU state to check out the error.
 	 */
 	 */
-	fpusave = m->externup->fpusave;
+	fpusave = up->fpusave;
 	_fxsave(fpusave);
 	_fxsave(fpusave);
 	_stts();
 	_stts();
-	m->externup->fpustate = Idle;
+	up->fpustate = Idle;
 
 
 	if(ureg->ip & KZERO)
 	if(ureg->ip & KZERO)
 		panic("#MF: ip=%#p", ureg->ip);
 		panic("#MF: ip=%#p", ureg->ip);
@@ -352,20 +352,20 @@ xfpuxf(Ureg* ureg, void* v)
 	else
 	else
 		cm =  "Unknown";
 		cm =  "Unknown";
 
 
-	snprint(m->externup->genbuf, sizeof(m->externup->genbuf),
+	snprint(up->genbuf, sizeof(up->genbuf),
 		"sys: fp: %s Exception mxcsr=%#ux", cm, mxcsr);
 		"sys: fp: %s Exception mxcsr=%#ux", cm, mxcsr);
-	return m->externup->genbuf;
+	return up->genbuf;
 }
 }
 
 
 void
 void
 fpuxf(Ureg *ureg, void *p)
 fpuxf(Ureg *ureg, void *p)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	char *n;
 	char *n;
 
 
 	n = xfpuxf(ureg, p);
 	n = xfpuxf(ureg, p);
 	if(n != nil)
 	if(n != nil)
-		postnote(m->externup, 1, n, NDebug);
+		postnote(up, 1, n, NDebug);
 }
 }
 
 
 char*
 char*
@@ -377,7 +377,7 @@ acfpuxf(Ureg *ureg, void *p)
 static char*
 static char*
 xfpumf(Ureg* ureg, void* v)
 xfpumf(Ureg* ureg, void* v)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	Fxsave *fpusave;
 	Fxsave *fpusave;
 
 
 	/*
 	/*
@@ -387,10 +387,10 @@ xfpumf(Ureg* ureg, void* v)
 	/*
 	/*
 	 * Save FPU state to check out the error.
 	 * Save FPU state to check out the error.
 	 */
 	 */
-	fpusave = m->externup->fpusave;
+	fpusave = up->fpusave;
 	_fxsave(fpusave);
 	_fxsave(fpusave);
 	_stts();
 	_stts();
-	m->externup->fpustate = Idle;
+	up->fpustate = Idle;
 
 
 	if(ureg->ip & KZERO)
 	if(ureg->ip & KZERO)
 		panic("#MF: ip=%#p rip=%#p", ureg->ip, fpusave->rip);
 		panic("#MF: ip=%#p rip=%#p", ureg->ip, fpusave->rip);
@@ -414,12 +414,12 @@ xfpumf(Ureg* ureg, void* v)
 void
 void
 fpumf(Ureg *ureg, void *p)
 fpumf(Ureg *ureg, void *p)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	char *n;
 	char *n;
 
 
 	n = xfpumf(ureg, p);
 	n = xfpumf(ureg, p);
 	if(n != nil)
 	if(n != nil)
-		postnote(m->externup, 1, n, NDebug);
+		postnote(up, 1, n, NDebug);
 }
 }
 
 
 char*
 char*
@@ -431,30 +431,30 @@ acfpumf(Ureg *ureg, void *p)
 static char*
 static char*
 xfpunm(Ureg* ureg, void* v)
 xfpunm(Ureg* ureg, void* v)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	Fxsave *fpusave;
 	Fxsave *fpusave;
 
 
 	/*
 	/*
 	 * #NM - Device Not Available (Vector 7).
 	 * #NM - Device Not Available (Vector 7).
 	 */
 	 */
-	if(m->externup == nil)
+	if(up == nil)
 		panic("#NM: fpu in kernel: ip %#p\n", ureg->ip);
 		panic("#NM: fpu in kernel: ip %#p\n", ureg->ip);
 
 
 	/*
 	/*
 	 * Someone tried to use the FPU in a note handler.
 	 * Someone tried to use the FPU in a note handler.
 	 * That's a no-no.
 	 * That's a no-no.
 	 */
 	 */
-	if(m->externup->fpustate & Hold)
+	if(up->fpustate & Hold)
 		return "sys: floating point in note handler";
 		return "sys: floating point in note handler";
 
 
 	if(ureg->ip & KZERO)
 	if(ureg->ip & KZERO)
 		panic("#NM: proc %d %s state %d ip %#p\n",
 		panic("#NM: proc %d %s state %d ip %#p\n",
-			m->externup->pid, m->externup->text, m->externup->fpustate, ureg->ip);
+			up->pid, up->text, up->fpustate, ureg->ip);
 
 
-	switch(m->externup->fpustate){
+	switch(up->fpustate){
 	case Busy:
 	case Busy:
 	default:
 	default:
-		panic("#NM: state %d ip %#p\n", m->externup->fpustate, ureg->ip);
+		panic("#NM: state %d ip %#p\n", up->fpustate, ureg->ip);
 		break;
 		break;
 	case Init:
 	case Init:
 		/*
 		/*
@@ -468,10 +468,10 @@ xfpunm(Ureg* ureg, void* v)
 		_clts();
 		_clts();
 		_fninit();
 		_fninit();
 		_fwait();
 		_fwait();
-		_fldcw(&m->fcw);
-		_ldmxcsr(&m->mxcsr);
-		m->externup->fpusave = (void*)((PTR2UINT(m->externup->fxsave) + 15) & ~15);
-		m->externup->fpustate = Busy;
+		_fldcw(&machp()->fcw);
+		_ldmxcsr(&machp()->mxcsr);
+		up->fpusave = (void*)((PTR2UINT(up->fxsave) + 15) & ~15);
+		up->fpustate = Busy;
 		break;
 		break;
 	case Idle:
 	case Idle:
 		/*
 		/*
@@ -479,7 +479,7 @@ xfpunm(Ureg* ureg, void* v)
 		 * exceptions, there's no way to restore the state without
 		 * exceptions, there's no way to restore the state without
 		 * generating an unmasked exception.
 		 * generating an unmasked exception.
 		 */
 		 */
-		fpusave = m->externup->fpusave;
+		fpusave = up->fpusave;
 		if((fpusave->fsw & ~fpusave->fcw) & (Sff|P|U|O|Z|D|I))
 		if((fpusave->fsw & ~fpusave->fcw) & (Sff|P|U|O|Z|D|I))
 			return fpunote();
 			return fpunote();
 
 
@@ -489,7 +489,7 @@ xfpunm(Ureg* ureg, void* v)
 		fpusave->fcw &= ~Sff;
 		fpusave->fcw &= ~Sff;
 		_clts();
 		_clts();
 		_fxrstor(fpusave);
 		_fxrstor(fpusave);
-		m->externup->fpustate = Busy;
+		up->fpustate = Busy;
 		break;
 		break;
 	}
 	}
 	return nil;
 	return nil;
@@ -498,12 +498,12 @@ xfpunm(Ureg* ureg, void* v)
 void
 void
 fpunm(Ureg *ureg, void *p)
 fpunm(Ureg *ureg, void *p)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	char *n;
 	char *n;
 
 
 	n = xfpunm(ureg, p);
 	n = xfpunm(ureg, p);
 	if(n != nil)
 	if(n != nil)
-		postnote(m->externup, 1, n, NDebug);
+		postnote(up, 1, n, NDebug);
 }
 }
 
 
 char*
 char*
@@ -515,7 +515,7 @@ acfpunm(Ureg *ureg, void *p)
 void
 void
 fpuinit(void)
 fpuinit(void)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	uint64_t r;
 	uint64_t r;
 	Fxsave *fxsave;
 	Fxsave *fxsave;
 	uint8_t buf[sizeof(Fxsave)+15];
 	uint8_t buf[sizeof(Fxsave)+15];
@@ -536,15 +536,15 @@ fpuinit(void)
 	fxsave = (Fxsave*)((PTR2UINT(buf) + 15) & ~15);
 	fxsave = (Fxsave*)((PTR2UINT(buf) + 15) & ~15);
 	memset(fxsave, 0, sizeof(Fxsave));
 	memset(fxsave, 0, sizeof(Fxsave));
 	_fxsave(fxsave);
 	_fxsave(fxsave);
-	m->fcw = RCn|PCd|P|U|D;
+	machp()->fcw = RCn|PCd|P|U|D;
 	if(fxsave->mxcsrmask == 0)
 	if(fxsave->mxcsrmask == 0)
-		m->mxcsrmask = 0x0000FFBF;
+		machp()->mxcsrmask = 0x0000FFBF;
 	else
 	else
-		m->mxcsrmask = fxsave->mxcsrmask;
-	m->mxcsr = (Rn|Pm|Um|Dm) & m->mxcsrmask;
+		machp()->mxcsrmask = fxsave->mxcsrmask;
+	machp()->mxcsr = (Rn|Pm|Um|Dm) & machp()->mxcsrmask;
 	_stts();
 	_stts();
 
 
-	if(m->machno != 0)
+	if(machp()->machno != 0)
 		return;
 		return;
 
 
 	/*
 	/*

+ 1 - 1
sys/src/9/k10/fpu.c.old

@@ -463,7 +463,7 @@ fpuinit(void)
 	m->mxcsr = (Rn|Pm|Um|Dm) & m->mxcsrmask;
 	m->mxcsr = (Rn|Pm|Um|Dm) & m->mxcsrmask;
 	_stts();
 	_stts();
 
 
-	if(m->machno != 0)
+	if(machp()->machno != 0)
 		return;
 		return;
 
 
 	/*
 	/*

+ 1 - 1
sys/src/9/k10/io.h

@@ -1,4 +1,4 @@
-/* 
+/*
  * This file is part of the UCB release of Plan 9. It is subject to the license
  * This file is part of the UCB release of Plan 9. It is subject to the license
  * terms in the LICENSE file found in the top-level directory of this
  * terms in the LICENSE file found in the top-level directory of this
  * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No

+ 1 - 1
sys/src/9/k10/ioapic.c

@@ -266,7 +266,7 @@ ioapicintrdd(uint32_t* hi, uint32_t* lo)
 				break;
 				break;
 		}
 		}
 		unlock(&dflock);
 		unlock(&dflock);
-	
+
 		*hi = i<<24;
 		*hi = i<<24;
 		break;
 		break;
 	}
 	}

+ 1 - 1
sys/src/9/k10/iob.h

@@ -1,4 +1,4 @@
-/* 
+/*
  * This file is part of the UCB release of Plan 9. It is subject to the license
  * This file is part of the UCB release of Plan 9. It is subject to the license
  * terms in the LICENSE file found in the top-level directory of this
  * terms in the LICENSE file found in the top-level directory of this
  * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No

+ 1 - 1
sys/src/9/k10/l64acidt.S

@@ -83,7 +83,7 @@ _aciretnested:
 	iretq
 	iretq
 
 
 .globl acidthandlers
 .globl acidthandlers
-acidthandlers:	
+acidthandlers:
 	CALL _acintrp; .byte IdtDE		/* #DE Divide-by-Zero Error */
 	CALL _acintrp; .byte IdtDE		/* #DE Divide-by-Zero Error */
 	CALL _acintrp; .byte IdtDB		/* #DB Debug */
 	CALL _acintrp; .byte IdtDB		/* #DB Debug */
 	CALL _acintrp; .byte IdtNMI		/* #NMI Borked */
 	CALL _acintrp; .byte IdtNMI		/* #NMI Borked */

+ 7 - 7
sys/src/9/k10/l64idt.S

@@ -20,7 +20,7 @@
 	* EIP of interrupted code 8(%rsp)
 	* EIP of interrupted code 8(%rsp)
 	* EIP from the call from the idthandlers. (%rsp)
 	* EIP from the call from the idthandlers. (%rsp)
 	* We, finally, need to push the error code and type.,
 	* We, finally, need to push the error code and type.,
-	* then the registers. 
+	* then the registers.
 	* Why the call from IDThandlers? So we can get a way to point
 	* Why the call from IDThandlers? So we can get a way to point
 	* to the type. We don't need to save 0(%rsp), we just need
 	* to the type. We don't need to save 0(%rsp), we just need
 	* it to get the type. We can pop it and throw it away when
 	* it to get the type. We can pop it and throw it away when
@@ -37,14 +37,14 @@
 	* is on the stack. For others, it's not. To make the stacks
 	* is on the stack. For others, it's not. To make the stacks
 	* look identical for the common code and exit we save %rax and line things up.
 	* look identical for the common code and exit we save %rax and line things up.
 	*/
 	*/
-	
+
 .globl ire
 .globl ire
 .globl irx
 .globl irx
 .globl irxe
 .globl irxe
-// When we enter: 
+// When we enter:
 // registers are NOT saved. We need to save them all.
 // registers are NOT saved. We need to save them all.
 // return PC is on the stat8(%rsp). It should be left there.
 // return PC is on the stat8(%rsp). It should be left there.
-// @ (%rsp) is the PC from the vector table. 
+// @ (%rsp) is the PC from the vector table.
 // So indirecting on that will get us the interrupt #.
 // So indirecting on that will get us the interrupt #.
 // We need to get what the return PC is pointing to into %rdi.
 // We need to get what the return PC is pointing to into %rdi.
 // We no longer need to make the stack look the same as in Plan 9
 // We no longer need to make the stack look the same as in Plan 9
@@ -58,8 +58,8 @@ _intrp:
 	// Now %rax points to the vector number.
 	// Now %rax points to the vector number.
 	JMP	_intrcommon
 	JMP	_intrcommon
 
 
-// For intre, error is at top of stack on trap. But then we call here 
-// from the interrupt vectors so error is at 8(%rsp). 
+// For intre, error is at top of stack on trap. But then we call here
+// from the interrupt vectors so error is at 8(%rsp).
 // I just realized I think intre means interrupt exception, e.g. page fault.
 // I just realized I think intre means interrupt exception, e.g. page fault.
 .globl _intre
 .globl _intre
 _intre:
 _intre:
@@ -69,7 +69,7 @@ _intre:
 	XCHGQ	%rax, (%rsp)
 	XCHGQ	%rax, (%rsp)
 	// Now %rax points to the vector number.
 	// Now %rax points to the vector number.
 
 
-// When we get here: 
+// When we get here:
 // %RAX points to our vector number, i.e. "return" pc from calls below.
 // %RAX points to our vector number, i.e. "return" pc from calls below.
 // For intrp, (%rsp) is bogus code, 8(%rsp) is pointer to vno
 // For intrp, (%rsp) is bogus code, 8(%rsp) is pointer to vno
 // for intre, (%rsp) is pointer to vno, 8(%rsp) is error code.
 // for intre, (%rsp) is pointer to vno, 8(%rsp) is error code.

+ 5 - 5
sys/src/9/k10/l64vsyscall.S

@@ -10,7 +10,7 @@
  * starting the user program up. First time.
  * starting the user program up. First time.
  */
  */
 	.globl touser
 	.globl touser
-touser:	
+touser:
 	CLI
 	CLI
 	SWAPGS
 	SWAPGS
 	// we should be able to skip this step. We'll see.
 	// we should be able to skip this step. We'll see.
@@ -34,7 +34,7 @@ touser:
 .global syscallentry
 .global syscallentry
 syscallentry:
 syscallentry:
 	incq	sce
 	incq	sce
-	SWAPGS	
+	SWAPGS
 	movq	%gs:0, %r15
 	movq	%gs:0, %r15
 	movq	16(%r15), %r15			/* m->proc */
 	movq	16(%r15), %r15			/* m->proc */
 	// NOTE! This assumes sizeof(Label) == 16!
 	// NOTE! This assumes sizeof(Label) == 16!
@@ -76,7 +76,7 @@ syscallentry:
 	CALL	syscall
 	CALL	syscall
 
 
 	.globl	syscallreturn
 	.globl	syscallreturn
-syscallreturn:	
+syscallreturn:
 #ifdef NOTNOW
 #ifdef NOTNOW
 	/* we do the TLS setup in linuxsyscall.c.
 	/* we do the TLS setup in linuxsyscall.c.
 	 * Leave this here in case we ever think it should be done
 	 * Leave this here in case we ever think it should be done
@@ -125,7 +125,7 @@ _linuxsyscallreturn:
 	MOVW	4(%rsp), FS
 	MOVW	4(%rsp), FS
 	*/
 	*/
 	MOVW	6(%rsp), GS
 	MOVW	6(%rsp), GS
-#endif	
+#endif
 
 
 	MOVQ	0(%rsp), %rCX			/* ip */
 	MOVQ	0(%rsp), %rCX			/* ip */
 	MOVQ	16(%rsp), %r11			/* flags */
 	MOVQ	16(%rsp), %r11			/* flags */
@@ -137,7 +137,7 @@ _linuxsyscallreturn:
 //	BYTE $0x48; SYSRET			/* SYSRETQ */
 //	BYTE $0x48; SYSRET			/* SYSRETQ */
 
 
 	.globl sysrforkret
 	.globl sysrforkret
-sysrforkret:	
+sysrforkret:
 //	CALL	linuxclonefinish(SB)
 //	CALL	linuxclonefinish(SB)
 	// DEBUG
 	// DEBUG
 	MOVQ	$0, %rAX
 	MOVQ	$0, %rAX

+ 102 - 93
sys/src/9/k10/main.c

@@ -53,7 +53,7 @@ static int numtcs = 32;		/* initial # of TCs */
 char dbgflg[256];
 char dbgflg[256];
 static int vflag = 1;
 static int vflag = 1;
 
 
-int nosmp = 0;
+int nosmp = 1;
 
 
 void
 void
 optionsinit(char* s)
 optionsinit(char* s)
@@ -103,28 +103,30 @@ options(int argc, char* argv[])
 }
 }
 
 
 void
 void
-squidboy(int apicno, Mach *m)
+squidboy(int apicno, Mach *mach)
 {
 {
 	// FIX QEMU. extern int64_t hz;
 	// FIX QEMU. extern int64_t hz;
 	int64_t hz;
 	int64_t hz;
-	sys->machptr[m->machno] = m;
+	sys->machptr[mach->machno] = mach;
 	/*
 	/*
 	 * Need something for initial delays
 	 * Need something for initial delays
 	 * until a timebase is worked out.
 	 * until a timebase is worked out.
 	 */
 	 */
-	m->cpuhz = 2000000000ll;
-	m->cpumhz = 2000;
-	m->perf.period = 1;
+	mach->cpuhz = 2000000000ll;
+	mach->cpumhz = 2000;
+	mach->perf.period = 1;
 
 
-	m->nixtype = NIXAC;
+	mach->nixtype = NIXAC;
 	// no NIXAC for now.
 	// no NIXAC for now.
-	m->nixtype = NIXTC;
+	mach->nixtype = NIXTC;
+
 
 
 	// NOTE: you can't do ANYTHING here before vsvminit.
 	// NOTE: you can't do ANYTHING here before vsvminit.
 	// PRINT WILL PANIC. So wait.
 	// PRINT WILL PANIC. So wait.
-	vsvminit(MACHSTKSZ, m->nixtype, m);
 
 
-	//DBG("Hello squidboy %d %d\n", apicno, m->machno);
+	vsvminit(MACHSTKSZ, mach->nixtype, mach);
+
+	//DBG("Hello squidboy %d %d\n", apicno, machp()->machno);
 
 
 	/*
 	/*
 	 * Beware the Curse of The Non-Interruptable Were-Temporary.
 	 * Beware the Curse of The Non-Interruptable Were-Temporary.
@@ -133,18 +135,19 @@ squidboy(int apicno, Mach *m)
 	/* Intel cpu's in archk10 must be reviewed */
 	/* Intel cpu's in archk10 must be reviewed */
 	if(hz == 0)
 	if(hz == 0)
 		hz = 2000000000ll;
 		hz = 2000000000ll;
-	m->cpuhz = hz;
-	m->cyclefreq = hz;
-	m->cpumhz = hz/1000000ll;
+	mach->cpuhz = hz;
+	mach->cyclefreq = hz;
+	mach->cpumhz = hz/1000000ll;
+
 
 
 	mmuinit();
 	mmuinit();
 	if(!apiconline())
 	if(!apiconline())
 		ndnr();
 		ndnr();
 	fpuinit();
 	fpuinit();
 
 
-	acmodeset(m->nixtype);
-	m->splpc = 0;
-	m->online = 1;
+	acmodeset(mach->nixtype);
+	mach->splpc = 0;
+	mach->online = 1;
 
 
 	/*
 	/*
 	 * CAUTION: no time sync done, etc.
 	 * CAUTION: no time sync done, etc.
@@ -155,11 +158,11 @@ squidboy(int apicno, Mach *m)
 	while(!active.thunderbirdsarego)
 	while(!active.thunderbirdsarego)
 		;
 		;
 	wrmsr(0x10, sys->epoch);
 	wrmsr(0x10, sys->epoch);
-	m->rdtsc = rdtsc();
+	mach->rdtsc = rdtsc();
 
 
 	print("cpu%d color %d role %s tsc %lld\n",
 	print("cpu%d color %d role %s tsc %lld\n",
-		m->machno, corecolor(m->machno), rolename[m->nixtype], m->rdtsc);
-	switch(m->nixtype){
+		mach->machno, corecolor(mach->machno), rolename[mach->nixtype], mach->rdtsc);
+	switch(mach->nixtype){
 	case NIXAC:
 	case NIXAC:
 		acmmuswitch();
 		acmmuswitch();
 		acinit();
 		acinit();
@@ -174,7 +177,7 @@ squidboy(int apicno, Mach *m)
 		 * At boot time the boot processor might set our role after
 		 * At boot time the boot processor might set our role after
 		 * we have decided to become an AC.
 		 * we have decided to become an AC.
 		 */
 		 */
-		vsvminit(MACHSTKSZ, NIXTC, m);
+		vsvminit(MACHSTKSZ, NIXTC, mach);
 
 
 		/*
 		/*
 		 * Enable the timer interrupt.
 		 * Enable the timer interrupt.
@@ -187,24 +190,24 @@ squidboy(int apicno, Mach *m)
 		ainc(&active.nonline);
 		ainc(&active.nonline);
 
 
 		/* Ready? steady? going to timer */
 		/* Ready? steady? going to timer */
-		ndnr();
+		//ndnr();
 
 
 		schedinit();
 		schedinit();
 		break;
 		break;
 	}
 	}
-	panic("squidboy returns (type %d)", m->nixtype);
+	panic("squidboy returns (type %d)", mach->nixtype);
 }
 }
 
 
 static void
 static void
 testiccs(void)
 testiccs(void)
 {
 {
 	int i;
 	int i;
-	Mach *mp;
+	Mach *mach;
 	extern void testicc(int);
 	extern void testicc(int);
 
 
 	/* setup arguments for all */
 	/* setup arguments for all */
 	for(i = 0; i < MACHMAX; i++)
 	for(i = 0; i < MACHMAX; i++)
-		if((mp = sys->machptr[i]) != nil && mp->online && mp->nixtype == NIXAC)
+		if((mach = sys->machptr[i]) != nil && mach->online && mach->nixtype == NIXAC)
 			testicc(i);
 			testicc(i);
 	print("bootcore: all cores done\n");
 	print("bootcore: all cores done\n");
 }
 }
@@ -219,24 +222,24 @@ testiccs(void)
 static void
 static void
 nixsquids(void)
 nixsquids(void)
 {
 {
-	Mach *m = machp();
-	Mach *mp;
+	Proc *up = machp()->externup;
+	Mach *mach;
 	int i;
 	int i;
 	uint64_t now, start;
 	uint64_t now, start;
 
 
 	/* Not AC for now :-) */
 	/* Not AC for now :-) */
 	for(i = 1; i <= MACHMAX; i++)
 	for(i = 1; i <= MACHMAX; i++)
 	//for(i = 1; i < MACHMAX; i++)
 	//for(i = 1; i < MACHMAX; i++)
-		if((mp = sys->machptr[i]) != nil && mp->online){
+		if((mach = sys->machptr[i]) != nil && mach->online){
 			/*
 			/*
 			 * Inter-core calls. A ensure *mp->iccall and mp->icargs
 			 * Inter-core calls. A ensure *mp->iccall and mp->icargs
 			 * go into different cache lines.
 			 * go into different cache lines.
 			 */
 			 */
-			mp->icc = mallocalign(sizeof *m->icc, ICCLNSZ, 0, 0);
-			mp->icc->fn = nil;
+			mach->icc = mallocalign(sizeof *machp()->icc, ICCLNSZ, 0, 0);
+			mach->icc->fn = nil;
 			if(i < numtcs){
 			if(i < numtcs){
 				sys->nmach++;
 				sys->nmach++;
-				mp->nixtype = NIXTC;
+				mach->nixtype = NIXTC;
 				sys->nc[NIXTC]++;
 				sys->nc[NIXTC]++;
 			}//else
 			}//else
 				//sys->nc[NIXAC]++;
 				//sys->nc[NIXAC]++;
@@ -245,7 +248,7 @@ nixsquids(void)
 	sys->epoch = rdtsc();
 	sys->epoch = rdtsc();
 	mfence();
 	mfence();
 	wrmsr(0x10, sys->epoch);
 	wrmsr(0x10, sys->epoch);
-	m->rdtsc = rdtsc();
+	machp()->rdtsc = rdtsc();
 	active.thunderbirdsarego = 1;
 	active.thunderbirdsarego = 1;
 	start = fastticks2us(fastticks(nil));
 	start = fastticks2us(fastticks(nil));
 	do{
 	do{
@@ -282,7 +285,7 @@ void wave(int c)
 	outb(0x3f8, c);
 	outb(0x3f8, c);
 }
 }
 
 
-void hi(char *s) 
+void hi(char *s)
 {
 {
 	if (! s)
 	if (! s)
 		s = "<NULL>";
 		s = "<NULL>";
@@ -291,14 +294,14 @@ void hi(char *s)
 }
 }
 
 
 /*
 /*
- * for gdb: 
- * call this anywhere in your code. 
+ * for gdb:
+ * call this anywhere in your code.
  *   die("yourturn with gdb\n");
  *   die("yourturn with gdb\n");
  *   gdb 9k
  *   gdb 9k
  *   target remote localhost:1234
  *   target remote localhost:1234
  *   display/i $pc
  *   display/i $pc
  *   set staydead = 0
  *   set staydead = 0
- *   stepi, and debug. 
+ *   stepi, and debug.
  * note, you can always resume after a die. Just set staydead = 0
  * note, you can always resume after a die. Just set staydead = 0
  */
  */
 
 
@@ -348,14 +351,14 @@ void put64(uint64_t v)
 
 
 void debugtouser(void *va)
 void debugtouser(void *va)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	uintptr_t uva = (uintptr_t) va;
 	uintptr_t uva = (uintptr_t) va;
 	PTE *pte, *pml4;
 	PTE *pte, *pml4;
 
 
-	pml4 = UINT2PTR(m->pml4->va);
+	pml4 = UINT2PTR(machp()->pml4->va);
 	mmuwalk(pml4, uva, 0, &pte, nil);
 	mmuwalk(pml4, uva, 0, &pte, nil);
-	iprint("va %p m %p m>pml4 %p m->pml4->va %p pml4 %p PTE 0x%lx\n", va,
-			m, m->pml4, m->pml4->va, (void *)pml4, *pte);
+	iprint("va %p m %p m>pml4 %p machp()->pml4->va %p pml4 %p PTE 0x%lx\n", va,
+			machp(), machp()->pml4, machp()->pml4->va, (void *)pml4, *pte);
 }
 }
 
 
 /*
 /*
@@ -378,7 +381,7 @@ static int x = 0x123456;
  * you create address spaces for procs, i.e. userinit()
  * you create address spaces for procs, i.e. userinit()
  */
  */
 static void
 static void
-teardownidmap(Mach *m)
+teardownidmap(Mach *mach)
 {
 {
 	int i;
 	int i;
 	uintptr_t va = 0;
 	uintptr_t va = 0;
@@ -388,7 +391,7 @@ teardownidmap(Mach *m)
 	 * report if there were that many, as that is odd.
 	 * report if there were that many, as that is odd.
 	 */
 	 */
 	for(i = 0; i < 512; i++, va += BIGPGSZ) {
 	for(i = 0; i < 512; i++, va += BIGPGSZ) {
-		if (mmuwalk(UINT2PTR(m->pml4->va), va, 1, &p, nil) != 1)
+		if (mmuwalk(UINT2PTR(mach->pml4->va), va, 1, &p, nil) != 1)
 			break;
 			break;
 		if (! *p)
 		if (! *p)
 			break;
 			break;
@@ -398,7 +401,7 @@ teardownidmap(Mach *m)
 	iprint("Teardown: zapped %d PML1 entries\n", i);
 	iprint("Teardown: zapped %d PML1 entries\n", i);
 
 
 	for(i = 2; i < 4; i++) {
 	for(i = 2; i < 4; i++) {
-		if (mmuwalk(UINT2PTR(m->pml4->va), 0, i, &p, nil) != i) {
+		if (mmuwalk(UINT2PTR(mach->pml4->va), 0, i, &p, nil) != i) {
 			iprint("weird; 0 not mapped at %d\n", i);
 			iprint("weird; 0 not mapped at %d\n", i);
 			continue;
 			continue;
 		}
 		}
@@ -412,43 +415,47 @@ teardownidmap(Mach *m)
 void
 void
 main(uint32_t mbmagic, uint32_t mbaddress)
 main(uint32_t mbmagic, uint32_t mbaddress)
 {
 {
-	Mach *m = entrym;
+	Mach *mach = entrym;
 	/* when we get here, entrym is set to core0 mach. */
 	/* when we get here, entrym is set to core0 mach. */
-	sys->machptr[m->machno] = m;
+	sys->machptr[mach->machno] = entrym;
 	// Very special case for BSP only. Too many things
 	// Very special case for BSP only. Too many things
 	// assume this is set.
 	// assume this is set.
-	wrmsr(GSbase, PTR2UINT(&sys->machptr[m->machno]));
-	if (machp() != m)
-		panic("m and machp() are different!!\n");
+	wrmsr(GSbase, PTR2UINT(&sys->machptr[mach->machno]));
+	if (machp() != mach)
+		panic("mach and machp() are different!!\n");
 	assert(sizeof(Mach) <= PGSZ);
 	assert(sizeof(Mach) <= PGSZ);
 
 
 	/*
 	/*
 	 * Check that our data is on the right boundaries.
 	 * Check that our data is on the right boundaries.
 	 * This works because the immediate value is in code.
 	 * This works because the immediate value is in code.
 	 */
 	 */
-	if (x != 0x123456) 
+	//cgaprint(800, "hello harvey\n");
+	//for(;;);
+	if (x != 0x123456)
 		panic("Data is not set up correctly\n");
 		panic("Data is not set up correctly\n");
 	memset(edata, 0, end - edata);
 	memset(edata, 0, end - edata);
 
 
-	m = (void *) (KZERO + 1048576 + 11*4096);
+// TODO(aki): figure this out.
+	mach = (void *) (KZERO + 1048576 + 11*4096);
+	if(mach != machp()){ cgapost(0x01);for(;;); }
 	sys = (void *) (KZERO + 1048576);
 	sys = (void *) (KZERO + 1048576);
 
 
+
 	/*
 	/*
 	 * ilock via i8250enable via i8250console
 	 * ilock via i8250enable via i8250console
-	 * needs m->machno, sys->machptr[] set, and
+	 * needs machp()->machno, sys->machptr[] set, and
 	 * also 'up' set to nil.
 	 * also 'up' set to nil.
 	 */
 	 */
 	cgapost(sizeof(uintptr_t)*8);
 	cgapost(sizeof(uintptr_t)*8);
-	memset(m, 0, sizeof(Mach));
-
-	m->machno = 0;
-	m->online = 1;
-	m->nixtype = NIXTC;
-	sys->machptr[m->machno] = &sys->mach;
-	m->stack = PTR2UINT(sys->machstk);
-	*(uintptr_t*)m->stack = STACKGUARD;
-	m->vsvm = sys->vsvmpage;
-	m->externup = (void *)0;
+	memset(mach, 0, sizeof(Mach));
+
+	mach->machno = 0;
+	mach->online = 1;
+	mach->nixtype = NIXTC;
+	mach->stack = PTR2UINT(sys->machstk);
+	*(uintptr_t*)mach->stack = STACKGUARD;
+	mach->vsvm = sys->vsvmpage;
+	mach->externup = (void *)0;
 	active.nonline = 1;
 	active.nonline = 1;
 	active.exiting = 0;
 	active.exiting = 0;
 	active.nbooting = 0;
 	active.nbooting = 0;
@@ -461,21 +468,21 @@ main(uint32_t mbmagic, uint32_t mbaddress)
 	 * Need something for initial delays
 	 * Need something for initial delays
 	 * until a timebase is worked out.
 	 * until a timebase is worked out.
 	 */
 	 */
-	m->cpuhz = 2000000000ll;
-	m->cpumhz = 2000;
+	mach->cpuhz = 2000000000ll;
+	mach->cpumhz = 2000;
 
 
 	cgainit();
 	cgainit();
 	i8250console("0");
 	i8250console("0");
-	
+
 	consputs = cgaconsputs;
 	consputs = cgaconsputs;
 
 
 	/* It all ends here. */
 	/* It all ends here. */
-	vsvminit(MACHSTKSZ, NIXTC, m);
-	if (machp() != m)
+	vsvminit(MACHSTKSZ, NIXTC, mach);
+	if (machp() != mach)
 		panic("After vsvminit, m and machp() are different");
 		panic("After vsvminit, m and machp() are different");
 
 
-	sys->nmach = 1;	
-	
+	sys->nmach = 1;
+
 	fmtinit();
 	fmtinit();
 	print("\nHarvey\n");
 	print("\nHarvey\n");
 
 
@@ -483,11 +490,11 @@ main(uint32_t mbmagic, uint32_t mbaddress)
 		multiboot(mbmagic, mbaddress, vflag);
 		multiboot(mbmagic, mbaddress, vflag);
 	}
 	}
 
 
-	m->perf.period = 1;
+	mach->perf.period = 1;
 	if((hz = archhz()) != 0ll){
 	if((hz = archhz()) != 0ll){
-		m->cpuhz = hz;
-		m->cyclefreq = hz;
-		m->cpumhz = hz/1000000ll;
+		mach->cpuhz = hz;
+		mach->cyclefreq = hz;
+		mach->cpumhz = hz/1000000ll;
 	}
 	}
 	//iprint("archhz returns 0x%lld\n", hz);
 	//iprint("archhz returns 0x%lld\n", hz);
 	//iprint("NOTE: if cpuidhz runs too fast, we get die early with a NULL pointer\n");
 	//iprint("NOTE: if cpuidhz runs too fast, we get die early with a NULL pointer\n");
@@ -495,7 +502,7 @@ main(uint32_t mbmagic, uint32_t mbaddress)
 
 
 	/*
 	/*
 	 * Mmuinit before meminit because it
 	 * Mmuinit before meminit because it
-	 * flushes the TLB via m->pml4->pa.
+	 * flushes the TLB via machp()->pml4->pa.
 	 */
 	 */
 	mmuinit();
 	mmuinit();
 
 
@@ -505,9 +512,9 @@ main(uint32_t mbmagic, uint32_t mbaddress)
 	archinit();
 	archinit();
 	mallocinit();
 	mallocinit();
 
 
-	/* test malloc. It's easier to find out it's broken here, 
+	/* test malloc. It's easier to find out it's broken here,
 	 * not deep in some call chain.
 	 * not deep in some call chain.
-	 * See next note. 
+	 * See next note.
 	 *
 	 *
 	void *v = malloc(1234);
 	void *v = malloc(1234);
 	hi("v "); put64((uint64_t)v); hi("\n");
 	hi("v "); put64((uint64_t)v); hi("\n");
@@ -525,7 +532,7 @@ main(uint32_t mbmagic, uint32_t mbaddress)
 	 * things like that completely broken).
 	 * things like that completely broken).
 	 */
 	 */
 if (0){	acpiinit(); hi("	acpiinit();\n");}
 if (0){	acpiinit(); hi("	acpiinit();\n");}
-	
+
 	umeminit();
 	umeminit();
 	trapinit();
 	trapinit();
 
 
@@ -545,7 +552,8 @@ if (0){	acpiinit(); hi("	acpiinit();\n");}
 	if(!nosmp) {
 	if(!nosmp) {
 		sipi();
 		sipi();
 	}
 	}
-	teardownidmap(m);
+//working.
+	teardownidmap(mach);
 	timersinit();
 	timersinit();
 	fpuinit();
 	fpuinit();
 	psinit(conf.nproc);
 	psinit(conf.nproc);
@@ -566,19 +574,20 @@ if (0){	acpiinit(); hi("	acpiinit();\n");}
 		testiccs();
 		testiccs();
 	}
 	}
 
 
-	print("CPU Freq. %dMHz\n", m->cpumhz);
+	print("CPU Freq. %dMHz\n", mach->cpumhz);
 
 
 	print("schedinit...\n");
 	print("schedinit...\n");
+
 	schedinit();
 	schedinit();
 }
 }
 
 
 void
 void
 init0(void)
 init0(void)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	char buf[2*KNAMELEN];
 	char buf[2*KNAMELEN];
 
 
-	m->externup->nerrlab = 0;
+	up->nerrlab = 0;
 
 
 	/*
 	/*
 	 * if(consuart == nil)
 	 * if(consuart == nil)
@@ -590,10 +599,10 @@ init0(void)
 	 * These are o.k. because rootinit is null.
 	 * These are o.k. because rootinit is null.
 	 * Then early kproc's will have a root and dot.
 	 * Then early kproc's will have a root and dot.
 	 */
 	 */
-	m->externup->slash = namec("#/", Atodir, 0, 0);
-	pathclose(m->externup->slash->path);
-	m->externup->slash->path = newpath("/");
-	m->externup->dot = cclone(m->externup->slash);
+	up->slash = namec("#/", Atodir, 0, 0);
+	pathclose(up->slash->path);
+	up->slash->path = newpath("/");
+	up->dot = cclone(up->slash);
 
 
 	devtabinit();
 	devtabinit();
 
 
@@ -625,10 +634,10 @@ bootargs(uintptr_t base)
 	 * Push the boot args onto the stack.
 	 * Push the boot args onto the stack.
 	 * Make sure the validaddr check in syscall won't fail
 	 * Make sure the validaddr check in syscall won't fail
 	 * because there are fewer than the maximum number of
 	 * because there are fewer than the maximum number of
-	 * args by subtracting sizeof(m->externup->arg).
+	 * args by subtracting sizeof(up->arg).
 	 */
 	 */
 	i = oargblen+1;
 	i = oargblen+1;
-	p = UINT2PTR(STACKALIGN(base + BIGPGSZ - sizeof(entrym->externup->arg) - i));
+	p = UINT2PTR(STACKALIGN(base + BIGPGSZ - sizeof(((Proc*)0)->arg) - i));
 	memmove(p, oargb, i);
 	memmove(p, oargb, i);
 
 
 	/*
 	/*
@@ -653,7 +662,7 @@ bootargs(uintptr_t base)
 void
 void
 userinit(void)
 userinit(void)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	Proc *p;
 	Proc *p;
 	Segment *s;
 	Segment *s;
 	KMap *k;
 	KMap *k;
@@ -681,7 +690,7 @@ userinit(void)
 	 * AMD64 stack must be quad-aligned.
 	 * AMD64 stack must be quad-aligned.
 	 */
 	 */
 	p->sched.pc = PTR2UINT(init0);
 	p->sched.pc = PTR2UINT(init0);
-	p->sched.sp = PTR2UINT(p->kstack+KSTACK-sizeof(m->externup->arg)-sizeof(uintptr_t));
+	p->sched.sp = PTR2UINT(p->kstack+KSTACK-sizeof(up->arg)-sizeof(uintptr_t));
 	p->sched.sp = STACKALIGN(p->sched.sp);
 	p->sched.sp = STACKALIGN(p->sched.sp);
 
 
 	/*
 	/*
@@ -746,22 +755,22 @@ confinit(void)
 static void
 static void
 shutdown(int ispanic)
 shutdown(int ispanic)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	int ms, once;
 	int ms, once;
 
 
 	lock(&active);
 	lock(&active);
 	if(ispanic)
 	if(ispanic)
 		active.ispanic = ispanic;
 		active.ispanic = ispanic;
-	else if(m->machno == 0 && m->online == 0)
+	else if(machp()->machno == 0 && machp()->online == 0)
 		active.ispanic = 0;
 		active.ispanic = 0;
-	once = m->online;
-	m->online = 0;
+	once = machp()->online;
+	machp()->online = 0;
 	adec(&active.nonline);
 	adec(&active.nonline);
 	active.exiting = 1;
 	active.exiting = 1;
 	unlock(&active);
 	unlock(&active);
 
 
 	if(once)
 	if(once)
-		iprint("cpu%d: exiting\n", m->machno);
+		iprint("cpu%d: exiting\n", machp()->machno);
 
 
 	spllo();
 	spllo();
 	for(ms = 5*1000; ms > 0; ms -= TK2MS(2)){
 	for(ms = 5*1000; ms > 0; ms -= TK2MS(2)){
@@ -770,7 +779,7 @@ shutdown(int ispanic)
 			break;
 			break;
 	}
 	}
 
 
-	if(active.ispanic && m->machno == 0){
+	if(active.ispanic && machp()->machno == 0){
 		if(cpuserver)
 		if(cpuserver)
 			delay(30000);
 			delay(30000);
 		else
 		else

+ 1 - 1
sys/src/9/k10/mem.h

@@ -1,4 +1,4 @@
-/* 
+/*
  * This file is part of the UCB release of Plan 9. It is subject to the license
  * This file is part of the UCB release of Plan 9. It is subject to the license
  * terms in the LICENSE file found in the top-level directory of this
  * terms in the LICENSE file found in the top-level directory of this
  * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No

+ 75 - 75
sys/src/9/k10/mmu.c

@@ -31,32 +31,32 @@
 void
 void
 mmuflushtlb(uint64_t u)
 mmuflushtlb(uint64_t u)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 
 
-	m->tlbpurge++;
-	if(m->pml4->daddr){
-		memset(UINT2PTR(m->pml4->va), 0, m->pml4->daddr*sizeof(PTE));
-		m->pml4->daddr = 0;
+	machp()->tlbpurge++;
+	if(machp()->pml4->daddr){
+		memset(UINT2PTR(machp()->pml4->va), 0, machp()->pml4->daddr*sizeof(PTE));
+		machp()->pml4->daddr = 0;
 	}
 	}
-	cr3put(m->pml4->pa);
+	cr3put(machp()->pml4->pa);
 }
 }
 
 
 void
 void
 mmuflush(void)
 mmuflush(void)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	Mpl pl;
 	Mpl pl;
 
 
 	pl = splhi();
 	pl = splhi();
-	m->externup->newtlb = 1;
-	mmuswitch(m->externup);
+	up->newtlb = 1;
+	mmuswitch(up);
 	splx(pl);
 	splx(pl);
 }
 }
 
 
 static void
 static void
 mmuptpfree(Proc* proc, int clear)
 mmuptpfree(Proc* proc, int clear)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	int l;
 	int l;
 	PTE *pte;
 	PTE *pte;
 	Page **last, *page;
 	Page **last, *page;
@@ -78,7 +78,7 @@ mmuptpfree(Proc* proc, int clear)
 		proc->mmuptp[l] = nil;
 		proc->mmuptp[l] = nil;
 	}
 	}
 
 
-	m->pml4->daddr = 0;
+	machp()->pml4->daddr = 0;
 }
 }
 
 
 static void
 static void
@@ -117,7 +117,7 @@ dumpptepg(int lvl, uintptr_t pa)
 void
 void
 dumpmmu(Proc *p)
 dumpmmu(Proc *p)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	int i;
 	int i;
 	Page *pg;
 	Page *pg;
 
 
@@ -129,26 +129,26 @@ dumpmmu(Proc *p)
 				" daddr %#ulx next %#p prev %#p\n",
 				" daddr %#ulx next %#p prev %#p\n",
 				pg, pg->va, pg->pa, pg->daddr, pg->next, pg->prev);
 				pg, pg->va, pg->pa, pg->daddr, pg->next, pg->prev);
 	}
 	}
-	print("pml4 %#ullx\n", m->pml4->pa);
-	if(0)dumpptepg(4, m->pml4->pa);
+	print("pml4 %#ullx\n", machp()->pml4->pa);
+	if(0)dumpptepg(4, machp()->pml4->pa);
 }
 }
 
 
 void
 void
 dumpmmuwalk(uint64_t addr)
 dumpmmuwalk(uint64_t addr)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	int l;
 	int l;
 	PTE *pte, *pml4;
 	PTE *pte, *pml4;
 
 
-	pml4 = UINT2PTR(m->pml4->va);
+	pml4 = UINT2PTR(machp()->pml4->va);
 	if((l = mmuwalk(pml4, addr, 3, &pte, nil)) >= 0)
 	if((l = mmuwalk(pml4, addr, 3, &pte, nil)) >= 0)
-		print("cpu%d: mmu l%d pte %#p = %llux\n", m->machno, l, pte, *pte);
+		print("cpu%d: mmu l%d pte %#p = %llux\n", machp()->machno, l, pte, *pte);
 	if((l = mmuwalk(pml4, addr, 2, &pte, nil)) >= 0)
 	if((l = mmuwalk(pml4, addr, 2, &pte, nil)) >= 0)
-		print("cpu%d: mmu l%d pte %#p = %llux\n", m->machno, l, pte, *pte);
+		print("cpu%d: mmu l%d pte %#p = %llux\n", machp()->machno, l, pte, *pte);
 	if((l = mmuwalk(pml4, addr, 1, &pte, nil)) >= 0)
 	if((l = mmuwalk(pml4, addr, 1, &pte, nil)) >= 0)
-		print("cpu%d: mmu l%d pte %#p = %llux\n", m->machno, l, pte, *pte);
+		print("cpu%d: mmu l%d pte %#p = %llux\n", machp()->machno, l, pte, *pte);
 	if((l = mmuwalk(pml4, addr, 0, &pte, nil)) >= 0)
 	if((l = mmuwalk(pml4, addr, 0, &pte, nil)) >= 0)
-		print("cpu%d: mmu l%d pte %#p = %llux\n", m->machno, l, pte, *pte);
+		print("cpu%d: mmu l%d pte %#p = %llux\n", machp()->machno, l, pte, *pte);
 }
 }
 
 
 static Page mmuptpfreelist;
 static Page mmuptpfreelist;
@@ -206,7 +206,7 @@ mmuptpalloc(void)
 void
 void
 mmuswitch(Proc* proc)
 mmuswitch(Proc* proc)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	PTE *pte;
 	PTE *pte;
 	Page *page;
 	Page *page;
 	Mpl pl;
 	Mpl pl;
@@ -222,28 +222,28 @@ mmuswitch(Proc* proc)
 		proc->newtlb = 0;
 		proc->newtlb = 0;
 	}
 	}
 
 
-	if(m->pml4->daddr){
-		memset(UINT2PTR(m->pml4->va), 0, m->pml4->daddr*sizeof(PTE));
-		m->pml4->daddr = 0;
+	if(machp()->pml4->daddr){
+		memset(UINT2PTR(machp()->pml4->va), 0, machp()->pml4->daddr*sizeof(PTE));
+		machp()->pml4->daddr = 0;
 	}
 	}
 
 
-	pte = UINT2PTR(m->pml4->va);
+	pte = UINT2PTR(machp()->pml4->va);
 	for(page = proc->mmuptp[3]; page != nil; page = page->next){
 	for(page = proc->mmuptp[3]; page != nil; page = page->next){
 		pte[page->daddr] = PPN(page->pa)|PteU|PteRW|PteP;
 		pte[page->daddr] = PPN(page->pa)|PteU|PteRW|PteP;
-		if(page->daddr >= m->pml4->daddr)
-			m->pml4->daddr = page->daddr+1;
-		page->prev = m->pml4;
+		if(page->daddr >= machp()->pml4->daddr)
+			machp()->pml4->daddr = page->daddr+1;
+		page->prev = machp()->pml4;
 	}
 	}
 
 
 	tssrsp0(machp(), STACKALIGN(PTR2UINT(proc->kstack+KSTACK)));
 	tssrsp0(machp(), STACKALIGN(PTR2UINT(proc->kstack+KSTACK)));
-	cr3put(m->pml4->pa);
+	cr3put(machp()->pml4->pa);
 	splx(pl);
 	splx(pl);
 }
 }
 
 
 void
 void
 mmurelease(Proc* proc)
 mmurelease(Proc* proc)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	Page *page, *next;
 	Page *page, *next;
 
 
 	mmuptpfree(proc, 0);
 	mmuptpfree(proc, 0);
@@ -263,21 +263,21 @@ mmurelease(Proc* proc)
 		wakeup(&pga.r);
 		wakeup(&pga.r);
 	proc->mmuptp[0] = nil;
 	proc->mmuptp[0] = nil;
 
 
-	tssrsp0(m, STACKALIGN(m->stack+MACHSTKSZ));
-	cr3put(m->pml4->pa);
+	tssrsp0(machp(), STACKALIGN(machp()->stack+MACHSTKSZ));
+	cr3put(machp()->pml4->pa);
 }
 }
 
 
 static void
 static void
 checkpte(uintmem ppn, void *a)
 checkpte(uintmem ppn, void *a)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	int l;
 	int l;
 	PTE *pte, *pml4;
 	PTE *pte, *pml4;
 	uint64_t addr;
 	uint64_t addr;
 	char buf[240], *s;
 	char buf[240], *s;
 
 
 	addr = PTR2UINT(a);
 	addr = PTR2UINT(a);
-	pml4 = UINT2PTR(m->pml4->va);
+	pml4 = UINT2PTR(machp()->pml4->va);
 	pte = 0;
 	pte = 0;
 	s = buf;
 	s = buf;
 	*s = 0;
 	*s = 0;
@@ -300,7 +300,7 @@ checkpte(uintmem ppn, void *a)
 		l, pte, pte?*pte:~0);
 		l, pte, pte?*pte:~0);
 	return;
 	return;
 Panic:
 Panic:
-	
+
 	seprint(s, buf+sizeof buf,
 	seprint(s, buf+sizeof buf,
 		"checkpte: l%d addr %#p ppn %#ullx kaddr %#p pte %#p = %llux",
 		"checkpte: l%d addr %#p ppn %#ullx kaddr %#p pte %#p = %llux",
 		l, a, ppn, KADDR(ppn), pte, pte?*pte:~0);
 		l, a, ppn, KADDR(ppn), pte, pte?*pte:~0);
@@ -315,14 +315,14 @@ Panic:
 static void
 static void
 mmuptpcheck(Proc *proc)
 mmuptpcheck(Proc *proc)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	int lvl, npgs, i;
 	int lvl, npgs, i;
 	Page *lp, *p, *pgs[16], *fp;
 	Page *lp, *p, *pgs[16], *fp;
 	uint idx[16];
 	uint idx[16];
 
 
 	if(proc == nil)
 	if(proc == nil)
 		return;
 		return;
-	lp = m->pml4;
+	lp = machp()->pml4;
 	for(lvl = 3; lvl >= 2; lvl--){
 	for(lvl = 3; lvl >= 2; lvl--){
 		npgs = 0;
 		npgs = 0;
 		for(p = proc->mmuptp[lvl]; p != nil; p = p->next){
 		for(p = proc->mmuptp[lvl]; p != nil; p = p->next){
@@ -350,7 +350,7 @@ mmuptpcheck(Proc *proc)
 				panic("ptpcheck: wrong prev");
 				panic("ptpcheck: wrong prev");
 			}
 			}
 		}
 		}
-		
+
 	}
 	}
 	npgs = 0;
 	npgs = 0;
 	for(fp = proc->mmuptp[0]; fp != nil; fp = fp->next){
 	for(fp = proc->mmuptp[0]; fp != nil; fp = fp->next){
@@ -381,7 +381,7 @@ pteflags(uint attr)
 }
 }
 
 
 /*
 /*
- * pg->pgszi indicates the page size in m->pgsz[] used for the mapping.
+ * pg->pgszi indicates the page size in machp()->pgsz[] used for the mapping.
  * For the user, it can be either 2*MiB or 1*GiB pages.
  * For the user, it can be either 2*MiB or 1*GiB pages.
  * For 2*MiB pages, we use three levels, not four.
  * For 2*MiB pages, we use three levels, not four.
  * For 1*GiB pages, we use two levels.
  * For 1*GiB pages, we use two levels.
@@ -389,7 +389,7 @@ pteflags(uint attr)
 void
 void
 mmuput(uintptr_t va, Page *pg, uint attr)
 mmuput(uintptr_t va, Page *pg, uint attr)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	int lvl, user, x, pgsz;
 	int lvl, user, x, pgsz;
 	PTE *pte;
 	PTE *pte;
 	Page *page, *prev;
 	Page *page, *prev;
@@ -403,25 +403,25 @@ mmuput(uintptr_t va, Page *pg, uint attr)
 		panic("mmuput: zero pa");
 		panic("mmuput: zero pa");
 
 
 	if(DBGFLG){
 	if(DBGFLG){
-		snprint(buf, sizeof buf, "cpu%d: up %#p mmuput %#p %#P %#ux\n", 
-			m->machno, m->externup, va, pa, attr);
+		snprint(buf, sizeof buf, "cpu%d: up %#p mmuput %#p %#P %#ux\n",
+			machp()->machno, up, va, pa, attr);
 		print("%s", buf);
 		print("%s", buf);
 	}
 	}
 	assert(pg->pgszi >= 0);
 	assert(pg->pgszi >= 0);
-	pgsz = m->pgsz[pg->pgszi];
+	pgsz = machp()->pgsz[pg->pgszi];
 	if(pa & (pgsz-1))
 	if(pa & (pgsz-1))
 		panic("mmuput: pa offset non zero: %#ullx\n", pa);
 		panic("mmuput: pa offset non zero: %#ullx\n", pa);
 	pa |= pteflags(attr);
 	pa |= pteflags(attr);
 
 
 	pl = splhi();
 	pl = splhi();
 	if(DBGFLG)
 	if(DBGFLG)
-		mmuptpcheck(m->externup);
+		mmuptpcheck(up);
 	user = (va < KZERO);
 	user = (va < KZERO);
 	x = PTLX(va, 3);
 	x = PTLX(va, 3);
 
 
-	pte = UINT2PTR(m->pml4->va);
+	pte = UINT2PTR(machp()->pml4->va);
 	pte += x;
 	pte += x;
-	prev = m->pml4;
+	prev = machp()->pml4;
 
 
 	for(lvl = 3; lvl >= 0; lvl--){
 	for(lvl = 3; lvl >= 0; lvl--){
 		if(user){
 		if(user){
@@ -430,7 +430,7 @@ mmuput(uintptr_t va, Page *pg, uint attr)
 			if(pgsz == 1ull*GiB && lvl == 2)	/* use 1G */
 			if(pgsz == 1ull*GiB && lvl == 2)	/* use 1G */
 				break;
 				break;
 		}
 		}
-		for(page = m->externup->mmuptp[lvl]; page != nil; page = page->next)
+		for(page = up->mmuptp[lvl]; page != nil; page = page->next)
 			if(page->prev == prev && page->daddr == x){
 			if(page->prev == prev && page->daddr == x){
 				if(*pte == 0){
 				if(*pte == 0){
 					print("mmu: jmk and nemo had fun\n");
 					print("mmu: jmk and nemo had fun\n");
@@ -440,19 +440,19 @@ mmuput(uintptr_t va, Page *pg, uint attr)
 			}
 			}
 
 
 		if(page == nil){
 		if(page == nil){
-			if(m->externup->mmuptp[0] == nil)
+			if(up->mmuptp[0] == nil)
 				page = mmuptpalloc();
 				page = mmuptpalloc();
 			else {
 			else {
-				page = m->externup->mmuptp[0];
-				m->externup->mmuptp[0] = page->next;
+				page = up->mmuptp[0];
+				up->mmuptp[0] = page->next;
 			}
 			}
 			page->daddr = x;
 			page->daddr = x;
-			page->next = m->externup->mmuptp[lvl];
-			m->externup->mmuptp[lvl] = page;
+			page->next = up->mmuptp[lvl];
+			up->mmuptp[lvl] = page;
 			page->prev = prev;
 			page->prev = prev;
 			*pte = PPN(page->pa)|PteU|PteRW|PteP;
 			*pte = PPN(page->pa)|PteU|PteRW|PteP;
-			if(lvl == 3 && x >= m->pml4->daddr)
-				m->pml4->daddr = x+1;
+			if(lvl == 3 && x >= machp()->pml4->daddr)
+				machp()->pml4->daddr = x+1;
 		}
 		}
 		x = PTLX(va, lvl-1);
 		x = PTLX(va, lvl-1);
 
 
@@ -481,8 +481,8 @@ mmuput(uintptr_t va, Page *pg, uint attr)
 	splx(pl);
 	splx(pl);
 
 
 	if(DBGFLG){
 	if(DBGFLG){
-		snprint(buf, sizeof buf, "cpu%d: up %#p new pte %#p = %#llux\n", 
-			m->machno, m->externup, pte, pte?*pte:~0);
+		snprint(buf, sizeof buf, "cpu%d: up %#p new pte %#p = %#llux\n",
+			machp()->machno, up, pte, pte?*pte:~0);
 		print("%s", buf);
 		print("%s", buf);
 	}
 	}
 
 
@@ -649,13 +649,13 @@ vmapalloc(usize size)
 void*
 void*
 vmap(uintptr_t pa, usize size)
 vmap(uintptr_t pa, usize size)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	uintptr_t va;
 	uintptr_t va;
 	usize o, sz;
 	usize o, sz;
 
 
 	DBG("vmap(%#p, %lud) pc=%#p\n", pa, size, getcallerpc(&pa));
 	DBG("vmap(%#p, %lud) pc=%#p\n", pa, size, getcallerpc(&pa));
 
 
-	if(m->machno != 0)
+	if(machp()->machno != 0)
 		panic("vmap");
 		panic("vmap");
 
 
 	/*
 	/*
@@ -702,12 +702,12 @@ vmap(uintptr_t pa, usize size)
 void
 void
 vunmap(void* v, usize size)
 vunmap(void* v, usize size)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	uintptr_t va;
 	uintptr_t va;
 
 
 	DBG("vunmap(%#p, %lud)\n", v, size);
 	DBG("vunmap(%#p, %lud)\n", v, size);
 
 
-	if(m->machno != 0)
+	if(machp()->machno != 0)
 		panic("vunmap");
 		panic("vunmap");
 
 
 	/*
 	/*
@@ -729,7 +729,7 @@ int
 mmuwalk(PTE* pml4, uintptr_t va, int level, PTE** ret,
 mmuwalk(PTE* pml4, uintptr_t va, int level, PTE** ret,
 	uint64_t (*alloc)(usize))
 	uint64_t (*alloc)(usize))
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	int l;
 	int l;
 	uintmem pa;
 	uintmem pa;
 	PTE *pte;
 	PTE *pte;
@@ -738,7 +738,7 @@ mmuwalk(PTE* pml4, uintptr_t va, int level, PTE** ret,
 
 
 	pl = splhi();
 	pl = splhi();
 	if(DBGFLG > 1)
 	if(DBGFLG > 1)
-		DBG("mmuwalk%d: va %#p level %d\n", m->machno, va, level);
+		DBG("mmuwalk%d: va %#p level %d\n", machp()->machno, va, level);
 	pte = &pml4[PTLX(va, 3)];
 	pte = &pml4[PTLX(va, 3)];
 	for(l = 3; l >= 0; l--){
 	for(l = 3; l >= 0; l--){
 		if(l == level)
 		if(l == level)
@@ -765,7 +765,7 @@ mmuwalk(PTE* pml4, uintptr_t va, int level, PTE** ret,
 uintmem
 uintmem
 mmuphysaddr(uintptr_t va)
 mmuphysaddr(uintptr_t va)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	int l;
 	int l;
 	PTE *pte;
 	PTE *pte;
 	uintmem mask, pa;
 	uintmem mask, pa;
@@ -776,7 +776,7 @@ mmuphysaddr(uintptr_t va)
 	 * but will do as an experiment. Usual
 	 * but will do as an experiment. Usual
 	 * question, should va be void* or uintptr?
 	 * question, should va be void* or uintptr?
 	 */
 	 */
-	l = mmuwalk(UINT2PTR(m->pml4->va), va, 0, &pte, nil);
+	l = mmuwalk(UINT2PTR(machp()->pml4->va), va, 0, &pte, nil);
 	DBG("physaddr: va %#p l %d\n", va, l);
 	DBG("physaddr: va %#p l %d\n", va, l);
 	if(l < 0)
 	if(l < 0)
 		return ~0;
 		return ~0;
@@ -794,32 +794,32 @@ Page mach0pml4;
 void
 void
 mmuinit(void)
 mmuinit(void)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	uint8_t *p;
 	uint8_t *p;
 	Page *page;
 	Page *page;
 	uint64_t o, pa, r, sz;
 	uint64_t o, pa, r, sz;
 
 
 	archmmu();
 	archmmu();
-	DBG("mach%d: %#p pml4 %#p npgsz %d\n", m->machno, m, m->pml4, m->npgsz);
+	DBG("mach%d: %#p pml4 %#p npgsz %d\n", machp()->machno, machp(), machp()->pml4, machp()->npgsz);
 
 
-	if(m->machno != 0){
+	if(machp()->machno != 0){
 		/* NIX: KLUDGE: Has to go when each mach is using
 		/* NIX: KLUDGE: Has to go when each mach is using
 		 * its own page table
 		 * its own page table
 		 */
 		 */
-		p = UINT2PTR(m->stack);
+		p = UINT2PTR(machp()->stack);
 		p += MACHSTKSZ;
 		p += MACHSTKSZ;
 
 
 		memmove(p, UINT2PTR(mach0pml4.va), PTSZ);
 		memmove(p, UINT2PTR(mach0pml4.va), PTSZ);
-		m->pml4 = &m->pml4kludge;
-		m->pml4->va = PTR2UINT(p);
-		m->pml4->pa = PADDR(p);
-		m->pml4->daddr = mach0pml4.daddr;	/* # of user mappings in pml4 */
+		machp()->pml4 = &machp()->pml4kludge;
+		machp()->pml4->va = PTR2UINT(p);
+		machp()->pml4->pa = PADDR(p);
+		machp()->pml4->daddr = mach0pml4.daddr;	/* # of user mappings in pml4 */
 
 
 		r = rdmsr(Efer);
 		r = rdmsr(Efer);
 		r |= Nxe;
 		r |= Nxe;
 		wrmsr(Efer, r);
 		wrmsr(Efer, r);
-		cr3put(m->pml4->pa);
-		DBG("m %#p pml4 %#p\n", m, m->pml4);
+		cr3put(machp()->pml4->pa);
+		DBG("m %#p pml4 %#p\n", machp(), machp()->pml4);
 		return;
 		return;
 	}
 	}
 
 
@@ -827,7 +827,7 @@ mmuinit(void)
 	page->pa = cr3get();
 	page->pa = cr3get();
 	page->va = PTR2UINT(KADDR(page->pa));
 	page->va = PTR2UINT(KADDR(page->pa));
 
 
-	m->pml4 = page;
+	machp()->pml4 = page;
 
 
 	r = rdmsr(Efer);
 	r = rdmsr(Efer);
 	r |= Nxe;
 	r |= Nxe;

+ 1 - 1
sys/src/9/k10/physalloc.c

@@ -530,7 +530,7 @@ physinit(uintmem a, uint64_t size)
 				b->size = (addr-b->base) + len;
 				b->size = (addr-b->base) + len;
 			for(i = 0; i < Ndoms; i++)
 			for(i = 0; i < Ndoms; i++)
 				if(bal[i].kmin && &bal[i] != b)
 				if(bal[i].kmin && &bal[i] != b)
-				if(bal[i].base < b->base + b->size && 
+				if(bal[i].base < b->base + b->size &&
 				   bal[i].base + bal[i].size > b->base + b->size)
 				   bal[i].base + bal[i].size > b->base + b->size)
 					panic("physinit: doms overlap");
 					panic("physinit: doms overlap");
 		}
 		}

+ 14 - 14
sys/src/9/k10/pmcio.c

@@ -21,7 +21,7 @@
 #include	"../port/pmc.h"
 #include	"../port/pmc.h"
 
 
 
 
-/* non portable, for intel will be CPUID.0AH.EDX 
+/* non portable, for intel will be CPUID.0AH.EDX
  */
  */
 
 
 enum {
 enum {
@@ -38,7 +38,7 @@ pmcnregs(void)
 }
 }
 
 
 //PeHo|PeGo
 //PeHo|PeGo
-#define PeAll	(PeOS|PeUsr)	
+#define PeAll	(PeOS|PeUsr)
 #define SetEvMsk(v, e) ((v)|(((e)&PeEvMskL)|(((e)<<(PeEvMsksh-8))&PeEvMskH)))
 #define SetEvMsk(v, e) ((v)|(((e)&PeEvMskL)|(((e)<<(PeEvMsksh-8))&PeEvMskH)))
 #define SetUMsk(v, u) ((v)|(((u)<<8ull)&PeUnMsk))
 #define SetUMsk(v, u) ((v)|(((u)<<8ull)&PeUnMsk))
 
 
@@ -203,16 +203,16 @@ pmcctlstr(char *str, int nstr, PmcCtl *p)
 		ns += snprint(str + ns, nstr - ns, "enable\n");
 		ns += snprint(str + ns, nstr - ns, "enable\n");
 	else
 	else
 		ns += snprint(str + ns, nstr - ns, "disable\n");
 		ns += snprint(str + ns, nstr - ns, "disable\n");
-		
+
 	if (p->user && p->user != PmcCtlNullval)
 	if (p->user && p->user != PmcCtlNullval)
 		ns += snprint(str + ns, nstr - ns, "user\n");
 		ns += snprint(str + ns, nstr - ns, "user\n");
 	if (p->os && p->user != PmcCtlNullval)
 	if (p->os && p->user != PmcCtlNullval)
 		ns += snprint(str + ns, nstr - ns, "os\n");
 		ns += snprint(str + ns, nstr - ns, "os\n");
-	
+
 	//TODO, inverse pmctrans?
 	//TODO, inverse pmctrans?
 	if(!p->nodesc)
 	if(!p->nodesc)
 		ns += snprint(str + ns, nstr - ns, "%s\n", p->descstr);
 		ns += snprint(str + ns, nstr - ns, "%s\n", p->descstr);
-	else 
+	else
 		ns += snprint(str + ns, nstr - ns, "no desc\n");
 		ns += snprint(str + ns, nstr - ns, "no desc\n");
 	return ns;
 	return ns;
 }
 }
@@ -281,7 +281,7 @@ pmcwclose(PmcWait *w)
 static void
 static void
 waitnotstale(Mach *mp, PmcCtr *p)
 waitnotstale(Mach *mp, PmcCtr *p)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	PmcWait *w;
 	PmcWait *w;
 
 
 	p->stale = 1;
 	p->stale = 1;
@@ -329,12 +329,12 @@ shouldipi(Mach *mp)
 uint64_t
 uint64_t
 pmcgetctr(uint32_t coreno, uint32_t regno)
 pmcgetctr(uint32_t coreno, uint32_t regno)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	PmcCtr *p;
 	PmcCtr *p;
 	Mach *mp;
 	Mach *mp;
 	uint64_t v;
 	uint64_t v;
 
 
-	if(coreno == m->machno){
+	if(coreno == machp()->machno){
 		v = getctr(regno);
 		v = getctr(regno);
 		if (pmcdebug) {
 		if (pmcdebug) {
 			print("int getctr[%#ux, %#ux] = %#llux\n", regno, coreno, v);
 			print("int getctr[%#ux, %#ux] = %#llux\n", regno, coreno, v);
@@ -361,11 +361,11 @@ pmcgetctr(uint32_t coreno, uint32_t regno)
 int
 int
 pmcsetctr(uint32_t coreno, uint64_t v, uint32_t regno)
 pmcsetctr(uint32_t coreno, uint64_t v, uint32_t regno)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	PmcCtr *p;
 	PmcCtr *p;
 	Mach *mp;
 	Mach *mp;
 
 
-	if(coreno == m->machno){
+	if(coreno == machp()->machno){
 		if (pmcdebug) {
 		if (pmcdebug) {
 			print("int getctr[%#ux, %#ux] = %#llux\n", regno, coreno, v);
 			print("int getctr[%#ux, %#ux] = %#llux\n", regno, coreno, v);
 		}
 		}
@@ -405,11 +405,11 @@ ctl2ctl(PmcCtl *dctl, PmcCtl *sctl)
 int
 int
 pmcsetctl(uint32_t coreno, PmcCtl *pctl, uint32_t regno)
 pmcsetctl(uint32_t coreno, PmcCtl *pctl, uint32_t regno)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	PmcCtr *p;
 	PmcCtr *p;
 	Mach *mp;
 	Mach *mp;
 
 
-	if(coreno == m->machno)
+	if(coreno == machp()->machno)
 		return setctl(pctl, regno);
 		return setctl(pctl, regno);
 
 
 	mp = sys->machptr[coreno];
 	mp = sys->machptr[coreno];
@@ -427,11 +427,11 @@ pmcsetctl(uint32_t coreno, PmcCtl *pctl, uint32_t regno)
 int
 int
 pmcgetctl(uint32_t coreno, PmcCtl *pctl, uint32_t regno)
 pmcgetctl(uint32_t coreno, PmcCtl *pctl, uint32_t regno)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	PmcCtr *p;
 	PmcCtr *p;
 	Mach *mp;
 	Mach *mp;
 
 
-	if(coreno == m->machno)
+	if(coreno == machp()->machno)
 		return getctl(pctl, regno);
 		return getctl(pctl, regno);
 
 
 	mp = sys->machptr[coreno];
 	mp = sys->machptr[coreno];

+ 5 - 5
sys/src/9/k10/qmalloc.c

@@ -115,10 +115,10 @@ static	Lock		mainlock;
  * Experiment: per-core quick lists.
  * Experiment: per-core quick lists.
  * change quicklist to be
  * change quicklist to be
  * static	Qlist	quicklist[MACHMAX][NQUICK+1];
  * static	Qlist	quicklist[MACHMAX][NQUICK+1];
- * and define QLIST to be quicklist[m->machno]
+ * and define QLIST to be quicklist[machp()->machno]
  *
  *
- * using quicklist[m->machno] runs out of memory soon.
- * using quicklist[m->machno%4] yields times worse than using quicklist!
+ * using quicklist[machp()->machno] runs out of memory soon.
+ * using quicklist[machp()->machno%4] yields times worse than using quicklist!
  */
  */
 #define QLIST	quicklist
 #define QLIST	quicklist
 
 
@@ -549,11 +549,11 @@ mallocalign(uint32_t nbytes, uint32_t align, int32_t offset, uint32_t span)
 void*
 void*
 smalloc(uint32_t size)
 smalloc(uint32_t size)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	void *v;
 	void *v;
 
 
 	while((v = malloc(size)) == nil)
 	while((v = malloc(size)) == nil)
-		tsleep(&m->externup->sleep, return0, 0, 100);
+		tsleep(&up->sleep, return0, 0, 100);
 	memset(v, 0, size);
 	memset(v, 0, size);
 
 
 	return v;
 	return v;

+ 9 - 9
sys/src/9/k10/sdata.c

@@ -721,7 +721,7 @@ retry:
 			drive->sectors = drive->c*drive->h*drive->s;
 			drive->sectors = drive->c*drive->h*drive->s;
 		atarwmmode(drive, cmdport, ctlport, dev);
 		atarwmmode(drive, cmdport, ctlport, dev);
 	}
 	}
-	atadmamode(drive);	
+	atadmamode(drive);
 
 
 	if(DEBUG & DbgCONFIG){
 	if(DEBUG & DbgCONFIG){
 		print("dev %2.2uX port %uX config %4.4uX capabilities %4.4uX",
 		print("dev %2.2uX port %uX config %4.4uX capabilities %4.4uX",
@@ -762,7 +762,7 @@ ataprobe(int cmdport, int ctlport, int irq)
 	Drive *drive;
 	Drive *drive;
 	int dev, error, rhi, rlo;
 	int dev, error, rhi, rlo;
 	static int nonlegacy = 'C';
 	static int nonlegacy = 'C';
-	
+
 	if(cmdport == 0) {
 	if(cmdport == 0) {
 		print("ataprobe: cmdport is 0\n");
 		print("ataprobe: cmdport is 0\n");
 		return nil;
 		return nil;
@@ -909,7 +909,7 @@ tryedd1:
 	ctlr->irq = irq;
 	ctlr->irq = irq;
 	ctlr->tbdf = BUSUNKNOWN;
 	ctlr->tbdf = BUSUNKNOWN;
 	ctlr->command = Cedd;		/* debugging */
 	ctlr->command = Cedd;		/* debugging */
-	
+
 	switch(cmdport){
 	switch(cmdport){
 	default:
 	default:
 		sdev->idno = nonlegacy;
 		sdev->idno = nonlegacy;
@@ -970,7 +970,7 @@ ataprobew(DevConf *cf)
 {
 {
 	//char *p;
 	//char *p;
 	ISAConf isa;
 	ISAConf isa;
-	
+
 	if (cf->nports != 2)
 	if (cf->nports != 2)
 		error(Ebadarg);
 		error(Ebadarg);
 
 
@@ -1028,7 +1028,7 @@ atamodesense(Drive* drive, uint8_t* cmd)
 static int
 static int
 atastandby(Drive* drive, int period)
 atastandby(Drive* drive, int period)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	Ctlr* ctlr;
 	Ctlr* ctlr;
 	int cmdport, done;
 	int cmdport, done;
 
 
@@ -1277,7 +1277,7 @@ atapktinterrupt(Drive* drive)
 static int
 static int
 atapktio(Drive* drive, uint8_t* cmd, int clen)
 atapktio(Drive* drive, uint8_t* cmd, int clen)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	Ctlr *ctlr;
 	Ctlr *ctlr;
 	int as, cmdport, ctlport, len, r, timeo;
 	int as, cmdport, ctlport, len, r, timeo;
 
 
@@ -1505,7 +1505,7 @@ atagenioretry(Drive* drive)
 static int
 static int
 atagenio(Drive* drive, uint8_t* cmd, int clen)
 atagenio(Drive* drive, uint8_t* cmd, int clen)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	uint8_t *p;
 	uint8_t *p;
 	Ctlr *ctlr;
 	Ctlr *ctlr;
 	int64_t lba, len;
 	int64_t lba, len;
@@ -2163,7 +2163,7 @@ if(0){
 	 * /
 	 * /
 	memset(&isa, 0, sizeof(isa));
 	memset(&isa, 0, sizeof(isa));
 	isa.port = 0x180;		/ * change this for your machine * /
 	isa.port = 0x180;		/ * change this for your machine * /
-	isa.irq = 11;			/ * change this for your machine * / 
+	isa.irq = 11;			/ * change this for your machine * /
 
 
 	port = isa.port+0x0C;
 	port = isa.port+0x0C;
 	channel = pcmspecial("MK2001MPL", &isa);
 	channel = pcmspecial("MK2001MPL", &isa);
@@ -2285,7 +2285,7 @@ atarctl(SDunit* unit, char* p, int l)
 static int
 static int
 atawctl(SDunit* unit, Cmdbuf* cb)
 atawctl(SDunit* unit, Cmdbuf* cb)
 {
 {
-	Mach *m = machp();
+	Proc *up = machp()->externup;
 	int period;
 	int period;
 	Ctlr *ctlr;
 	Ctlr *ctlr;
 	Drive *drive;
 	Drive *drive;

Some files were not shown because too many files changed in this diff