github.com/xushiwei/go@v0.0.0-20130601165731-2b9d83f45bc9/src/cmd/5l/l.h (about)

     1  // Inferno utils/5l/l.h
     2  // http://code.google.com/p/inferno-os/source/browse/utils/5l/l.h
     3  //
     4  //	Copyright © 1994-1999 Lucent Technologies Inc.  All rights reserved.
     5  //	Portions Copyright © 1995-1997 C H Forsyth (forsyth@terzarima.net)
     6  //	Portions Copyright © 1997-1999 Vita Nuova Limited
     7  //	Portions Copyright © 2000-2007 Vita Nuova Holdings Limited (www.vitanuova.com)
     8  //	Portions Copyright © 2004,2006 Bruce Ellis
     9  //	Portions Copyright © 2005-2007 C H Forsyth (forsyth@terzarima.net)
    10  //	Revisions Copyright © 2000-2007 Lucent Technologies Inc. and others
    11  //	Portions Copyright © 2009 The Go Authors.  All rights reserved.
    12  //
    13  // Permission is hereby granted, free of charge, to any person obtaining a copy
    14  // of this software and associated documentation files (the "Software"), to deal
    15  // in the Software without restriction, including without limitation the rights
    16  // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    17  // copies of the Software, and to permit persons to whom the Software is
    18  // furnished to do so, subject to the following conditions:
    19  //
    20  // The above copyright notice and this permission notice shall be included in
    21  // all copies or substantial portions of the Software.
    22  //
    23  // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    24  // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    25  // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
    26  // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    27  // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    28  // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    29  // THE SOFTWARE.
    30  
    31  #include	<u.h>
    32  #include	<libc.h>
    33  #include	<bio.h>
    34  #include	"5.out.h"
    35  
    36  enum
    37  {
    38  	thechar = '5',
    39  	PtrSize = 4,
    40  	IntSize = 4,
    41  	MaxAlign = 8,	// max data alignment
    42  	FuncAlign = 4  // single-instruction alignment
    43  };
    44  
    45  #ifndef	EXTERN
    46  #define	EXTERN	extern
    47  #endif
    48  
    49  /* do not undefine this - code will be removed eventually */
    50  #define	CALLEEBX
    51  
    52  #define	dynptrsize	0
    53  
    54  typedef	struct	Adr	Adr;
    55  typedef	struct	Sym	Sym;
    56  typedef	struct	Autom	Auto;
    57  typedef	struct	Prog	Prog;
    58  typedef	struct	Reloc	Reloc;
    59  typedef	struct	Optab	Optab;
    60  typedef	struct	Oprang	Oprang;
    61  typedef	uchar	Opcross[32][2][32];
    62  typedef	struct	Count	Count;
    63  
    64  #define	P		((Prog*)0)
    65  #define	S		((Sym*)0)
    66  #define	TNAME		(cursym?cursym->name:noname)
    67  
    68  struct	Adr
    69  {
    70  	union
    71  	{
    72  		struct {
    73  			int32	u0offset;
    74  			int32	u0offset2; // argsize
    75  		} u0off;
    76  		char*	u0sval;
    77  		Ieee	u0ieee;
    78  		char*	u0sbig;
    79  	} u0;
    80  	Sym*	sym;
    81  	Sym*	gotype;
    82  	char	type;
    83  	char	reg;
    84  	char	name;
    85  	char	class;
    86  };
    87  
    88  #define	offset	u0.u0off.u0offset
    89  #define	offset2	u0.u0off.u0offset2
    90  #define	sval	u0.u0sval
    91  #define	scon	sval
    92  #define	ieee	u0.u0ieee
    93  #define	sbig	u0.u0sbig
    94  
    95  struct	Reloc
    96  {
    97  	int32	off;
    98  	uchar	siz;
    99  	uchar	done;
   100  	int16	type;
   101  	int32	add;
   102  	int32	xadd;
   103  	Sym*	sym;
   104  	Sym*	xsym;
   105  };
   106  
   107  struct	Prog
   108  {
   109  	Adr	from;
   110  	Adr	to;
   111  	union
   112  	{
   113  		int32	u0regused;
   114  		Prog*	u0forwd;
   115  	} u0;
   116  	Prog*	cond;
   117  	Prog*	link;
   118  	Prog*	pcrel;
   119  	int32	pc;
   120  	int32	line;
   121  	int32	spadj;
   122  	uchar	mark;
   123  	uchar	optab;
   124  	uchar	as;
   125  	uchar	scond;
   126  	uchar	reg;
   127  	uchar	align;	// unused
   128  };
   129  
   130  #define	regused	u0.u0regused
   131  #define	forwd	u0.u0forwd
   132  #define	datasize	reg
   133  #define	textflag	reg
   134  
   135  #define	iscall(p)	((p)->as == ABL)
   136  
   137  struct	Sym
   138  {
   139  	char*	name;
   140  	char*	extname;	// name used in external object files
   141  	short	type;
   142  	short	version;
   143  	uchar	dupok;
   144  	uchar	reachable;
   145  	uchar	cgoexport;
   146  	uchar	leaf;
   147  	int32	dynid;
   148  	int32	plt;
   149  	int32	got;
   150  	int32	value;
   151  	int32	sig;
   152  	int32	size;
   153  	int32	align;	// if non-zero, required alignment in bytes
   154  	int32	elfsym;
   155  	int32	locals;	// size of stack frame locals area
   156  	int32	args;	// size of stack frame incoming arguments area
   157  	uchar	special;
   158  	uchar	fnptr;	// used as fn ptr
   159  	uchar	stkcheck;
   160  	uchar	hide;
   161  	Sym*	hash;	// in hash table
   162  	Sym*	allsym;	// in all symbol list
   163  	Sym*	next;	// in text or data list
   164  	Sym*	sub;	// in SSUB list
   165  	Sym*	outer;	// container of sub
   166  	Sym*	gotype;
   167  	Sym*	reachparent;
   168  	Sym*	queue;
   169  	char*	file;
   170  	char*	dynimplib;
   171  	char*	dynimpvers;
   172  	struct Section*	sect;
   173  	
   174  	// STEXT
   175  	Auto*	autom;
   176  	Prog*	text;
   177  	
   178  	// SDATA, SBSS
   179  	uchar*	p;
   180  	int32	np;
   181  	int32	maxp;
   182  	Reloc*	r;
   183  	int32	nr;
   184  	int32	maxr;
   185  	int 	rel_ro;
   186  };
   187  
   188  #define SIGNINTERN	(1729*325*1729)
   189  
   190  struct	Autom
   191  {
   192  	Sym*	asym;
   193  	Auto*	link;
   194  	int32	aoffset;
   195  	short	type;
   196  	Sym*	gotype;
   197  };
   198  struct	Optab
   199  {
   200  	char	as;
   201  	uchar	a1;
   202  	char	a2;
   203  	uchar	a3;
   204  	uchar	type;
   205  	char	size;
   206  	char	param;
   207  	char	flag;
   208  	uchar	pcrelsiz;
   209  };
   210  struct	Oprang
   211  {
   212  	Optab*	start;
   213  	Optab*	stop;
   214  };
   215  struct	Count
   216  {
   217  	int32	count;
   218  	int32	outof;
   219  };
   220  
   221  enum
   222  {
   223  	LFROM		= 1<<0,
   224  	LTO		= 1<<1,
   225  	LPOOL		= 1<<2,
   226  	LPCREL		= 1<<3,
   227  
   228  	C_NONE		= 0,
   229  	C_REG,
   230  	C_REGREG,
   231  	C_REGREG2,
   232  	C_SHIFT,
   233  	C_FREG,
   234  	C_PSR,
   235  	C_FCR,
   236  
   237  	C_RCON,		/* 0xff rotated */
   238  	C_NCON,		/* ~RCON */
   239  	C_SCON,		/* 0xffff */
   240  	C_LCON,
   241  	C_LCONADDR,
   242  	C_ZFCON,
   243  	C_SFCON,
   244  	C_LFCON,
   245  
   246  	C_RACON,
   247  	C_LACON,
   248  
   249  	C_SBRA,
   250  	C_LBRA,
   251  
   252  	C_HAUTO,	/* halfword insn offset (-0xff to 0xff) */
   253  	C_FAUTO,	/* float insn offset (0 to 0x3fc, word aligned) */
   254  	C_HFAUTO,	/* both H and F */
   255  	C_SAUTO,	/* -0xfff to 0xfff */
   256  	C_LAUTO,
   257  
   258  	C_HOREG,
   259  	C_FOREG,
   260  	C_HFOREG,
   261  	C_SOREG,
   262  	C_ROREG,
   263  	C_SROREG,	/* both S and R */
   264  	C_LOREG,
   265  
   266  	C_PC,
   267  	C_SP,
   268  	C_HREG,
   269  
   270  	C_ADDR,		/* reference to relocatable address */
   271  
   272  	C_GOK,
   273  
   274  /* mark flags */
   275  	FOLL		= 1<<0,
   276  	LABEL		= 1<<1,
   277  	LEAF		= 1<<2,
   278  
   279  	STRINGSZ	= 200,
   280  	MINSIZ		= 64,
   281  	NENT		= 100,
   282  	MAXIO		= 8192,
   283  	MAXHIST		= 20,	/* limit of path elements for history symbols */
   284  	MINLC	= 4,
   285  };
   286  
   287  #ifndef COFFCVT
   288  
   289  EXTERN	int32	HEADR;			/* length of header */
   290  EXTERN	int	HEADTYPE;		/* type of header */
   291  EXTERN	int32	INITDAT;		/* data location */
   292  EXTERN	int32	INITRND;		/* data round above text location */
   293  EXTERN	int32	INITTEXT;		/* text location */
   294  EXTERN	char*	INITENTRY;		/* entry point */
   295  EXTERN	char*	LIBINITENTRY;		/* shared library entry point */
   296  EXTERN	int32	autosize;
   297  EXTERN	Auto*	curauto;
   298  EXTERN	Auto*	curhist;
   299  EXTERN	Prog*	curp;
   300  EXTERN	Sym*	cursym;
   301  EXTERN	Sym*	datap;
   302  EXTERN	int	debug[128];
   303  EXTERN	Sym*	etextp;
   304  EXTERN	char*	noname;
   305  EXTERN	Prog*	lastp;
   306  EXTERN	int32	lcsize;
   307  EXTERN	char	literal[32];
   308  EXTERN	int	nerrors;
   309  EXTERN	int32	instoffset;
   310  EXTERN	Opcross	opcross[8];
   311  EXTERN	Oprang	oprange[ALAST];
   312  EXTERN	char*	outfile;
   313  EXTERN	int32	pc;
   314  EXTERN	uchar	repop[ALAST];
   315  EXTERN	char*	interpreter;
   316  EXTERN	char*	rpath;
   317  EXTERN	uint32	stroffset;
   318  EXTERN	int32	symsize;
   319  EXTERN	Sym*	textp;
   320  EXTERN	int	version;
   321  EXTERN	char	xcmp[C_GOK+1][C_GOK+1];
   322  EXTERN	Prog	zprg;
   323  EXTERN	int	dtype;
   324  EXTERN	int	tlsoffset;
   325  EXTERN	int	armsize;
   326  EXTERN	int	goarm;
   327  EXTERN	Sym*	adrgotype;	// type symbol on last Adr read
   328  EXTERN	Sym*	fromgotype;	// type symbol on last p->from read
   329  
   330  extern	char*	anames[];
   331  extern	Optab	optab[];
   332  
   333  void	addpool(Prog*, Adr*);
   334  EXTERN	Prog*	blitrl;
   335  EXTERN	Prog*	elitrl;
   336  
   337  EXTERN	int	goarm;
   338  
   339  void	initdiv(void);
   340  EXTERN	Prog*	prog_div;
   341  EXTERN	Prog*	prog_divu;
   342  EXTERN	Prog*	prog_mod;
   343  EXTERN	Prog*	prog_modu;
   344  
   345  #pragma	varargck	type	"A"	int
   346  #pragma	varargck	type	"C"	int
   347  #pragma	varargck	type	"D"	Adr*
   348  #pragma	varargck	type	"I"	uchar*
   349  #pragma	varargck	type	"N"	Adr*
   350  #pragma	varargck	type	"P"	Prog*
   351  #pragma	varargck	type	"S"	char*
   352  #pragma	varargck	type	"Z"	char*
   353  #pragma	varargck	type	"i"	char*
   354  
   355  int	Aconv(Fmt*);
   356  int	Cconv(Fmt*);
   357  int	Dconv(Fmt*);
   358  int	Iconv(Fmt*);
   359  int	Nconv(Fmt*);
   360  int	Oconv(Fmt*);
   361  int	Pconv(Fmt*);
   362  int	Sconv(Fmt*);
   363  int	aclass(Adr*);
   364  void	addhist(int32, int);
   365  Prog*	appendp(Prog*);
   366  void	asmb(void);
   367  void	asmout(Prog*, Optab*, int32*);
   368  int32	atolwhex(char*);
   369  Prog*	brloop(Prog*);
   370  void	buildop(void);
   371  void	buildrep(int, int);
   372  void	cflush(void);
   373  int	chipzero(Ieee*);
   374  int	chipfloat(Ieee*);
   375  int	cmp(int, int);
   376  int	compound(Prog*);
   377  double	cputime(void);
   378  void	diag(char*, ...);
   379  void	divsig(void);
   380  void	dodata(void);
   381  void	doprof1(void);
   382  void	doprof2(void);
   383  int32	entryvalue(void);
   384  void	exchange(Prog*);
   385  void	follow(void);
   386  void	hputl(int);
   387  int	isnop(Prog*);
   388  void	listinit(void);
   389  Sym*	lookup(char*, int);
   390  void	cput(int);
   391  void	hput(int32);
   392  void	lput(int32);
   393  void	lputb(int32);
   394  void	lputl(int32);
   395  void*	mysbrk(uint32);
   396  void	names(void);
   397  void	nocache(Prog*);
   398  int	ocmp(const void*, const void*);
   399  int32	opirr(int);
   400  Optab*	oplook(Prog*);
   401  int32	oprrr(int, int);
   402  int32	olr(int32, int, int, int);
   403  int32	olhr(int32, int, int, int);
   404  int32	olrr(int, int, int, int);
   405  int32	olhrr(int, int, int, int);
   406  int32	osr(int, int, int32, int, int);
   407  int32	oshr(int, int32, int, int);
   408  int32	ofsr(int, int, int32, int, int, Prog*);
   409  int32	osrr(int, int, int, int);
   410  int32	oshrr(int, int, int, int);
   411  int32	omvl(Prog*, Adr*, int);
   412  void	patch(void);
   413  void	prasm(Prog*);
   414  void	prepend(Prog*, Prog*);
   415  Prog*	prg(void);
   416  int	pseudo(Prog*);
   417  int32	regoff(Adr*);
   418  int	relinv(int);
   419  int32	rnd(int32, int32);
   420  void	softfloat(void);
   421  void	span(void);
   422  void	strnput(char*, int);
   423  int32	symaddr(Sym*);
   424  void	undef(void);
   425  void	vputb(uint64);
   426  void	vputl(uint64);
   427  void	wputb(uint16);
   428  void	wput(int32);
   429  void    wputl(ushort w);
   430  void	xdefine(char*, int, int32);
   431  void	noops(void);
   432  int32	immrot(uint32);
   433  int32	immaddr(int32);
   434  int32	opbra(int, int);
   435  int	brextra(Prog*);
   436  int	isbranch(Prog*);
   437  void	fnptrs(void);
   438  void	doelf(void);
   439  void	dozerostk(void); // used by -Z
   440  
   441  vlong		addaddr(Sym *s, Sym *t);
   442  vlong		addsize(Sym *s, Sym *t);
   443  vlong		addstring(Sym *s, char *str);
   444  vlong		adduint16(Sym *s, uint16 v);
   445  vlong		adduint32(Sym *s, uint32 v);
   446  vlong		adduint64(Sym *s, uint64 v);
   447  vlong		adduint8(Sym *s, uint8 v);
   448  vlong		adduintxx(Sym *s, uint64 v, int wid);
   449  
   450  /* Native is little-endian */
   451  #define	LPUT(a)	lputl(a)
   452  #define	WPUT(a)	wputl(a)
   453  #define	VPUT(a)	abort()
   454  
   455  #endif
   456  
   457  /* Used by ../ld/dwarf.c */
   458  enum
   459  {
   460  	DWARFREGSP = 13
   461  };