xref: /netbsd/usr.sbin/gspa/gspa/gsp_ass.h (revision bf9ec67e)
1 /*	$NetBSD: gsp_ass.h,v 1.8 2001/06/13 10:46:06 wiz Exp $	*/
2 /*
3  * GSP assembler - definitions
4  *
5  * Copyright (c) 1993 Paul Mackerras.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  * 3. All advertising materials mentioning features or use of this software
17  *    must display the following acknowledgement:
18  *      This product includes software developed by Paul Mackerras.
19  * 4. The name of the author may not be used to endorse or promote products
20  *    derived from this software without specific prior written permission
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33 
34 #include <stddef.h>
35 #include <sys/types.h>
36 /*#include <alloca.h>*/
37 
38 #define MAXLINE		133
39 
40 typedef char	bool;
41 #define TRUE	1
42 #define FALSE	0
43 
44 #define YYDEBUG	1
45 
46 /* Structure for symbol in symbol table */
47 typedef struct symbol {
48 	int16_t	flags;
49 	int16_t	ndefn;
50 	unsigned	value;
51 	unsigned	lineno;
52 	struct symbol	*next;
53 	struct numlab	*nlab;
54 	char		name[1];
55 } *symbol;
56 
57 /* Values for flags */
58 #define DEFINED		1
59 #define SET_LABEL	2
60 #define NUMERIC_LABEL	4
61 
62 #define NOT_YET		65535U		/* line no. for `not defined yet' */
63 
64 /* Info about successive numeric labels */
65 struct numlab {
66 	unsigned	value;
67 	unsigned	lineno;
68 	struct numlab	*next;
69 };
70 
71 /* Structure for expressions */
72 typedef struct expr {
73 	int	e_op;
74 	union {
75 		struct {
76 			struct expr *left;
77 			struct expr *right;
78 		} e_s;
79 		symbol	sym;
80 		int32_t	val;
81 	} e_u;
82 } *expr;
83 #define e_left	e_u.e_s.left
84 #define e_right	e_u.e_s.right
85 #define e_sym	e_u.sym
86 #define e_val	e_u.val
87 
88 /* Operators other than '+', '-', etc. */
89 #define SYM	1
90 #define CONST	2
91 #define NEG	3
92 
93 /* Structure for an operand */
94 typedef struct operand {
95 	char	type;
96 	char	mode;			/* EA mode */
97 	int16_t	reg_no;
98 	union {
99 		expr	value;
100 		char	*string;
101 	} op_u;
102 	struct operand	*next;
103 } *operand;
104 
105 /* Values for operand type */
106 #define REG	1		/* register operand */
107 #define EXPR	2		/* expression operand */
108 #define EA	4		/* effective address */
109 #define STR_OPN	8		/* string operand */
110 
111 /* Addressing modes */
112 /* NB codes for modes with an expression must be > other modes */
113 #define M_REG		0	/* R */
114 #define M_IND		1	/* *R */
115 #define M_POSTINC	2	/* *R+ */
116 #define M_PREDEC	3	/* *-R */
117 #define M_INDXY		4	/* *R.XY (pixt only) */
118 #define M_INDEX		5	/* *R(n) */
119 #define M_ABSOLUTE	6	/* @adr */
120 
121 /* Register names */
122 #define A0	0x20
123 #define B0	0x50
124 #define SP	0x6F		/* (r1 & r2 & REGFILE) != 0 iff */
125 #define REGFILE	0x60		/* r1 and r2 are in the same file */
126 
127 /* Prototypes */
128 operand abs_adr(expr);
129 operand add_operand(operand, operand);
130 void *alloc(size_t nbytes);
131 expr bexpr(int, expr, expr);
132 void do_asg(char *, expr, int flags);
133 void do_list_pc(void);
134 void do_show_val(int32_t);
135 int eval_expr(expr, int32_t *, unsigned *);
136 operand expr_op(expr);
137 expr fold(expr);
138 void free_expr(expr);
139 void free_operands(operand);
140 int get_line(char *lp, int maxlen);
141 expr here_expr(void);
142 expr id_expr(char *);
143 void lex_init(char *line);
144 void list_error(char *);
145 void listing(void);
146 symbol lookup(char *id, bool makeit);
147 expr num_expr(int);
148 void p1err(char *fmt, ...)
149 	__attribute__((__format__(__printf__, 1, 2)));
150 void perr(char *fmt, ...)
151 	__attribute__((__format__(__printf__, 1, 2)));
152 void pseudo(int code, operand operands);
153 void push_input(char *fn);
154 void putcode(u_int16_t *, int);
155 operand reg_ind(int, int);
156 operand reg_index(int, expr);
157 operand reg_indxy(int, char *);
158 operand reg_op(int reg);
159 void reset_numeric_labels(void);
160 void set_label(char *);
161 void set_numeric_label(int);
162 void start_at(u_int32_t);
163 void statement(char *opcode, operand operands);
164 operand string_op(char *);
165 void ucasify(char *);
166 void yyerror(char *err);
167 int yylex(void);
168 
169 
170 extern unsigned pc;
171 extern short pass2;
172 
173 extern int lineno;
174 extern int err_count;
175 extern char line[], *lineptr;
176 
177 #if defined(sparc) && !defined(__NetBSD__)
178 #include <alloca.h>
179 #else
180 #ifdef __GNUC__
181 #define alloca __builtin_alloca
182 #endif
183 #endif
184 
185 #ifndef BSD
186 #ifndef amiga
187 #define bcopy(s, d, l) memcpy(d, s, l)
188 #endif
189 #endif
190 
191 #define new(x)	((x) = alloc (sizeof(*(x))))
192