xref: /netbsd-src/usr.sbin/gspa/gspa/gsp_pseu.c (revision 76dfffe33547c37f8bdd446e3e4ab0f3c16cea4b)
1 /*
2  * GSP assembler - assembler directives
3  *
4  * Copyright (c) 1993 Paul Mackerras.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  * 3. All advertising materials mentioning features or use of this software
16  *    must display the following acknowledgement:
17  *      This product includes software developed by Paul Mackerras.
18  * 4. The name of the author may not be used to endorse or promote products
19  *    derived from this software withough specific prior written permission
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 #include "gsp_ass.h"
33 #include "gsp_code.h"
34 
35 extern unsigned highest_pc, line_pc;
36 
37 void
38 pseudo(int code, operand ops)
39 {
40 	operand o;
41 	int32_t val;
42 	unsigned ln;
43 	u_int16_t words[2];
44 
45 	switch( code ){
46 	case ORG:
47 		if( ops == NULL )
48 			break;
49 		if( ops->type != EXPR ){
50 			perr("Inappropriate operand");
51 			break;
52 		}
53 		if( !eval_expr(ops->op_u.value, &val, &ln) ){
54 			p1err("ORG operand must be defined on pass 1");
55 			break;
56 		}
57 		if( pc > highest_pc )
58 			highest_pc = pc;
59 		line_pc = pc = val;
60 		do_list_pc();
61 		break;
62 #ifdef EQU
63 	case EQU:
64 		if( label == NULL ){
65 			perr("Label required");
66 			break;
67 		}
68 		if( ops == NULL )
69 			break;
70 		if( ops->type != EXPR ){
71 			perr("Inappropriate operand");
72 			break;
73 		}
74 		do_asg(label, ops->op_u.value, 0);
75 		break;
76 #endif /* EQU */
77 	case WORD:
78 	case LONG:
79 		if( ops == NULL )
80 			break;
81 		for( o = ops; o != NULL; o = o->next ){
82 			if( o->type != EXPR ){
83 				perr("Inappropriate operand");
84 				continue;
85 			}
86 			if( pass2 ){
87 				eval_expr(o->op_u.value, &val, &ln);
88 				words[0] = val;
89 				if( code == LONG ){
90 					words[1] = val >> 16;
91 					putcode(words, 2);
92 				} else {
93 					if( val < -32768 || val > 65535 )
94 						perr("Word value too large");
95 					putcode(words, 1);
96 				}
97 			} else
98 				pc += code == LONG? 0x20: 0x10;
99 		}
100 		return;
101 	case INCL:
102 		if( ops == NULL )
103 			break;
104 		if( ops->type != STR_OPN ){
105 			perr("Require filename string");
106 			break;
107 		}
108 		push_input(ops->op_u.string);
109 		break;
110 	case BLKB:
111 	case BLKW:
112 	case BLKL:
113 		if( ops == NULL )
114 			break;
115 		if( ops->type != EXPR ){
116 			perr("Inappropriate operand");
117 			break;
118 		}
119 		if( !eval_expr(ops->op_u.value, &val, &ln) ){
120 			p1err(".BLK%c operand must be defined on pass 1",
121 				code==BLKB? 'B': code==BLKW? 'W': 'L');
122 			break;
123 		}
124 		val *= 8;
125 		if( code == BLKB )
126 			val = (val + 8) & ~15;	/* round to word */
127 		else
128 			val *= (code==BLKW? 2: 4);
129 		pc += val;
130 		do_list_pc();
131 		break;
132 	case START:
133 		if( !pass2 || ops == NULL )
134 			break;
135 		if( ops->type != EXPR ){
136 			perr("Inappropriate operand");
137 			break;
138 		}
139 		eval_expr(ops->op_u.value, &val, &ln);
140 		start_at(val);
141 		do_show_val(val);
142 		break;
143 	}
144 	if( ops == NULL )
145 		perr("Insufficient operands");
146 	else if( ops->next != NULL )
147 		perr("Extra operands ignored");
148 }
149