Pristine Ack-5.5
[Ack-5.5.git] / mach / proto / as / comm0.h
1 /* $Id: comm0.h,v 2.12 1994/06/24 13:21:52 ceriel Exp $ */
2 /*
3  * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
4  * See the copyright notice in the ACK home directory, in the file "Copyright".
5  */
6 /* @(#)comm0.h  1.8 */
7 /*
8  * All preprocessor based options/constants/functions
9  */
10
11 /* ========== ON/OFF options (use #define in mach0.c) ========== */
12
13 /*
14  * The following options are available, to be set/removed in "mach0.c":
15  *      THREE_PASS:     three passes needed for branch optimization
16  *      BYTES_REVERSED: lowest target address for word high-order byte
17  *      WORDS_REVERSED: lowest target address for long high-order byte
18  *      LISTING:        include listing facilities
19  *      RELOCATION:     relocatable code generated
20  *      DEBUG:          for debugging purposes only
21  *      TMPDIR:         directory for temporary files
22  *      ASLD:           combined assembler/linker
23  */
24
25 /* ========== constants (use #undef, #define in mach0.c) ========== */
26
27 /* table sizes */
28 #define STRINGMAX       200     /* <= 256 */
29 #define SECTMAX         64
30 #define NAMEMAX         80
31 #define MEMINCR         2048
32
33 /* Some character constants for parsing */
34 #define ASC_LPAR        '['
35 #define ASC_RPAR        ']'
36 #define ASC_SQUO        '\''
37 #define ASC_DQUO        '"'
38 #define ASC_COMM        '!'
39 #define ISALPHA(c)      (isalpha(c) || (c) == '_' || (c) == '.')
40 #define ISALNUM(c)      (isalnum(c) || (c) == '_')
41
42 #define GENLAB          "I"             /* compiler generated labels */
43
44 #define valu_t          short           /* type of expression values */
45 #define ADDR_T          unsigned short  /* type of dot */
46 #define word_t          short           /* type of keyword value */
47 /*
48  * NOTE: word_t is introduced to reduce the tokenfile size for machines
49  * with large expressions but smaller opcodes (68000)
50  */
51
52 #define ALIGNWORD       1
53 #define ALIGNSECT       1
54
55 #define machstart(x)    /* nothing */
56 #define machfinish(x)   /* nothing */
57
58 #define SETBASE(sp)     ((long)(sp)->s_base)
59
60 #define VALWIDTH        4
61
62 /* ========== Machine dependent option/constant settings ========== */
63
64 #include        "mach0.c"
65
66 /* ========== default option setting ========== */
67
68 #ifndef ASLD
69 #ifndef RELOCATION
70 separate linker only possible if relocation info produced
71 #endif /* RELOCATION */
72 #endif /* ASLD */
73
74 #ifndef DEBUG
75 #define DEBUG   1
76 #endif
77
78 /* ========== Machine independent type declarations ========== */
79
80 #ifdef _include
81 _include        <stdio.h>
82 _include        <ctype.h>
83 _include        <signal.h>
84 #else
85 #include        <stdio.h>
86 #include        <ctype.h>
87 #include        <signal.h>
88 #endif
89
90 #ifdef ASLD
91 #include        "arch.h"
92 #endif
93 #include        "out.h"
94
95 #if DEBUG == 0
96 #define assert(ex)      /* nothing */
97 #endif
98
99 #if DEBUG == 1
100 #define assert(ex)      {if (!(ex)) assert1();}
101 #endif
102
103 #if DEBUG == 2
104 #define assert(ex)      {if (!(ex)) assert2(__FILE__, __LINE__);}
105 #endif
106
107 #define CTRL(x)         ((x) & 037)
108
109 #define lowb(z)         ((int)(z) & 0xFF)
110 #define loww(z)         ((int)(z) & 0xFFFF)
111
112 #define fitb(x)         ((((x) + 0x80) & ~((int)0xFF)) == 0)
113 #define fitw(x)         ((((x) + 0x8000L) & ~0xFFFFL) == 0)
114
115 #define fit(x)          if (!(x)) nofit()
116
117 #define PASS_1          0
118 #define PASS_2          1
119 #define PASS_3          2
120
121 #ifdef THREE_PASS
122 #define PASS_SYMB       (pass != PASS_1)
123 #define PASS_RELO       (pass != PASS_1)
124 #else
125 #define PASS_SYMB       1
126 #define PASS_RELO       1
127 #endif /* THREE_PASS */
128
129 #ifdef ASLD
130 #define RELOMOVE(a,b)   /* empty */
131 #else
132 #define RELOMOVE(a,b)   {a = b; b = 0;}
133 #endif
134
135 /* symbol table management */
136 #define H_SIZE          307             /* hash size, must be od */
137 #define H_KEY           (0*H_SIZE)      /* key symbol headers */
138 #define H_LOCAL         (1*H_SIZE)      /* module symbol headers */
139 #ifdef ASLD
140 #define H_GLOBAL        (2*H_SIZE)      /* external symbol headers */
141 #define H_TOTAL         (3*H_SIZE)
142 #else
143 #define H_TOTAL         (2*H_SIZE)
144 #endif
145
146 /* numeric label table management */
147 #define FB_SIZE         10
148 #define FB_HEAD         (0*FB_SIZE)
149 #define FB_TAIL         (1*FB_SIZE)
150 #define FB_BACK         (2*FB_SIZE)
151 #define FB_FORW         (3*FB_SIZE)
152
153 /* miscellaneous */
154 #define KEYDEFINE       0
155 #define KEYSECT         12
156 #define DOTGAIN         DOTSCT->s_gain
157
158 /* ========== type declarations ========== */
159
160 struct expr_t {
161         short   typ;
162         valu_t  val;
163 };
164
165 typedef struct expr_t   expr_t;
166
167 struct item_t {
168         struct item_t *
169                 i_next; /* linked lists with same hash value */
170         short   i_type;
171         /*
172          * the i_type field is used for two different purposes:
173          *      - the token type for keywords, returned by yylex()
174          *      - the symbol type for IDENT and FBSYM tokens
175          */
176         valu_t  i_valu;         /* symbol value */
177         char    *i_name;        /* symbol name */
178 };
179
180 struct common_t {
181         struct common_t *
182                 c_next;
183         struct item_t *c_it;
184 #ifndef ASLD
185         valu_t  c_size;
186 #endif
187 };
188
189 typedef struct common_t common_t;
190
191 typedef struct item_t   item_t;
192
193 struct sect_t {
194         short   s_flag;         /* some flag bits */
195         ADDR_T  s_base;         /* section base */
196         ADDR_T  s_size;         /* section size */
197         ADDR_T  s_comm;         /* length of commons */
198         ADDR_T  s_zero;         /* delayed emit1(0) */
199         ADDR_T  s_lign;         /* section alignment */
200         long    s_foff;         /* section file offset */
201         item_t  *s_item;        /* points to section name */
202 #ifdef THREE_PASS
203         ADDR_T  s_gain;         /* gain in PASS_2 */
204 #endif
205 };
206
207 typedef struct sect_t   sect_t;
208
209 /* ========== flag field bits ========== */
210
211 /* s_flag bits: */
212 #define BASED           1       /* at fixed position */
213
214 /* sflag bits: */
215 #define SYM_EXT         001     /* external symbols */
216 #define SYM_LOC         002     /* local symbols */
217 #define SYM_LAB         004     /* local, compiler-generated labels */
218 #define SYM_SMB         010     /* .symb symbols */
219 #define SYM_LIN         020     /* .line and .file */
220 #define SYM_SCT         040     /* section names */
221 #define SYM_DEF         073     /* default value */
222
223 /*
224  * extra type bits out of S_ETC, internal use only
225  * S_VAR:
226  *  - type not known at end of PASS_1 (S_VAR|S_UND)
227  *  - value not known at end of PASS_2 (S_VAR|S_ABS)
228  * S_DOT:
229  *  - dot expression
230  */
231 #define S_VAR           0x0200
232 #define S_DOT           0x0400
233 /* should be tested by preprocessor
234  * due to error in preprocessor it cannot
235  * test performed at compiletime by a switch now
236  * #if (S_ETC|S_COM|S_VAR|S_DOT) != S_ETC
237  * incorrect type bits
238  * #endif
239  */
240
241 /* parts of the a.out file */
242 #define PARTEMIT        0
243 #define PARTRELO        1
244 #define PARTNAME        2
245 #define PARTCHAR        3
246 #define PARTS           4
247
248 #ifdef BYTES_REVERSED
249 #ifdef WORDS_REVERSED
250 #define MACHREL_BWR     (RELBR|RELWR)
251 #else
252 #define MACHREL_BWR     (RELBR)
253 #endif
254 #else
255 #ifdef WORDS_REVERSED
256 #define MACHREL_BWR     (RELWR)
257 #else
258 #define MACHREL_BWR     (0)
259 #endif
260 #endif
261
262 extern FILE *fopen();   /* some systems don't have this in stdio.h */