xref: /netbsd/usr.sbin/gspa/gspa/gsp_ass.h (revision 48c5de3c)
1 /*	$NetBSD: gsp_ass.h,v 1.13 2011/08/30 18:53:41 joerg 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 <err.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 GSPA_A0	0x20
123 #define GSPA_B0	0x50
124 #define GSPA_SP	0x6F		/* (r1 & r2 & REGFILE) != 0 iff */
125 #define GSPA_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 expr bexpr(int, expr, expr);
131 void do_asg(char *, expr, int flags);
132 void do_list_pc(void);
133 void do_show_val(int32_t);
134 int eval_expr(expr, int32_t *, unsigned *);
135 operand expr_op(expr);
136 expr fold(expr);
137 void free_expr(expr);
138 void free_operands(operand);
139 int get_line(char *lp, int maxlen);
140 expr here_expr(void);
141 expr id_expr(char *);
142 void lex_init(char *line);
143 void list_error(char *);
144 void listing(void);
145 symbol lookup(char *id, bool makeit);
146 expr num_expr(int);
147 void p1err(const char *fmt, ...) __printflike(1, 2);
148 void perr(const char *fmt, ...) __printflike(1, 2);
149 void pseudo(int code, operand operands);
150 void push_input(char *fn);
151 void putcode(u_int16_t *, int);
152 operand reg_ind(int, int);
153 operand reg_index(int, expr);
154 operand reg_indxy(int, char *);
155 operand reg_op(int reg);
156 void reset_numeric_labels(void);
157 void set_label(char *);
158 void set_numeric_label(int);
159 void start_at(u_int32_t);
160 void statement(char *opcode, operand operands);
161 operand string_op(char *);
162 void ucasify(char *);
163 __dead void yyerror(const char *err);
164 int yylex(void);
165 
166 
167 extern unsigned pc;
168 extern short pass2;
169 
170 extern unsigned lineno;
171 extern int err_count;
172 extern char line[], *lineptr;
173 
174 #if defined(sparc) && !defined(__NetBSD__)
175 #include <alloca.h>
176 #else
177 #ifdef __GNUC__
178 #define alloca __builtin_alloca
179 #endif
180 #endif
181 
182 #define new(x)	((x) = emalloc(sizeof(*(x))))
183