BSD 3 development
[unix-history] / usr / src / cmd / as / as.h
CommitLineData
4d0e73ae
JR
1/* Copyright (c) 1979 Regents of the University of California */
2#define readonly
3#define NINST 300
4#define NSYM 4000
5#define NHASH (NSYM+1)
6#define NLOC 4 /* number of location ctrs */
7#define NCPS 8 /* number of characters per symbol, fixed */
8
9/*
10 * Symbol types
11 */
12#define XUNDEF 0x0
13#define XABS 0x2
14#define XTEXT 0x4
15#define XDATA 0x6
16#define XBSS 0x8
17#define XDATAO 0xA
18#define XBSSO 0xC
19#define XTEXTO 0xE
20#define XABSO 0x10
21#define XUNDEFO 0x12
22
23#define XTXRN 0xA /* external symbol */
24#define XXTRN 0x1
25#define XTYPE 0x1E
26
27#define XFORW 0x20 /* Was forward-referenced when undefined */
28
29#define ERR (-1)
30#define NBPW 32 /* Bits per word */
31
32#define AMASK 017
33
34/*
35 * Actual argument syntax types
36 */
37#define AREG 1 /* %r */
38#define ABASE 2 /* (%r) */
39#define ADECR 3 /* -(%r) */
40#define AINCR 4 /* (%r)+ */
41#define ADISP 5 /* expr(%r) */
42#define AEXP 6 /* expr */
43#define AIMM 7 /* $ expr */
44#define ASTAR 8 /* * */
45#define AINDX 16 /* [%r] */
46
47/*
48 * Argument access types used to test validity of operands to operators
49 */
50#define ACCA (8<<3) /* address only */
51#define ACCR (1<<3) /* read */
52#define ACCW (2<<3) /* write */
53#define ACCM (3<<3) /* modify */
54#define ACCB (4<<3) /* branch displacement */
55#define ACCI (5<<3) /* XFC code */
56
57/*
58 * Argument data types
59 */
60#define TYPB 0 /* byte */
61#define TYPW 1 /* word */
62#define TYPL 2 /* long */
63#define TYPQ 3 /* quad */
64#define TYPF 4 /* floating */
65#define TYPD 5 /* double floating */
66
67#define TYPMASK 7
68
69/* reference types for loader */
70#define PCREL 1
71#define LEN1 2
72#define LEN2 4
73#define LEN4 6
74#define LEN8 8
75
76#define TMPC 7 /* offset into the string /tmp/aaaXXX for creating tmp file names*/
77#define HW 01
78#define FW 03
79#define DW 07
80
81#include <pagsiz.h>
82
83#define round(x,y) (((x)+(y)) & ~(y))
84
85#define STABTYPS 0340
86#define STABFLAG 0200
87
88/*
89 * Follows are the definitions for the symbol table tags, which are
90 * all unsigned characters..
91 * High value tags are generated by the asembler for internal
92 * use.
93 * Low valued tags are the parser coded tokens the scanner returns.
94 * There are several pertinant bounds in this ordering:
95 * a) Symbols greater than JXQUESTIONABLE
96 * are used by the jxxx bumper, indicating that
97 * the symbol table entry is a jxxx entry
98 * that has yet to be bumped.
99 * b) Symbols greater than IGNOREBOUND are not
100 * bequeathed to the loader; they are truly
101 * for assembler internal use only.
102 * c) Symbols greater than OKTOBUMP represent
103 * indices into the program text that should
104 * be changed in preceeding jumps or aligns
105 * must get turned into their long form.
106 */
107
108#define TAGMASK 0xFF
109
110# define JXACTIVE 0xFF /*jxxx instruction size unknown*/
111# define JXNOTYET 0xFE /*jxxx instruction size known, but not yet expanded*/
112# define JXALIGN 0xFD /*align jxxx entry*/
113# define JXINACTIVE 0xFC /*jxxx instruction size known and expanded*/
114
115#define JXQUESTIONABLE 0xFB
116
117# define JXTUNNEL 0xFA /*jxxx instruction that jumps to another*/
118# define OBSOLETE 0xF9 /*erroneously entered symbol*/
119
120#define IGNOREBOUND 0xF8 /*symbols greater than this are ignored*/
121# define STABFLOATING 0xF7
122# define LABELID 0xF6
123
124#define OKTOBUMP 0xF5
125# define STABFIXED 0xF4
126
127/*
128 * astoks.h contains reserved word codings the parser should
129 * know about
130 */
131#include "astoks.h"
132
133/*
134 * The structure for one symbol table entry.
135 * Symbol table entries are used for both user defined symbols,
136 * and symbol slots generated to create the jxxx jump from
137 * slots.
138 */
139
140#define symfirstfields char *name; unsigned char tag, type
141
142struct symtab{
143 symfirstfields;
144#ifdef vax
145 short ___hole;
146#endif
147 /*save*/ char ptype; /*tag == NAME*/
148
149#define jxbump ptype /*tag == JX..., how far to expand*/
150
151 /*save*/ char other; /*for stab info*/
152
153 /*save*/ short desc; /*tag == NAME*/
154
155#define jxfear desc /*how far needs to be bumped*/
156
157 /*save*/ long value; /*address in the segment*/
158 char jxoveralign; /*if a JXXX, jumped over an align*/
159 short index; /*which segment*/
160 struct symtab *dest; /*if JXXX, where going to*/
161#ifdef DJXXX
162 short jxline; /*source line of the jump from*/
163#endif
164};
165
166struct instab{
167 symfirstfields;
168
169#define opcode type /*use the same field as symtab.type*/
170
171 char nargs; /*how many arguments*/
172 char argtype[6]; /*argument type info*/
173};
174
175struct arg { /*one argument to an instruction*/
176 char atype;
177 char areg1;
178 char areg2;
179 char dispsize; /*usually d124, unless have B^, etc*/
180 struct exp *xp;
181};
182
183struct exp {
184 char xtype;
185 char xloc;
186 long xvalue;
187 struct symtab *xname;
188 union{
189 double dvalue;
190 struct {
191 unsigned int doub_MSW, doub_LSW;
192 } dis_dvalue;
193 } doubval;
194};
195
196/*
197 * Magic layout macros
198 */
199#define MINBYTE -128
200#define MAXBYTE 127
201#define MINWORD -32768
202#define MAXWORD 32767
203
204#define LITFLTMASK 0x000043F0 /*really magic*/
205/*
206 * Is the floating point double word in xp a
207 * short literal floating point number?
208 */
209#define slitflt(xp) \
210 ( (xp->doubval.dis_dvalue.doub_LSW == 0) \
211 && ((xp->doubval.dis_dvalue.doub_MSW & LITFLTMASK) \
212 == xp->doubval.dis_dvalue.doub_MSW) )
213
214#define extlitflt(xp) \
215 xp->doubval.dis_dvalue.doub_MSW >> 4
216
217/*
218 * Structure that appears at the head of a.out
219 */
220struct hdr {
221 long magic;
222 long tsize;
223 long dsize;
224 long bsize;
225 long ssize;
226 long entry;
227 long trsize;
228 long drsize;
229};
230
231 struct arg arglist[6]; /*building operands in instructions*/
232 struct exp explist[20]; /*building up a list of expressions*/
233
234 /*
235 * Communication between the scanner and the jxxx handlers.
236 * lastnam: the last name seen on the input
237 * lastjxxx: pointer to the last symbol table entry for
238 * a jump from
239 */
240 extern struct symtab *lastnam;
241 extern struct symtab *lastjxxx;
242 /*
243 * For each of the named .text .data segments
244 * (introduced by .text <expr>), we maintain
245 * the current value of the dot, and the Files where
246 * the information for each of the segments is salted
247 * away.
248 *
249 * Use of rulesfile and usefile is unclear
250 */
251 extern struct exp usedot[NLOC+NLOC];
252 extern FILE *usefile[NLOC+NLOC];
253 extern FILE *rusefile[NLOC+NLOC];
254 /*
255 * Strings used to construct the temporary files
256 * for each of the named segments in pass 2.
257 */
258 extern char *tmpn2; /* /tmp/aaaXXXX */
259 extern char *tmpn3; /* /tmp/aabXXX */
260
261 extern struct exp *dotp; /*the current dot location*/
262 extern int loctr;
263 extern long tsize; /* total text size */
264 extern long dsize; /* total data size */
265 extern long datbase; /* base of the data segment */
266 /*
267 * Bitoff and bitfield keep track of the packing into
268 * bytes mandated by the expression syntax <expr> ':' <expr>
269 */
270 extern int bitoff;
271 extern long bitfield;
272
273 /*
274 * The lexical analyzer builds up symbols in yytext. Lookup
275 * expects its argument in this buffer
276 */
277 extern char yytext[NCPS+2]; /* text buffer for lexical */
278 /*
279 * Variables to manage the input assembler source file
280 */
281 extern int lineno; /*the line number*/
282 extern char *dotsname; /*the name of the as source*/
283 /*extern FILE stdin*;*/ /*the as source input*/
284
285 extern FILE *txtfil; /* file for text*/
286 extern FILE *tmpfil; /* interpass communication*/
287 extern FILE *relfil; /* holds relocation informtion*/
288
289 extern int passno; /* 1 or 2 */
290
291 extern int anyerrs; /*errors assembling arguments*/
292 extern int silent; /*don't mention the errors*/
293 extern int savelabels; /*save labels in a.out*/
294 int orgwarn; /* questionable origin ? */
295 int useVM; /*use virtual memory temp file*/
296#ifdef DEBUG
297 extern int debug;
298 extern int toktrace;
299#endif
300 /*
301 * Information about the instructions
302 */
303 struct instab *itab[NINST]; /*maps opcodes to instructions*/
304 extern readonly struct instab instab[];
305
306 int curlen; /*current storage size*/
307
308 struct symtab **lookup(); /*argument in yytext*/
309 struct symtab *symalloc();
310
311#ifdef METRIC
312 int outcounters; /*should we print them?*/
313 int nhcollision;
314 int nhashed;
315 int nentered;
316 int lgtmpfile;
317 int jxxxiterate;
318 int jxxxtunnel; /*how many tunnel jumps done*/
319 int jxdeadlock;
320 int nbadjxsegs;
321#endif
322
323
324#define outb(val) {dotp->xvalue++; if (passno==2) putc((val), txtfil);}
325
326#define outs(cp, lg) dotp->xvalue += (lg); if (passno == 2) fwrite((cp), 1, (lg), txtfil)
327
328/*
329 * Most of the time, the argument to flushfield is a power of two constant,
330 * the calculations involving it can be optimized to shifts.
331 */
332#define flushfield(n) if (bitoff != 0) Flushfield( ( (bitoff+n-1) /n ) * n)