summaryrefslogtreecommitdiff
path: root/sdas/aspdk13/pdk13mch.c
blob: 65adaa687c852d68b6ef2899d28d018d5bde05fa (plain) (blame)
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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
 /* pdk14mch.c */

/*
 *  Copyright (C) 1998-2011  Alan R. Baldwin
 *
 *  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/>.
 *
 *
 * Alan R. Baldwin
 * 721 Berkeley St.
 * Kent, Ohio  44240
 *
 *   This Assember Ported by
 *      John L. Hartman (JLH)
 *      jhartman at compuserve dot com
 *      noice at noicedebugger dot com
 *
 *  Benny Kim (2011/07/21)
 *  bennykim at coreriver dot com
 *  Fixed bugs in relative address with "."
 */

#include "sdas.h"
#include "asxxxx.h"
#include "pdk.h"

char    *cpu    = "Padauk 13";
char    *dsft   = "asm";

/*
 * Process machine ops.
 */
VOID
machine(struct mne *mp)
{
        a_uint op;
        int combine;

        /* Set the target in case it was not automatically
         * configured from the executable filename.
         */
        set_sdas_target (TARGET_ID_PDK13);

        op = mp->m_valu;
        combine = 0;

        /* Default instructions are only used for A -> K instructions.
         * Although they may be (ab)used for other types.
         */
        struct inst def = {op, 0xFF};
        switch (mp->m_type) {

        case S_MOV: {
                struct inst ioa = {0x0080, 0x1F};
                struct inst aio = {0x00A0, 0x1F};
                struct inst ma = {0x05C0, 0x3F};
                struct inst am = {0x07C0, 0x3F};
                emov(def, ioa, aio, ma, am);
                break;
        }

        case S_IDXM: {
                struct inst am = {op | 1, 0x1E};
                struct inst ma = {op, 0x1E};
                eidxm(am, ma);
                break;
        }

        case S_SUB:
                combine = 0x40;
                /* fallthrough */
        case S_ADD: {
                struct inst ma = {0x0400 | combine, 0x3F};
                struct inst am = {0x0600 | combine, 0x3F};
                earith(def, ma, am);
                break;
        }

        case S_SUBC:
                combine = 0x40;
                /* fallthrough */
        case S_ADDC: {
                struct inst ma = {0x0480 | combine, 0x3F};
                struct inst am = {0x0680 | combine, 0x3F};
                struct inst a = {0x0010 + (combine >> 6), 0x00};
                struct inst m = {0x0800 + combine, 0x3F};
                earithc(ma, am, m, a);
                break;
        }

        case S_SLC:
        case S_SRC:
        case S_SL:
        case S_SR: {
                if (mp->m_type == S_SRC || mp->m_type == S_SLC)
                        combine = 2;
                if (mp->m_type == S_SL || mp->m_type == S_SLC)
                        combine += 1;

                struct inst a = {0x001A + combine, 0x00};
                struct inst m = {0x0A80 + (combine << 6), 0x3F};
                eshift(a, m);
                break;
        }

        case S_OR:
        case S_XOR:
        case S_AND: {
                if (mp->m_type == S_OR) {
                        combine = 0x40;
                } else
                if (mp->m_type == S_XOR) {
                        combine = 0x80;
                }

                struct inst ma = {0x0500 | combine, 0x3F};
                struct inst am = {0x0700 | combine, 0x3F};
                struct inst ioa = {0x0060, 0x1F};
                ebit(def, ma, am, mp->m_type == S_XOR ? &ioa : NULL);
                break;
        }

        case S_NEG:
                combine = 0x40;
                /* fallthrough */
        case S_NOT: {
                struct inst m = {0x0A00 | combine, 0x3F};
                enot(def, m);
                break;
        }

        case S_SET1: {
                struct inst io = {0x0F00, 0x1F};
                struct inst m = {0x0310, 0x0F};
                ebitn(io, m, /*N offset*/5);
                break;
        }

        case S_SET0: {
                struct inst io = {0x0E00, 0x1F};
                struct inst m = {0x0300, 0x0F};
                ebitn(io, m, /*N offset*/5);
                break;
        }

        case S_CEQSN: {
                struct inst m = {0x0B80, 0xFF};
                def.op |= combine << 2;
                eskip(def, m);
                break;
        }

        case S_T1SN: {
                struct inst io = {0x0D00, 0x1F};
                struct inst m = {0x0210, 0x0F};
                ebitn(io, m, /*N offset*/5);
                break;
        }

        case S_T0SN: {
                struct inst io = {0x0C00, 0x1F};
                struct inst m = {0x0200, 0x0F};
                ebitn(io, m, /*N offset*/5);
                break;
        }

        case S_DZSN:
                combine = 0x40;
                /* fallthrough */
        case S_IZSN: {
                struct inst m = {0x0880 | combine, 0x3F};
                ezsn(def, m);
                break;
        }

        case S_RET: {
                struct inst k = {0x0100, 0xFF};
                eret(def, k);
                break;
        }

        case S_INC:
        case S_DEC:
        case S_CLEAR:
                def.mask = 0x3F;
                eone(def);
                break;

        case S_CALL:
        case S_GOTO: {
                struct expr e;
                clrexpr(&e);
                waddrmode =  1;
                expr(&e, 0);
                waddrmode =  0;
                outrwp(&e, def.op, 0x3FF, /*jump=*/1);
                break;
        }

        case S_XCH:
                def.mask = 0x3F;
                exch(def);
                break;

        case S_PUSHAF:
        case S_POPAF:
                epupo(def);
                break;

        case S_LDT16:
        case S_STT16:
                def.mask = 0x3E;
                eone(def);
                break;

        case S_SWAP:
        case S_PCADD:
              eopta(def);
              break;

        /* Simple instructions consisting of only one opcode and no args */
        case S_RETI:
        case S_NOP:
        case S_ENGINT:
        case S_DISGINT:
        case S_STOPSYS:
        case S_STOPEXE:
        case S_RESET:
        case S_WDRESET:
        case S_MUL:
        case S_LDSPTL: /* undocumented */
        case S_LDSPTH: /* undocumented */
                outaw(op);
                break;
        }
}

/*
 * Machine specific initialization
 */

VOID
minit(void)
{
        /*
         * Byte Order
         */
        hilo = 0;

        /*
         * Address Space
         */
        exprmasks(3);
}