Setting up repository
[linux-libre-firmware.git] / as31 / as31 / as31.h
1 /* ----------------------------------------------------------------------
2  * FILE: as31.h
3  * PACKAGE: as31 - 8031/8051 Assembler.
4  *
5  * DESCRIPTION:
6  *      The sole header file for the 8031/8051 assembler package.
7  *      It defines several structures used by the yacc stack.
8  *      It defines several macros for testing the bitsize of numeric
9  *      quantities.
10  *
11  *      Some macros to extract information from the mode structure.
12  *
13  * REVISION HISTORY:
14  *      Jan. 19, 1990 - Created. (Ken Stauffer)
15  *
16  * AUTHOR:
17  *      All code in this file written by Ken Stauffer (University of Calgary).
18  *      January, 1990.
19  *
20  */
21
22 #include <stdio.h>
23 #include <string.h>
24
25 // include directive
26 #define INC_CMD ".inc"
27
28 /* ----------------------------------------------------------------------
29  * user / keyword symbol structures:
30  */
31
32 struct opcode {
33         char *name;
34         int type;
35         unsigned char *bytes;
36 };
37
38 struct symbol {
39         char *name;
40         char predefined;
41         char type;
42         long value;
43         struct symbol *next;
44 };
45
46 #define UNDEF   0
47 #define LABEL   1
48
49 /* these are unused... maybe someday the can be used and the */
50 /* parser can check that each addressing mode is using the */
51 /* correct type of data, or a generic LABEL type */
52 #define BIT     2
53 #define IMEM    3
54 #define EMEM    3
55 #define CONST   4
56 #define REG     5
57
58 /* ----------------------------------------------------------------------
59  * addressing mode stuff:
60  */
61
62 struct mode {
63         unsigned char mode;             /* value to index with */
64         unsigned char size;             /* # of bytes used */
65         unsigned char orval;            /* value OR'd to obcode */
66         unsigned char byte1;            /* extra byte 1 */
67         unsigned char byte2;            /* extra byte 2 */
68 };
69
70 #define set_md(m,a)     ((m).mode=(a))
71 #define set_sz(m,a)     ((m).size=(a))
72 #define set_ov(m,a)     ((m).orval=(a))
73 #define set_b1(m,a)     ((m).byte1=(a))
74 #define set_b2(m,a)     ((m).byte2=(a))
75
76 #define get_md(m)       ((m).mode)
77 #define get_sz(m)       ((m).size)
78 #define get_ov(m)       ((m).orval)
79 #define get_b1(m)       ((m).byte1)
80 #define get_b2(m)       ((m).byte2)
81
82 /* ----------------------------------------------------------------------
83  * yacc stack stuff:
84  */
85
86 struct value {
87         long v;
88         unsigned char d;                /* expression defined flag */
89 };
90
91 union ystack {
92         long value;
93         struct value val;
94         struct opcode *op;
95         struct symbol *sym;
96         struct mode mode;
97         char *str;
98 };
99
100 #define YYSTYPE union ystack
101
102 /* ----------------------------------------------------------------------
103  * IS_BIT_MAPPED_RAM:
104  *      True is the byte 'a' is the byte address of a bit mapped
105  *      RAM location.
106  */
107 #define isbmram(a)      (((a)&0xf0)==0x20)
108
109 /* ----------------------------------------------------------------------
110  * IS_BIT_MAPPED_SFR:
111  *      True is the byte 'a' is the byte address of a bit mapped
112  *      SPECIAL FUCTION REGISTER.
113  */
114 #define isbmsfr(a)      (((a)&0x80) && !((a) & 0x07))
115
116 /* ----------------------------------------------------------------------
117  * isbit8, ...
118  *      Macros to check the sizes of values and to convert
119  *      a value to a certain, size.
120  *
121  */
122 #define size8           (~0x00ff)
123 #define size11          (~0x07ff)
124 #define size13          (~0x1fff)
125 #define size16          (~0xffff)
126
127 #define size10          (~0x03ff)
128 #define size12          (~0x0fff)
129 #define size15          (~0x7fff)
130
131 #define isbit8(v)       ( !( ((v)>=0) ? (v)&size8 : -(v)>=128) )
132 #define isbit11(v)      ( !( ((v)>=0) ? (v)&size11 : (-(v))&size10 ) )
133 #define isbit13(v)      ( !( ((v)>=0) ? (v)&size13 : (-(v))&size12 ) )
134 #define isbit16(v)      ( !( ((v)>=0) ? (v)&size16 : (-(v))&size15 ) )
135
136 /* ----------------------------------------------------------------------
137  * Size of user hash table.  Use a prime number for best performance
138  */
139 #define HASHTABSIZE             4999
140
141 /* ----------------------------------------------------------------------
142  * Macros to nicely test which pass we are in.
143  */
144 #define pass1                   (!pass)
145 #define pass2                   (pass)
146
147
148
149 /* from lexer.c */
150 extern int yylex(void);
151 extern int seek_eol(void);
152 extern const char *get_last_token(void);
153 extern int lineno;
154
155
156 /* from parser.y */
157 extern int yyparse(void);
158 extern void clear_location_counter(void);
159
160
161 /* from emitter.c */
162 extern void emitusage(void);
163 extern const char *emit_extension(const char *ftype);
164 extern const char *emit_desc_lookup(int num);
165 extern const char *emit_desc_to_name_lookup(const char *desc);
166 extern int emitopen(const char *file, const char *ftype, const char *arg);
167 extern void emitclose(void);
168 extern void emitaddr(unsigned long a);
169 extern void emitbyte(int b);
170
171
172 /* from symbol.c */
173 extern struct opcode *lookop(const char *s);
174 extern struct symbol *looksym(const char *s);
175 extern void syminit(void);
176 extern void freesym(void);
177
178
179 /* from run.c */
180 extern int run_as31(const char *infile, int lst, int use_stdout,
181                     const char *fmt, const char *arg, const char *customoutfile);
182 extern void error(const char *fmt, ...);
183 extern void warn(const char *fmt, ...);
184 extern void mesg_f(const char *fmt, ...);
185 extern int dashl;
186 extern int pass;
187 extern int abort_asap;
188 extern unsigned long lc;
189 extern FILE *listing;
190
191
192 /* from as31.c or as31_gtk.c */
193 extern void mesg(const char *str);
194 extern void showhelp(const char *cmd);
195