-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathopc11.c
More file actions
235 lines (214 loc) · 7.72 KB
/
Copy pathopc11.c
File metadata and controls
235 lines (214 loc) · 7.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
/*
opc11.c - Part of macxx, a cross assembler family for various micro-processors
Copyright (C) 2008 David Shepperd
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef MAC_11
#define MAC_11 1
#endif
#include "token.h"
#include "pst_tokens.h"
#include "exproper.h"
#include "listctrl.h"
#include "pdp11.h"
/* The following are variables specific to the particular assembler */
const int macxx_name_mask = MACXX_M_11;
const char macxx_name[] = "mac11";
const char *macxx_target = "pdp11";
const char *macxx_descrip = "Cross assembler for the PDP11.";
#if 0
uint16_t macxx_rel_salign = 1; /* default alignment for .REL. segment */
uint16_t macxx_rel_dalign = 1; /* default alignment for data in .REL. segment */
uint16_t macxx_abs_salign = 1; /* default alignments for .ABS. segment */
uint16_t macxx_abs_dalign = 1; /* default alignments for .ABS. segment */
#else
uint16_t macxx_salign = 1; /* default alignment segments by LLF */
uint16_t macxx_dalign = 1; /* default alignment data within segment */
#endif
uint16_t macxx_min_dalign = 0; /* alignment required by the hardware */
char macxx_mau = 8; /* number of bits/minimum addressable unit */
char macxx_bytes_mau = 1; /* number of bytes/mau */
char macxx_mau_byte = 1; /* number of mau's in a byte */
char macxx_mau_word = 2; /* number of mau's in a word */
char macxx_mau_long = 4; /* number of mau's in a long */
char macxx_nibbles_byte = 3; /* For the listing output routines */
char macxx_nibbles_word = 6;
char macxx_nibbles_long = 11;
uint32_t macxx_edm_default = ED_TRUNC|ED_CPU; /* |ED_LC|ED_GBL; */ /* default edmask */
uint32_t macxx_lm_default = ~(LIST_ME|LIST_MEB|LIST_MES|LIST_LD|LIST_COD); /* default list mask */
int current_radix = 8; /* default the radix to octal */
char expr_open = '<'; /* char that opens an expression */
char expr_close = '>'; /* char that closes an expression */
/* char expr_escape = '^'; */ /* char that escapes a unary expression term */
char macro_arg_open = '<'; /* char that opens a macro argument */
char macro_arg_close = '>'; /* char that closes a macro argument */
char macro_arg_escape = '^'; /* char that escapes a macro argument */
char macro_arg_gensym = '?'; /* char indicating generated symbol for macro */
char macro_arg_genval = '\\'; /* char indicating generated value for macro */
char open_operand = '('; /* char that opens an operand indirection */
char close_operand = ')'; /* char that closes an operand indirection */
int max_opcode_length = 16; /* significant length of opcode names */
int max_symbol_length = 16; /* significant length of symbol names */
/* End of processor specific stuff */
struct rinit
{
char *name;
uint32_t value;
};
static struct rinit reginit[] = {
{ "R0",0},
{ "R1",1},
{ "R2",2},
{ "R3",3},
{ "R4",4},
{ "R5",5},
{ "R6",6},
{ "R7",7},
{ "SP",6},
{ "PC",7},
#if 0
{ "r0",0},
{ "r1",1},
{ "r2",2},
{ "r3",3},
{ "r4",4},
{ "r5",5},
{ "r6",6},
{ "r7",7},
{ "sp",6},
{ "pc",7},
#endif
{ 0,0}
};
int ust_init( void )
{
if ( options[QUAL_PREDEFINE] )
{
SS_struct *ptr;
struct rinit *ri = reginit;
while ( ri->name != 0 )
{
if ((ptr = sym_lookup(ri->name,SYM_INSERT_IF_NOT_FOUND)) == 0)
{
sprintf(emsg,"Unable to insert symbol %s into symbol table",
ri->name);
bad_token((char *)0,emsg);
continue;
}
ptr->flg_defined = 1; /* defined */
ptr->flg_ref = 1; /* referenced */
ptr->flg_macLocal = 0; /* not local */
ptr->flg_gasLocal = 0;
ptr->flg_global = 0; /* not global */
ptr->flg_label = 0; /* can redefine it */
ptr->flg_fixed_addr = 1;
ptr->ss_fnd = 0; /* no associated file */
ptr->flg_register = 1; /* it's a register */
ptr->flg_abs = 1; /* it's not relocatible */
ptr->flg_exprs = 0; /* no expression with it */
ptr->ss_seg = 0; /* not an offset from a segment */
ptr->ss_value = ri->value; /* value */
ri += 1; /* next */
}
}
quoted_ascii_strings = FALSE;
return 0;
}
EA source,dest;
extern int type0(int inst, int bwl);
extern int type1(int inst, int bwl);
extern int type2(int inst, int bwl);
extern int type3(int inst, int bwl);
extern int type4(int inst, int bwl);
extern int type5(int inst, int bwl);
extern int type6(int inst, int bwl);
extern int type7(int inst, int bwl);
extern int type8(int inst, int bwl);
extern int type9(int inst, int bwl);
extern int type10(int inst, int bwl);
extern int type11(int inst, int bwl);
extern int type12(int inst, int bwl);
static int (*opctbl[])() = { type0,type1,type2,type3,type4,type5,type6,type7,
type8,type9,type10,type11,type12};
void do_opcode(Opcode *opc)
{
int i;
EXP_stk *ep;
ep = exprs_stack;
for (i=0;i<EXPR_MAXSTACKS;++i,++ep)
{
ep->tag = 'w'; /* select default size */
ep->tag_len = 1; /* and 1 element */
ep->forward_reference = 0;
ep->register_reference = 0;
ep->register_mask = 0;
ep->stack->expr_code = EXPR_VALUE;
if ( !i )
{
ep->ptr = 1;
ep->stack->expr_value = opc->op_value;
ep->psuedo_value = opc->op_value;
}
else
{
ep->ptr = 0;
ep->stack->expr_value = 0;
ep->psuedo_value = 0;
}
}
ep = exprs_stack;
source.eamode = dest.eamode = 0;
source.mode = dest.mode = 0;
source.exp = ep+1; /* source expression loads into stacks 1 */
dest.exp = ep+2; /* dest expression loads into stacks 2 */
if ((current_offset&1) != 0)
{
bad_token((char *)0,"Instructions must start on even byte boundary");
++current_offset;
}
if ((opc->op_class&0xF) > sizeof(opctbl)/sizeof(void *))
{
bad_token(tkn_ptr,"Undecodable opcode; MAC11 internal error, please call dial-a-prayer");
}
(*opctbl[opc->op_class&0xF])(opc->op_value,opc->op_amode);
ep = exprs_stack; /* point to stack 0 */
ep->stack->expr_value |= (source.eamode<<6) | dest.eamode;
ep->ptr = compress_expr(ep);
if (list_bin)
compress_expr_psuedo(ep);
p1o_any(ep); /* output the opcode */
++ep; /* skip to stack 1 */
if ( ep->ptr ) /* If there's something there */
{
ep->ptr = compress_expr(ep);
if (list_bin)
compress_expr_psuedo(ep);
p1o_any(ep); /* output it */
}
++ep; /* Skip to stack 2 */
if ( ep->ptr ) /* If there's something there */
{
ep->ptr = compress_expr(ep);
if (list_bin)
compress_expr_psuedo(ep);
p1o_any(ep); /* output it */
}
}
int op_ntype( void )
{
f1_eatit();
return 1;
}
#ifndef MAC_11
#define MAC_11 1
#endif
#include "opcommon.h"