xref: /original-bsd/old/as.vax/as.h (revision 92d3de31)
1 /*
2  *	Copyright (c) 1982 Regents of the University of California
3  *	@(#)as.h 4.11 12/15/82
4  */
5 #ifdef VMS
6 # define	vax	1
7 # define	VAX	1
8 #endif VMS
9 
10 #define	reg	register
11 
12 #include <sys/types.h>
13 #ifdef UNIX
14 
15 #ifdef FLEXNAMES
16 #  include <a.out.h>
17 #  include <stab.h>
18 #else not FLEXNAMES
19 #  define ONLIST
20 #  include "a.out.h"
21 #  include <stab.h>
22 #endif FLEXNAMES
23 
24 #endif UNIX
25 #ifdef VMS
26 
27 #ifdef UNIXDEVEL
28 #  include <a.out.h>
29 #else not UNIXDEVEL
30 #  include <aout.h>
31 #endif not UNIXDEVEL
32 
33 #endif VMS
34 
35 #define readonly
36 #define	NINST		300
37 
38 #define	NEXP		20	/* max number of expr. terms per instruction */
39 #define	NARG		6	/* max number of args per instruction */
40 #define	NHASH		1103	/* hash table is dynamically extended */
41 #define	TNAMESIZE	32	/* maximum length of temporary file names */
42 #define	NLOC		4	/* number of location ctrs */
43 
44 #ifdef UNIX
45 # ifndef	FLEXNAMES
46 #	ifndef	NCPS
47 #		define	NCPS	8	/* number of characters per symbol*/
48 #	endif
49 # else
50 #	ifdef NCPS
51 #		undef	NCPS
52 #	endif
53 #	define	NCPS	4096	/* needed to allocate yytext */
54 # endif
55 # endif UNIX
56 
57 # ifdef VMS
58 # ifdef NCPS
59 #	undef	NCPS
60 # endif NCPS
61 #	define	NCPS	15
62 # endif VMS
63 
64 /*
65  * Symbol types
66  */
67 #define	XUNDEF	0x0
68 #define	XABS	0x2
69 #define	XTEXT	0x4
70 #define	XDATA	0x6
71 #define	XBSS	0x8
72 
73 #define	XXTRN	0x1
74 #define	XTYPE	0x1E
75 
76 #define	XFORW	0x20	/* Was forward-referenced when undefined */
77 
78 #define	ERR	(-1)
79 #define	NBPW	32	/* Bits per word */
80 
81 #define	AMASK	017
82 
83 /*
84  * Actual argument syntax types
85  */
86 #define	AREG	1	/* %r */
87 #define	ABASE	2	/* (%r) */
88 #define	ADECR	3	/* -(%r) */
89 #define	AINCR	4	/* (%r)+ */
90 #define	ADISP	5	/* expr(%r) */
91 #define	AEXP	6	/* expr */
92 #define	AIMM	7	/* $ expr */
93 #define	ASTAR	8	/* * */
94 #define	AINDX	16	/* [%r] */
95 /*
96  *	Definitions for the things found in ``instrs''
97  */
98 #define	INSTTAB 1
99 #include "instrs.h"
100 
101 /*
102  *	Tells outrel what it is relocating
103  *	RELOC_PCREL is an implicit argument to outrel; it is or'ed in
104  *	with a TYPX
105  */
106 #define	RELOC_PCREL	(1<<TYPLG)
107 /*
108  *	reference types for loader
109  */
110 #define	PCREL	1
111 #define	LEN1	2
112 #define	LEN2	4
113 #define	LEN4	6
114 #define	LEN8	8
115 #define	LEN16	10
116 
117 extern	int	reflen[];	/* {LEN*+PCREL} ==> number of bytes */
118 extern	int	lgreflen[];	/* {LEN*+PCREL} ==> lg number of bytes */
119 extern	int	len124[];	/* {1,2,4,8,16} ==> {LEN1, LEN2, LEN4, LEN8} */
120 extern	char	mod124[];	/* {1,2,4,8,16} ==> {bits to construct operands */
121 extern	int	type_124[];	/* {1,2,4,8,16} ==> {TYPB,TYPW,TYPL,TYPQ,TYPO} */
122 extern	int	ty_NORELOC[];	/* {TYPB..TYPH} ==> {1 if relocation not OK */
123 extern	int	ty_float[];	/* {TYPB..TYPH} ==> {1 if floating number */
124 extern	int	ty_LEN[];	/* {TYPB..TYPH} ==> {LEN1..LEN16} */
125 extern	int	ty_nbyte[];	/* {TYPB..TYPH} ==> {1,2,4,8,16} */
126 extern	int	ty_nlg[];	/* {TYPB..TYPH} ==> lg{1,2,4,8,16} */
127 extern	char	*ty_string[];	/* {TYPB..TYPH} ==> printable */
128 
129 #define	TMPC	7
130 #define	HW	0x1
131 #define	FW	0x3
132 #define	DW	0x7
133 #define	OW	0xF
134 
135 #ifdef UNIX
136 #  include <pagsiz.h>
137 #endif UNIX
138 
139 #ifdef VMS
140 #  define PAGRND	0x1FFL
141 #endif VMS
142 
143 #define	round(x,y)	(((x)+(y)) & ~(y))
144 
145 #define	STABTYPS	0340
146 #define	STABFLAG	0200
147 
148 /*
149  *	Follows are the definitions for the symbol table tags, which are
150  *	all unsigned characters..
151  *	High value tags are generated by the asembler for internal
152  *	use.
153  *	Low valued tags are the parser coded tokens the scanner returns.
154  *	There are several pertinant bounds in this ordering:
155  *		a)	Symbols greater than JXQUESTIONABLE
156  *			are used by the jxxx bumper, indicating that
157  *			the symbol table entry is a jxxx entry
158  *			that has yet to be bumped.
159  *		b)	Symbols greater than IGNOREBOUND are not
160  *			bequeathed to the loader; they are truly
161  *			for assembler internal use only.
162  *		c)	Symbols greater than OKTOBUMP represent
163  *			indices into the program text that should
164  *			be changed in preceeding jumps or aligns
165  *			must get turned into their long form.
166  */
167 
168 #define	TAGMASK		0xFF
169 
170 #	define	JXACTIVE	0xFF	/*jxxx size unknown*/
171 #	define	JXNOTYET	0xFE	/*jxxx size known, but not yet expanded*/
172 #	define	JXALIGN		0xFD	/*align jxxx entry*/
173 #	define	JXINACTIVE	0xFC	/*jxxx size known and expanded*/
174 
175 #define	JXQUESTIONABLE		0xFB
176 
177 #	define	JXTUNNEL	0xFA	/*jxxx that jumps to another*/
178 #	define	OBSOLETE	0xF9	/*erroneously entered symbol*/
179 
180 #define	IGNOREBOUND	0xF8		/*symbols greater than this are ignored*/
181 #	define	STABFLOATING	0xF7
182 #	define	LABELID		0xF6
183 
184 #define	OKTOBUMP	0xF5
185 #	define	STABFIXED	0xF4
186 
187 /*
188  *	astoks.h contains reserved word codings the parser should
189  *	know about
190  */
191 #include "astoks.h"
192 
193 /*
194  *	The structure for one symbol table entry.
195  *	Symbol table entries are used for both user defined symbols,
196  *	and symbol slots generated to create the jxxx jump from
197  *	slots.
198  *	Caution: the instructions are stored in a shorter version
199  *	of the struct symtab, using all fields in sym_nm and
200  *	tag.  The fields used in sym_nm are carefully redeclared
201  *	in struct Instab and struct instab (see below).
202  *	If struct nlist gets changed, then Instab and instab may
203  *	have to be changed.
204  */
205 
206 struct symtab{
207 		struct	nlist	s_nm;
208 		u_char	s_tag;		/* assembler tag */
209 		u_char	s_ptype;	/* if tag == NAME */
210 		u_char	s_jxoveralign;	/* if a JXXX, jumped over align */
211 		short	s_index;	/* which segment */
212 		struct	symtab *s_dest;	/* if JXXX, where going to */
213 #ifdef DJXXX
214 		short	s_jxline;	/* source line of the jump from */
215 #endif
216 };
217 /*
218  *	Redefinitions of the fields in symtab for
219  *	use when the symbol table entry marks a jxxx instruction.
220  */
221 #define	s_jxbump	s_ptype		/* tag == JX..., how far to expand */
222 #define	s_jxfear	s_desc		/* how far needs to be bumped */
223 /*
224  *	Redefinitions of fields in the struct nlist for symbols so that
225  *	one saves typing, and so that they conform
226  *	with the old naming conventions.
227  */
228 #ifdef	FLEXNAMES
229 #define	s_name	s_nm.n_un.n_name	/* name pointer */
230 #define	s_nmx	s_nm.n_un.n_strx	/* string table index */
231 #else 	not FLEXNAMES
232 #define	s_name	s_nm.n_name
233 #endif
234 #define	s_type	s_nm.n_type		/* type of the symbol */
235 #define	s_other	s_nm.n_other		/* other information for sdb */
236 #define	s_desc	s_nm.n_desc		/* type descriptor */
237 #define	s_value	s_nm.n_value		/* value of the symbol, or sdb delta */
238 
239 struct	instab{
240 	struct	nlist	s_nm;		/* instruction name, type (opcode) */
241 	u_char	s_tag;
242 	u_char	s_eopcode;
243 	char	s_pad[2];		/* round to 20 bytes */
244 };
245 typedef	struct	instab	*Iptr;
246 /*
247  *	The fields nm.n_desc and nm.n_value total 6 bytes; this is
248  *	just enough for the 6 bytes describing the argument types.
249  *	We use a macro to define access to these 6 bytes, assuming that
250  *	they are allocated adjacently.
251  *	IF THE FORMAT OF STRUCT nlist CHANGES, THESE MAY HAVE TO BE CHANGED.
252  *
253  *	Instab is cleverly declared to look very much like the combination of
254  *	a struct symtab and a struct nlist.
255  */
256 /*
257  *	With the 1981 VAX architecture reference manual,
258  *	DEC defined and named two byte opcodes.
259  *	In addition, DEC defined four new one byte instructions for
260  *	queue manipulation.
261  *	The assembler was patched in 1982 to reflect this change.
262  *
263  *	The two byte opcodes are preceded with an escape byte
264  *	(usually an ESCD) and an opcode byte.
265  *	For one byte opcodes, the opcode is called the primary opcode.
266  *	For two byte opcodes, the second opcode is called the primary opcode.
267  *
268  *	We store the primary opcode in I_popcode,
269  *	and the escape opcode in I_eopcode.
270  *
271  *	For one byte opcodes in the basic arhitecture,
272  *		I_eopcode is CORE
273  *	For one byte opcodes in the new architecture definition,
274  *		I_eopcode is NEW
275  *	For the two byte opcodes, I_eopcode is the escape byte.
276  *
277  *	The assembler checks if a NEW or two byte opcode is used,
278  *	and issues a warning diagnostic.
279  */
280 /*
281  *	For upward compatability reasons, we can't have the two opcodes
282  *	forming an operator specifier byte(s) be physically adjacent
283  *	in the instruction table.
284  *	We define a structure and a constructor that is used in
285  *	the instruction generator.
286  */
287 struct Opcode{
288 	u_char	Op_eopcode;
289 	u_char	Op_popcode;
290 };
291 
292 #define	BADPOINT	0xAAAAAAAA
293 /*
294  *	See if a structured opcode is bad
295  */
296 #define	ITABCHECK(o)	((itab[o.Op_eopcode] != (Iptr*)BADPOINT) && (itab[o.Op_eopcode][o.Op_popcode] != (Iptr)BADPOINT))
297 /*
298  *	Index the itab by a structured opcode
299  */
300 #define	ITABFETCH(o)	itab[o.Op_eopcode][o.Op_popcode]
301 
302 struct	Instab{
303 #ifdef FLEXNAMES
304 	char	*I_name;
305 #else not FLEXNAMES
306 	char	I_name[NCPS];
307 #endif
308 	u_char	I_popcode;		/* basic op code */
309 	char	I_nargs;
310 	char	I_args[6];
311 	u_char	I_s_tag;
312 	u_char	I_eopcode;
313 	char	I_pad[2];		/* round to 20 bytes */
314 };
315 /*
316  *	Redefinitions of fields in the struct nlist for instructions so that
317  *	one saves typing, and conforms to the old naming conventions
318  */
319 #define	i_popcode	s_nm.n_type	/* use the same field as symtab.type */
320 #define	i_eopcode	s_eopcode
321 #define	i_nargs		s_nm.n_other	/* number of arguments */
322 #define	fetcharg(ptr, n) ((struct Instab *)ptr)->I_args[n]
323 
324 struct	arg {				/*one argument to an instruction*/
325 	char	a_atype;
326 	char	a_areg1;
327 	char	a_areg2;
328 	char	a_dispsize;		/*usually d124, unless have B^, etc*/
329 	struct	exp *a_xp;
330 };
331 /*
332  *	Definitions for numbers and expressions.
333  */
334 #include "asnumber.h"
335 struct	exp {
336 	Bignum	e_number;	/* 128 bits of #, plus tag */
337 	char	e_xtype;
338 	char	e_xloc;
339 	struct	symtab		*e_xname;
340 };
341 #define	e_xvalue	e_number.num_num.numIl_int.Il_long
342 
343 #define		MINLIT		0
344 #define		MAXLIT		63
345 
346 #define		MINBYTE		-128
347 #define		MAXBYTE		127
348 #define		MINUBYTE	0
349 #define		MAXUBYTE	255
350 
351 #define		MINWORD		-32768
352 #define		MAXWORD		32767
353 #define		MINUWORD	0
354 #define		MAXUWORD	65535
355 
356 #define		ISLIT(x)	(((x) >= MINLIT) && ((x) <= MAXLIT))
357 #define		ISBYTE(x)	(((x) >= MINBYTE) && ((x) <= MAXBYTE))
358 #define		ISUBYTE(x)	(((x) >= MINUBYTE) && ((x) <= MAXUBYTE))
359 #define		ISWORD(x)	(((x) >= MINWORD) && ((x) <= MAXWORD))
360 #define		ISUWORD(x)	(((x) >= MINUWORD) && ((x) <= MAXUWORD))
361 
362 	extern	struct	arg	arglist[NARG];	/*building operands in instructions*/
363 	extern	struct	exp	explist[NEXP];	/*building up a list of expressions*/
364 	extern	struct	exp	*xp;		/*current free expression*/
365 	/*
366 	 *	Communication between the scanner and the jxxx handlers.
367 	 *	lastnam:	the last name seen on the input
368 	 *	lastjxxx:	pointer to the last symbol table entry for
369 	 *			a jump from
370 	 */
371 	extern	struct	symtab	*lastnam;
372 	extern	struct	symtab	*lastjxxx;
373 
374 #ifdef VMS
375 	extern	char	*vms_obj_ptr;		/* object buffer pointer */
376 	extern	char	sobuf[];		/* object buffer         */
377 	extern	int	objfil;			/* VMS object file descriptor */
378 #endif VMS
379 
380 	/*
381 	 *	Lgensym is used to make up funny names for local labels.
382 	 *	lgensym[i] is the current funny number to put after
383 	 *	references to if, lgensym[i]-1 is for ib.
384 	 *	genref[i] is set when the label is referenced before
385 	 *	it is defined (i.e. 2f) so that we can be sure these
386 	 *	labels are always defined to avoid weird diagnostics
387 	 *	from the loader later.
388 	 */
389 	extern	int	lgensym[10];
390 	extern	char	genref[10];
391 
392 	extern	char	tmpn1[TNAMESIZE];	/* Interpass temporary */
393 	extern	struct	exp	*dotp;		/* the current dot location */
394 	extern	int	loctr;
395 
396 	extern	struct	exec	hdr;		/* a.out header */
397 	extern	u_long	tsize;			/* total text size */
398 	extern	u_long	dsize;			/* total data size */
399 	extern	u_long	trsize;			/* total text relocation size */
400 	extern	u_long	drsize;			/* total data relocation size */
401 	extern	u_long	datbase;		/* base of the data segment */
402 	/*
403 	 *	Bitoff and bitfield keep track of the packing into
404 	 *	bytes mandated by the expression syntax <expr> ':' <expr>
405 	 */
406 	extern	int	bitoff;
407 	extern	long	bitfield;
408 
409 	/*
410 	 *	The lexical analyzer builds up symbols in yytext.  Lookup
411 	 *	expects its argument in this buffer
412 	 */
413 	extern	char	yytext[NCPS+2];		/* text buffer for lexical */
414 	/*
415 	 *	Variables to manage the input assembler source file
416 	 */
417 	extern	int	lineno;			/*the line number*/
418 	extern	char	*dotsname;		/*the name of the as source*/
419 
420 	extern	FILE	*tmpfil;		/* interpass communication*/
421 
422 	extern	int	passno;			/* 1 or 2 */
423 
424 	extern	int	anyerrs;		/*errors as'ing arguments*/
425 	extern	int	anywarnings;		/*warnings as'ing arguments*/
426 	extern	int	silent;			/*don't mention the errors*/
427 	extern	int	savelabels;		/*save labels in a.out*/
428 	extern	int	orgwarn;		/* questionable origin ? */
429 	extern	int	useVM;			/*use virtual memory temp file*/
430 	extern	int	jxxxJUMP;		/*use jmp instead of brw for jxxx */
431 	extern	int	readonlydata;		/*initialized data into text space*/
432 	extern	int	nGHnumbers;		/* GH numbers used */
433 	extern	int	nGHopcodes;		/* GH opcodes used */
434 	extern	int	nnewopcodes;		/* new opcodes used */
435 #ifdef DEBUG
436 	extern	int	debug;
437 	extern	int	toktrace;
438 #endif
439 	/*
440 	 *	Information about the instructions
441 	 */
442 	extern	struct	instab	**itab[NINST];	/*maps opcodes to instructions*/
443 	extern  readonly struct Instab instab[];
444 
445 	extern	int	curlen;			/*current literal storage size*/
446 	extern	int	d124;			/*current pointer storage size*/
447 
448 	struct	symtab	**lookup();		/*argument in yytext*/
449 	struct 	symtab	*symalloc();
450 
451 	char	*Calloc();
452 	char	*ClearCalloc();
453 
454 #define outb(val) {dotp->e_xvalue++; if (passno==2) bputc((val), (txtfil));}
455 
456 #define outs(cp, lg) dotp->e_xvalue += (lg); if (passno == 2) bwrite((cp), (lg), (txtfil))
457 
458 #ifdef UNIX
459 #define	Outb(o)	outb(o)
460 #endif UNIX
461 
462 #ifdef VMS
463 #define	Outb(o)	{*vms_obj_ptr++=-1;*vms_obj_ptr++=(char)o;dotp->e_xvalue+=1;}
464 #endif VMS
465 
466 /*
467  *	Most of the time, the argument to flushfield is a power of two constant,
468  *	the calculations involving it can be optimized to shifts.
469  */
470 #define flushfield(n) if (bitoff != 0)  Flushfield( ( (bitoff+n-1) /n ) * n)
471 
472 /*
473  * The biobuf structure and associated routines are used to write
474  * into one file at several places concurrently.  Calling bopen
475  * with a biobuf structure sets it up to write ``biofd'' starting
476  * at the specified offset.  You can then use ``bwrite'' and/or ``bputc''
477  * to stuff characters in the stream, much like ``fwrite'' and ``fputc''.
478  * Calling bflush drains all the buffers and MUST be done before exit.
479  */
480 struct	biobuf {
481 	short	b_nleft;		/* Number free spaces left in b_buf */
482 /* Initialize to be less than BUFSIZ initially, to boundary align in file */
483 	char	*b_ptr;			/* Next place to stuff characters */
484 	char	b_buf[BUFSIZ];		/* The buffer itself */
485 	off_t	b_off;			/* Current file offset */
486 	struct	biobuf *b_link;		/* Link in chain for bflush() */
487 };
488 #define	bputc(c,b) ((b)->b_nleft ? (--(b)->b_nleft, *(b)->b_ptr++ = (c)) \
489 		       : bflushc(b, c))
490 #define BFILE	struct biobuf
491 
492 	extern	BFILE	*biobufs;	/* head of the block I/O buffer chain */
493 	extern	int	biofd;		/* file descriptor for block I/O file */
494 	extern	off_t	boffset;	/* physical position in logical file */
495 
496 	/*
497 	 *	For each of the named .text .data segments
498 	 *	(introduced by .text <expr>), we maintain
499 	 *	the current value of the dot, and the BFILE where
500 	 *	the information for each of the segments is placed
501 	 *	during the second pass.
502 	 */
503 	extern	struct	exp	usedot[NLOC + NLOC];
504 	extern		BFILE	*usefile[NLOC + NLOC];
505 	extern		BFILE	*txtfil;/* file for text and data: into usefile */
506 	/*
507 	 *	Relocation information for each segment is accumulated
508 	 *	seperately from the others.  Writing the relocation
509 	 *	information is logically viewed as writing to one
510 	 *	relocation saving file for  each segment; physically
511 	 *	we have a bunch of buffers allocated internally that
512 	 *	contain the relocation information.
513 	 */
514 	struct	relbufdesc	*rusefile[NLOC + NLOC];
515 	struct	relbufdesc	*relfil;
516