changelog shortlog tags branches changeset file revisions annotate raw help

Mercurial > hg > plan9front / sys/src/cmd/7l/l.h

revision 7144: d0b9ab522e8b
child 7145: 84d616f1d180
     1.1new file mode 100644
     1.2--- /dev/null
     1.3+++ b/sys/src/cmd/7l/l.h
     1.4@@ -0,0 +1,430 @@
     1.5+#include	<u.h>
     1.6+#include	<libc.h>
     1.7+#include	<bio.h>
     1.8+#include	"../7c/7.out.h"
     1.9+
    1.10+#ifndef	EXTERN
    1.11+#define	EXTERN	extern
    1.12+#endif
    1.13+
    1.14+#define	LIBNAMELEN	300
    1.15+
    1.16+void	addlibpath(char*);
    1.17+int	fileexists(char*);
    1.18+int	find1(long, int);
    1.19+char*	findlib(char*);
    1.20+
    1.21+typedef	struct	Adr	Adr;
    1.22+typedef	struct	Autom	Auto;
    1.23+typedef	struct	Count	Count;
    1.24+typedef	struct	Ieee	Ieee;
    1.25+typedef	struct	Prog	Prog;
    1.26+typedef	struct	Sym	Sym;
    1.27+typedef	struct	Mask	Mask;
    1.28+typedef	struct	Optab	Optab;
    1.29+typedef	struct	Oprang	Oprang;
    1.30+typedef	uchar	Opcross[32][2][32];
    1.31+
    1.32+#define	P		((Prog*)0)
    1.33+#define	S		((Sym*)0)
    1.34+#define	TNAME		(curtext&&curtext->from.sym?curtext->from.sym->name:noname)
    1.35+
    1.36+struct	Adr
    1.37+{
    1.38+	union
    1.39+	{
    1.40+		vlong	u0offset;
    1.41+		char*	u0sval;
    1.42+		Ieee*	u0ieee;
    1.43+	} u0;
    1.44+	union
    1.45+	{
    1.46+		Auto*	u1autom;
    1.47+		Sym*	u1sym;
    1.48+	} u1;
    1.49+	char	type;
    1.50+	char	reg;
    1.51+	char	name;
    1.52+	char	class;
    1.53+};
    1.54+
    1.55+#define	offset	u0.u0offset
    1.56+#define	sval	u0.u0sval
    1.57+#define	ieee	u0.u0ieee
    1.58+
    1.59+#define	autom	u1.u1autom
    1.60+#define	sym	u1.u1sym
    1.61+
    1.62+struct	Prog
    1.63+{
    1.64+	Adr	from;
    1.65+	Adr	from3;	/* third register operand */
    1.66+	Adr	to;
    1.67+	union
    1.68+	{
    1.69+		long	u0regused;
    1.70+		Prog*	u0forwd;
    1.71+	} u0;
    1.72+	Prog*	cond;
    1.73+	Prog*	link;
    1.74+	vlong	pc;
    1.75+	long	line;
    1.76+	uchar	mark;
    1.77+	ushort	optab;
    1.78+	ushort	as;
    1.79+	uchar	reg;
    1.80+};
    1.81+#define	regused	u0.u0regused
    1.82+#define	forwd	u0.u0forwd
    1.83+
    1.84+struct	Sym
    1.85+{
    1.86+	char	*name;
    1.87+	short	type;
    1.88+	short	version;
    1.89+	short	become;
    1.90+	short	frame;
    1.91+	uchar	subtype;
    1.92+	ushort	file;
    1.93+	vlong	value;
    1.94+	long	sig;
    1.95+	Sym*	link;
    1.96+};
    1.97+
    1.98+#define SIGNINTERN	(1729*325*1729)	/* signature of internal functions such as _div */
    1.99+
   1.100+struct	Autom
   1.101+{
   1.102+	Sym*	asym;
   1.103+	Auto*	link;
   1.104+	long	aoffset;
   1.105+	short	type;
   1.106+};
   1.107+
   1.108+struct	Optab
   1.109+{
   1.110+	ushort	as;
   1.111+	char	a1;
   1.112+	char	a2;
   1.113+	char	a3;
   1.114+	char	type;
   1.115+	char	size;
   1.116+	char	param;
   1.117+	char	flag;
   1.118+};
   1.119+struct	Oprang
   1.120+{
   1.121+	Optab*	start;
   1.122+	Optab*	stop;
   1.123+};
   1.124+struct	Mask
   1.125+{
   1.126+	uchar	s;
   1.127+	uchar	e;
   1.128+	uchar	r;
   1.129+	uvlong	v;
   1.130+};
   1.131+
   1.132+enum
   1.133+{
   1.134+	STEXT		= 1,
   1.135+	SDATA,
   1.136+	SBSS,
   1.137+	SDATA1,
   1.138+	SXREF,
   1.139+	SLEAF,
   1.140+	SFILE,
   1.141+	SCONST,
   1.142+	SSTRING,
   1.143+	SUNDEF,
   1.144+
   1.145+	SIMPORT,
   1.146+	SEXPORT,
   1.147+
   1.148+	LFROM		= 1<<0,
   1.149+	LTO		= 1<<1,
   1.150+	LPOOL		= 1<<2,
   1.151+
   1.152+	C_NONE		= 0,
   1.153+	C_REG,
   1.154+	C_RSP,		/* D_REG or D_SP */
   1.155+	C_SHIFT,		/* D_SHIFT: shift type, amount, value */
   1.156+	C_EXTREG,	/* D_EXTREG: reg, ext type, shift */
   1.157+	C_FREG,
   1.158+	C_SPR,
   1.159+	C_COND,
   1.160+
   1.161+	C_ZCON,		/* 0 (matching C_REG, not C_RSP, allowing REGZERO) */
   1.162+	C_ADDCON0,	/* 12-bit unsigned, unshifted */
   1.163+	C_ADDCON,	/* 12-bit unsigned, shifted left by 0 or 12 */
   1.164+	C_MOVCON,	/* generated by a 16-bit constant, optionally inverted and/or shifted by multiple of 16 */
   1.165+	C_BITCON,	/* bimm32 */
   1.166+	C_ABCON,	/* could be C_ADDCON or C_BITCON */
   1.167+	C_MBCON,	/* could be C_MOVCON or C_BITCON */
   1.168+	C_LCON,		/* 32-bit constant */
   1.169+	C_FCON,		/* floating-point constant */
   1.170+	C_VCON,		/* 64-bit constant */
   1.171+
   1.172+	C_AACON,	/* ADDCON offset in auto constant $a(FP) */
   1.173+	C_LACON,	/* 32-bit offset in auto constant $a(FP) */
   1.174+
   1.175+	C_AECON,	/* ADDCON offset in extern constant $e(SB) */
   1.176+
   1.177+	C_SBRA,
   1.178+	C_LBRA,
   1.179+
   1.180+	C_NPAUTO,	/* -512 <= x < 0, 0 mod 8 */
   1.181+	C_NSAUTO,	/* -256 <= x < 0 */
   1.182+	C_PSAUTO,	/* 0 to 255 */
   1.183+	C_PPAUTO,	/* 0 to 504, 0 mod 8 */
   1.184+	C_UAUTO4K,	/* 0 to 4095 */
   1.185+	C_UAUTO8K,	/* 0 to 8190, 0 mod 2 */
   1.186+	C_UAUTO16K,	/* 0 to 16380, 0 mod 4 */
   1.187+	C_UAUTO32K,	/* 0 to 32760, 0 mod 8 */
   1.188+	C_UAUTO64K,	/* 0 to 65520, 0 mod 16 */
   1.189+	C_LAUTO,		/* any other 32-bit constant */
   1.190+
   1.191+	C_SEXT1,		/* 0 to 4095, direct */
   1.192+	C_SEXT2,		/* 0 to 8190 */
   1.193+	C_SEXT4,		/* 0 to 16380 */
   1.194+	C_SEXT8,		/* 0 to 32760 */
   1.195+	C_SEXT16,	/* 0 to 65520 */
   1.196+	C_LEXT,
   1.197+
   1.198+	C_NPOREG,	/* mirror NPAUTO etc, except for ZOREG */
   1.199+	C_NSOREG,
   1.200+	C_ZOREG,
   1.201+	C_PSOREG,
   1.202+	C_PPOREG,
   1.203+	C_UOREG4K,
   1.204+	C_UOREG8K,
   1.205+	C_UOREG16K,
   1.206+	C_UOREG32K,
   1.207+	C_UOREG64K,
   1.208+	C_LOREG,
   1.209+
   1.210+	C_ADDR,		/* relocatable address for dynamic loading */
   1.211+	C_ROFF,		/* register offset (inc register extended) */
   1.212+	C_XPOST,
   1.213+	C_XPRE,
   1.214+
   1.215+	C_VREG,
   1.216+
   1.217+	C_GOK,
   1.218+	C_NCLASS,	/* must be last */
   1.219+
   1.220+/* mark flags */
   1.221+	FOLL		= 1<<0,
   1.222+	LABEL	= 1<<1,
   1.223+	LEAF		= 1<<2,
   1.224+	FLOAT		= 1<<3,
   1.225+	BRANCH		= 1<<4,
   1.226+	LOAD		= 1<<5,
   1.227+	SYNC		= 1<<6,
   1.228+	NOSCHED		= 1<<7,
   1.229+
   1.230+	MINSIZ		= 64,
   1.231+
   1.232+	Roffset	= 22,		/* no. bits for offset in relocation address */
   1.233+	Rindex	= 10,		/* no. bits for index in relocation address */
   1.234+
   1.235+	STACKALIGN = 16,	/* alignment of stack */
   1.236+	PCSZ=	8,	/* size of PC */
   1.237+};
   1.238+
   1.239+enum
   1.240+{
   1.241+
   1.242+	STRINGSZ	= 200,
   1.243+	NHASH		= 10007,
   1.244+	NHUNK		= 100000,
   1.245+	MAXIO		= 8192,
   1.246+	MAXHIST		= 20,	/* limit of path elements for history symbols */
   1.247+};
   1.248+
   1.249+EXTERN union
   1.250+{
   1.251+	struct
   1.252+	{
   1.253+		uchar	obuf[MAXIO];			/* output buffer */
   1.254+		uchar	ibuf[MAXIO];			/* input buffer */
   1.255+	} u;
   1.256+	char	dbuf[1];
   1.257+} buf;
   1.258+
   1.259+#define	cbuf	u.obuf
   1.260+#define	xbuf	u.ibuf
   1.261+
   1.262+EXTERN	long	HEADR;			/* length of header */
   1.263+EXTERN	int	HEADTYPE;		/* type of header */
   1.264+EXTERN	long	INITDAT;		/* data location */
   1.265+EXTERN	long	INITRND;		/* data round above text location */
   1.266+EXTERN	long	INITTEXT;		/* text location */
   1.267+EXTERN	long	INITTEXTP;		/* text location (physical) */
   1.268+EXTERN	char*	INITENTRY;		/* entry point */
   1.269+EXTERN	long	autosize;
   1.270+EXTERN	Biobuf	bso;
   1.271+EXTERN	long	bsssize;
   1.272+EXTERN	int	cbc;
   1.273+EXTERN	uchar*	cbp;
   1.274+EXTERN	int	cout;
   1.275+EXTERN	Auto*	curauto;
   1.276+EXTERN	Auto*	curhist;
   1.277+EXTERN	Prog*	curp;
   1.278+EXTERN	Prog*	curtext;
   1.279+EXTERN	Prog*	datap;
   1.280+EXTERN	long	datsize;
   1.281+EXTERN	char	debug[128];
   1.282+EXTERN	Prog*	etextp;
   1.283+EXTERN	Prog*	firstp;
   1.284+
   1.285+EXTERN	char	fnuxi4[4];
   1.286+EXTERN	char	fnuxi8[8];
   1.287+EXTERN	char	inuxi1[1];
   1.288+EXTERN	char	inuxi2[2];
   1.289+EXTERN	char	inuxi4[4];
   1.290+EXTERN	uchar	inuxi8[8];
   1.291+
   1.292+EXTERN	Sym*	hash[NHASH];
   1.293+EXTERN	Sym*	histfrog[MAXHIST];
   1.294+EXTERN	int	histfrogp;
   1.295+EXTERN	int	histgen;
   1.296+EXTERN	char*	hunk;
   1.297+
   1.298+EXTERN	char*	library[50];
   1.299+EXTERN	char*	libraryobj[50];
   1.300+EXTERN	int	libraryp;
   1.301+EXTERN	Prog*	lastp;
   1.302+EXTERN	long	lcsize;
   1.303+EXTERN	char	literal[32];
   1.304+EXTERN	int	nerrors;
   1.305+EXTERN	long	nhunk;
   1.306+EXTERN	char*	noname;
   1.307+EXTERN	vlong	instoffset;
   1.308+EXTERN	Opcross	opcross[8];
   1.309+EXTERN	char*	outfile;
   1.310+EXTERN	vlong	pc;
   1.311+EXTERN	uchar	repop[ALAST];
   1.312+EXTERN	long	symsize;
   1.313+EXTERN	Prog*	textp;
   1.314+EXTERN	vlong	textsize;
   1.315+EXTERN	long	thunk;
   1.316+EXTERN	int	version;
   1.317+EXTERN	char	xcmp[C_NCLASS][C_NCLASS];
   1.318+EXTERN	int	xrefresolv;
   1.319+EXTERN	Prog	zprg;
   1.320+EXTERN	int	dtype;
   1.321+
   1.322+EXTERN	int	doexp, dlm;
   1.323+EXTERN	int	imports, nimports;
   1.324+EXTERN	int	exports, nexports;
   1.325+EXTERN	char*	EXPTAB;
   1.326+EXTERN	Prog	undefp;
   1.327+
   1.328+#define	UP	(&undefp)
   1.329+
   1.330+extern	char*	anames[];
   1.331+extern	char*	cnames[];
   1.332+extern	Optab	optab[];
   1.333+
   1.334+EXTERN	Prog*	blitrl;
   1.335+EXTERN	Prog*	elitrl;
   1.336+
   1.337+#pragma	varargck	argpos	diag 1
   1.338+
   1.339+#pragma	varargck	type	"A"	int
   1.340+#pragma	varargck	type	"A"	uint
   1.341+#pragma	varargck	type	"C"	int
   1.342+#pragma	varargck	type	"D"	Adr*
   1.343+#pragma	varargck	type	"N"	Adr*
   1.344+#pragma	varargck	type	"P"	Prog*
   1.345+#pragma	varargck	type	"S"	char*
   1.346+
   1.347+
   1.348+int	Aconv(Fmt*);
   1.349+int	Cconv(Fmt*);
   1.350+int	Dconv(Fmt*);
   1.351+int	Nconv(Fmt*);
   1.352+int	Pconv(Fmt*);
   1.353+int	Rconv(Fmt*);
   1.354+int	Sconv(Fmt*);
   1.355+int	aclass(Adr*);
   1.356+void	addpool(Prog*, Adr*);
   1.357+vlong	atolwhex(char*);
   1.358+void	asmb(void);
   1.359+void	asmdyn(void);
   1.360+void	asmlc(void);
   1.361+void	asmout(Prog*, Optab*);
   1.362+void	asmsym(void);
   1.363+Prog*	brchain(Prog*);
   1.364+Prog*	brloop(Prog*);
   1.365+void	buildop(void);
   1.366+void	buildrep(int, int);
   1.367+void	cflush(void);
   1.368+void	ckoff(Sym*, long);
   1.369+int	chipfloat(Ieee*);
   1.370+int	cmp(int, int);
   1.371+int	compound(Prog*);
   1.372+void	cput(int);
   1.373+void	datblk(long, long, int);
   1.374+void	diag(char*, ...);
   1.375+void	dodata(void);
   1.376+void	doprof1(void);
   1.377+void	doprof2(void);
   1.378+void	dynreloc(Sym*, long, int);
   1.379+vlong	entryvalue(void);
   1.380+void	errorexit(void);
   1.381+void	export(void);
   1.382+void	follow(void);
   1.383+void	gethunk(void);
   1.384+void	histtoauto(void);
   1.385+void*	halloc(usize);
   1.386+int	isnop(Prog*);
   1.387+double	ieeedtod(Ieee*);
   1.388+long	ieeedtof(Ieee*);
   1.389+void	import(void);
   1.390+void	ldobj(int, long, char*);
   1.391+void	listinit(void);
   1.392+void	llput(vlong);
   1.393+void	llputl(vlong);
   1.394+void	loadlib(void);
   1.395+Sym*	lookup(char*, int);
   1.396+void	lput(long);
   1.397+void	lputl(long);
   1.398+void	mkfwd(void);
   1.399+int	movcon(vlong);
   1.400+void*	mysbrk(ulong);
   1.401+void	names(void);
   1.402+void	nocache(Prog*);
   1.403+void	nuxiinit(void);
   1.404+void	objfile(char*);
   1.405+vlong	offsetshift(vlong, int);
   1.406+Optab*	oplook(Prog*);
   1.407+void	patch(void);
   1.408+int	pseudo(Prog*);
   1.409+void	prasm(Prog*);
   1.410+Prog*	prg(void);
   1.411+void	putsymb(char*, int, vlong, int);
   1.412+void	readundefs(char*, int);
   1.413+long	regoff(Adr*);
   1.414+int	relinv(int);
   1.415+vlong	rnd(vlong, long);
   1.416+void	span(void);
   1.417+void	undef(void);
   1.418+void	wput(long);
   1.419+void	wputl(long);
   1.420+void	noops(void);
   1.421+Mask*	findmask(uvlong);
   1.422+void	xdefine(char*, int, long);
   1.423+void	xfol(Prog*);
   1.424+void	zerosig(char*);
   1.425+
   1.426+
   1.427+#pragma	varargck	type	"R"	int
   1.428+
   1.429+/* for ../ld */
   1.430+#define	isbranch(a)	((a) == AB)
   1.431+#define	iscall(a)	((a) == ABL)
   1.432+#define	isreturn(a)	((a) == ARETURN || (a) == ARET || (a) == AERET)
   1.433+#define	branchop()	AB
   1.434+#define	canfollow(a)	((a) != ATEXT && (a) != ABCASE)