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