Browse Source

Plan 9 from Bell Labs 2013-03-27

David du Colombier 11 years ago
parent
commit
0fee95e9b7

+ 24 - 14
sys/src/9/bcm/trap.c

@@ -18,6 +18,8 @@ typedef struct Intregs Intregs;
 typedef struct Vctl Vctl;
 
 enum {
+	Debug = 0,
+
 	Nvec = 8,		/* # of vectors at start of lexception.s */
 	Fiqenable = 1<<7,
 };
@@ -194,6 +196,26 @@ trapname(int psr)
 	return s;
 }
 
+/* this is quite helpful during mmu and cache debugging */
+static void
+ckfaultstuck(uintptr va)
+{
+	static int cnt, lastpid;
+	static uintptr lastva;
+
+	if (va == lastva && up->pid == lastpid) {
+		++cnt;
+		if (cnt >= 2)
+			/* fault() isn't fixing the underlying cause */
+			panic("fault: %d consecutive faults for va %#p",
+				cnt+1, va);
+	} else {
+		cnt = 0;
+		lastva = va;
+		lastpid = up->pid;
+	}
+}
+
 /*
  *  called by trap to handle access faults
  */
@@ -202,8 +224,6 @@ faultarm(Ureg *ureg, uintptr va, int user, int read)
 {
 	int n, insyscall;
 	char buf[ERRMAX];
-	static int cnt, lastpid;
-	static ulong lastva;
 
 	if(up == nil) {
 		dumpregs(ureg);
@@ -211,18 +231,8 @@ faultarm(Ureg *ureg, uintptr va, int user, int read)
 	}
 	insyscall = up->insyscall;
 	up->insyscall = 1;
-	/* this is quite helpful during mmu and cache debugging */
-	if(va == lastva && up->pid == lastpid) {
-		++cnt;
-		if (cnt >= 2)
-			/* fault() isn't fixing the underlying cause */
-			panic("fault: %d consecutive faults for va %#lux",
-				cnt+1, va);
-	} else {
-		cnt = 0;
-		lastva = va;
-		lastpid = up->pid;
-	}
+	if (Debug)
+		ckfaultstuck(va);
 
 	n = fault(va, read);
 	if(n < 0){

+ 24 - 13
sys/src/9/kw/trap.c

@@ -13,6 +13,8 @@
 #include "arm.h"
 
 enum {
+	Debug = 0,
+
 	Ntimevec = 20,			/* # of time buckets for each intr */
 	Nvecs = 256,
 };
@@ -311,6 +313,26 @@ trapname(int psr)
 	return s;
 }
 
+/* this is quite helpful during mmu and cache debugging */
+static void
+ckfaultstuck(uintptr va)
+{
+	static int cnt, lastpid;
+	static uintptr lastva;
+
+	if (va == lastva && up->pid == lastpid) {
+		++cnt;
+		if (cnt >= 2)
+			/* fault() isn't fixing the underlying cause */
+			panic("fault: %d consecutive faults for va %#p",
+				cnt+1, va);
+	} else {
+		cnt = 0;
+		lastva = va;
+		lastpid = up->pid;
+	}
+}
+
 /*
  *  called by trap to handle access faults
  */
@@ -328,19 +350,8 @@ faultarm(Ureg *ureg, uintptr va, int user, int read)
 	}
 	insyscall = up->insyscall;
 	up->insyscall = 1;
-
-	/* this is quite helpful during mmu and cache debugging */
-	if(va == lastva && up->pid == lastpid) {
-		++cnt;
-		if (cnt >= 2)
-			/* fault() isn't fixing the underlying cause */
-			panic("fault: %d consecutive faults for va %#lux",
-				cnt+1, va);
-	} else {
-		cnt = 0;
-		lastva = va;
-		lastpid = up->pid;
-	}
+	if (Debug)
+		ckfaultstuck(va);
 
 	n = fault(va, read);
 	if(n < 0){

+ 2 - 1
sys/src/9/ppc/mkfile

@@ -2,6 +2,7 @@ CONF=ucu
 CONFLIST=blast ucu
 
 loadaddr = 0x80100000
+physaddr = 0x00100000
 
 objtype=power
 </$objtype/mkfile
@@ -85,7 +86,7 @@ it:V: $p$CONF
 
 9ucu:	$CONF.c $OBJ $LIB
 	$CC $CFLAGS '-DKERNDATE='`{date -n} $CONF.c
-	$LD -R0x1000 -H5 -o $target -T$loadaddr -l $OBJ $CONF.$O $LIB
+	$LD -R0x1000 -H5 -o $target -T$loadaddr -P$physaddr -l $OBJ $CONF.$O $LIB
 
 install:V: $p$CONF
 	cp $p$CONF /$objtype/$p$CONF

+ 28 - 52
sys/src/cmd/5l/asm.c

@@ -216,58 +216,8 @@ asmb(void)
 		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?? */
+		debug['S'] = 1;			/* symbol table */
+		elf32(ARM, ELFDATA2LSB, 0, nil);
 		break;
 	}
 	cflush();
@@ -306,6 +256,18 @@ wput(long l)
 		cflush();
 }
 
+void
+wputl(long l)
+{
+
+	cbp[0] = l;
+	cbp[1] = l>>8;
+	cbp += 2;
+	cbc -= 2;
+	if(cbc <= 0)
+		cflush();
+}
+
 void
 lput(long l)
 {
@@ -334,6 +296,20 @@ lputl(long l)
 		cflush();
 }
 
+void
+llput(vlong v)
+{
+	lput(v>>32);
+	lput(v);
+}
+
+void
+llputl(vlong v)
+{
+	lputl(v);
+	lputl(v>>32);
+}
+
 void
 cflush(void)
 {

+ 5 - 0
sys/src/cmd/5l/l.h

@@ -2,6 +2,7 @@
 #include	<libc.h>
 #include	<bio.h>
 #include	"../5c/5.out.h"
+#include	"../8l/elf.h"
 
 #ifndef	EXTERN
 #define	EXTERN	extern
@@ -224,6 +225,7 @@ EXTERN	int	HEADTYPE;		/* type of header */
 EXTERN	long	INITDAT;		/* data location */
 EXTERN	long	INITRND;		/* data round above text location */
 EXTERN	long	INITTEXT;		/* text location */
+EXTERN	long	INITTEXTP;		/* text location (physical) */
 EXTERN	char*	INITENTRY;		/* entry point */
 EXTERN	long	autosize;
 EXTERN	Biobuf	bso;
@@ -359,6 +361,8 @@ void	loadlib(void);
 void	listinit(void);
 Sym*	lookup(char*, int);
 void	cput(int);
+void	llput(vlong);
+void	llputl(vlong);
 void	lput(long);
 void	lputl(long);
 void	mkfwd(void);
@@ -397,6 +401,7 @@ void	strnput(char*, int);
 void	undef(void);
 void	undefsym(Sym*);
 void	wput(long);
+void	wputl(long);
 void	xdefine(char*, int, long);
 void	xfol(Prog*);
 void	zerosig(char*);

+ 5 - 0
sys/src/cmd/5l/mkfile

@@ -11,12 +11,15 @@ OFILES=\
 	span.$O\
 	enam.$O\
 	compat.$O\
+	elf.$O\
 
 HFILES=\
 	l.h\
 	../5c/5.out.h\
+	../8l/elf.h\
 
 BIN=/$objtype/bin
+CFLAGS=$CFLAGS -. -I.
 </sys/src/cmd/mkone
 
 ../5c/enam.c: ../5c/5.out.h
@@ -24,6 +27,8 @@ BIN=/$objtype/bin
 
 enam.$O:	../5c/enam.c
 	$CC $CFLAGS ../5c/enam.c
+elf.$O:	../8l/elf.c
+	$CC $CFLAGS ../8l/elf.c
 
 x:V:	$O.out
 	$O.out -la -o/dev/null x.5

+ 11 - 2
sys/src/cmd/5l/obj.c

@@ -70,6 +70,7 @@ main(int argc, char *argv[])
 	curtext = P;
 	HEADTYPE = -1;
 	INITTEXT = -1;
+	INITTEXTP = -1;
 	INITDAT = -1;
 	INITRND = -1;
 	INITENTRY = 0;
@@ -96,6 +97,11 @@ main(int argc, char *argv[])
 		if(a)
 			INITTEXT = atolwhex(a);
 		break;
+	case 'P':
+		a = ARGF();
+		if(a)
+			INITTEXTP = atolwhex(a);
+		break;
 	case 'D':
 		a = ARGF();
 		if(a)
@@ -208,7 +214,7 @@ main(int argc, char *argv[])
 			INITRND = 1024;
 		break;
 	case 7:	/* elf executable */
-		HEADR = rnd(52L+3*32L, 16);
+		HEADR = rnd(Ehdr32sz+3*Phdr32sz, 16);
 		if(INITTEXT == -1)
 			INITTEXT = 4096+HEADR;
 		if(INITDAT == -1)
@@ -217,6 +223,8 @@ main(int argc, char *argv[])
 			INITRND = 4;
 		break;
 	}
+	if (INITTEXTP == -1)
+		INITTEXTP = INITTEXT;
 	if(INITDAT != 0 && INITRND != 0)
 		print("warning: -D0x%lux is ignored because of -R0x%lux\n",
 			INITDAT, INITRND);
@@ -468,7 +476,8 @@ objfile(char *file)
 			l |= (e[3] & 0xff) << 16;
 			l |= (e[4] & 0xff) << 24;
 			seek(f, l, 0);
-			l = read(f, &arhdr, SAR_HDR);
+			/* need readn to read the dumps (at least) */
+			l = readn(f, &arhdr, SAR_HDR);
 			if(l != SAR_HDR)
 				goto bad;
 			if(strncmp(arhdr.fmag, ARFMAG, sizeof(arhdr.fmag)))

+ 5 - 115
sys/src/cmd/6l/asm.c

@@ -28,15 +28,15 @@ entryvalue(void)
 	return s->value;
 }
 
-void
-wputl(ushort w)
+/* these need to take long arguments to be compatible with elf.c */void
+wputl(long w)
 {
 	cput(w);
 	cput(w>>8);
 }
 
 void
-wput(ushort w)
+wput(long w)
 {
 	cput(w>>8);
 	cput(w);
@@ -220,120 +220,10 @@ asmb(void)
 		llput(vl);			/* va of entry */
 		break;
 	case 5:
-		strnput("\177ELF", 4);		/* e_ident */
-		cput(1);			/* class = 32 bit */
-		cput(1);			/* data = LSB */
-		cput(1);			/* version = CURRENT */
-		if(debug['P']){			/* boot/embedded/standalone */
-			cput(255);
-			cput(0);
-		}
-		else{
-			cput(0);		/* osabi = SYSV */
-			cput(0);		/* abiversion = 3 */
-		}
-		strnput("", 7);
-		wputl(2);			/* type = EXEC */
-		if(debug['8'])
-			wputl(3);		/* machine = 386 */
-		else
-			wputl(62);		/* machine = AMD64 */
-		lputl(1L);			/* version = CURRENT */
-		lputl(PADDR(entryvalue()));	/* entry vaddr */
-		lputl(52L);			/* offset to first phdr */
-		lputl(0L);			/* offset to first shdr */
-		lputl(0L);			/* processor specific flags */
-		wputl(52);			/* Ehdr size */
-		wputl(32);			/* Phdr size */
-		wputl(3);			/* # of Phdrs */
-		wputl(0);			/* Shdr size */
-		wputl(0);			/* # of Shdrs */
-		wputl(0);			/* Shdr string size */
-
-		lputl(1L);			/* text - type = PT_LOAD */
-		lputl(HEADR);			/* file offset */
-		lputl(INITTEXT);		/* vaddr */
-		lputl(PADDR(INITTEXT));		/* paddr */
-		lputl(textsize);		/* file size */
-		lputl(textsize);		/* memory size */
-		lputl(0x05L);			/* protections = RX */
-		lputl(INITRND);			/* alignment */
-
-		lputl(1L);			/* data - type = PT_LOAD */
-		lputl(HEADR+textsize);		/* file offset */
-		lputl(INITDAT);			/* vaddr */
-		lputl(PADDR(INITDAT));		/* paddr */
-		lputl(datsize);			/* file size */
-		lputl(datsize+bsssize);		/* memory size */
-		lputl(0x06L);			/* protections = RW */
-		lputl(INITRND);			/* alignment */
-
-		lputl(0L);			/* symbols - type = PT_NULL */
-		lputl(HEADR+textsize+datsize);	/* file offset */
-		lputl(0L);
-		lputl(0L);
-		lputl(symsize);			/* symbol table size */
-		lputl(lcsize);			/* line number size */
-		lputl(0x04L);			/* protections = R */
-		lputl(0x04L);			/* alignment */
+		elf32(debug['8']? I386: AMD64, ELFDATA2LSB, 0, nil);
 		break;
 	case 6:
-		strnput("\177ELF", 4);		/* e_ident */
-		cput(2);			/* class = 64 bit */
-		cput(1);			/* data = LSB */
-		cput(1);			/* version = CURRENT */
-		if(debug['P']){			/* boot/embedded/standalone */
-			cput(255);
-			cput(0);
-		}
-		else{
-			cput(0);		/* osabi = SYSV */
-			cput(0);		/* abiversion = 3 */
-		}
-		strnput("", 7);
-		wputl(2);			/* type = EXEC */
-		wputl(62);			/* machine = AMD64 */
-		lputl(1L);			/* version = CURRENT */
-		if(debug['P'])			/* boot/embedded/standalone */
-			llputl(PADDR(entryvalue()));
-		else
-			llputl(entryvalue());	/* entry vaddr */
-		llputl(64ull);			/* offset to first phdr */
-		llputl(0);			/* offset to first shdr */
-		lputl(0L);			/* processor specific flags */
-		wputl(64);			/* E64hdr size */
-		wputl(56);			/* P64hdr size */
-		wputl(3);			/* # of P64hdrs */
-		wputl(64);			/* S64hdr size */
-		wputl(0);			/* # of S64hdrs */
-		wputl(0);			/* S64hdr string size */
-
-		lputl(1L);			/* text - type = PT_LOAD */
-		lputl(0x05L);			/* protections = RX */
-		llputl(HEADR);			/* file offset */
-		llputl(INITTEXT);		/* vaddr */
-		llput(PADDR(INITTEXT));		/* paddr */
-		llput(textsize);		/* file size */
-		llput(textsize);		/* memory size */
-		llput(INITRND);			/* alignment */
-
-		lputl(1L);			/* data - type = PT_LOAD */
-		lputl(0x06L);			/* protections = RW */
-		llputl(HEADR+textsize);		/* file offset */
-		llputl(INITDAT);		/* vaddr */
-		llputl(PADDR(INITDAT));		/* paddr */
-		llputl(datsize);		/* file size */
-		llputl(datsize+bsssize);	/* memory size */
-		llputl(INITRND);		/* alignment */
-
-		lputl(0L);			/* symbols - type = PT_NULL */
-		lputl(0x04L);			/* protections = R */
-		llputl(HEADR+textsize+datsize);	/* file offset */
-		llputl(0);
-		llputl(0);
-		llputl(symsize);		/* symbol table size */
-		llputl(lcsize);			/* line number size */
-		llputl(0x04ull);		/* alignment */
+		elf64(AMD64, ELFDATA2LSB, 0, nil);
 		break;
 	}
 	cflush();

+ 7 - 1
sys/src/cmd/6l/l.h

@@ -2,6 +2,7 @@
 #include	<libc.h>
 #include	<bio.h>
 #include	"../6c/6.out.h"
+#include	"../8l/elf.h"
 
 #ifndef	EXTERN
 #define	EXTERN	extern
@@ -252,6 +253,7 @@ EXTERN	long	HEADTYPE;
 EXTERN	vlong	INITDAT;
 EXTERN	long	INITRND;
 EXTERN	vlong	INITTEXT;
+EXTERN	vlong	INITTEXTP;
 EXTERN	char*	INITENTRY;		/* entry point */
 EXTERN	Biobuf	bso;
 EXTERN	long	bsssize;
@@ -370,6 +372,8 @@ void	ldobj(int, long, char*);
 void	loadlib(void);
 void	listinit(void);
 Sym*	lookup(char*, int);
+void	llput(vlong v);
+void	llputl(vlong v);
 void	lput(long);
 void	lputl(long);
 void	main(int, char*[]);
@@ -385,10 +389,12 @@ int	relinv(int);
 long	reuse(Prog*, Sym*);
 vlong	rnd(vlong, vlong);
 void	span(void);
+void	strnput(char*, int);
 void	undef(void);
 void	undefsym(Sym*);
 vlong	vaddr(Adr*);
-void	wput(ushort);
+void	wput(long);
+void	wputl(long);
 void	xdefine(char*, int, vlong);
 void	xfol(Prog*);
 int	zaddr(uchar*, Adr*, Sym*[]);

+ 5 - 1
sys/src/cmd/6l/mkfile

@@ -10,12 +10,15 @@ OFILES=\
 	list.$O\
 	enam.$O\
 	compat.$O\
+	elf.$O\
 
 HFILES=\
 	l.h\
 	../6c/6.out.h\
+	../8l/elf.h\
 
 BIN=/$objtype/bin
+CFLAGS=$CFLAGS -. -I.
 CFILES=${OFILES:%.$O=%.c}
 CFILES=${CFILES:enam.c=../6c/enam.c}
 UPDATE=\
@@ -28,4 +31,5 @@ UPDATE=\
 
 enam.$O:	../6c/enam.c
 	$CC $CFLAGS ../6c/enam.c
-
+elf.$O:	../8l/elf.c
+	$CC $CFLAGS ../8l/elf.c

+ 12 - 3
sys/src/cmd/6l/obj.c

@@ -68,6 +68,7 @@ main(int argc, char *argv[])
 	outfile = "6.out";
 	HEADTYPE = -1;
 	INITTEXT = -1;
+	INITTEXTP = -1;
 	INITDAT = -1;
 	INITRND = -1;
 	INITENTRY = 0;
@@ -98,6 +99,11 @@ main(int argc, char *argv[])
 		if(a)
 			INITTEXT = atolwhex(a);
 		break;
+	case 'P':
+		a = ARGF();
+		if(a)
+			INITTEXTP = atolwhex(a);
+		break;
 	case 'D':
 		a = ARGF();
 		if(a)
@@ -155,7 +161,7 @@ main(int argc, char *argv[])
 			INITRND = 0x200000;
 		break;
 	case 5:	/* elf32 executable */
-		HEADR = rnd(52L+3*32L, 16);
+		HEADR = rnd(Ehdr32sz+3*Phdr32sz, 16);
 		if(INITTEXT == -1)
 			INITTEXT = 0xf0110000L;
 		if(INITDAT == -1)
@@ -164,7 +170,7 @@ main(int argc, char *argv[])
 			INITRND = 4096;
 		break;
 	case 6:	/* ELF64 executable */
-		HEADR = rnd(64L+3*56L, 16);
+		HEADR = rnd(Ehdr64sz+3*Phdr64sz, 16);
 		if(INITTEXT == -1)
 			INITTEXT = 0x200000+HEADR;
 		if(INITDAT == -1)
@@ -173,6 +179,8 @@ main(int argc, char *argv[])
 			INITRND = 0x200000;
 		break;
 	}
+	if (INITTEXTP == -1)
+		INITTEXTP = INITTEXT;
 	if(INITDAT != 0 && INITRND != 0)
 		print("warning: -D0x%llux is ignored because of -R0x%lux\n",
 			INITDAT, INITRND);
@@ -527,7 +535,8 @@ objfile(char *file)
 			l |= (e[3] & 0xff) << 16;
 			l |= (e[4] & 0xff) << 24;
 			seek(f, l, 0);
-			l = read(f, &arhdr, SAR_HDR);
+			/* need readn to read the dumps (at least) */
+			l = readn(f, &arhdr, SAR_HDR);
 			if(l != SAR_HDR)
 				goto bad;
 			if(strncmp(arhdr.fmag, ARFMAG, sizeof(arhdr.fmag)))

+ 18 - 49
sys/src/cmd/8l/asm.c

@@ -2,8 +2,6 @@
 
 #define	Dbufslop	100
 
-#define PADDR(a)	((ulong)(a) & ~0xF0000000)
-
 long
 entryvalue(void)
 {
@@ -28,15 +26,16 @@ entryvalue(void)
 	return s->value;
 }
 
+/* these need to take long arguments to be compatible with elf.c */
 void
-wputl(ushort w)
+wputl(long w)
 {
 	cput(w);
 	cput(w>>8);
 }
 
 void
-wput(ushort w)
+wput(long w)
 {
 	cput(w>>8);
 	cput(w);
@@ -60,6 +59,20 @@ lputl(long l)
 	cput(l>>24);
 }
 
+void
+llput(vlong v)
+{
+	lput(v>>32);
+	lput(v);
+}
+
+void
+llputl(vlong v)
+{
+	lputl(v);
+	lputl(v>>32);
+}
+
 void
 strnput(char *s, int n)
 {
@@ -335,51 +348,7 @@ asmb(void)
 		wputl(0x0000);			/* overlay number */
 		break;
 	case 5:
-		strnput("\177ELF", 4);		/* e_ident */
-		cput(1);			/* class = 32 bit */
-		cput(1);			/* data = LSB */
-		cput(1);			/* version = CURRENT */
-		strnput("", 9);
-		wputl(2);			/* type = EXEC */
-		wputl(3);			/* machine = 386 */
-		lputl(1L);			/* version = CURRENT */
-		lputl(PADDR(entryvalue()));	/* entry vaddr */
-		lputl(52L);			/* offset to first phdr */
-		lputl(0L);			/* offset to first shdr */
-		lputl(0L);			/* flags = 386 */
-		wputl(52);			/* Ehdr size */
-		wputl(32);			/* Phdr size */
-		wputl(3);			/* # of Phdrs */
-		wputl(0);			/* Shdr size */
-		wputl(0);			/* # of Shdrs */
-		wputl(0);			/* Shdr string size */
-
-		lputl(1L);			/* text - type = PT_LOAD */
-		lputl(HEADR);			/* file offset */
-		lputl(INITTEXT);		/* vaddr */
-		lputl(PADDR(INITTEXT));		/* paddr */
-		lputl(textsize);		/* file size */
-		lputl(textsize);		/* memory size */
-		lputl(0x05L);			/* protections = RX */
-		lputl(INITRND);			/* alignment */
-
-		lputl(1L);			/* data - type = PT_LOAD */
-		lputl(HEADR+textsize);		/* file offset */
-		lputl(INITDAT);			/* vaddr */
-		lputl(PADDR(INITDAT));		/* paddr */
-		lputl(datsize);			/* file size */
-		lputl(datsize+bsssize);		/* memory size */
-		lputl(0x06L);			/* protections = RW */
-		lputl(INITRND);			/* alignment */
-
-		lputl(0L);			/* data - type = PT_NULL */
-		lputl(HEADR+textsize+datsize);	/* file offset */
-		lputl(0L);
-		lputl(0L);
-		lputl(symsize);			/* symbol table size */
-		lputl(lcsize);			/* line number size */
-		lputl(0x04L);			/* protections = R */
-		lputl(0x04L);			/* alignment */
+		elf32(I386, ELFDATA2LSB, 0, nil);
 		break;
 	}
 	cflush();

+ 7 - 1
sys/src/cmd/8l/l.h

@@ -2,6 +2,7 @@
 #include	<libc.h>
 #include	<bio.h>
 #include	"../8c/8.out.h"
+#include	"../8l/elf.h"
 
 #ifndef	EXTERN
 #define	EXTERN	extern
@@ -216,6 +217,7 @@ EXTERN	long	HEADTYPE;
 EXTERN	long	INITDAT;
 EXTERN	long	INITRND;
 EXTERN	long	INITTEXT;
+EXTERN	long	INITTEXTP;
 EXTERN	char*	INITENTRY;		/* entry point */
 EXTERN	Biobuf	bso;
 EXTERN	long	bsssize;
@@ -331,6 +333,8 @@ void	listinit(void);
 Sym*	lookup(char*, int);
 void	lput(long);
 void	lputl(long);
+void	llput(vlong v);
+void	llputl(vlong v);
 void	main(int, char*[]);
 void	mkfwd(void);
 void*	mysbrk(ulong);
@@ -344,10 +348,12 @@ int	relinv(int);
 long	reuse(Prog*, Sym*);
 long	rnd(long, long);
 void	span(void);
+void	strnput(char*, int);
 void	undef(void);
 void	undefsym(Sym*);
 long	vaddr(Adr*);
-void	wput(ushort);
+void	wput(long);
+void	wputl(long);
 void	xdefine(char*, int, long);
 void	xfol(Prog*);
 int	zaddr(uchar*, Adr*, Sym*[]);

+ 5 - 1
sys/src/cmd/8l/mkfile

@@ -10,12 +10,15 @@ OFILES=\
 	list.$O\
 	enam.$O\
 	compat.$O\
+	elf.$O\
 
 HFILES=\
 	l.h\
 	../8c/8.out.h\
+	../8l/elf.h\
 
 BIN=/$objtype/bin
+CFLAGS=$CFLAGS -. -I.
 CFILES=${OFILES:%.$O=%.c}
 CFILES=${CFILES:enam.c=../8c/enam.c}
 UPDATE=\
@@ -28,4 +31,5 @@ UPDATE=\
 
 enam.$O:	../8c/enam.c
 	$CC $CFLAGS ../8c/enam.c
-
+elf.$O:	../8l/elf.c
+	$CC $CFLAGS ../8l/elf.c

+ 11 - 2
sys/src/cmd/8l/obj.c

@@ -68,6 +68,7 @@ main(int argc, char *argv[])
 	outfile = "8.out";
 	HEADTYPE = -1;
 	INITTEXT = -1;
+	INITTEXTP = -1;
 	INITDAT = -1;
 	INITRND = -1;
 	INITENTRY = 0;
@@ -98,6 +99,11 @@ main(int argc, char *argv[])
 		if(a)
 			INITTEXT = atolwhex(a);
 		break;
+	case 'P':
+		a = ARGF();
+		if(a)
+			INITTEXTP = atolwhex(a);
+		break;
 	case 'D':
 		a = ARGF();
 		if(a)
@@ -202,7 +208,7 @@ main(int argc, char *argv[])
 			Bprint(&bso, "HEADR = 0x%ld\n", HEADR);
 		break;
 	case 5:	/* elf executable */
-		HEADR = rnd(52L+3*32L, 16);
+		HEADR = rnd(Ehdr32sz+3*Phdr32sz, 16);
 		if(INITTEXT == -1)
 			INITTEXT = 0x80100020L;
 		if(INITDAT == -1)
@@ -211,6 +217,8 @@ main(int argc, char *argv[])
 			INITRND = 4096;
 		break;
 	}
+	if (INITTEXTP == -1)
+		INITTEXTP = INITTEXT;
 	if(INITDAT != 0 && INITRND != 0)
 		print("warning: -D0x%lux is ignored because of -R0x%lux\n",
 			INITDAT, INITRND);
@@ -511,7 +519,8 @@ objfile(char *file)
 			l |= (e[3] & 0xff) << 16;
 			l |= (e[4] & 0xff) << 24;
 			seek(f, l, 0);
-			l = read(f, &arhdr, SAR_HDR);
+			/* need readn to read the dumps (at least) */
+			l = readn(f, &arhdr, SAR_HDR);
 			if(l != SAR_HDR)
 				goto bad;
 			if(strncmp(arhdr.fmag, ARFMAG, sizeof(arhdr.fmag)))

+ 2 - 1
sys/src/cmd/kl/obj.c

@@ -379,7 +379,8 @@ objfile(char *file)
 			l |= (e[3] & 0xff) << 16;
 			l |= (e[4] & 0xff) << 24;
 			seek(f, l, 0);
-			l = read(f, &arhdr, SAR_HDR);
+			/* need readn to read the dumps (at least) */
+			l = readn(f, &arhdr, SAR_HDR);
 			if(l != SAR_HDR)
 				goto bad;
 			if(strncmp(arhdr.fmag, ARFMAG, sizeof(arhdr.fmag)))

+ 53 - 176
sys/src/cmd/ql/asm.c

@@ -1,6 +1,5 @@
 #include	"l.h"
 
-#define	KMASK	0xF0000000
 #define JMPSZ	sizeof(u32int)		/* size of bootstrap jump section */
 
 #define	LPUT(c)\
@@ -46,52 +45,11 @@ entryvalue(void)
 }
 
 static void
-endelfsectab(void)
+elf32jmp(Putl putl)
 {
-	seek(cout, HEADR+textsize+datsize+symsize, 0);
-	lput(1);			/* Section name (string tbl index) */
-	lput(1);			/* Section type */
-	lput(2|4);			/* Section flags */
-	lput(INITTEXT & ~KMASK);	/* Section virtual addr at execution */
-	lput(HEADR);			/* Section file offset */
-	lput(textsize);			/* Section size in bytes */
-	lput(0);			/* Link to another section */
-	lput(0);			/* Additional section information */
-	lput(0x10000L);			/* Section alignment */
-	lput(0);			/* Entry size if section holds table */
-
-	lput(7);			/* Section name (string tbl index) */
-	lput(1);			/* Section type */
-	lput(2|1);			/* Section flags */
-	lput(INITDAT & ~KMASK);		/* Section virtual addr at execution */
-	lput(HEADR+textsize);		/* Section file offset */
-	lput(datsize);			/* Section size in bytes */
-	lput(0);			/* Link to another section */
-	lput(0);			/* Additional section information */
-	lput(0x10000L);			/* Section alignment */
-	lput(0);			/* Entry size if section holds table */
-
-	/* string section header */
-	lput(12);			/* Section name (string tbl index) */
-	lput(3);			/* Section type */
-	lput(1 << 5);			/* Section flags */
-	lput(0);			/* Section virtual addr at execution */
-	lput(HEADR+textsize+datsize+symsize+3*40);	/* Section file offset */
-	lput(14);			/* Section size in bytes */
-	lput(0);			/* Link to another section */
-	lput(0);			/* Additional section information */
-	lput(1);			/* Section alignment */
-	lput(0);			/* Entry size if section holds table */
-
-	/* string table */
-	cput(0);
-	strnput(".text", 5);
-	cput(0);
-	strnput(".data", 5);
-	cput(0);
-	strnput(".strtab", 7);
-	cput(0);
-	cput(0);
+	/* describe a tiny text section at end with jmp to start; see below */
+	elf32phdr(putl, PT_LOAD, HEADR+textsize-JMPSZ, 0xFFFFFFFC, 0xFFFFFFFC,
+		JMPSZ, JMPSZ, R|X, 0);	/* text */
 }
 
 void
@@ -142,10 +100,6 @@ asmb(void)
 		}
 		prevpc = pc;
 	}
-	/* for virtex 4, inject a jmp instruction after other text */
-	if(HEADTYPE == 6)
-		/* branch to absolute entry address (0xfffe2100) */
-		lput((18 << 26) | (0x03FFFFFC & entryvalue()) | 2);
 
 	if(debug['a'])
 		Bprint(&bso, "\n");
@@ -156,7 +110,13 @@ asmb(void)
 	curtext = P;
 	switch(HEADTYPE) {
 	case 6:
+		/*
+		 * but first, for virtex 4, inject a jmp instruction after
+		 * other text: branch to absolute entry address (0xfffe2100).
+		 */
+		lput((18 << 26) | (0x03FFFFFC & entryvalue()) | 2);
 		textsize += JMPSZ;
+		cflush();
 		/* fall through */
 	case 0:
 	case 1:
@@ -364,136 +324,16 @@ asmb(void)
 		break;
 	case 5:
 		/*
-		 * customised for blue/gene,
-		 * notably the alignment and KMASK masking.
+		 * intended for blue/gene
 		 */
-		strnput("\177ELF", 4);		/* e_ident */
-		CPUT(1);			/* class = 32 bit */
-		CPUT(2);			/* data = MSB */
-		CPUT(1);			/* version = CURRENT */
-		strnput("", 9);
-		lput((2L<<16)|20L);		/* type = EXEC; machine = PowerPC */
-		lput(1L);			/* version = CURRENT */
-		lput(entryvalue() & ~KMASK);	/* entry vaddr */
-		lput(52L);			/* offset to first phdr */
-
-		if(debug['S']){
-			lput(HEADR+textsize+datsize+symsize);	/* offset to first shdr */
-			lput(0L);		/* flags = PPC */
-			lput((52L<<16)|32L);	/* Ehdr & Phdr sizes*/
-			lput((3L<<16)|40L);	/* # Phdrs & Shdr size */
-			lput((3L<<16)|2L);	/* # Shdrs & shdr string size */
-		}
-		else{
-			lput(0L);
-			lput(0L);		/* flags = PPC */
-			lput((52L<<16)|32L);	/* Ehdr & Phdr sizes*/
-			lput((3L<<16)|0L);	/* # Phdrs & Shdr size */
-			lput((3L<<16)|0L);	/* # Shdrs & shdr string size */
-		}
-
-		lput(1L);			/* text - type = PT_LOAD */
-		lput(HEADR);			/* file offset */
-		lput(INITTEXT & ~KMASK);	/* vaddr */
-		lput(INITTEXT);			/* paddr */
-		lput(textsize);			/* file size */
-		lput(textsize);			/* memory size */
-		lput(0x05L);			/* protections = RX */
-		lput(0x10000L);			/* alignment */
-
-		lput(1L);			/* data - type = PT_LOAD */
-		lput(HEADR+textsize);		/* file offset */
-		lput(INITDAT & ~KMASK);		/* vaddr */
-		lput(INITDAT);			/* paddr */
-		lput(datsize);			/* file size */
-		lput(datsize);			/* memory size */
-		lput(0x07L);			/* protections = RWX */
-		lput(0x10000L);			/* 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?? */
-		cflush();
-
-		if(debug['S'])
-			endelfsectab();
+		elf32(POWER, ELFDATA2MSB, 0, nil);
 		break;
 	case 6:
 		/*
-		 * customised for virtex 4 boot,
-		 * notably the alignment and KMASK masking.
+		 * intended for virtex 4 boot
 		 */
-		strnput("\177ELF", 4);		/* e_ident */
-		CPUT(1);			/* class = 32 bit */
-		CPUT(2);			/* data = MSB */
-		CPUT(1);			/* version = CURRENT */
-		strnput("", 9);
-		lput((2L<<16)|20L);		/* type = EXEC; machine = PowerPC */
-		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((3L<<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((3L<<16)|0L);	/* # Shdrs & shdr string size */
-		}
-
-		lput(1L);			/* text - type = PT_LOAD */
-		lput(HEADR);			/* file offset */
-		lput(INITTEXT);			/* vaddr */
-		lput(INITTEXT);			/* paddr */
-		lput(textsize-JMPSZ);		/* file size */
-		lput(textsize-JMPSZ);		/* 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?? */
-
-		/* add tiny text section at end with jmp to start */
-		lput(1L);			/* text - type = PT_LOAD */
-		lput(HEADR+textsize-JMPSZ);	/* file offset */
-		lput(0xFFFFFFFC);		/* vaddr */
-		lput(0xFFFFFFFC);		/* paddr */
-		lput(JMPSZ);			/* file size */
-		lput(JMPSZ);			/* memory size */
-		lput(0x05L);			/* protections = RX */
-		lput(0);			/* disable alignment */
-		cflush();
-
-		if(debug['S'])
-			endelfsectab();
+		debug['S'] = 1;			/* symbol table */
+		elf32(POWER, ELFDATA2MSB, 1, elf32jmp);
 		break;
 	}
 	cflush();
@@ -528,12 +368,49 @@ wput(long l)
 }
 
 void
-lput(long l)
+wputl(long l)
 {
+	cbp[0] = l;
+	cbp[1] = l>>8;
+	cbp += 2;
+	cbc -= 2;
+	if(cbc <= 0)
+		cflush();
+}
 
+void
+lput(long l)
+{
 	LPUT(l);
 }
 
+void
+lputl(long c)
+{
+	cbp[0] = (c);
+	cbp[1] = (c)>>8;
+	cbp[2] = (c)>>16;
+	cbp[3] = (c)>>24;
+	cbp += 4;
+	cbc -= 4;
+	if(cbc <= 0)
+		cflush();
+}
+
+void
+llput(vlong v)
+{
+	lput(v>>32);
+	lput(v);
+}
+
+void
+llputl(vlong v)
+{
+	lputl(v);
+	lputl(v>>32);
+}
+
 void
 cflush(void)
 {

+ 7 - 0
sys/src/cmd/ql/l.h

@@ -2,6 +2,7 @@
 #include	<libc.h>
 #include	<bio.h>
 #include	"../qc/q.out.h"
+#include	"../8l/elf.h"
 
 #ifndef	EXTERN
 #define	EXTERN	extern
@@ -189,6 +190,7 @@ EXTERN	int	HEADTYPE;		/* type of header */
 EXTERN	long	INITDAT;		/* data location */
 EXTERN	long	INITRND;		/* data round above text location */
 EXTERN	long	INITTEXT;		/* text location */
+EXTERN	long	INITTEXTP;		/* text location (physical) */
 EXTERN	char*	INITENTRY;		/* entry point */
 EXTERN	long	autosize;
 EXTERN	Biobuf	bso;
@@ -303,7 +305,10 @@ void	loadlib(void);
 void	listinit(void);
 void	initmuldiv(void);
 Sym*	lookup(char*, int);
+void	llput(vlong);
+void	llputl(vlong);
 void	lput(long);
+void	lputl(long);
 void	mkfwd(void);
 void*	mysbrk(ulong);
 void	names(void);
@@ -327,9 +332,11 @@ int	relinv(int);
 long	rnd(long, long);
 void	sched(Prog*, Prog*);
 void	span(void);
+void	strnput(char*, int);
 void	undef(void);
 void	undefsym(Sym*);
 void	wput(long);
+void	wputl(long);
 void	xdefine(char*, int, long);
 void	xfol(Prog*);
 void	zerosig(char*);

+ 5 - 0
sys/src/cmd/ql/mkfile

@@ -14,15 +14,20 @@ OFILES=\
 	cnam.$O\
 	sched.$O\
 	compat.$O\
+	elf.$O\
 
 HFILES=\
 	l.h\
 	../qc/q.out.h\
+	../8l/elf.h\
 
 BIN=/$objtype/bin
+CFLAGS=$CFLAGS -. -I.
 </sys/src/cmd/mkone
 
 enam.$O:	../qc/enam.c
 	$CC $CFLAGS ../qc/enam.c
+elf.$O:	../8l/elf.c
+	$CC $CFLAGS ../8l/elf.c
 cnam.c:	l.h
 	rc mkcname

+ 12 - 3
sys/src/cmd/ql/obj.c

@@ -74,6 +74,7 @@ main(int argc, char *argv[])
 	curtext = P;
 	HEADTYPE = -1;
 	INITTEXT = -1;
+	INITTEXTP = -1;
 	INITDAT = -1;
 	INITRND = -1;
 	INITENTRY = 0;
@@ -97,6 +98,11 @@ main(int argc, char *argv[])
 		if(a)
 			INITTEXT = atolwhex(a);
 		break;
+	case 'P':
+		a = ARGF();
+		if(a)
+			INITTEXTP = atolwhex(a);
+		break;
 	case 'D':
 		a = ARGF();
 		if(a)
@@ -203,7 +209,7 @@ main(int argc, char *argv[])
 			INITRND = 0;
 		break;
 	case 5:	/* elf executable */
-		HEADR = rnd(52L+3*32L, 16);
+		HEADR = rnd(Ehdr32sz+3*Phdr32sz, 16);
 		if(INITTEXT == -1)
 			INITTEXT = 0x00400000L+HEADR;
 		if(INITDAT == -1)
@@ -212,7 +218,7 @@ main(int argc, char *argv[])
 			INITRND = 0;
 		break;
 	case 6:	/* elf for virtex 4 */
-		HEADR = rnd(52L+4*32L, 16);
+		HEADR = rnd(Ehdr32sz+4*Phdr32sz, 16); /* extra phdr for JMP */
 		if(INITTEXT == -1)
 			INITTEXT = 0x00400000L+HEADR;
 		if(INITDAT == -1)
@@ -221,6 +227,8 @@ main(int argc, char *argv[])
 			INITRND = 0;
 		break;
 	}
+	if (INITTEXTP == -1)
+		INITTEXTP = INITTEXT;
 	if(INITDAT != 0 && INITRND != 0)
 		print("warning: -D0x%lux is ignored because of -R0x%lux\n",
 			INITDAT, INITRND);
@@ -466,7 +474,8 @@ objfile(char *file)
 			l |= (e[3] & 0xff) << 16;
 			l |= (e[4] & 0xff) << 24;
 			seek(f, l, 0);
-			l = read(f, &arhdr, SAR_HDR);
+			/* need readn to read the dumps (at least) */
+			l = readn(f, &arhdr, SAR_HDR);
 			if(l != SAR_HDR)
 				goto bad;
 			if(strncmp(arhdr.fmag, ARFMAG, sizeof(arhdr.fmag)))

+ 51 - 58
sys/src/cmd/vl/asm.c

@@ -83,6 +83,12 @@ long	BADOFFSET	=	-1;
 			cflush();\
 	}
 
+void
+cput(long l)
+{
+	CPUT(l);
+}
+
 void
 objput(long l)	/* emit long in byte order appropriate to object machine */
 {
@@ -95,12 +101,56 @@ objhput(short s)
 	HPUT(s);
 }
 
+void
+wput(long l)
+{
+
+	cbp[0] = l>>8;
+	cbp[1] = l;
+	cbp += 2;
+	cbc -= 2;
+	if(cbc <= 0)
+		cflush();
+}
+
+void
+wputl(long l)
+{
+
+	cbp[0] = l;
+	cbp[1] = l>>8;
+	cbp += 2;
+	cbc -= 2;
+	if(cbc <= 0)
+		cflush();
+}
+
 void
 lput(long l)		/* emit long in big-endian byte order */
 {
 	LBEPUT(l);
 }
 
+void
+lputl(long l)		/* emit long in big-endian byte order */
+{
+	LLEPUT(l);
+}
+
+void
+llput(vlong v)
+{
+	lput(v>>32);
+	lput(v);
+}
+
+void
+llputl(vlong v)
+{
+	lputl(v);
+	lputl(v>>32);
+}
+
 long
 entryvalue(void)
 {
@@ -391,64 +441,7 @@ asmb(void)
 		lput(0x80L);			/* flags */
 		break;
 	case 5:
-		/* first part of ELF is byte-wide parts, thus no byte-order issues */
-		strnput("\177ELF", 4);		/* e_ident */
-		CPUT(1);			/* class = 32 bit */
-		CPUT(little? 1: 2);		/* data: 1 = LSB, 2 = MSB */
-		CPUT(1);			/* version = 1 */
-		strnput("", 9);			/* reserved for expansion */
-		/* entire remainder of ELF file is in target byte order */
-
-		/* file header part of ELF header */
-		objhput(2);			/* type = EXEC */
-		objhput(8);			/* machine = MIPS */
-		objput(1L);			/* version = CURRENT */
-		objput(entryvalue());		/* entry vaddr */
-		objput(52L);			/* offset to first phdr */
-		objput(0L);			/* offset to first shdr */
-		objput(0L);			/* flags (no MIPS flags defined) */
-		objhput(52);			/* Ehdr size */
-		objhput(32);			/* Phdr size */
-		objhput(3);			/* # of Phdrs */
-		objhput(0);			/* Shdr size */
-		objhput(0);			/* # of Shdrs */
-		objhput(0);			/* Shdr string size */
-
-		/* "Program headers" - one per chunk of file to load */
-
-		/*
-		 * include ELF headers in text -- 8l doesn't,
-		 * but in theory it aids demand loading.
-		 */
-		objput(1L);			/* text: type = PT_LOAD */
-		objput(0L);			/* file offset */
-		objput(INITTEXT-HEADR);		/* vaddr */
-		objput(INITTEXT-HEADR);		/* paddr */
-		objput(HEADR+textsize);		/* file size */
-		objput(HEADR+textsize);		/* memory size */
-		objput(0x05L);			/* protections = RX */
-		objput(0x1000L);		/* page-align text off's & vaddrs */
-
-		objput(1L);			/* data: type = PT_LOAD */
-		objput(HEADR+textsize);		/* file offset */
-		objput(INITDAT);		/* vaddr */
-		objput(INITDAT);		/* paddr */
-		objput(datsize);		/* file size */
-		objput(datsize+bsssize);	/* memory size */
-		objput(0x06L);			/* protections = RW */
-		if(INITDAT % 4096 == 0 && (HEADR + textsize) % 4096 == 0)
-			objput(0x1000L);	/* page-align data off's & vaddrs */
-		else
-			objput(0L);		/* do not claim alignment */
-
-		objput(0L);			/* P9 symbols: type = PT_NULL */
-		objput(HEADR+textsize+datsize);	/* file offset */
-		objput(0L);
-		objput(0L);
-		objput(symsize);		/* symbol table size */
-		objput(lcsize);			/* line number size */
-		objput(0x04L);			/* protections = R */
-		objput(0L);			/* do not claim alignment */
+		elf32(MIPS, little? ELFDATA2LSB: ELFDATA2MSB, 0, nil);
 		break;
 	case 6:
 		break;

+ 8 - 0
sys/src/cmd/vl/l.h

@@ -2,6 +2,7 @@
 #include	<libc.h>
 #include	<bio.h>
 #include	"../vc/v.out.h"
+#include	"../8l/elf.h"
 
 #ifndef	EXTERN
 #define	EXTERN	extern
@@ -189,6 +190,7 @@ EXTERN	int	HEADTYPE;		/* type of header */
 EXTERN	long	INITDAT;		/* data location */
 EXTERN	long	INITRND;		/* data round above text location */
 EXTERN	long	INITTEXT;		/* text location */
+EXTERN	long	INITTEXTP;		/* text location (physical) */
 EXTERN	char*	INITENTRY;		/* entry point */
 EXTERN	long	autosize;
 EXTERN	Biobuf	bso;
@@ -282,6 +284,7 @@ void	buildop(void);
 void	buildrep(int, int);
 void	cflush(void);
 int	cmp(int, int);
+void	cput(long);
 int	compound(Prog*);
 double	cputime(void);
 void	datblk(long, long, int);
@@ -305,7 +308,10 @@ void	ldobj(int, long, char*);
 void	loadlib(void);
 void	listinit(void);
 Sym*	lookup(char*, int);
+void	llput(vlong);
+void	llputl(vlong);
 void	lput(long);
+void	lputl(long);
 void	bput(long);
 void	mkfwd(void);
 void*	mysbrk(ulong);
@@ -331,6 +337,8 @@ void	sched(Prog*, Prog*);
 void	span(void);
 void	strnput(char*, int);
 void	undef(void);
+void	wput(long);
+void	wputl(long);
 void	xdefine(char*, int, long);
 void	xfol(Prog*);
 void	xfol(Prog*);

+ 5 - 0
sys/src/cmd/vl/mkfile

@@ -12,16 +12,21 @@ OFILES=\
 	span.$O\
 	enam.$O\
 	compat.$O\
+	elf.$O\
 
 HFILES=\
 	l.h\
 	../vc/v.out.h\
+	../8l/elf.h\
 
 BIN=/$objtype/bin
+CFLAGS=$CFLAGS -. -I.
 </sys/src/cmd/mkone
 
 enam.$O:	../vc/enam.c
 	$CC $CFLAGS ../vc/enam.c
+elf.$O:	../8l/elf.c
+	$CC $CFLAGS ../8l/elf.c
 
 x:V:	$O.out
 	$O.out -la -o/dev/null x.v

+ 11 - 2
sys/src/cmd/vl/obj.c

@@ -49,6 +49,7 @@ main(int argc, char *argv[])
 	curtext = P;
 	HEADTYPE = -1;
 	INITTEXT = -1;
+	INITTEXTP = -1;
 	INITDAT = -1;
 	INITRND = -1;
 	INITENTRY = 0;
@@ -77,6 +78,11 @@ main(int argc, char *argv[])
 		if(a)
 			INITTEXT = atolwhex(a);
 		break;
+	case 'P':
+		a = ARGF();
+		if(a)
+			INITTEXTP = atolwhex(a);
+		break;
 	case 'D':
 		a = ARGF();
 		if(a)
@@ -173,7 +179,7 @@ main(int argc, char *argv[])
 			INITRND = 0;
 		break;
 	case 5:	/* sgi unix elf executable */
-		HEADR = rnd(52L+3*32L, 16);
+		HEADR = rnd(Ehdr32sz+3*Phdr32sz, 16);
 		if(INITTEXT == -1)
 			INITTEXT = 0x00400000L+HEADR;
 		if(INITDAT == -1)
@@ -191,6 +197,8 @@ main(int argc, char *argv[])
 			INITRND = 4096;
 		break;
 	}
+	if (INITTEXTP == -1)
+		INITTEXTP = INITTEXT;
 	if(INITDAT != 0 && INITRND != 0)
 		print("warning: -D0x%lux is ignored because of -R0x%lux\n",
 			INITDAT, INITRND);
@@ -426,7 +434,8 @@ objfile(char *file)
 			l |= (e[3] & 0xff) << 16;
 			l |= (e[4] & 0xff) << 24;
 			seek(f, l, 0);
-			l = read(f, &arhdr, SAR_HDR);
+			/* need readn to read the dumps (at least) */
+			l = readn(f, &arhdr, SAR_HDR);
 			if(l != SAR_HDR)
 				goto bad;
 			if(strncmp(arhdr.fmag, ARFMAG, sizeof(arhdr.fmag)))