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