Commit | Line | Data |
---|---|---|
8c1020c4 | 1 | /* Copyright (c) 1980 Regents of the University of California */ |
b9653ef8 | 2 | /* "@(#)as.h 4.2 %G%" */ |
8c1020c4 BJ |
3 | #ifdef VMS |
4 | # define vax 1 | |
5 | # define VAX 1 | |
6 | #endif VMS | |
7 | ||
8 | #define readonly | |
9 | ||
10 | #define NINST 300 | |
11 | ||
12 | #define NEXP 20 /* max number of expr. terms per instruction */ | |
13 | #define NARG 6 /* max number of args per instruction */ | |
14 | #define NHASH 1103 /* hash table is dynamically extended */ | |
15 | #define TNAMESIZE 32 /* maximum length of temporary file names */ | |
16 | #define NLOC 4 /* number of location ctrs */ | |
17 | ||
18 | #ifdef UNIX | |
19 | # ifndef FLEXNAMES | |
20 | # ifndef NCPS | |
21 | # define NCPS 8 /* number of characters per symbol*/ | |
22 | # endif | |
23 | # else | |
24 | # ifdef NCPS | |
25 | # undef NCPS | |
26 | # endif | |
27 | # define NCPS BUFSIZ /* needed to allocate yytext */ | |
28 | # endif | |
29 | # endif UNIX | |
30 | ||
31 | # ifdef VMS | |
32 | # ifdef NCPS | |
33 | # undef NCPS | |
34 | # endif NCPS | |
35 | # define NCPS 15 | |
36 | # endif VMS | |
37 | ||
38 | /* | |
39 | * Symbol types | |
40 | */ | |
41 | #define XUNDEF 0x0 | |
42 | #define XABS 0x2 | |
43 | #define XTEXT 0x4 | |
44 | #define XDATA 0x6 | |
45 | #define XBSS 0x8 | |
46 | ||
47 | #define XXTRN 0x1 | |
48 | #define XTYPE 0x1E | |
49 | ||
50 | #define XFORW 0x20 /* Was forward-referenced when undefined */ | |
51 | ||
52 | #define ERR (-1) | |
53 | #define NBPW 32 /* Bits per word */ | |
54 | ||
55 | #define AMASK 017 | |
56 | ||
57 | /* | |
58 | * Actual argument syntax types | |
59 | */ | |
60 | #define AREG 1 /* %r */ | |
61 | #define ABASE 2 /* (%r) */ | |
62 | #define ADECR 3 /* -(%r) */ | |
63 | #define AINCR 4 /* (%r)+ */ | |
64 | #define ADISP 5 /* expr(%r) */ | |
65 | #define AEXP 6 /* expr */ | |
66 | #define AIMM 7 /* $ expr */ | |
67 | #define ASTAR 8 /* * */ | |
68 | #define AINDX 16 /* [%r] */ | |
69 | ||
70 | /* | |
71 | * Argument access types used to test validity of operands to operators | |
72 | */ | |
73 | #define ACCA (8<<3) /* address only */ | |
74 | #define ACCR (1<<3) /* read */ | |
75 | #define ACCW (2<<3) /* write */ | |
76 | #define ACCM (3<<3) /* modify */ | |
77 | #define ACCB (4<<3) /* branch displacement */ | |
78 | #define ACCI (5<<3) /* XFC code */ | |
79 | ||
80 | /* | |
81 | * Argument data types | |
82 | */ | |
83 | #define TYPB 0 /* byte */ | |
84 | #define TYPW 1 /* word */ | |
85 | #define TYPL 2 /* long */ | |
86 | #define TYPQ 3 /* quad */ | |
87 | #define TYPF 4 /* floating */ | |
88 | #define TYPD 5 /* double floating */ | |
89 | ||
90 | #define TYPMASK 7 | |
91 | ||
92 | /* reference types for loader */ | |
93 | #define PCREL 1 | |
94 | #define LEN1 2 | |
95 | #define LEN2 4 | |
96 | #define LEN4 6 | |
97 | #define LEN8 8 | |
98 | /* | |
99 | * reflen table converts between LEN* and PCREL to numbers | |
100 | * of bytes. | |
101 | * lgreflen table is the lg base 2 of the values in reflen. | |
102 | */ | |
103 | extern int reflen[]; /* reference lengths */ | |
104 | extern int lgrefltn[]; /* lg reference lengths */ | |
105 | ||
106 | #define TMPC 7 | |
107 | #define HW 01 | |
108 | #define FW 03 | |
109 | #define DW 07 | |
110 | ||
111 | #ifdef UNIX | |
112 | # include <pagsiz.h> | |
113 | #endif UNIX | |
114 | ||
115 | #ifdef VMS | |
116 | # define PAGRND 0x1FFL | |
117 | #endif VMS | |
118 | ||
119 | #define round(x,y) (((x)+(y)) & ~(y)) | |
120 | ||
121 | #define STABTYPS 0340 | |
122 | #define STABFLAG 0200 | |
123 | ||
124 | /* | |
125 | * Follows are the definitions for the symbol table tags, which are | |
126 | * all unsigned characters.. | |
127 | * High value tags are generated by the asembler for internal | |
128 | * use. | |
129 | * Low valued tags are the parser coded tokens the scanner returns. | |
130 | * There are several pertinant bounds in this ordering: | |
131 | * a) Symbols greater than JXQUESTIONABLE | |
132 | * are used by the jxxx bumper, indicating that | |
133 | * the symbol table entry is a jxxx entry | |
134 | * that has yet to be bumped. | |
135 | * b) Symbols greater than IGNOREBOUND are not | |
136 | * bequeathed to the loader; they are truly | |
137 | * for assembler internal use only. | |
138 | * c) Symbols greater than OKTOBUMP represent | |
139 | * indices into the program text that should | |
140 | * be changed in preceeding jumps or aligns | |
141 | * must get turned into their long form. | |
142 | */ | |
143 | ||
144 | #define TAGMASK 0xFF | |
145 | ||
146 | # define JXACTIVE 0xFF /*jxxx size unknown*/ | |
147 | # define JXNOTYET 0xFE /*jxxx size known, but not yet expanded*/ | |
148 | # define JXALIGN 0xFD /*align jxxx entry*/ | |
149 | # define JXINACTIVE 0xFC /*jxxx size known and expanded*/ | |
150 | ||
151 | #define JXQUESTIONABLE 0xFB | |
152 | ||
153 | # define JXTUNNEL 0xFA /*jxxx that jumps to another*/ | |
154 | # define OBSOLETE 0xF9 /*erroneously entered symbol*/ | |
155 | ||
156 | #define IGNOREBOUND 0xF8 /*symbols greater than this are ignored*/ | |
157 | # define STABFLOATING 0xF7 | |
158 | # define LABELID 0xF6 | |
159 | ||
160 | #define OKTOBUMP 0xF5 | |
161 | # define STABFIXED 0xF4 | |
162 | ||
163 | /* | |
164 | * astoks.h contains reserved word codings the parser should | |
165 | * know about | |
166 | */ | |
167 | #include "astoks.h" | |
168 | ||
169 | /* | |
170 | * The structure for one symbol table entry. | |
171 | * Symbol table entries are used for both user defined symbols, | |
172 | * and symbol slots generated to create the jxxx jump from | |
173 | * slots. | |
174 | */ | |
175 | ||
176 | #define symfirstfields char *name; unsigned char tag, type | |
177 | ||
178 | struct symtab{ | |
179 | symfirstfields; | |
180 | short ___hole; | |
181 | char ptype; /*tag == NAME*/ | |
182 | ||
183 | #define jxbump ptype /*tag == JX..., how far to expand*/ | |
184 | ||
185 | char other; /*for stab info*/ | |
186 | ||
187 | short desc; /*tag == NAME*/ | |
188 | ||
189 | #define jxfear desc /*how far needs to be bumped*/ | |
190 | ||
191 | long value; /*address in the segment*/ | |
192 | char jxoveralign; /*if a JXXX, jumped over an align*/ | |
193 | short index; /*which segment*/ | |
194 | struct symtab *dest; /*if JXXX, where going to*/ | |
195 | #ifdef DJXXX | |
196 | short jxline; /*source line of the jump from*/ | |
197 | #endif | |
198 | }; | |
199 | ||
200 | struct instab{ | |
201 | symfirstfields; | |
202 | ||
203 | #define opcode type /*use the same field as symtab.type*/ | |
204 | ||
205 | char nargs; /*how many arguments*/ | |
206 | char argtype[6]; /*argument type info*/ | |
207 | }; | |
208 | ||
209 | struct arg { /*one argument to an instruction*/ | |
210 | char atype; | |
211 | char areg1; | |
212 | char areg2; | |
213 | char dispsize; /*usually d124, unless have B^, etc*/ | |
214 | struct exp *xp; | |
215 | }; | |
216 | ||
217 | struct exp { | |
218 | long xvalue; /* MUST be the first field (look at union Double) */ | |
219 | long yvalue; /* MUST be second field; least sig word of a double */ | |
220 | char xtype; | |
221 | char xloc; | |
222 | struct symtab *xname; | |
223 | }; | |
224 | ||
225 | #define doub_MSW xvalue | |
226 | #define doub_LSW yvalue | |
227 | ||
228 | union Double { | |
229 | struct{ | |
230 | long doub_MSW; | |
231 | long doub_LSW; | |
232 | } dis_dvalue; | |
233 | double dvalue; | |
234 | }; | |
235 | ||
236 | struct Quad { | |
237 | long quad_low_long; | |
238 | long quad_high_long; | |
239 | }; | |
240 | ||
241 | /* | |
242 | * Magic layout macros | |
243 | */ | |
244 | #define MINBYTE -128 | |
245 | #define MAXBYTE 127 | |
246 | #define MINWORD -32768 | |
247 | #define MAXWORD 32767 | |
248 | ||
249 | #define LITFLTMASK 0x000043F0 /*really magic*/ | |
250 | /* | |
251 | * Is the floating point double word in xp a | |
252 | * short literal floating point number? | |
253 | */ | |
254 | #define slitflt(xp) \ | |
255 | ( (xp->doub_LSW == 0) \ | |
256 | && ( (xp->doub_MSW & LITFLTMASK) \ | |
257 | == xp->doub_MSW) ) | |
258 | /* | |
259 | * If it is a slitflt, then extract the 6 interesting bits | |
260 | */ | |
261 | #define extlitflt(xp) \ | |
262 | xp->doub_MSW >> 4 | |
263 | ||
264 | extern struct arg arglist[NARG]; /*building operands in instructions*/ | |
265 | extern struct exp explist[NEXP]; /*building up a list of expressions*/ | |
266 | extern struct exp *xp; /*current free expression*/ | |
267 | /* | |
268 | * Communication between the scanner and the jxxx handlers. | |
269 | * lastnam: the last name seen on the input | |
270 | * lastjxxx: pointer to the last symbol table entry for | |
271 | * a jump from | |
272 | */ | |
273 | extern struct symtab *lastnam; | |
274 | extern struct symtab *lastjxxx; | |
275 | ||
276 | #ifdef VMS | |
277 | extern char *vms_obj_ptr; /* object buffer pointer */ | |
278 | extern char sobuf[]; /* object buffer */ | |
279 | extern int objfil; /* VMS object file descriptor */ | |
280 | #endif VMS | |
281 | ||
282 | /* | |
283 | * Lgensym is used to make up funny names for local labels. | |
284 | * lgensym[i] is the current funny number to put after | |
285 | * references to if, lgensym[i]-1 is for ib. | |
286 | * genref[i] is set when the label is referenced before | |
287 | * it is defined (i.e. 2f) so that we can be sure these | |
288 | * labels are always defined to avoid weird diagnostics | |
289 | * from the loader later. | |
290 | */ | |
291 | extern int lgensym[10]; | |
292 | extern char genref[10]; | |
293 | ||
294 | extern char tmpn1[TNAMESIZE]; /* Interpass temporary */ | |
295 | extern struct exp *dotp; /* the current dot location */ | |
296 | extern int loctr; | |
297 | ||
298 | extern struct exec hdr; /* a.out header */ | |
299 | extern u_long tsize; /* total text size */ | |
300 | extern u_long dsize; /* total data size */ | |
301 | extern u_long trsize; /* total text relocation size */ | |
302 | extern u_long drsize; /* total data relocation size */ | |
303 | extern u_long datbase; /* base of the data segment */ | |
304 | /* | |
305 | * Bitoff and bitfield keep track of the packing into | |
306 | * bytes mandated by the expression syntax <expr> ':' <expr> | |
307 | */ | |
308 | extern int bitoff; | |
309 | extern long bitfield; | |
310 | ||
311 | /* | |
312 | * The lexical analyzer builds up symbols in yytext. Lookup | |
313 | * expects its argument in this buffer | |
314 | */ | |
315 | extern char yytext[NCPS+2]; /* text buffer for lexical */ | |
316 | /* | |
317 | * Variables to manage the input assembler source file | |
318 | */ | |
319 | extern int lineno; /*the line number*/ | |
320 | extern char *dotsname; /*the name of the as source*/ | |
321 | ||
322 | extern FILE *tmpfil; /* interpass communication*/ | |
323 | ||
324 | extern int passno; /* 1 or 2 */ | |
325 | ||
326 | extern int anyerrs; /*errors assembling arguments*/ | |
327 | extern int silent; /*don't mention the errors*/ | |
328 | extern int savelabels; /*save labels in a.out*/ | |
329 | extern int orgwarn; /* questionable origin ? */ | |
330 | extern int useVM; /*use virtual memory temp file*/ | |
331 | #ifdef DEBUG | |
332 | extern int debug; | |
333 | extern int toktrace; | |
334 | #endif | |
335 | /* | |
336 | * Information about the instructions | |
337 | */ | |
338 | extern struct instab *itab[NINST]; /*maps opcodes to instructions*/ | |
339 | extern readonly struct instab instab[]; | |
340 | ||
341 | extern int curlen; /*current literal storage size*/ | |
342 | extern int d124; /*current pointer storage size*/ | |
343 | ||
344 | struct symtab **lookup(); /*argument in yytext*/ | |
345 | struct symtab *symalloc(); | |
346 | ||
347 | #define outb(val) {dotp->xvalue++; if (passno==2) bputc((val), (txtfil));} | |
348 | ||
349 | #define outs(cp, lg) dotp->xvalue += (lg); if (passno == 2) bwrite((cp), (lg), (txtfil)) | |
350 | ||
351 | /* | |
352 | * Most of the time, the argument to flushfield is a power of two constant, | |
353 | * the calculations involving it can be optimized to shifts. | |
354 | */ | |
355 | #define flushfield(n) if (bitoff != 0) Flushfield( ( (bitoff+n-1) /n ) * n) | |
356 | ||
357 | /* | |
358 | * The biobuf structure and associated routines are used to write | |
359 | * into one file at several places concurrently. Calling bopen | |
360 | * with a biobuf structure sets it up to write ``biofd'' starting | |
361 | * at the specified offset. You can then use ``bwrite'' and/or ``bputc'' | |
362 | * to stuff characters in the stream, much like ``fwrite'' and ``fputc''. | |
363 | * Calling bflush drains all the buffers and MUST be done before exit. | |
364 | */ | |
365 | struct biobuf { | |
366 | short b_nleft; /* Number free spaces left in b_buf */ | |
367 | /* Initialize to be less than BUFSIZ initially, to boundary align in file */ | |
368 | char *b_ptr; /* Next place to stuff characters */ | |
369 | char b_buf[BUFSIZ]; /* The buffer itself */ | |
370 | off_t b_off; /* Current file offset */ | |
371 | struct biobuf *b_link; /* Link in chain for bflush() */ | |
372 | }; | |
373 | #define bputc(c,b) ((b)->b_nleft ? (--(b)->b_nleft, *(b)->b_ptr++ = (c)) \ | |
374 | : bflushc(b, c)) | |
375 | #define BFILE struct biobuf | |
376 | ||
377 | extern BFILE *biobufs; /* head of the block I/O buffer chain */ | |
378 | extern int biofd; /* file descriptor for block I/O file */ | |
379 | extern off_t boffset; /* physical position in logical file */ | |
380 | ||
381 | /* | |
382 | * For each of the named .text .data segments | |
383 | * (introduced by .text <expr>), we maintain | |
384 | * the current value of the dot, and the BFILE where | |
385 | * the information for each of the segments is placed | |
386 | * during the second pass. | |
387 | */ | |
388 | extern struct exp usedot[NLOC + NLOC]; | |
389 | extern BFILE *usefile[NLOC + NLOC]; | |
390 | extern BFILE *txtfil;/* file for text and data: into usefile */ | |
391 | /* | |
392 | * Relocation information for each segment is accumulated | |
393 | * seperately from the others. Writing the relocation | |
394 | * information is logically viewed as writing to one | |
395 | * relocation saving file for each segment; physically | |
396 | * we have a bunch of buffers allocated internally that | |
397 | * contain the relocation information. | |
398 | */ | |
399 | struct relbufdesc *rusefile[NLOC + NLOC]; | |
400 | struct relbufdesc *relfil; |