Subversion Repositories pentevo

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1186 savelij 1
/* codenano.c */
2
/*****************************************************************************/
3
/* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only                     */
4
/*                                                                           */
5
/* AS-Portierung                                                             */
6
/*                                                                           */
7
/* Codegenerator HP Nanoprocessor                                            */
8
/*                                                                           */
9
/*****************************************************************************/
10
 
11
#include "stdinc.h"
12
#include <ctype.h>
13
#include <string.h>
14
 
15
#include "nls.h"
16
#include "strutil.h"
17
#include "chunks.h"
18
#include "asmdef.h"
19
#include "asmsub.h"
20
#include "asmpars.h"
21
#include "asmitree.h"
22
#include "codevars.h"
23
#include "codepseudo.h"
24
#include "headids.h"
25
#include "errmsg.h"
26
#include "onoff_common.h"
27
 
28
#include "codenano.h"
29
 
30
/*---------------------------------------------------------------------------*/
31
 
32
static CPUVar CPUNANO;
33
 
34
/*---------------------------------------------------------------------------*/
35
 
36
static void DecodeBit(Word Index)
37
{
38
        if (ChkArgCnt(1,1))
39
        {
40
                Word val;
41
                Boolean OK;
42
 
43
                val = EvalStrIntExpression(&ArgStr[1], UInt3, &OK);
44
                if (!OK) return;
45
 
46
                BAsmCode[0] = Index | val;
47
                CodeLen = 1;
48
        }
49
}
50
 
51
static void DecodeFixed(Word Index)
52
{
53
        if (ChkArgCnt(0,0))
54
        {
55
                BAsmCode[0] = Index;
56
                CodeLen = 1;
57
        }
58
}
59
 
60
static void DecodeImm(Word Index)
61
{
62
        if (ChkArgCnt(1,1))
63
        {
64
                Word val;
65
                Boolean OK;
66
 
67
                val = EvalStrIntExpression(&ArgStr[1], UInt8, &OK);
68
                if (!OK) return;
69
 
70
                BAsmCode[0] = Index;
71
                BAsmCode[1] = val;
72
                CodeLen = 2;
73
        }
74
}
75
 
76
static void DecodeReg(Word Index)
77
{
78
        if (ChkArgCnt(1,1))
79
        {
80
                Word reg;
81
                Boolean OK;
82
 
83
                reg = EvalStrIntExpression(&ArgStr[1], UInt4, &OK);
84
                if (!OK) return;
85
 
86
                BAsmCode[0] = Index | reg;
87
                CodeLen = 1;
88
        }
89
}
90
 
91
static void DecodeRegImm(Word Index)
92
{
93
        if (ChkArgCnt(2,2))
94
        {
95
                Word reg;
96
                Word val;
97
                Boolean OK;
98
 
99
                reg = EvalStrIntExpression(&ArgStr[1], UInt4, &OK);
100
                if (!OK) return;
101
 
102
                val = EvalStrIntExpression(&ArgStr[2], UInt8, &OK);
103
                if (!OK) return;
104
 
105
                BAsmCode[0] = Index | reg;
106
                BAsmCode[1] = val;
107
                CodeLen = 2;
108
        }
109
}
110
 
111
static void DecodeDev(Word Index)
112
{
113
        if (ChkArgCnt(1,1))
114
        {
115
                Word dev;
116
                Boolean OK;
117
 
118
                dev = EvalStrIntExpression(&ArgStr[1], UInt4, &OK);
119
                if (!OK) return;
120
                if (Index == 0x50 && dev == 15) /* OTA 15 not allowed */
121
                {
122
                        WrError(ErrNum_OverRange);
123
                        return;
124
                }
125
 
126
                BAsmCode[0] = Index | dev;
127
                CodeLen = 1;
128
        }
129
}
130
 
131
static void DecodeDevImm(Word Index)
132
{
133
        if (ChkArgCnt(2,2))
134
        {
135
                Word dev;
136
                Word val;
137
                Boolean OK;
138
 
139
                dev = EvalStrIntExpression(&ArgStr[1], UInt4, &OK);
140
                if (!OK) return;
141
 
142
                val = EvalStrIntExpression(&ArgStr[2], UInt8, &OK);
143
                if (!OK) return;
144
 
145
                if (dev == 15)  /* OTR 15,xx not allowed */
146
                {
147
                        WrError(ErrNum_OverRange);
148
                        return;
149
                }
150
 
151
                BAsmCode[0] = Index | dev;
152
                BAsmCode[1] = val;
153
                CodeLen = 2;
154
        }
155
}
156
 
157
static void DecodeDirect(Word Index)
158
{
159
        if (ChkArgCnt(1,1))
160
        {
161
                Word val;
162
                Boolean OK;
163
 
164
                val = EvalStrIntExpression(&ArgStr[1], UInt3, &OK);
165
                if (!OK) return;
166
                if (val == 7)
167
                {
168
                        WrError(ErrNum_OverRange);
169
                        return;
170
                }
171
 
172
                BAsmCode[0] = Index | val;
173
                CodeLen = 1;
174
        }
175
}
176
 
177
static void DecodeAddress(Word Index)
178
{
179
        if (ChkArgCnt(1,1))
180
        {
181
                Word val;
182
                Boolean OK;
183
 
184
                val = EvalStrIntExpression(&ArgStr[1], UInt11, &OK);
185
                if (!OK) return;
186
 
187
                BAsmCode[0] = Index | (val >> 8);
188
                BAsmCode[1] = val & 0xff;
189
                CodeLen = 2;
190
        }
191
}
192
 
193
 
194
/*---------------------------------------------------------------------------*/
195
 
196
static void AddBit(const char *NName, Word NCode)
197
{
198
        AddInstTable(InstTable, NName, NCode, DecodeBit);
199
}
200
 
201
static void AddFixed(const char *NName, Word NCode)
202
{
203
        AddInstTable(InstTable, NName, NCode, DecodeFixed);
204
}
205
 
206
static void AddImm(const char *NName, Word NCode)
207
{
208
        AddInstTable(InstTable, NName, NCode, DecodeImm);
209
}
210
 
211
static void AddReg(const char *NName, Word NCode)
212
{
213
        AddInstTable(InstTable, NName, NCode, DecodeReg);
214
}
215
 
216
static void AddRegImm(const char *NName, Word NCode)
217
{
218
        AddInstTable(InstTable, NName, NCode, DecodeRegImm);
219
}
220
 
221
static void AddDev(const char *NName, Word NCode)
222
{
223
        AddInstTable(InstTable, NName, NCode, DecodeDev);
224
}
225
 
226
static void AddDevImm(const char *NName, Word NCode)
227
{
228
        AddInstTable(InstTable, NName, NCode, DecodeDevImm);
229
}
230
 
231
static void AddDirect(const char *NName, Word NCode)
232
{
233
        AddInstTable(InstTable, NName, NCode, DecodeDirect);
234
}
235
 
236
static void AddAddress(const char *NName, Word NCode)
237
{
238
        AddInstTable(InstTable, NName, NCode, DecodeAddress);
239
}
240
 
241
static void InitFields(void)
242
{
243
        InstTable = CreateInstTable(57);
244
 
245
  add_null_pseudo(InstTable);
246
 
247
        /* A. Accumulator Group */
248
        AddBit("SBS", 0x10);
249
        AddBit("SBZ", 0x30);
250
        AddBit("SBN", 0x20);
251
        AddBit("CBN", 0xA0);
252
        AddFixed("INB", 0x00);
253
        AddFixed("IND", 0x02);
254
        AddFixed("DEB", 0x01);
255
        AddFixed("DED", 0x03);
256
        AddFixed("CLA", 0x04);
257
        AddFixed("CMA", 0x05);
258
        AddFixed("LSA", 0x07);
259
        AddFixed("RSA", 0x06);
260
        AddFixed("SES", 0x1f);
261
        AddFixed("SEZ", 0x3f);
262
        AddImm("LDR", 0xcf);
263
 
264
        /* B. Register Transfer Group */
265
        AddReg("LDA", 0x60);
266
        AddReg("STA", 0x70);
267
        AddReg("LDI", 0xe0);
268
        AddReg("STI", 0xf0);
269
        AddRegImm("STR", 0xd0);
270
 
271
        /* C. Extend Register Group */
272
        AddFixed("STE", 0xb4);
273
        AddFixed("CLE", 0xb5);
274
 
275
        /* D. Interrupt Group */
276
        AddFixed("DSI", 0xaf);
277
        AddFixed("ENI", 0x2f);
278
 
279
        /* E. Comparator Group */
280
        AddFixed("SLT", 0x09);
281
        AddFixed("SEQ", 0x0a);
282
        AddFixed("SAZ", 0x0b);
283
        AddFixed("SLE", 0x0c);
284
        AddFixed("SGE", 0x0d);
285
        AddFixed("SNE", 0x0e);
286
        AddFixed("SAN", 0x0f);
287
        AddFixed("SGT", 0x08);
288
 
289
        /* F. Input/Output Group */
290
        AddDev("INA", 0x40);
291
        AddDev("OTA", 0x50);
292
        AddDevImm("OTR", 0xc0);
293
        AddDirect("STC", 0x28);
294
        AddDirect("CLC", 0xa8);
295
        AddDirect("SFS", 0x18);
296
        AddDirect("SFZ", 0x38);
297
        AddFixed("RTI", 0x90);
298
        AddFixed("RTE", 0xb1);
299
        AddFixed("NOP", 0x5f);
300
        AddReg("JAI", 0x90);
301
        AddReg("JAS", 0x98);
302
 
303
        /* G. Program Control Group */
304
        AddAddress("JMP", 0x80);
305
        AddAddress("JSB", 0x88);
306
        AddFixed("RTS", 0xb8);
307
        AddFixed("RSE", 0xb9);
308
}
309
 
310
static void DeinitFields(void)
311
{
312
        DestroyInstTable(InstTable);
313
}
314
 
315
/*---------------------------------------------------------------------------*/
316
 
317
static void MakeCode_NANO(void)
318
{
319
        if (!LookupInstTable(InstTable, OpPart.str.p_str))
320
                WrStrErrorPos(ErrNum_UnknownInstruction, &OpPart);
321
}
322
 
323
static Boolean IsDef_NANO(void)
324
{
325
        return False;
326
}
327
 
328
static void SwitchFrom_NANO(void)
329
{
330
        DeinitFields();
331
}
332
 
333
static void SwitchTo_NANO(void)
334
{
335
        const TFamilyDescr *pDescr;
336
 
337
        TurnWords = False;
338
        SetIntConstMode(eIntConstModeC);
339
 
340
        pDescr = FindFamilyByName("NANO");
341
        PCSymbol = "*";
342
        HeaderID = pDescr->Id;
343
        NOPCode = 0x5f;
344
        DivideChars = ",";
345
        HasAttrs = False;
346
 
347
        ValidSegs = (1 << SegCode);
348
        Grans[SegCode] = 1;
349
        ListGrans[SegCode] = 1;
350
        SegInits[SegCode] = 0x0000;
351
        SegLimits[SegCode] = 0x07ff;
352
 
353
        MakeCode = MakeCode_NANO;
354
        IsDef = IsDef_NANO;
355
        SwitchFrom = SwitchFrom_NANO;
356
        InitFields();
357
}
358
 
359
void codenano_init(void)
360
{
361
        CPUNANO = AddCPU("NANO", SwitchTo_NANO);
362
 
363
        AddCopyright("HP Nanoprocessor Generator (C) 2022 Haruo Asano");
364
}