[go: up one dir, main page]

File: avra.h

package info (click to toggle)
avra 1.3.0-3
  • links: PTS
  • area: main
  • in suites: bullseye, buster, stretch
  • size: 2,704 kB
  • sloc: pascal: 31,903; ansic: 6,415; asm: 758; sh: 84; makefile: 46
file content (370 lines) | stat: -rw-r--r-- 10,636 bytes parent folder | download
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
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
/***********************************************************************
 *
 *  avra - Assembler for the Atmel AVR microcontroller series
 *
 *  Copyright (C) 1998-2006 Jon Anders Haugum, Tobias Weber
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; see the file COPYING.  If not, write to
 *  the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 *  Boston, MA 02111-1307, USA.
 *
 *
 *  Authors of avra can be reached at:
 *     email: jonah@omegav.ntnu.no, tobiw@suprafluid.com
 *     www: http://sourceforge.net/projects/avra
 */

#ifndef _AVRA_H_ /* avoid multiple inclusion */
#define _AVRA_H_

#include <stdio.h>
#include <time.h>

#ifndef VER_MAJOR
#  define VER_MAJOR 1
#endif
#ifndef VER_MINOR
#  define VER_MINOR 3
#endif
#ifndef VER_RELEASE
#  define VER_RELEASE 0
#endif
#ifndef VER_BUILD
#  define VER_BUILD 1
#endif
#ifndef VER_DATE
#  define VER_DATE    "8 May 2010"
#endif

#define IS_HOR_SPACE(x)	((x == ' ') || (x == 9))
#define IS_LABEL(x)	(isalnum(x) || (x == '%') || (x == '_'))
#define IS_END_OR_COMMENT(x)	((x == ';') || (x == 10) || (x == 13) || (x == '\0') || (x == 12))
#define IS_ENDLINE(x)	((x == 10) || (x == 13) || (x == '\0') || (x == 12))
#define IS_SEPARATOR(x)	((x == ' ') || (x == ',') || (x == '[') || (x == ']'))

#define LINEBUFFER_LENGTH 256
#define MAX_NESTED_MACROLOOPS 256

#define MAX_MACRO_ARGS 10

/* warning switches */

/* Option enumeration */
enum {
	ARG_DEFINE = 0,		/* --define, -D            */
	ARG_INCLUDEPATH,	/* --includedir, -I        */
	ARG_LISTMAC,		/* --listmac               */
	ARG_MAX_ERRORS,		/* --max_errors            */
	ARG_COFF,		/* --coff                  */
	ARG_DEVICES,		/* --devices               */
	ARG_VER,		/* --version               */
	ARG_HELP,		/* --help, -h              */
	ARG_WRAP,		/* --wrap                  */
	ARG_WARNINGS,		/* --warn, -W              */
	ARG_FILEFORMAT,		/* --filetype              */
	ARG_LISTFILE,		/* --listfile              */
	ARG_OUTFILE,		/* --outfile   */
	ARG_MAPFILE,		/* --mapfile   */
	ARG_DEBUGFILE,		/* --debugfile */
	ARG_EEPFILE,		/* --eepfile   */
	ARG_COUNT
};

enum {
	MSGTYPE_ERROR = 0,
	MSGTYPE_WARNING,
	MSGTYPE_MESSAGE,
	MSGTYPE_OUT_OF_MEM,
	MSGTYPE_MESSAGE_NO_LF,		/* B.A. : Like MSGTYPE_MESSAGE, but without /n */
	MSGTYPE_APPEND			/* B.A. : Print Message without any header and without /n. To append messages */
	/*	MSGTYPE_INCLUDE		B.A. Removed. Was not in used */
};

enum {
	PASS_1 = 0,
	PASS_2
};

enum {
	SEGMENT_CODE = 0,
	SEGMENT_DATA,
	SEGMENT_EEPROM
};

enum {
	TERM_END = 0,
	TERM_SPACE,
	TERM_COMMA,
	TERM_EQUAL,
	TERM_DASH,
	TERM_DOUBLEQUOTE,
	TERM_COLON
};

/* Structures */

struct prog_info
{
	struct args *args;
	struct device *device;
	struct file_info *fi;
	struct macro_call *macro_call;
	struct macro_line *macro_line;
	FILE *list_file;
	int list_on;
	int map_on;
	char *list_line;
	char *root_path;
	FILE *obj_file;
	struct hex_file_info *hfi;
	struct hex_file_info *eep_hfi;
	int segment;
	int cseg_addr;
	int dseg_addr;
	int eseg_addr;
	int cseg_count;
	int dseg_count;
	int eseg_count;
	int error_count;
	int max_errors;
	int warning_count;
	struct include_file *last_include_file;
	struct include_file *first_include_file;
	struct def *first_def;
	struct def *last_def;
	struct label *first_label;
	struct label *last_label;
	struct label *first_constant;
	struct label *last_constant;
	struct label *first_variable;
	struct label *last_variable;
	struct label *first_blacklist;	/* B.A. : List for undefined symbols. Needed to make forward references safe */
	struct label *last_blacklist;
	struct macro *first_macro;
	struct macro *last_macro;
	struct macro_call *first_macro_call;
	struct macro_call *last_macro_call;
	struct orglist *first_orglist;	/* B.A. : List of used memory segments. Needed for overlap-check */
	struct orglist *last_orglist;
	int conditional_depth;
	time_t time;			/* B.A. : Use a global timestamp for listing header and %hour% ... tags */
	/* coff additions */
	FILE *coff_file;
	/* Warning additions */
	int NoRegDef;
	int pass;
	
};

struct file_info
{
	FILE *fp;
	struct include_file *include_file;
	char buff[LINEBUFFER_LENGTH];
	char scratch[LINEBUFFER_LENGTH];
	int line_number;
	int exit_file;
	struct label *label;
};

struct hex_file_info
{
	FILE *fp;
	int count;
	int linestart_addr;
	int segment;
	unsigned char hex_line[16];
};

struct include_file
{
	struct include_file *next;
	char *name;
	int num;
};

struct def
{
	struct def *next;
	char *name;
	int reg;
};

struct label
{
	struct label *next;
	char *name;
	int value;
};

struct macro
{
	struct macro *next;
	char *name;
	struct include_file *include_file;
	int first_line_number;
	struct macro_line *first_macro_line;
	struct macro_label *first_label;
};

struct macro_label
{
	char *label;
	struct macro_label *next;
	int running_number;
};

struct macro_line
{
	struct macro_line *next;
	char *line;
};

struct macro_call
{
	struct macro_call *next;
	int line_number;
	struct include_file *include_file;
	struct macro_call *prev_on_stack;
	struct macro *macro;
	int line_index;
	int prev_line_index;
	int nest_level;
	struct label *first_label;
	struct label *last_label;
};

struct orglist
{
	struct orglist *next;
	int segment;
	int start;
	int length;
};

/* Prototypes */
/* avra.c */
int assemble(struct prog_info *pi);
int load_arg_defines(struct prog_info *pi);
struct prog_info *get_pi(struct args *args);
void free_pi(struct prog_info *pi);
void prepare_second_pass(struct prog_info *pi);
void print_msg(struct prog_info *pi, int type, char *fmt, ... );
void get_rootpath(struct prog_info *pi, struct args *args);

int def_const(struct prog_info *pi, const char *name, int value);
int def_var(struct prog_info *pi, char *name, int value);
int def_blacklist(struct prog_info *pi, const char *name);
int def_orglist(struct prog_info *pi);					/* B.A. : Test for overlapping segments */
int fix_orglist(struct prog_info *pi);
void print_orglist(struct prog_info *pi);
int test_orglist(struct prog_info *pi);
int get_label(struct prog_info *pi,char *name,int *value);
int get_constant(struct prog_info *pi,char *name,int *value);
int get_variable(struct prog_info *pi,char *name,int *value);
struct label *test_label(struct prog_info *pi,char *name,char *message);
struct label *test_constant(struct prog_info *pi,char *name,char *message);
struct label *test_variable(struct prog_info *pi,char *name,char *message);
struct label *test_blacklist(struct prog_info *pi,char *name,char *message);
struct label *search_symbol(struct prog_info *pi,struct label *first,char *name,char *message);
void free_defs(struct prog_info *pi);
void free_labels(struct prog_info *pi);
void free_constants(struct prog_info *pi);
void free_blacklist(struct prog_info *pi);
void free_variables(struct prog_info *pi);
void free_orglist(struct prog_info *pi);


/* parser.c */
int parse_file(struct prog_info *pi, char *filename);
int parse_line(struct prog_info *pi, char *line);
char *get_next_token(char *scratch, int term);
char *fgets_new(struct prog_info *pi, char *s, int size, FILE *stream);

/* expr.c */
int get_expr(struct prog_info *pi, char *data, int *value);
//int get_operator(char *op);
//int test_operator_at_precedence(int operator, int precedence);
//int calc(struct prog_info *pi, int left, int operator, int right);
//int get_function(char *function);
//int do_function(int function, int value);
//int log2(int value);
int get_symbol(struct prog_info *pi, char *label_name, int *data);
int par_length(char *data);

/* mnemonic.c */
int parse_mnemonic(struct prog_info *pi);
int get_mnemonic_type(struct prog_info *pi);
int get_register(struct prog_info *pi, char *data);
int get_bitnum(struct prog_info *pi, char *data, int *ret);
int get_indirect(struct prog_info *pi, char *operand);
int is_supported(struct prog_info *pi, char *name);
int count_supported_instructions(int flags);

/* directiv.c */
int parse_directive(struct prog_info *pi);
int get_directive_type(char *directive);
char *term_string(struct prog_info *pi, char *string);
int parse_db(struct prog_info *pi, char *next);
void write_db(struct prog_info *pi, char byte, char *prev, int count);
int spool_conditional(struct prog_info *pi, int only_endif);
int check_conditional(struct prog_info *pi, char *buff, int *current_depth, int *do_next, int only_endif);
int test_include(const char *filename);

/* macro.c */
int read_macro(struct prog_info *pi, char *name);
struct macro *get_macro(struct prog_info *pi, char *name);
struct macro_label *get_macro_label(char *line, struct macro *macro);
int expand_macro(struct prog_info *pi, struct macro *macro, char *rest_line);


/* file.c */
int open_out_files(struct prog_info *pi, char *filename);
void close_out_files(struct prog_info *pi);
struct hex_file_info *open_hex_file(char *filename);
void close_hex_file(struct hex_file_info *hfi);
void write_ee_byte(struct prog_info *pi, int address, unsigned char data);
void write_prog_word(struct prog_info *pi, int address, int data);
void do_hex_line(struct hex_file_info *hfi);
FILE *open_obj_file(struct prog_info *pi, char *filename);
void close_obj_file(struct prog_info *pi, FILE *fp);
void write_obj_record(struct prog_info *pi, int address, int data);
void unlink_out_files(struct prog_info *pi, char *filename);

/* map.c */
void write_map_file(struct prog_info *pi);
char *Space(char *n);

/* stdextra.c */
int nocase_strcmp(char *s, char *t);
int nocase_strncmp(char *s, char *t, int n);
char *nocase_strstr(char *s, char *t);
int atox(char *s);
int atoi_n(char *s, int n);
int atox_n(char *s, int n);
char *my_strlwr(char *in);
char *my_strupr(char *in);

/* coff.c */
FILE *open_coff_file(struct prog_info *pi, char *filename);
void write_coff_file(struct prog_info *pi);
void write_coff_eeprom( struct prog_info *pi, int address, unsigned char data);
void write_coff_program( struct prog_info *pi, int address, unsigned int data);
void close_coff_file(struct prog_info *pi, FILE *fp);
int parse_stabs( struct prog_info *pi, char *p );
int parse_stabn( struct prog_info *pi, char *p );

#endif /* end of avra.h */