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