forked from StarWolf3000/vasm-mirror
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vasm.h
319 lines (281 loc) · 7.95 KB
/
vasm.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
/* vasm.h main header file for vasm */
/* (c) in 2002-2019 by Volker Barthelmann */
#include <stdlib.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <ctype.h>
#include <string.h>
typedef struct symbol symbol;
typedef struct section section;
typedef struct dblock dblock;
typedef struct sblock sblock;
typedef struct expr expr;
typedef struct macro macro;
typedef struct source source;
typedef struct listing listing;
typedef struct regsym regsym;
#define MAXPADBYTES 8 /* max. pattern size to pad alignments */
#include "cpu.h"
#include "symbol.h"
#include "reloc.h"
#include "syntax.h"
#include "symtab.h"
#include "expr.h"
#include "parse.h"
#include "atom.h"
#include "cond.h"
#include "supp.h"
#if defined(BIGENDIAN)&&!defined(LITTLEENDIAN)
#define LITTLEENDIAN (!BIGENDIAN)
#endif
#if !defined(BIGENDIAN)&&defined(LITTLEENDIAN)
#define BIGENDIAN (!LITTLEENDIAN)
#endif
#ifndef MNEMONIC_VALID
#define MNEMONIC_VALID(i) 1
#endif
#ifndef OPERAND_OPTIONAL
#define OPERAND_OPTIONAL(p,t) 0
#endif
#ifndef START_PARENTH
#define START_PARENTH(x) ((x)=='(')
#endif
#ifndef END_PARENTH
#define END_PARENTH(x) ((x)==')')
#endif
#ifndef CHKIDEND
#define CHKIDEND(s,e) (e)
#endif
#define MAXPATHLEN 1024
/* include paths */
struct include_path {
struct include_path *next;
char *path;
int compdir_based;
};
/* source files */
struct source_file {
struct source_file *next;
struct include_path *incpath;
int index;
char *name;
char *text;
size_t size;
};
/* source texts (main file, include files or macros) */
struct source {
struct source *parent;
int parent_line;
struct source_file *srcfile;
char *name;
char *text;
size_t size;
struct source *defsrc;
int defline;
macro *macro;
unsigned long repeat;
char *irpname;
struct macarg *irpvals;
int cond_level;
struct macarg *argnames;
int num_params;
char *param[MAXMACPARAMS+1];
int param_len[MAXMACPARAMS+1];
#if MAX_QUALIFIERS > 0
int num_quals;
char *qual[MAX_QUALIFIERS];
int qual_len[MAX_QUALIFIERS];
#endif
unsigned long id;
char *srcptr;
int line;
size_t bufsize;
char *linebuf;
#ifdef CARGSYM
expr *cargexp;
#endif
#ifdef REPTNSYM
long reptn;
#endif
};
/* section flags */
#define HAS_SYMBOLS 1
#define RESOLVE_WARN 2
#define UNALLOCATED 4
#define LABELS_ARE_LOCAL 8
#define ABSOLUTE 16
#define PREVABS 32 /* saved ABSOLUTE-flag during RORG-block */
#define IN_RORG 64
#define NEAR_ADDRESSING 128
#define SECRSRVD (1L<<24) /* bits 24..31 are reserved for output modules */
/* section description */
struct section {
struct section *next;
char *name;
char *attr;
atom *first;
atom *last;
taddr align;
uint8_t pad[MAXPADBYTES];
int padbytes;
uint32_t flags;
uint32_t memattr; /* type of memory, used by some object formats */
taddr org;
taddr pc;
unsigned long idx; /* usable by output module */
};
/* mnemonic description */
typedef struct mnemonic {
char *name;
#if MAX_OPERANDS!=0
int operand_type[MAX_OPERANDS];
#endif
mnemonic_extension ext;
} mnemonic;
/* operand size flags (ORed with size in bits) */
#define OPSZ_BITS(x) ((x) & 0xff)
#define OPSZ_FLOAT 0x100 /* operand stored as floating point */
#define OPSZ_SWAP 0x200 /* operand stored with swapped bytes */
/* listing table */
#define MAXLISTSRC 120
struct listing {
listing *next;
source *src;
int line;
int error;
atom *atom;
section *sec;
taddr pc;
char txt[MAXLISTSRC];
};
extern listing *first_listing,*last_listing,*cur_listing;
extern int done,final_pass,nostdout;
extern int warn_unalloc_ini_dat;
extern int listena,listformfeed,listlinesperpage,listnosyms;
extern int mnemonic_cnt;
extern int nocase,no_symbols,pic_check,secname_attr,exec_out,chklabels;
extern taddr inst_alignment;
extern hashtable *mnemohash;
extern source *cur_src;
extern section *current_section;
extern char *filename;
extern char *debug_filename; /* usually an absolute C source file name */
extern char *inname,*outname,*listname,*compile_dir;
extern char *output_format;
extern char emptystr[];
extern char vasmsym_name[];
extern unsigned long long taddrmask;
#define ULLTADDR(x) (((unsigned long long)x)&taddrmask)
extern taddr taddrmin,taddrmax;
/* provided by main assembler module */
extern int debug;
void leave(void);
void set_default_output_format(char *);
FILE *locate_file(char *,char *,struct include_path **);
source *include_source(char *);
source *new_source(char *,struct source_file *,char *,size_t);
void end_source(source *);
void set_section(section *);
section *new_section(char *,char *,int);
section *new_org(taddr);
section *find_section(char *,char *);
void switch_section(char *,char *);
void switch_offset_section(char *,taddr);
void add_align(section *,taddr,expr *,int,unsigned char *);
section *default_section(void);
#if NOT_NEEDED
section *restore_section(void);
section *restore_org(void);
#endif
int end_rorg(void);
void try_end_rorg(void);
void start_rorg(taddr);
void print_section(FILE *,section *);
struct include_path *new_include_path(char *);
void set_listing(int);
void set_list_title(char *,int);
void write_listing(char *);
#define setfilename(x) filename=(x)
#define getfilename() filename
#define setdebugname(x) debug_filename=(x)
#define getdebugname() debug_filename
/* provided by error.c */
extern int errors,warnings;
extern int max_errors;
extern int no_warn;
void general_error(int,...);
void syntax_error(int,...);
void cpu_error(int,...);
void output_error(int,...);
void output_atom_error(int,atom *,...);
void modify_gen_err(int,...);
void modify_syntax_err(int,...);
void modify_cpu_err(int,...);
void disable_warning(int);
#define ierror(x) general_error(4,(x),__LINE__,__FILE__)
/* provided by cpu.c */
extern int bitsperbyte;
extern int bytespertaddr;
extern mnemonic mnemonics[];
extern char *cpu_copyright;
extern char *cpuname;
extern int debug;
int init_cpu();
int cpu_args(char *);
char *parse_cpu_special(char *);
operand *new_operand();
int parse_operand(char *text,int len,operand *out,int requires);
#define PO_SKIP 2
#define PO_MATCH 1
#define PO_NOMATCH 0
#define PO_CORRUPT -1
size_t instruction_size(instruction *,section *,taddr);
dblock *eval_instruction(instruction *,section *,taddr);
dblock *eval_data(operand *,size_t,section *,taddr);
#if HAVE_INSTRUCTION_EXTENSION
void init_instruction_ext(instruction_ext *);
#endif
#if MAX_QUALIFIERS!=0
char *parse_instruction(char *,int *,char **,int *,int *);
int set_default_qualifiers(char **,int *);
#endif
#if HAVE_CPU_OPTS
void cpu_opts_init(section *);
void cpu_opts(void *);
void print_cpu_opts(FILE *,void *);
#endif
/* provided by syntax.c */
extern char *syntax_copyright;
extern char commentchar;
extern hashtable *dirhash;
extern char *defsectname;
extern char *defsecttype;
int init_syntax();
int syntax_args(char *);
void parse(void);
char *parse_macro_arg(struct macro *,char *,struct namelen *,struct namelen *);
int expand_macro(source *,char **,char *,int);
char *skip(char *);
char *skip_operand(char *);
void eol(char *);
char *const_prefix(char *,int *);
char *const_suffix(char *,char *);
char *get_local_label(char **);
/* provided by output_xxx.c */
#ifdef OUTTOS
extern int tos_hisoft_dri;
#endif
#ifdef OUTHUNK
extern int hunk_onlyglobal;
#endif
int init_output_test(char **,void (**)(FILE *,section *,symbol *),int (**)(char *));
int init_output_elf(char **,void (**)(FILE *,section *,symbol *),int (**)(char *));
int init_output_bin(char **,void (**)(FILE *,section *,symbol *),int (**)(char *));
int init_output_srec(char **,void (**)(FILE *,section *,symbol *),int (**)(char *));
int init_output_vobj(char **,void (**)(FILE *,section *,symbol *),int (**)(char *));
int init_output_hunk(char **,void (**)(FILE *,section *,symbol *),int (**)(char *));
int init_output_aout(char **,void (**)(FILE *,section *,symbol *),int (**)(char *));
int init_output_tos(char **,void (**)(FILE *,section *,symbol *),int (**)(char *));
int init_output_xfile(char **,void (**)(FILE *,section *,symbol *),int (**)(char *));
int init_output_atari_com(char **,void (**)(FILE *,section *,symbol *),int (**)(char *));