Browse Source

Plan 9 from Bell Labs 2012-09-18

David du Colombier 11 years ago
parent
commit
0a770563dd

+ 1 - 1
amd64/include/u.h

@@ -10,7 +10,7 @@ typedef unsigned long long uintptr;
 typedef unsigned long	usize;
 typedef	ushort		Rune;
 typedef union FPdbleword FPdbleword;
-typedef uvlong		jmp_buf[2];
+typedef uintptr		jmp_buf[2];
 #define	JMPBUFSP	0
 #define	JMPBUFPC	1
 #define	JMPBUFDPC	0

+ 5 - 5
sys/lib/acid/kernel

@@ -32,7 +32,7 @@ IHASHSIZE = 64;
 defn imagecacheline(h) {
 	while h != 0 do {
 		complex Image h;
-		print (h\X, " ", qid(h.qid), " type ", h.type\D, " ref ", h.ref, " next ", h.next\X, " ", cname(h.c.name), "\n");
+		print (h\X, " ", qid(h.qid), " type ", h.type\D, " ref ", h.ref, " next ", h.next\X, " ", path(h.c.path), "\n");
 		h = h.hash;
 	}
 }
@@ -56,9 +56,9 @@ defn chan(c) {
 	print("chan(", c\X, "): ref=", c.ref\D, " #", d.dc\r, c.dev\D, " (", q.path, " ", q.vers\D, " ", q.type\X, ")");
 	print(" fid=", c.fid\D, " iounit=", c.iounit\D);
 	if c.ref != 0 then {
-		print(" ", cname(c.name), " mchan=", c.mchan\X);
+		print(" ", path(c.path), " mchan=", c.mchan\X);
 		if c.mchan != 0 then {
-			print(" ", cname(c.mchan.name));
+			print(" ", path(c.mchan.path));
 		}
 	}
 	print("\n");
@@ -186,7 +186,7 @@ defn procenv(p) {
 
 	e = p.egrp;
 	complex Egrp e;
-	v = e.entries;
+	v = e.ent;
 	while v != 0 do {
 		complex Evalue v;
 		print(*(v.name\s), "=");
@@ -333,7 +333,7 @@ PTEPERTAB = (PTEMAPMEM/BY2PG);
 defn up() {
 	local mach;
 
-	MACHADDR = KZERO+0x4000;
+	MACHADDR = KZERO+0x15000;
 	mach = MACHADDR;
 	complex Mach mach;
 	return mach.externup;

+ 10 - 3
sys/man/3/ip

@@ -143,10 +143,10 @@ written to it will be looped back.
 .B "unbind
 Disassociate the physical device from an IP interface.
 .TP
-.BI add\  "local mask remote mtu " proxy
+.BI add\  "local [ mask remote mtu " proxy " ]
 .PD 0
 .TP
-.BI try\  "local mask remote mtu " proxy
+.BI try\  "local [ mask remote mtu " proxy " ]
 .PD
 Add a local IP address to the interface.
 .I Try
@@ -381,7 +381,7 @@ indicate what routing protocol originated the route.
 Writing to
 .B /net/iproute
 changes the route table.  The messages are:
-.TF "\fLtag \fIstring\fR"
+.TF "\fLroute \fItarget\fR"
 .PD
 .TP
 .B flush
@@ -399,6 +399,13 @@ same target and mask, replace it.
 .BI remove\  "target mask"
 Remove a route with a matching target and mask.
 .
+.TP
+.BI route\  target
+Print on the console the route to address
+.IR target ,
+if any.
+Primarily a debugging aid.
+.
 .SS "Address resolution
 The file
 .B /net/arp

+ 38 - 0
sys/src/9/ip/iproute.c

@@ -781,6 +781,31 @@ routeflush(Fs *f, Route *r, char *tag)
 	return 0;
 }
 
+Route *
+iproute(Fs *fs, uchar *ip)
+{
+	if(isv4(ip))
+		return v4lookup(fs, ip+IPv4off, nil);
+	else
+		return v6lookup(fs, ip, nil);
+}
+
+static void
+printroute(Route *r)
+{
+	int nifc;
+	char t[5], *iname, ifbuf[5];
+	uchar addr[IPaddrlen], mask[IPaddrlen], gate[IPaddrlen];
+
+	convroute(r, addr, mask, gate, t, &nifc);
+	iname = "-";
+	if(nifc != -1) {
+		iname = ifbuf;
+		snprint(ifbuf, sizeof ifbuf, "%d", nifc);
+	}
+	print(rformat, addr, mask, gate, t, r->tag, iname);
+}
+
 long
 routewrite(Fs *f, Chan *c, char *p, int n)
 {
@@ -791,6 +816,7 @@ routewrite(Fs *f, Chan *c, char *p, int n)
 	uchar mask[IPaddrlen];
 	uchar gate[IPaddrlen];
 	IPaux *a, *na;
+	Route *q;
 
 	cb = parsecmd(p, n);
 	if(waserror()){
@@ -846,6 +872,18 @@ routewrite(Fs *f, Chan *c, char *p, int n)
 		na = newipaux(a->owner, cb->f[1]);
 		c->aux = na;
 		free(a);
+	} else if(strcmp(cb->f[0], "route") == 0) {
+		if(cb->nf < 2)
+			error(Ebadarg);
+		if (parseip(addr, cb->f[1]) == -1)
+			error(Ebadip);
+
+		q = iproute(f, addr);
+		print("%I: ", addr);
+		if(q == nil)
+			print("no route\n");
+		else
+			printroute(q);
 	}
 
 	poperror();

+ 1 - 1
sys/src/9/port/sysproc.c

@@ -140,7 +140,7 @@ sysrfork(ulong *arg)
 		incref(p->pgrp);
 	}
 	if(flag & RFNOMNT)
-		up->pgrp->noattach = 1;
+		p->pgrp->noattach = 1;
 
 	if(flag & RFREND)
 		p->rgrp = newrgrp();

+ 57 - 0
sys/src/cmd/5l/asm.c

@@ -80,6 +80,7 @@ asmb(void)
 	case 1:
 	case 2:
 	case 5:
+	case 7:
 		OFFSET = HEADR+textsize;
 		seek(cout, OFFSET, 0);
 		break;
@@ -124,6 +125,8 @@ asmb(void)
 			OFFSET += rnd(datsize, 4096);
 			seek(cout, OFFSET, 0);
 			break;
+		case 7:
+			break;
 		}
 		if(!debug['s'])
 			asmsym();
@@ -212,6 +215,60 @@ asmb(void)
 		lputl(0xe3300000);		/* nop */
 		lputl(0xe3300000);		/* nop */
 		break;
+	case 7:	/* elf */
+		strnput("\177ELF", 4);		/* e_ident */
+		cput(1);			/* class = 32 bit */
+		cput(2);			/* data = MSB */
+		cput(1);			/* version = CURRENT */
+		strnput("", 9);
+		lput((2L<<16)|40);		/* type = EXEC; machine = ARM */
+		lput(1L);			/* version = CURRENT */
+		lput(entryvalue());		/* entry vaddr */
+		lput(52L);			/* offset to first phdr */
+
+		debug['S'] = 1;			/* no symbol table */
+		if(debug['S']){
+			lput(HEADR+textsize+datsize+symsize);	/* offset to first shdr */
+			lput(0L);		/* flags = PPC */
+			lput((52L<<16)|32L);	/* Ehdr & Phdr sizes*/
+			lput((4L<<16)|40L);	/* # Phdrs & Shdr size */
+			lput((4L<<16)|2L);	/* # Shdrs & shdr string size */
+		}
+		else{
+			lput(0L);
+			lput(0L);		/* flags = PPC */
+			lput((52L<<16)|32L);	/* Ehdr & Phdr sizes*/
+			lput((4L<<16)|0L);	/* # Phdrs & Shdr size */
+			lput((4L<<16)|0L);	/* # Shdrs & shdr string size */
+		}
+
+		lput(1L);			/* text - type = PT_LOAD */
+		lput(HEADR);			/* file offset */
+		lput(INITTEXT);			/* vaddr */
+		lput(INITTEXT);			/* paddr */
+		lput(textsize);			/* file size */
+		lput(textsize);			/* memory size */
+		lput(0x05L);			/* protections = RX */
+		lput(0);			/* alignment */
+
+		lput(1L);			/* data - type = PT_LOAD */
+		lput(HEADR+textsize);		/* file offset */
+		lput(INITDAT);			/* vaddr */
+		lput(INITDAT);			/* paddr */
+		lput(datsize);			/* file size */
+		lput(datsize+bsssize);		/* memory size */
+		lput(0x07L);			/* protections = RWX */
+		lput(0);			/* alignment */
+
+		lput(0L);			/* data - type = PT_NULL */
+		lput(HEADR+textsize+datsize);	/* file offset */
+		lput(0L);			/* vaddr */
+		lput(0L);			/* paddr */
+		lput(symsize);			/* symbol table size */
+		lput(lcsize);			/* line number size */
+		lput(0x04L);			/* protections = R */
+		lput(0x04L);			/* alignment code?? */
+		break;
 	}
 	cflush();
 }

+ 10 - 0
sys/src/cmd/5l/obj.c

@@ -19,6 +19,7 @@ char	*thestring 	= "arm";
  *	-H4				is IXP1200 (raw)
  *	-H5 -T0xC0008010 -R1024		is ipaq
  *	-H6 -R4096			no header with segments padded to pages
+ *	-H7				is elf
  */
 
 static int
@@ -183,6 +184,15 @@ main(int argc, char *argv[])
 		if(INITRND == -1)
 			INITRND = 1024;
 		break;
+	case 7:	/* elf executable */
+		HEADR = rnd(52L+3*32L, 16);
+		if(INITTEXT == -1)
+			INITTEXT = 4096+HEADR;
+		if(INITDAT == -1)
+			INITDAT = 0;
+		if(INITRND == -1)
+			INITRND = 4;
+		break;
 	}
 	if(INITDAT != 0 && INITRND != 0)
 		print("warning: -D0x%lux is ignored because of -R0x%lux\n",

+ 2 - 0
sys/src/cmd/6c/reg.c

@@ -50,6 +50,8 @@ regopt(Prog *p)
 	lastr = R;
 	nvar = 0;
 	regbits = RtoB(D_SP) | RtoB(D_AX) | RtoB(D_X0);
+	if(REGEXT)
+		regbits |= RtoB(REGEXT) | RtoB(REGEXT-1);
 	for(z=0; z<BITS; z++) {
 		externs.b[z] = 0;
 		params.b[z] = 0;

+ 12 - 5
sys/src/cmd/6c/txt.c

@@ -1,5 +1,7 @@
 #include "gc.h"
 
+static	int	resvreg[nelem(reg)];
+
 void
 ginit(void)
 {
@@ -94,6 +96,7 @@ ginit(void)
 	if(0)
 		com64init();
 
+	memset(reg, 0, sizeof(reg));
 	for(i=0; i<nelem(reg); i++) {
 		reg[i] = 1;
 		if(i >= D_AX && i <= D_R15 && i != D_SP)
@@ -101,6 +104,10 @@ ginit(void)
 		if(i >= D_X0 && i <= D_X7)
 			reg[i] = 0;
 	}
+	/* keep two external registers */
+	reg[REGEXT] = 1;
+	reg[REGEXT-1] = 1;
+	memmove(resvreg, reg, sizeof(resvreg));
 }
 
 void
@@ -111,10 +118,10 @@ gclean(void)
 
 	reg[D_SP]--;
 	for(i=D_AX; i<=D_R15; i++)
-		if(reg[i])
+		if(reg[i] && !resvreg[i])
 			diag(Z, "reg %R left allocated", i);
 	for(i=D_X0; i<=D_X7; i++)
-		if(reg[i])
+		if(reg[i] && !resvreg[i])
 			diag(Z, "reg %R left allocated", i);
 	while(mnstring)
 		outstring("", 1L);
@@ -179,7 +186,7 @@ nareg(void)
 
 	n = 0;
 	for(i=D_AX; i<=D_R15; i++)
-		if(reg[i] == 0)
+		if(reg[i] == 0 && !resvreg[i])
 			n++;
 	return n;
 }
@@ -337,7 +344,7 @@ regalloc(Node *n, Node *tn, Node *o)
 				goto out;
 		}
 		for(i=D_AX; i<=D_R15; i++)
-			if(reg[i] == 0)
+			if(reg[i] == 0 && !resvreg[i])
 				goto out;
 		diag(tn, "out of fixed registers");
 		goto err;
@@ -350,7 +357,7 @@ regalloc(Node *n, Node *tn, Node *o)
 				goto out;
 		}
 		for(i=D_X0; i<=D_X7; i++)
-			if(reg[i] == 0)
+			if(reg[i] == 0 && !resvreg[i])
 				goto out;
 		diag(tn, "out of float registers");
 		goto out;

+ 3 - 0
sys/src/cmd/6l/span.c

@@ -668,6 +668,9 @@ asmandsz(Adr *a, int r, int rex, int m64)
 
 	rex &= (0x40 | Rxr);
 	v = a->offset;
+	if ((vlong)v != a->offset) 
+		print("asmandsz: Trying to emit %#ullx and 32 bits is not sufficient\n",
+			a->offset);
 	t = a->type;
 	if(a->index != D_NONE) {
 		if(t >= D_INDIR) {

+ 5 - 5
sys/src/cmd/cc/pickle.c

@@ -7,7 +7,7 @@ static char *kwd[] =
 	"$local", "$loop", "$return", "$tail", "$then",
 	"$union", "$whatis", "$while",
 };
-static char picklestr[] = "\tbp = pickle(bp, ep, un, ";
+static char picklestr[] = "\tpickle(s, un, ";
 
 static char*
 pmap(char *s)
@@ -153,10 +153,10 @@ picklemember(Type *t, long off)
 		if(s1 == S)
 			break;
 		if(s == S) {
-			Bprint(&outbuf, "\tbp = pickle_%s(bp, ep, un, (%s*)((char*)addr+%ld+_i*%ld));\n",
+			Bprint(&outbuf, "\tpickle_%s(s, un, (%s*)((char*)addr+%ld+_i*%ld));\n",
 				pmap(s1->name), pmap(s1->name), t->offset+off, t->width);
 		} else {
-			Bprint(&outbuf, "\tbp = pickle_%s(bp, ep, un, &addr->%s);\n",
+			Bprint(&outbuf, "\tpickle_%s(s, un, &addr->%s);\n",
 				pmap(s1->name), pmap(s->name));
 		}
 		break;
@@ -195,10 +195,10 @@ pickletype(Type *t)
 			goto asmstr;
 		an = pmap(s->name);
 
-		Bprint(&outbuf, "uchar*\npickle_%s(uchar *bp, uchar *ep, int un, %s *addr)\n{\n\tint _i = 0;\n\n\tUSED(_i);\n", an, an);
+		Bprint(&outbuf, "void\npickle_%s(void *s, int un, %s *addr)\n{\n\tint _i = 0;\n\n\tUSED(_i);\n", an, an);
 		for(l = t->link; l != T; l = l->down)
 			picklemember(l, 0);
-		Bprint(&outbuf, "\treturn bp;\n}\n\n");
+		Bprint(&outbuf, "}\n\n");
 		break;
 	asmstr:
 		if(s == S)

+ 4 - 0
sys/src/cmd/ip/dhcp.h

@@ -111,6 +111,10 @@ enum
 	ODtftpserver=		66,
 	ODbootfile=		67,
 
+	ODpxearch=		93,	/* see rfc 4578 */
+	ODpxeni=		94,
+	ODpxeguid=		97,
+
 	/* plan9 vendor info options, v4 addresses only (deprecated) */
 	OP9fsv4=		128,	/* plan9 file servers */
 	OP9authv4=		129,	/* plan9 auth servers */

+ 0 - 6
sys/src/cmd/ip/tftpd.c

@@ -340,12 +340,6 @@ options(int fd, char *buf, int bufsz, char *file, ushort oper, char *p, int dlen
 	if (nopts == 0)
 		return 0;		/* no options actually seen */
 
-	if (bp + 3 >= ep)
-		return -1;
-	*bp++ = '\0';
-	*bp++ = '\0';			/* overkill */
-	*bp++ = '\0';
-
 	if (write(fd, buf, bp - buf) < bp - buf) {
 		syslog(dbg, flog, "tftpd network write error on oack to %s: %r",
 			raddr);

+ 1 - 0
sys/src/cmd/plumb/plumber.c

@@ -15,6 +15,7 @@ Ruleset **rules;
 int	printerrors=1;
 jmp_buf	parsejmp;
 char	*lasterror;
+int mainstacksize = 20*1024;
 
 void
 makeports(Ruleset *rules[])

+ 2 - 0
sys/src/cmd/unix/u9fs/plan9.h

@@ -30,6 +30,7 @@ typedef unsigned long long int  uint64_t;
 #endif
 
 #include <inttypes.h>		/* for int64_t et al. */
+#include <stdlib.h>
 #include <stdarg.h>		/* for va_list, vararg macros */
 #ifndef va_copy
 #ifdef __va_copy
@@ -41,6 +42,7 @@ typedef unsigned long long int  uint64_t;
 #include <sys/types.h>
 #include <string.h>		/* for memmove */
 #include <unistd.h>		/* for write */
+#include <fcntl.h>
 
 #define ulong p9ulong		/* because sys/types.h has some of these sometimes */
 #define ushort p9ushort

+ 3 - 3
sys/src/cmd/unix/u9fs/remotehost.c

@@ -1,9 +1,8 @@
-#include <sys/types.h>
+#include <plan9.h>
 #include <sys/socket.h>	/* various networking crud */
 #include <netinet/in.h>
 #include <netinet/tcp.h>
 #include <netdb.h>
-#include <plan9.h>
 
 void
 getremotehostname(char *name, int nname)
@@ -26,7 +25,8 @@ getremotehostname(char *name, int nname)
 	strecpy(name, name+nname, hp->h_name);
 	on = 1;
 	setsockopt(0, SOL_SOCKET, SO_KEEPALIVE, (char*)&on, sizeof(on));
-
+#ifdef TCP_NODELAY
 	on = 1;
 	setsockopt(0, IPPROTO_TCP, TCP_NODELAY, (char*)&on, sizeof(on));
+#endif
 }