Pristine Ack-5.5
[Ack-5.5.git] / util / ass / ass00.h
1 /*
2  * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
3  * See the copyright notice in the ACK home directory, in the file "Copyright".
4  */
5 #include <stdio.h>
6 #include <em_spec.h>
7 #include <as_spec.h>
8 #include <em_flag.h>
9 #include <arch.h>
10 #include <local.h>
11
12 #define RCS_ASS "$Id: ass00.h,v 2.15 1994/06/24 10:15:04 ceriel Exp $"
13
14 /*
15  * compile time options
16  */
17
18 #define DUMP            1       /* dump between passes */
19 /*  #define TIMING          1       /* some timing measurements */
20 #define JOHAN           1       /* dump the loaded instructions */
21 #define MEMUSE          1       /* print memory usage statistics */
22
23 #ifndef DUMP
24 #define dump(x)                  /* nothing */
25 #endif
26
27 #ifndef TIMING
28 #define timing()                /* nothing */
29 #endif
30
31 #ifndef MEMUSE
32 #define memuse()                /* nothing */
33 #endif
34
35 /* Used to clear the upper byte(s) of characters.
36    Not nessecary if your C-compiler does not sign-extend char's
37 */
38
39 #ifdef CPM
40 # define        LC(ch)   ( ((ch)<'A' | (ch)>'Z' ) ? (ch) : ((ch)-('A'-'a')))
41 #else
42 # define        LC(ch)          (ch)
43 #endif
44
45 #define ctrunc(val)             ( (val)&0377 )
46
47 #define odd(n)                  ((n)&1)         /* Boolean odd function */
48
49 #define lnp_cast                (line_t *)
50 #define gbp_cast                (glob_t *)
51 #define lbp_cast                (locl_t *)
52 #define prp_cast                (proc_t *)
53 #define ptp_cast                (ptab_t *)
54 #define rlp_cast                (relc_t *)
55 #define pst_cast                (stat_t *)
56 #define chp_cast                (char   *)
57 #define ipp_cast                (int   **)
58 #define iip_cast                (int    *)
59 #define int_cast                (int     )
60
61 typedef struct lines            line_t;
62 typedef struct loc_label        locl_t;
63 typedef struct glob_label       glob_t;
64 typedef struct rel              relc_t;
65 typedef struct procstat         stat_t;
66 typedef struct sizes            siz_t;
67 typedef struct ar_hdr           arch_t;
68 typedef struct procs            proc_t;
69 typedef struct proctab          ptab_t;
70 typedef char *                  area_t;
71 typedef long                    cons_t;
72
73 typedef union {
74         cons_t  ad_i;
75         locl_t  *ad_lp;
76         glob_t  *ad_gp;
77         proc_t  *ad_pp;
78         struct sad_ln {
79                 short   ln_extra;
80                 short   ln_first;
81         }       ad_ln ;
82         struct sad_df {
83                 cons_t  df_i;
84                 glob_t  *df_gp;
85         }       ad_df;
86 }       addr_u;
87
88 typedef union {
89         cons_t  rel_i;
90         locl_t  *rel_lp;
91         glob_t  *rel_gp;
92 } rel_u;
93
94 #define FOFFSET         long             /* offset into file */
95
96 /*
97  * Global variables and definitions for EM1-assembler/loader
98  */
99
100 #define DEFINING        0       /* parameters for glolookup */
101 #define OCCURRING       1
102 #define INTERNING       2
103 #define EXTERNING       3
104 #define SEARCHING       4
105 #define ENTERING        5
106
107 #define PRO_OCC         0       /* parameters for prolookup */
108 #define PRO_DEF         1
109 #define PRO_INT         2
110 #define PRO_EXT         3
111
112 #define TRUE            1
113 #define FALSE           0
114
115 #define MAXBYTE 255
116
117 #define MAXSTRING       200     /* Maximum string length accepted */
118 #define LOCLABSIZE      128     /* size of local label hash table */
119                                 /* may not be smaller */
120 #define ABSSIZE         8
121
122 struct  lines {
123         char    instr_num;      /* index into mnemon[] */
124         char    type1;          /* see below */
125         line_t  *l_next;        /* next in chain */
126         char    *opoff;         /* pointer into opchoice[] */
127         addr_u  ad;             /* depending on type, various pointers */
128 };
129
130 /* contents of type1 */
131 #define MISSING         0       /* no operand */
132 #define CONST           1       /* ad contains operand */
133 #define PROCNAME        2       /* ad contains struct procs pointer */
134 #define GLOSYM          3       /* ad contains pointer into mproc[] */
135 #define LOCSYM          4       /* ad contains pointer into locs[] */
136 #define GLOOFF          5       /* ad contains CONST and GLOSYM in ad_df */
137 #define LINES           6       /* Line number setting, only param of pseudo*/
138 #define VALLOW          7       /* value's between LOW and HIGH are x-MID */
139 #define VALMID         50
140 #define VALHIGH       127       /* to avoid sign extension problems */
141
142 #define VAL1(x)         ((x)-VALMID)
143
144 /* Used to indicate a invalid contents of opoff */
145 #define NO_OFF          ((char *)-1)
146
147 struct  loc_label {
148         locl_t  *l_chain;       /* The next label with same low order bits */
149         char    l_hinum;        /* high bits of number of label */
150         char    l_defined;      /* see below */
151         int     l_min,l_max;    /* boundaries of value */
152 };
153
154 /* The structure containing procedure pertinent data */
155 /* Used for environment stacking for nested PRO's */
156
157 struct  procstat  {
158         line_t  *s_fline;       /* points to first line of procedure */
159         locl_t  (*s_locl)[1];    /* pointer to local labels */
160         proc_t  *s_curpro;      /* identifies current procedure */
161         relc_t  *s_fdata;       /* last datareloc before procedure */
162         stat_t  *s_prevstat;    /* backward chain of nested procedures */
163 } ;
164
165 /* contents of l_defined */
166 #define EMPTY           0       /* Empty slot */
167 #define NO              1       /* not defined yet */
168 #define YES             2       /* defined */
169 #define SEEN            3       /* intermediate state */
170 #define NOTPRESENT      4       /* Undefined and error message given */
171
172 struct  glob_label {
173         char    *g_name;
174         char    g_status;               /* see below */
175         union {
176                 cons_t  g_addr;         /* value if status&DEF */
177                 struct glob_label *g_gp; /* ref. to xglobs */
178         } g_val ;
179 };
180
181 #define glostring(gl)   ((gl)->g_name)
182
183 /* contents of g_status */
184 #define DEF             01      /* defined */
185 #define OCC             02      /* used */
186 #define EXT             04      /* external */
187
188 struct  rel {                   /* for relocation tables */
189         relc_t  *r_next;        /* chain */
190         FOFFSET r_off;          /* offset in text/data of word to relocate */
191         rel_u   r_val;          /* constant or pointer to global symbol */
192         int     r_typ;          /* different use in text or data */
193 };
194
195 /*
196  * When used with textrelocation r_typ contains the flag bits as defined
197  * in ip_spec.h together with the RELMNS bit if r_val contains an integer
198  */
199
200 #define RELMNS          020000          /* indicates integer i.s.o. glob */
201
202 /* Contents of r_typ when used with data relocation */
203 #define RELNULL         0
204 #define RELGLO          1
205 #define RELHEAD         2
206 #define RELLOC          3
207 #define RELADR          4
208
209 /* modes of data output */
210 #define DATA_NUL        0
211 #define DATA_REP        1
212 #define DATA_CONST      2
213 #define DATA_BSS        3
214 #define DATA_DPTR       4
215 #define DATA_IPTR       5
216 #define DATA_ICON       6
217 #define DATA_UCON       7
218 #define DATA_FCON       8
219 #define DATA_BYTES      9
220
221 /* name of procedure to be called first */
222 #define MAIN            "_m_a_i_n"
223
224 /* headers of datablocks written */
225 #define HEADREP         0
226 #define HEADBSS         1
227 #define HEADBYTE        2
228 #define HEADCONST       3
229 #define HEADDPTR        4
230 #define HEADIPTR        5
231 #define HEADICON        6
232 #define HEADUCON        7
233 #define HEADFCON        8
234
235 #define NDEFAULT        4       /* number of different sizes available */
236 struct  sizes {
237         int     n_mlab;         /* # of global labels per module */
238         int     n_glab;         /* # of extern global labels */
239         int     n_mproc;        /* # of local procs per module */
240         int     n_xproc;        /* # of external procs */
241         int     n_proc;         /* total # of procedures */
242 };
243
244 struct  procs {                 /* format of mprocs[] and xprocs[] */
245         char    *p_name;
246         char    p_status;       /* same bits as g_status except REL */
247         int     p_num;          /* unique procedure descriptor */
248 };
249
250 struct  proctab {
251         cons_t  pr_off;         /* distance from pb */
252         cons_t  pr_loc;         /* number of bytes locals */
253 };