-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathas6-tms7000.c
216 lines (196 loc) · 5.04 KB
/
as6-tms7000.c
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
/*
* TMS7000
*
* Basic symbol tables.
* Contain all of the instructions
* and register names.
*/
#include "as.h"
/*
* This array of symbol nodes
* make up the basic symbol table.
* The "syminit" routine links these
* nodes into the builtin symbol hash
* table at start-up time.
*/
SYM sym[] = {
{ 0, "a", TBR, RA },
{ 0, "b", TBR, RB },
{ 0, "st", TSR, RST },
{ 0, "defb", TDEFB, XXXX },
{ 0, "defw", TDEFW, XXXX },
{ 0, "defs", TDEFS, XXXX },
{ 0, "defm", TDEFM, XXXX },
{ 0, "org", TORG, XXXX },
{ 0, "equ", TEQU, XXXX },
{ 0, "export", TEXPORT, XXXX },
{ 0, ".byte", TDEFB, XXXX },
{ 0, ".word", TDEFW, XXXX },
{ 0, ".ds", TDEFS, XXXX },
{ 0, ".ascii", TDEFM, XXXX },
{ 0, ".org", TORG, XXXX },
{ 0, ".equ", TEQU, XXXX },
{ 0, ".export", TEXPORT, XXXX },
{ 0, "cond", TCOND, XXXX },
{ 0, "endc", TENDC, XXXX },
{ 0, "code", TSEGMENT, CODE },
{ 0, "data", TSEGMENT, DATA },
{ 0, "bss", TSEGMENT, BSS },
{ 0, "discard", TSEGMENT, DISCARD },
{ 0, "common", TSEGMENT, COMMON },
{ 0, "literal", TSEGMENT, LITERAL },
{ 0, "commondata", TSEGMENT, COMMONDATA },
{ 0, "buffers", TSEGMENT, BUFFERS },
{ 0, ".code", TSEGMENT, CODE },
{ 0, ".data", TSEGMENT, DATA },
{ 0, ".bss", TSEGMENT, BSS },
{ 0, ".discard", TSEGMENT, DISCARD },
{ 0, ".common", TSEGMENT, COMMON },
{ 0, ".literal", TSEGMENT, LITERAL },
{ 0, ".commondata", TSEGMENT, COMMONDATA },
{ 0, ".buffers", TSEGMENT, BUFFERS },
{ 0, ".reg", TSEGMENT, ZP },
{ 0, ".zp", TSEGMENT, ZP },
/* Mov is the 7 op form but has 3 extra forms */
/* x0 is implicit specials */
{ 0, "mov", TMOV, 0x02 },
/* Operations with 7 forms */
/* x0 and x1 block are not used */
{ 0, "and", TMULT, 0x03 },
{ 0, "or", TMULT, 0x04 },
{ 0, "xor", TMULT, 0x05 },
/* x6 is BTJO x7 is BTJZ */
{ 0, "add", TMULT, 0x08 },
{ 0, "adc", TMULT, 0x09 },
{ 0, "sub", TMULT, 0x0A },
{ 0, "sbb", TMULT, 0x0B },
{ 0, "mpy", TMULT, 0x0C },
{ 0, "cmp", TMULT, 0x0D },
{ 0, "dac", TMULT, 0x0E },
{ 0, "dsb", TMULT, 0x0F },
/* Ditto with offset following */
{ 0, "btjo", TMULTO, 0x06 },
{ 0, "btjz", TMULTO, 0x07 },
/* Three form ops (BR, CALL etc) */
{ 0, "lda", TIND, 0x0A },
{ 0, "sta", TIND, 0x0B },
{ 0, "br", TIND, 0x0C },
{ 0, "cmpa", TIND, 0x0D },
{ 0, "call", TIND, 0x0E },
/* Three form ops (CLR etc) */
{ 0, "dec", TR3, 0xB2 },
{ 0, "inc", TR3, 0xB3 },
{ 0, "inv", TR3, 0xB4 },
{ 0, "clr", TR3, 0xB5 },
{ 0, "xchb", TR3, 0xB6 },
{ 0, "swap", TR3, 0xB7 },
/* B8/B9 are push/pop */
/* BA is djnz */
{ 0, "decd", TR3, 0xBB },
{ 0, "rr", TR3, 0xBC },
{ 0, "rrc", TR3, 0xBD },
{ 0, "rl", TR3, 0xBE },
{ 0, "rlc", TR3, 0xBF },
/* Slightly odd - and have ST forms 08 0E*/
{ 0, "push", TPP, 0xB8 },
{ 0, "pop", TPP, 0xB9 },
/* Three form ops with offset */
{ 0, "djnz", TR3O, 0xBA },
/* P form ops */
/* MOVP has extra forms */
{ 0, "movp", TMOVP, 0x82 },
{ 0, "andp", TFORM, 0x83 },
{ 0, "orp", TFORM, 0x84 },
{ 0, "xorp", TFORM, 0x85 },
/* P form with offset */
{ 0, "btjop", TFORMO, 0x86 },
{ 0, "btjzp", TFORMO, 0x87 },
/* 0x0X implicits */
{ 0, "nop", TIMPL, 0x00 },
{ 0, "idle", TIMPL, 0x01 },
{ 0, "eint", TIMPL, 0x05 },
{ 0, "dint", TIMPL, 0x06 },
{ 0, "setc", TIMPL, 0x07 },
/* pop st */
{ 0, "stsp", TIMPL, 0x09 },
{ 0, "rets", TIMPL, 0x0A },
{ 0, "reti", TIMPL, 0x0B },
{ 0, "ldsp", TIMPL, 0x0D },
/* push st */
/* Branches with offset */
{ 0, "jmp", TJMP, 0xE0 },
{ 0, "jn", TBRA, 0xE1 },
{ 0, "jeq", TBRA, 0xE2 },
{ 0, "jz", TBRA, 0xE2 },
{ 0, "jc", TBRA, 0xE3 },
{ 0, "jhs", TBRA, 0xE3 },
{ 0, "jp", TREL, 0xE4 },
{ 0, "jpz", TBRA, 0xE5 },
{ 0, "jne", TBRA, 0xE6 },
{ 0, "jnz", TBRA, 0xE6 },
{ 0, "jl", TBRA, 0xE7 },
{ 0, "jnc", TBRA, 0xE7 },
/* Oddities */
{ 0, "clrc", TIMPL, 0xB0 },
{ 0, "tsta", TIMPL, 0xB0 },
{ 0, "tstb", TIMPL, 0xC1 },
{ 0, "trap", TTRAP, 0xE8 },
{ 0, "movd", TMOVD, 0x88 },
};
/*
* Set up the symbol table.
* Sweep through the initializations
* of the "phash", and link them into the
* buckets. Because it is here, a
* "sizeof" works.
*/
void syminit(void)
{
SYM *sp;
int hash;
sp = &sym[0];
while (sp < &sym[sizeof(sym)/sizeof(SYM)]) {
hash = symhash(sp->s_id);
sp->s_fp = phash[hash];
phash[hash] = sp;
++sp;
}
}
char *etext[] = {
/*10*/ "unexpected character",
"phase error",
"multiple definitions",
"syntax error",
"must be absolute",
/*15*/ "missing delimiter",
"invalid constant",
"address required",
"invalid id",
"bad mode",
/*20*/ "constant out of range",
"data in BSS",
"segment overflow",
"segment conflict",
"branch out of range",
/*25*/ "out of range",
"too many branches",
"divide by zero",
"register required",
"P register required"
/* 30 */
};
/*
* Make sure that the
* mode and register fields of
* the type of the "ADDR" pointed to
* by "ap" can participate in an addition
* or a subtraction.
*/
void isokaors(ADDR *ap, int paren)
{
int mode;
mode = ap->a_type&TMMODE;
if (mode == TUSER)
return;
aerr(ADDR_REQUIRED);
}