* asranlib/asranlib.c, link/lkar.h, link/lkar.c:
[fw/sdcc] / as / xa51 / xa_main.h
1 /* xa_main.h - Paul's XA51 Assembler
2
3    Copyright 1997,2002 Paul Stoffregen (paul at pjrc dot com)
4
5 This program is free software; you can redistribute it and/or modify it
6 under the terms of the GNU General Public License as published by the
7 Free Software Foundation; either version 3, or (at your option) any
8 later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program.  If not, see <http://www.gnu.org/licenses/>. */
17
18 #define SIZE8 0
19 #define SIZE16 1
20 #define SIZE32 2
21 #define UNKNOWN -1
22 #define WORD_REG 16384
23 #define BYTE_REG 32768
24
25 /* max # of bytes in db directive */
26 #define MAX_DB          2500
27
28 /* max # char in symbol name */
29 #define MAX_SYMBOL      1024
30
31 /* max # of bytes per line */
32 #define MAX_LINE        4096
33
34 /* REL() computes branch operand from dest and memory */
35 /* location of the jump instruction itself */
36 /* this is later adjusted by one for jcu, of course */
37 #define BRANCH_SPACING 2
38 #define REL(dest, mem) (((dest)-((((mem)+1)/(\
39 BRANCH_SPACING))*(BRANCH_SPACING)))/(BRANCH_SPACING))
40
41 #define NOP_OPCODE 0    /* opcode for NOP */
42
43 /* a linked list of all the symbols */
44
45 struct symbol {
46         char *name;
47         int value;
48         int istarget;   /* 1 if a branch target, 0 otherwise */
49         int isdef;      /* 1 if defined, 0 if no value yet */
50         int line_def;   /* line in which is was defined */
51         int isbit;      /* 1 if a bit address, 0 otherwise */
52         int issfr;
53         int isreg;      /* 1 if a register, 0 otehrwise */
54         int global ;    /* is defined as global */
55         char mode;      /* Absolute, Relative, Tmplabel, eXternal */
56         short lk_index; /* symbol index for the linker */
57         int area;       /* the area that this symbol is in */
58         struct symbol *next; };
59
60 /* a list of all the symbols that are branch targets */
61 /* (and will need to get aligned on 4 byte boundries) */
62
63 struct target {
64         char *name;
65         struct target *next; };
66
67 struct area_struct {
68         int start;
69         int alloc_position;
70         int defsEmitted;
71         int size;
72 };
73
74 extern int current_area;
75
76 #define MEM_POS (area[current_area].alloc_position)
77
78 enum {
79   AREA_CSEG=1,
80   AREA_DSEG,
81   // AREA_OSEG,
82   // AREA_ISEG,
83   AREA_BSEG,
84   AREA_XSEG,
85   AREA_XISEG,
86   AREA_XINIT,
87   AREA_GSINIT,
88   AREA_GSFINAL,
89   AREA_HOME,
90   AREA_SSEG,
91   NUM_AREAS=AREA_SSEG
92 };
93
94 extern struct area_struct area[NUM_AREAS];
95
96 extern FILE *yyin;
97 extern char *yytext;
98 extern int lineno;
99 extern int p1, p2, p3, mem, m_len;
100
101 extern struct symbol * build_sym_list(char *thename);
102 extern int assign_value(char *thename, int thevalue, char mode);
103 extern int mk_bit(char *thename, int current_area);
104 extern int mk_reg(char *thename);
105 extern void out(int *byte_list, int num);
106 extern int is_target(char *thename);
107 extern void pad_with_nop();
108 extern int binary2int(char *str);
109 extern int is_bit(char *thename);
110 extern int is_reg(char *thename);
111 extern struct symbol * is_def(char *thename);
112 extern struct symbol * is_ref(char *thename);
113 extern int get_value(char *thename);
114 extern struct symbol *findSymbol (char *thename);
115 extern char rel_line[2][132];
116 extern char operand[2][MAX_SYMBOL];
117 extern void error(char*);
118 int mk_bit(char*, int);
119 int mk_sfr(char*);
120 int mk_global(char*);
121 struct target * build_target_list(char *thename);
122 struct symbol * build_sym_list(char *);
123 int find_size_reg(int op1spec);
124 int find_size0(int isize);
125 int find_size1(int isize, int op1spec);
126 int find_size2(int isize, int op1spec, int op2spec);
127 int yyerror(char *s);
128 int imm_data4_signed(int value);
129 int imm_data4_unsigned(int value);
130 int imm_data5_unsigned(int value);
131 int imm_data8(int value);
132 int imm_data16(int value);
133 int reg(int reg_spec);
134 int reg_indirect(int reg_spec);
135 int lsb(int value);
136 int msb(int value);
137 int direct_addr(int value);
138 int bit_addr(int value);
139 int rel16(int pos, int dest);
140 int rel8(int pos, int dest);
141 char *areaToString (int area);
142
143 FILE *frel, *fmem, *list_fp, *sym_fp;
144
145 extern void relout();