forsyth20121205-174063a80cc13 years agoHistory
1569 lines · 27.8 KB · C
RawDownload
#include	"l.h" short	opa[20];short	*op; longentryvalue(void){	char *a;	Sym *s; 	a = INITENTRY;	if(*a >= '0' && *a <= '9')		return atolwhex(a);	s = lookup(a, 0);	if(s->type == 0)		return INITTEXT;	if(s->type != STEXT)		diag("entry not text: %s", s->name);	return s->value;} voidasmb(void){	Prog *p;	long v;	int a;	short *op1; 	if(debug['v'])		Bprint(&bso, "%5.2f asmb\n", cputime());	Bflush(&bso); 	seek(cout, HEADR, 0);	pc = INITTEXT;	curp = firstp;	for(p = firstp; p != P; p = p->link) {		if(p->as == ATEXT)			curtext = p;		if(p->pc != pc) {			if(!debug['a'])				print("%P\n", curp);			diag("phase error %lux sb %lux in %s", p->pc, pc, TNAME);			pc = p->pc;		}		curp = p;		if(debug['a'])			Bprint(&bso, "%lux:%P\n", pc, curp);		asmins(p);		if(cbc < sizeof(opa))			cflush();		for(op1 = opa; op1 < op; op1++) {			a = *op1;			*cbp++ = a >> 8;			*cbp++ = a;		}		a = 2*(op - opa);		pc += a;		cbc -= a;		if(debug['a']) {			for(op1 = opa; op1 < op; op1++)				if(op1 == opa)					Bprint(&bso, "\t\t%4ux", *op1 & 0xffff);				else					Bprint(&bso, " %4ux", *op1 & 0xffff);			if(op != opa)				Bprint(&bso, "\n");		}	}	cflush();	switch(HEADTYPE) {	case 0:	/* this is garbage */		seek(cout, rnd(HEADR+textsize, 8192), 0);		break;	case 1:	/* plan9 boot data goes into text */		seek(cout, rnd(HEADR+textsize, INITRND), 0);		break;	case 2:	/* plan 9 */		seek(cout, HEADR+textsize, 0);		break;	case 3:	/* next boot */		seek(cout, HEADR+rnd(textsize, INITRND), 0);		break;	case 4:	/* preprocess pilot */		seek(cout, HEADR+textsize, 0);		break;	} 	if(debug['v'])		Bprint(&bso, "%5.2f datblk\n", cputime());	Bflush(&bso); 	for(v = 0; v < datsize; v += sizeof(buf)-100) {		if(datsize-v > sizeof(buf)-100)			datblk(v, sizeof(buf)-100);		else			datblk(v, datsize-v);	} 	symsize = 0;	spsize = 0;	lcsize = 0; 	Bflush(&bso); 	switch(HEADTYPE) {	default:		seek(cout, rnd(HEADR+textsize, 8192)+datsize, 0);		break;	case 1:	/* plan9 boot data goes into text */		seek(cout, rnd(HEADR+textsize, INITRND)+datsize, 0);		break;	case 2:	/* plan 9 */		seek(cout, HEADR+textsize+datsize, 0);		break;	case 3:	/* next boot */		seek(cout, HEADR+rnd(textsize, INITRND)+datsize, 0);		break;	}	if(!debug['s']) {		if(debug['v'])			Bprint(&bso, "%5.2f sym\n", cputime());		asmsym();	}	Bflush(&bso);	if(!debug['s']) {		if(debug['v'])			Bprint(&bso, "%5.2f sp\n", cputime());		asmsp();	}	Bflush(&bso);	if(!debug['s']) {		if(debug['v'])			Bprint(&bso, "%5.2f pc\n", cputime());		asmlc();	}	cflush(); 	if(debug['v'])		Bprint(&bso, "%5.2f headr\n", cputime());	Bflush(&bso);	seek(cout, 0L, 0);	switch(HEADTYPE) {	default:		lput(0x160L<<16);		/* magic and sections */		lput(0L);			/* time and date */		lput(rnd(HEADR+textsize, 4096)+datsize);		lput(symsize);			/* nsyms */		lput((0x38L<<16)|7L);		/* size of optional hdr and flags */		lput((0413<<16)|0437L);		/* magic and version */		lput(rnd(HEADR+textsize, 4096));	/* sizes */		lput(datsize);		lput(bsssize);		lput(entryvalue());		/* va of entry */		lput(INITTEXT-HEADR);		/* va of base of text */		lput(INITDAT);			/* va of base of data */		lput(INITDAT+datsize);		/* va of base of bss */		lput(~0L);			/* gp reg mask */		lput(0L);		lput(0L);		lput(0L);		lput(0L);		lput(~0L);			/* gp value ?? */		break;	case 1:	/* plan9 boot data goes into text */		lput(0407);			/* magic */		lput(rnd(HEADR+textsize, INITRND)-HEADR+datsize);		/* sizes */		lput(0);		lput(bsssize);		lput(symsize);			/* nsyms */		lput(entryvalue());		/* va of entry */		lput(spsize);			/* sp offsets */		lput(lcsize);			/* line offsets */		break;	case 2:	/* plan 9 */		lput(0407);			/* magic */		lput(textsize);			/* sizes */		lput(datsize);		lput(bsssize);		lput(symsize);			/* nsyms */		lput(entryvalue());		/* va of entry */		lput(spsize);			/* sp offsets */		lput(lcsize);			/* line offsets */		break;	case 3:	/* next boot */		/* header */		lput(0xfeedfaceL);			/* magic */		lput(6);				/* 68040 */		lput(1);				/* more 68040 */		lput(5);				/* file type 'boot' */		lput(HEADTYPE);				/* number commands */		lput(HEADR-7*4);			/* sizeof commands */		lput(1);				/* no undefineds */		/* command 1 text */		lput(1);				/* command = 'segment' */		lput(124);				/* command size */		s16put("__TEXT");			/* botch?? entryvalue() */		lput(INITTEXT);				/* va of start */		lput(rnd(textsize, 8192));		/* va size */		lput(HEADR);				/* file offset */		lput(rnd(textsize, 8192));		/* file size */		lput(7);				/* max prot */		lput(7);				/* init prot */		lput(1);				/* number of sections */		lput(0);				/* flags */		/* text section */		s16put("__text");		s16put("__TEXT");			/* botch?? entryvalue() */		lput(INITTEXT);				/* va of start */		lput(textsize);				/* va size */		lput(HEADR);				/* file offset */		lput(2);				/* align */		lput(0);				/* reloff */		lput(0);				/* nreloc */		lput(0);				/* flags */		lput(0);				/* reserved1 */		lput(0);				/* reserved2 */		/* command 1 data */		lput(1);				/* command = 'segment' */		lput(192);				/* command size */		s16put("__DATA");		lput(INITDAT);				/* va of start */		lput(rnd(datsize, 8192));		/* va size */		lput(HEADR+rnd(textsize, 8192));	/* file offset */		lput(rnd(datsize, 8192));		/* file size */		lput(7);				/* max prot */		lput(7);				/* init prot */		lput(2);				/* number of sections */		lput(0);				/* flags */		/* data section */		s16put("__data");		s16put("__DATA");		lput(INITDAT);				/* va of start */		lput(datsize);				/* va size */		lput(HEADR+rnd(textsize, 8192));	/* file offset */		lput(2);				/* align */		lput(0);				/* reloff */		lput(0);				/* nreloc */		lput(0);				/* flags */		lput(0);				/* reserved1 */		lput(0);				/* reserved2 */		/* bss section */		s16put("__bss");		s16put("__DATA");		lput(INITDAT+datsize);			/* va of start */		lput(bsssize);				/* va size */		lput(0);				/* file offset */		lput(2);				/* align */		lput(0);				/* reloff */		lput(0);				/* nreloc */		lput(1);				/* flags = zero fill */		lput(0);				/* reserved1 */		lput(0);				/* reserved2 */		/* command 2 symbol */		lput(2);				/* command = 'symbol' */		lput(24);				/* command size */		lput(HEADR+rnd(textsize, INITRND)			+datsize);			/* symoff */		lput(symsize);				/* nsyms */		lput(spsize);				/* sp offsets */		lput(lcsize);				/* line offsets */		break;	}	cflush();} voidasmins(Prog *p){	Optab *o;	int t, a, b;	long v;	Prog *q; 	op = opa + 1;	if(special[p->from.type])	switch(p->from.type) { 	case D_CCR:		if(p->as != AMOVW)			goto bad;		a = asmea(p, &p->to);		if((a & 0170) == 010)			goto bad;		opa[0] = 0x42c0 | a;		/* mov from ccr */		return; 	case D_SR:		if(p->as != AMOVW)			goto bad;		a = asmea(p, &p->to);		if((a & 0170) == 010)			goto bad;		opa[0] = 0x40c0 | a;		/* mov from sr */		return; 	case D_USP:		if(p->as != AMOVL)			goto bad;		a = asmea(p, &p->to);		if((a & 0170) == 010) {			opa[0] = 0x4e68|(a&7);	/* mov usp An */			return;		}		t = 0x800;		goto movec1; 	case D_SFC:		t = 0x000;		goto movec1; 	case D_DFC:		t = 0x001;		goto movec1; 	case D_CACR:		t = 0x002;		goto movec1; 	case D_TC:		t = 0x003;		goto movec1; 	case D_ITT0:		t = 0x004;		goto movec1; 	case D_ITT1:		t = 0x005;		goto movec1; 	case D_DTT0:		t = 0x006;		goto movec1; 	case D_DTT1:		t = 0x007;		goto movec1; 	case D_VBR:		t = 0x801;		goto movec1; 	case D_CAAR:		t = 0x802;		goto movec1; 	case D_MSP:		t = 0x803;		goto movec1; 	case D_ISP:		t = 0x804;		goto movec1; 	case D_MMUSR:		t = 0x805;		goto movec1; 	case D_URP:		t = 0x806;		goto movec1; 	case D_SRP:		t = 0x807;		goto movec1; 	movec1:		if(p->as != AMOVL)			goto bad;		opa[0] = 0x4e7a;			/* mov spc Dn */		a = asmea(p, &p->to);		b = a & 0170;		if(b == 0 || b == 010) {			*op++ = (a<<12) | t;			return;		}		goto bad; 	case D_FPCR:		t = 0xb000;		goto movec3; 	case D_FPSR:		t = 0xa800;		goto movec3; 	case D_FPIAR:		t = 0xa400; 	movec3:		if(p->as != AMOVL)			goto bad;		op++;		a = asmea(p, &p->to);		opa[0] = optab[AFMOVEL].opcode0 | a;		opa[1] = t;		return;	}	if(special[p->to.type])	switch(p->to.type) { 	case D_CCR:		if(p->as != AMOVW)		/* botch, needs and, eor etc. */			goto bad;		a = asmea(p, &p->from);		if((a & 0170) == 010)			goto bad;		opa[0] = 0x44c0 | a;		/* mov to ccr */		return; 	case D_SR:		if(p->as != AMOVW)		/* botch, needs and, eor etc. */			goto bad;		a = asmea(p, &p->from);		if((a & 0170) == 010)			goto bad;		opa[0] = 0x46c0 | a;		/* mov to sr */		return; 	case D_USP:		if(p->as != AMOVL)			goto bad;		a = asmea(p, &p->from);		if((a & 0170) == 010) {			opa[0] = 0x4e60|(a&7);	/* mov An usp */			return;		}		t = 0x800;		goto movec2; 	case D_SFC:		t = 0x000;		goto movec2; 	case D_DFC:		t = 0x001;		goto movec2; 	case D_CACR:		t = 0x002;		goto movec2; 	case D_TC:		t = 0x003;		goto movec2; 	case D_ITT0:		t = 0x004;		goto movec2; 	case D_ITT1:		t = 0x005;		goto movec2; 	case D_DTT0:		t = 0x006;		goto movec2; 	case D_DTT1:		t = 0x007;		goto movec2; 	case D_VBR:		t = 0x801;		goto movec2; 	case D_CAAR:		t = 0x802;		goto movec2; 	case D_MSP:		t = 0x803;		goto movec2; 	case D_ISP:		t = 0x804;		goto movec2; 	case D_MMUSR:		t = 0x805;		goto movec2; 	case D_URP:		t = 0x806;		goto movec2; 	case D_SRP:		t = 0x807;		goto movec2; 	movec2:		if(p->as != AMOVL)			goto bad;		opa[0] = 0x4e7b;			/* mov Dn spc */		a = asmea(p, &p->from);		b = a & 0170;

Lines 1–500 of 1569.