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