386BSD 0.1 development
[unix-history] / usr / src / usr.bin / gas / as.h
CommitLineData
484e23e5
WJ
1/* as.h - global header file
2 Copyright (C) 1987 Free Software Foundation, Inc.
3
4This file is part of GAS, the GNU Assembler.
5
6GAS is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 1, or (at your option)
9any later version.
10
11GAS is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GAS; see the file COPYING. If not, write to
18the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
19
20#ifndef asH
21#define asH /* Don't declare things twice. */
22
23#if !defined(__STDC__) && !defined(const)
24#define const /* ignore */
25#endif
26
27#ifdef USG
28#define index strchr
29#define bzero(s,n) memset((s),0,(n))
30#define bcopy(from,to,n) memcpy((to),(from),(n))
31#define setbuffer(a,b,c)
32#endif
33
34/*
35 * CAPITALISED names are #defined.
36 * "lowercaseH" is #defined if "lowercase.h" has been #include-d.
37 * "lowercaseT" is a typedef of "lowercase" objects.
38 * "lowercaseP" is type "pointer to object of type 'lowercase'".
39 * "lowercaseS" is typedef struct ... lowercaseS.
40 *
41 * #define SUSPECT when debugging.
42 * #define DUMP to include data-structure dumpers.
43 * #define COMMON as "extern" for all modules except one, where you #define
44 * COMMON as "".
45 * If TEST is #defined, then we are testing a module: #define COMMON as "".
46 */
47
48
49
50/* These #defines are for parameters of entire assembler. */
51
52/* #define SUSPECT JF remove for speed testing */
53/* #define DUMP */
54#define NDEBUG /* JF disable asserts */
55/* These #includes are for type definitions etc. */
56
57/* #include "style.h" */
58#include <stdio.h>
59#include <assert.h>
60#define obstack_chunk_alloc xmalloc
61#define obstack_chunk_free xfree
62
63/* These defines are potentially useful */
64#define FALSE (0)
65#define TRUE (!FALSE)
66#define ASSERT assert
67#define BAD_CASE(value) \
68{ \
69 as_fatal ("Case value %d unexpected at line %d of file \"%s\"\n", \
70 value, __LINE__, __FILE__); \
71}
72
73
74
75\f
76/* These are assembler-wide concepts */
77
78
79#ifndef COMMON
80#ifdef TEST
81#define COMMON /* declare our COMMONs storage here. */
82#else
83#define COMMON extern /* our commons live elswhere */
84#endif
85#endif
86 /* COMMON now defined */
87
88#ifdef SUSPECT
89#define register /* no registers: helps debugging */
90#define know(p) ASSERT(p) /* know() is less ugly than #ifdef SUSPECT/ */
91 /* assert()/#endif. */
92#else
93#define know(p) /* know() checks are no-op.ed */
94#endif /* #ifdef SUSPECT */
95
96
97char *xmalloc(); /* keep C compilers happy */
98char *xrealloc(); /* " */
99void free(); /* " */
100#define xfree free
101\f
102/* input_scrub.c */
103
104/*
105 * Supplies sanitised buffers to read.c.
106 * Also understands printing line-number part of error messages.
107 */
108
109 /* Line number things. */
110int seen_at_least_1_file();
111void bump_line_counters();
112void new_logical_line();
113void as_where();
114void as_perror();
115void as_howmuch();
116 /* Sanitising things. */
117void input_scrub_begin();
118void input_scrub_end();
119char *input_scrub_new_file();
120char *input_scrub_next_buffer();
121\f
122/* subsegs.c Sub-segments. Also, segment(=expression type)s.*/
123
124/*
125 * This table describes the use of segments as EXPRESSION types.
126 *
127 * X_seg X_add_symbol X_subtract_symbol X_add_number
128 * SEG_NONE no (legal) expression
129 * SEG_PASS1 no (defined) "
130 * SEG_BIG * > 32 bits const.
131 * SEG_ABSOLUTE 0
132 * SEG_DATA * 0
133 * SEG_TEXT * 0
134 * SEG_BSS * 0
135 * SEG_UNKNOWN * 0
136 * SEG_DIFFERENCE 0 * 0
137 *
138 * The blank fields MUST be 0, and are nugatory.
139 * The '0' fields MAY be 0. The '*' fields MAY NOT be 0.
140 *
141 * SEG_BIG: X_add_number is < 0 if the result is in
142 * generic_floating_point_number. The value is -'c' where c is the
143 * character that introduced the constant. e.g. "0f6.9" will have -'f'
144 * as a X_add_number value.
145 * X_add_number > 0 is a count of how many littlenums it took to
146 * represent a bignum.
147 * SEG_DIFFERENCE:
148 * If segments of both symbols are known, they are the same segment.
149 * X_add_symbol != X_sub_symbol (then we just cancel them, => SEG_ABSOLUTE).
150 */
151
152typedef enum
153{
154 SEG_ABSOLUTE,
155 SEG_TEXT,
156 SEG_DATA,
157 SEG_BSS,
158 SEG_UNKNOWN,
159 SEG_NONE, /* Mythical Segment: NO expression seen. */
160 SEG_PASS1, /* Mythical Segment: Need another pass. */
161 SEG_GOOF, /* Only happens if AS has a logic error. */
162 /* Invented so we don't crash printing */
163 /* error message involving weird segment. */
164 SEG_BIG, /* Bigger than 32 bits constant. */
165 SEG_DIFFERENCE /* Mythical Segment: absolute difference. */
166} segT;
167#define SEG_MAXIMUM_ORDINAL (SEG_DIFFERENCE)
168
169typedef unsigned char subsegT;
170
171COMMON subsegT now_subseg;
172 /* What subseg we are accreting now? */
173
174
175COMMON segT now_seg;
176 /* Segment our instructions emit to. */
177 /* Only OK values are SEG_TEXT or SEG_DATA. */
178
179
180extern char *const seg_name[];
181extern const int seg_N_TYPE[];
182extern const segT N_TYPE_seg[];
183void subsegs_begin();
184void subseg_change();
185void subseg_new();
186\f
187/* relax() */
188
189typedef enum
190{
191 rs_fill, /* Variable chars to be repeated fr_offset */
192 /* times. Fr_symbol unused. */
193 /* Used with fr_offset == 0 for a constant */
194 /* length frag. */
195
196 rs_align, /* Align: Fr_offset: power of 2. */
197 /* 1 variable char: fill character. */
198 rs_org, /* Org: Fr_offset, fr_symbol: address. */
199 /* 1 variable char: fill character. */
200
201 rs_machine_dependent,
202#ifndef WORKING_DOT_WORD
203 rs_broken_word, /* JF: gunpoint */
204#endif
205}
206relax_stateT;
207
208/* typedef unsigned char relax_substateT; */
209/* JF this is more likely to leave the end of a struct frag on an align
210 boundry. Be very careful with this. */
211typedef unsigned long int relax_substateT;
212
213typedef unsigned long int relax_addressT;/* Enough bits for address. */
214 /* Still an integer type. */
215
216\f
217/* frags.c */
218
219/*
220 * A code fragment (frag) is some known number of chars, followed by some
221 * unknown number of chars. Typically the unknown number of chars is an
222 * instruction address whose size is yet unknown. We always know the greatest
223 * possible size the unknown number of chars may become, and reserve that
224 * much room at the end of the frag.
225 * Once created, frags do not change address during assembly.
226 * We chain the frags in (a) forward-linked list(s). The object-file address
227 * of the 1st char of a frag is generally not known until after relax().
228 * Many things at assembly time describe an address by {object-file-address
229 * of a particular frag}+offset.
230
231 BUG: it may be smarter to have a single pointer off to various different
232notes for different frag kinds. See how code pans out.
233
234
235 */
236struct frag /* a code fragment */
237{
238 long unsigned int fr_address; /* Object file address. */
239 struct frag *fr_next; /* Chain forward; ascending address order. */
240 /* Rooted in frch_root. */
241
242 long int fr_fix; /* (Fixed) number of chars we know we have. */
243 /* May be 0. */
244 long int fr_var; /* (Variable) number of chars after above. */
245 /* May be 0. */
246 struct symbol *fr_symbol; /* For variable-length tail. */
247 long int fr_offset; /* For variable-length tail. */
248 char *fr_opcode; /*->opcode low addr byte,for relax()ation*/
249 relax_stateT fr_type; /* What state is my tail in? */
250 relax_substateT fr_subtype;
251 /* These are needed only on the NS32K machines */
252 char fr_pcrel_adjust;
253 char fr_bsr;
254 char fr_literal [1]; /* Chars begin here. */
255 /* One day we will compile fr_literal[0]. */
256};
257#define SIZEOF_STRUCT_FRAG \
258 ((int)zero_address_frag.fr_literal-(int)&zero_address_frag)
259 /* We want to say fr_literal[0] above. */
260
261typedef struct frag fragS;
262
263COMMON fragS * frag_now; /* -> current frag we are building. */
264 /* This frag is incomplete. */
265 /* It is, however, included in frchain_now. */
266 /* Frag_now->fr_fix is bogus. Use: */
267/* Virtual frag_now->fr_fix==obstack_next_free(&frags)-frag_now->fr_literal.*/
268
269COMMON fragS zero_address_frag; /* For foreign-segment symbol fixups. */
270COMMON fragS bss_address_frag; /* For local common (N_BSS segment) fixups. */
271
272void frag_new();
273char * frag_more();
274char * frag_var();
275void frag_wane();
276void frag_align();
277\f
278
279/* main program "as.c" (command arguments etc) */
280
281COMMON char
282flagseen[128]; /* ['x'] TRUE if "-x" seen. */
283
284COMMON char *
285out_file_name; /* name of emitted object file */
286
287COMMON int need_pass_2; /* TRUE if we need a second pass. */
288
289
290#endif /* #ifdef asH */
291
292/* end: as.h */