OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [insight/] [sim/] [w65/] [gencode.c] - Blame information for rev 1774

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 578 markom
/* Program to write out opcode tables for the W65816 and friends
2
   Copyright (C) 1995 Free Software Foundation, Inc.
3
   Written by Steve Chamberlain sac@cygnus.com
4
 
5
 
6
GDB is free software; you can redistribute it and/or modify
7
it under the terms of the GNU General Public License as published by
8
the Free Software Foundation; either version 2, or (at your option)
9
any later version.
10
 
11
GDB is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
GNU General Public License for more details.
15
 
16
You should have received a copy of the GNU General Public License
17
along with this program; if not, write to the Free Software
18
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
19
 
20
 
21
#include <stdio.h>
22
 
23
 
24
struct opinfo
25
  {
26
    int code;
27
    char *opcode;
28
    char *mode;
29
    int clocks;
30
    int cpu;
31
    struct ainfo *ai;
32
    struct oinfo *oi;
33
  };
34
 
35
#define W16_ONLY 1
36
#define C02_ONLY 2
37
 
38
struct ainfo
39
  {
40
    char *name;
41
    char *enumname;
42
    char *disasmstring;
43
    char *sizer;
44
    char *reloc0;
45
    char *howlval;
46
 
47
    /* If addr val could be reg addr  - used for disasssmbly of
48
       args into reg names - you want lda <0x10 to turn into lda <r0
49
       but you don't want lda #0x10 to do the same. */
50
    char regflag;
51
  };
52
 
53
#define GET_M   1
54
#define SPECIAL_CASE    2
55
#define COP_GET         3
56
#define G2_GET          4
57
#define BRANCH          5
58
#define GET_X 6
59
#define STANDARD_PC_GET         7
60
#define PUSH_16 8
61
#define PUSH_8 9
62
#define PUSH_X 10
63
#define PUSH_M 11
64
#define POP_16 12
65
#define POP_8 13
66
#define POP_X 14
67
#define POP_M 15
68
#define STORE_M  16
69
#define STORE_X  17
70
struct oinfo
71
  {
72
    char *name;
73
    int howsrc;
74
    char *howto;
75
  };
76
struct oinfo olist[] =
77
{
78
  {"adc", GET_M, "{ int old_acc = GET_A; int old_src =src; src = old_src + old_acc + GET_CBIT; SET_NBIT_M(src); SET_VBIT_M(old_src, old_acc, src); SET_CBIT_M(src); SET_ZBIT_M(src); SET_A(src);}"},
79
  {"and", GET_M, "src = GET_A & src; SET_NBIT_M(src); SET_ZBIT_M(src);SET_A(src);"},
80
  {"asl", G2_GET, " src <<=1; SET_CBIT_M(src); SET_ZBIT_M(src);SET_NBIT_M(src);"},
81
  {"bcc", BRANCH, "GET_CBIT==0"},
82
  {"bcs", BRANCH, "GET_CBIT==1"},
83
  {"beq", BRANCH, "GET_ZBIT==1"},
84
  {"bit", GET_M, "SET_NBIT_M(src); SET_VBIT((src >> (GET_MBIT ? 6:14 ) &1)); SET_ZBIT_M (GET_A & src);"},
85
  {"bmi", BRANCH, "GET_NBIT==1"},
86
  {"bne", BRANCH, "GET_ZBIT==0"},
87
  {"bpl", BRANCH, "GET_NBIT==0"},
88
  {"bra", BRANCH, "1"},
89
  {"brk", SPECIAL_CASE,
90
   "\
91
{\
92
   if (GET_E == 1) \
93
     { PUSH16(GET_PC + 1); PUSH8 (GET_P | BFLAG); SET_P (GET_P | IFLAG); SET_ONLY_PC(fetch16 (0xfffe));}\
94
   else \
95
     { PUSH8 (GET_PBR_LOW); PUSH16 (GET_PC); PUSH8(GET_P); SET_P(GET_P |IFLAG); SET_PBRPC(fetch16 (0xffe6));};\
96
     }"},
97
  {"brl", BRANCH, "1"},
98
  {"bvc", BRANCH, "GET_VBIT==0"},
99
  {"bvs", BRANCH, "GET_VBIT==1"},
100
  {"clc", SPECIAL_CASE, "SET_CBIT(0);"},
101
  {"cld", SPECIAL_CASE, "SET_DBIT(0);"},
102
  {"cli", SPECIAL_CASE, "SET_IBIT(0);"},
103
  {"clv", SPECIAL_CASE, "SET_VBIT(0);"},
104
  {"cmp", GET_M, "src = GET_A - src; SET_ZBIT_M(src); SET_CBIT_M(~src); SET_NBIT_M(src);"},
105
  {"cop", COP_GET,
106
   "\
107
{\
108
   if (GET_E == 1) \
109
     { PUSH16(GET_PC + 1); PUSH8 (GET_P | BFLAG); SET_P ((GET_P | IFLAG) & ~DFLAG); SET_ONLY_PC(fetch16 (0xfff4));}\
110
   else \
111
     { PUSH8 (GET_PBR_LOW); PUSH16 (GET_PC); PUSH8(GET_P); SET_P((GET_P |IFLAG) & ~DFLAG); SET_PBRPC(fetch16 (0xffe4));};\
112
     }"},
113
  {"cpx", GET_X, "src = GET_X - src; SET_NBIT_X(src); SET_ZBIT_X(src); SET_CBIT_X(~src);"},
114
  {"cpy", GET_X, "src = GET_Y - src; SET_NBIT_X(src); SET_ZBIT_X(src); SET_CBIT_X(~src);"},
115
  {"dec", G2_GET, "src --; SET_NBIT_M(src); SET_ZBIT_M(src); "},
116
  {"dex", SPECIAL_CASE, "SET_X(GET_X -1); SET_NBIT_X(GET_X); SET_ZBIT_X(GET_X);"},
117
  {"dey", SPECIAL_CASE, "SET_Y(GET_Y -1); SET_NBIT_X(GET_Y); SET_ZBIT_X(GET_Y);"},
118
  {"eor", GET_M, "src = GET_A ^ src;  SET_NBIT_M(src); SET_ZBIT_M(src);SET_A(src); "},
119
  {"inc", G2_GET, "src ++; SET_NBIT_M(src); SET_ZBIT_M(src); "},
120
  {"inx", SPECIAL_CASE, "SET_X(GET_X +1); SET_NBIT_X(GET_X); SET_ZBIT_X(GET_X);"},
121
  {"iny", SPECIAL_CASE, "SET_Y(GET_Y +1); SET_NBIT_X(GET_Y); SET_ZBIT_X(GET_Y);"},
122
  {"jmp", STANDARD_PC_GET, "SET_ONLY_PC(lval);"},
123
  {"jsr", STANDARD_PC_GET, "if (l) { PUSH8(GET_PBR_LOW);} PUSH16(GET_PC); SET_ONLY_PC(lval);\n"},
124
  {"lda", GET_M, "SET_A(src); SET_NBIT_M(GET_A); SET_ZBIT_M(GET_A);"},
125
  {"ldx", GET_X, "SET_X(src);SET_NBIT_X(GET_X); SET_ZBIT_X(GET_X);"},
126
  {"ldy", GET_X, "SET_Y(src);SET_NBIT_X(GET_Y); SET_ZBIT_X(GET_Y);"},
127
  {"lsr", G2_GET,
128
       "SET_CBIT(src & 1); \
129
        SET_NBIT(0);       \
130
         src = src >> 1;   \
131
         SET_ZBIT_M(src);"},
132
  {"mvn", SPECIAL_CASE,
133
   "{ int dst_bank; int src_bank; dst_bank = fetch8 ( GET_PC)<<16; INC_PC(1); src_bank = fetch8 (GET_PC)<<16; INC_PC(1);\
134
       do {  store8 ( dst_bank + GET_X, fetch8 (src_bank +  GET_Y)); SET_X(GET_X+1); SET_Y(GET_Y+1); SET_A((GET_A-1) & 0xffff); } while (GET_A != 0xffff);}"},
135
  {"mvp", SPECIAL_CASE,
136
   "{ int dst_bank; int src_bank; dst_bank = fetch8 ( GET_PBRPC)<<16; INC_PC(1); src_bank = fetch8 (GET_PBRPC)<<16; INC_PC(1);\
137
       do {  store8 ( dst_bank + GET_X, fetch8 (src_bank + GET_Y)); SET_X(GET_X-1); SET_Y(GET_Y-1); SET_A((GET_A-1) & 0xffff); } while (GET_A != 0xffff);}"},
138
 
139
  {"nop", SPECIAL_CASE, ""},
140
{"ora", GET_M, "SET_A(GET_A | src); SET_NBIT_M(GET_A); SET_ZBIT_M(GET_A);"},
141
  {"pea", PUSH_16, "src = fetch16(GET_PBRPC); INC_PC(2);"},
142
  {"pei", PUSH_16, "src = fetch16(fetch8(GET_PBRPC) + GET_D); INC_PC(1);"},
143
  {"per", PUSH_16, "src = fetch16(GET_PBRPC) + GET_PC+2; INC_PC(2);"},
144
  {"pha", PUSH_M, "src = GET_A;"},
145
  {"phb", PUSH_8, "src = GET_DBR_LOW;"},
146
  {"phd", PUSH_16, "src = GET_DPR;"},
147
  {"phk", PUSH_8, "src = GET_PBR_LOW;"},
148
  {"php", PUSH_8, "src = GET_P;"},
149
  {"phx", PUSH_X, "src = GET_X;"},
150
  {"phy", PUSH_X, "src = GET_Y;"},
151
  {"pla", POP_M, "SET_A( src); SET_NBIT_M(GET_A);SET_ZBIT_M(GET_A);"},
152
  {"plb", POP_8, "SET_DBR_LOW(src);SET_NBIT_8(src); SET_ZBIT_8(src);"},
153
  {"pld", POP_16, "SET_DPR(src);SET_NBIT_16(src); SET_ZBIT_16(src);"},
154
  {"plp", POP_8, "SET_P(src); RETHINK;"},
155
  {"plx", POP_X, "SET_X(src);SET_NBIT_X(src);SET_ZBIT_X(src);"},
156
  {"ply", POP_X, "SET_Y(src);SET_NBIT_X(src);SET_ZBIT_X(src);"},
157
  {"rep", COP_GET, "SET_P(GET_P & ~src); RETHINK;"},
158
  {"rol", G2_GET, "src = (src << 1) | GET_CBIT; SET_CBIT((src >> (GET_MBIT ? 7 : 15)) &1); SET_ZBIT_M(src);"},
159
  {"ror", G2_GET, "{ int t = src; src  = (src>>1) | (GET_CBIT<<((GET_MBIT ? 8:16)-1));SET_NBIT_M(src);SET_ZBIT_M(src); SET_CBIT(t&1);}"},
160
  {"rti", SPECIAL_CASE, "{ int t; POP16(t); SET_ONLY_PC(t); if (GET_E==0) { POP8(t); SET_PBR(t);}  POP8(t);SET_P(t);}"},
161
  {"rtl", SPECIAL_CASE, "{ int t; POP24(t); SET_PBRPC(t);}"},
162
  {"rts", SPECIAL_CASE, "{ int t; POP16(t); SET_ONLY_PC(t);}"},
163
  {"sbc", GET_M,
164
   "{ int old_acc = GET_A & AMASK; int old_src = src & AMASK;  src = old_acc - old_src - !GET_CBIT; SET_A(src);\
165
    SET_CBIT(!(src>>(GET_MBIT?8:16) &1)); SET_VBIT_M(old_src,old_acc, src); SET_ZBIT_M(src); SET_NBIT_M(src);}"},
166
  {"sec", SPECIAL_CASE, "SET_CBIT(1);"},
167
  {"sed", SPECIAL_CASE, "SET_DBIT(1);"},
168
  {"sei", SPECIAL_CASE, "SET_IBIT(1);"},
169
  {"sep", COP_GET, "SET_P(GET_P | src);RETHINK;"},
170
  {"sta", STORE_M, "src = GET_A;"},
171
  {"stp", SPECIAL_CASE, "abort();"},
172
  {"stx", STORE_X, "src = GET_X;"},
173
  {"sty", STORE_X, "src = GET_Y;"},
174
  {"stz", STORE_M, "src = 0;"},
175
{"tax", SPECIAL_CASE, "SET_X(GET_A); SET_NBIT_X(GET_A);SET_ZBIT_X(GET_A);"},
176
{"tay", SPECIAL_CASE, "SET_Y(GET_A); SET_NBIT_X(GET_A);SET_ZBIT_X(GET_A);"},
177
  {"tcd", SPECIAL_CASE, "SET_DPR(GET_A); SET_NBIT_X(GET_A); SET_ZBIT_X(GET_A);"},
178
  {"tcs", SPECIAL_CASE, "SET_S(GET_A);"},
179
  {"tdc", SPECIAL_CASE, "SET_A(GET_DPR); SET_NBIT_M(GET_A); SET_ZBIT_M(GET_A);"},
180
  {"trb", G2_GET, "SET_ZBIT_M(src & GET_A); src = src & ~GET_A; "},
181
  {"tsb", G2_GET, "SET_ZBIT_M(src & GET_A); src = src | GET_A;"},
182
{"tsc", SPECIAL_CASE, "SET_A(GET_S); SET_NBIT_16(GET_A); SET_ZBIT_16(GET_A);"},
183
{"tsx", SPECIAL_CASE, "SET_X(GET_S); SET_NBIT_X(GET_X); SET_ZBIT_X(GET_X);"},
184
{"txa", SPECIAL_CASE, "SET_A(GET_X); SET_NBIT_M(GET_A); SET_ZBIT_M(GET_A);"},
185
  {"txs", SPECIAL_CASE, "SET_S(GET_X);"},
186
{"txy", SPECIAL_CASE, "SET_Y(GET_X); SET_NBIT_X(GET_Y); SET_ZBIT_X(GET_Y);"},
187
{"tya", SPECIAL_CASE, "SET_A(GET_Y); SET_NBIT_M(GET_A); SET_ZBIT_M(GET_A);"},
188
{"tyx", SPECIAL_CASE, "SET_X(GET_Y); SET_NBIT_X(GET_X); SET_ZBIT_X(GET_X);"},
189
  {"wai", SPECIAL_CASE, "wai();INC_PC(-1);"},
190
  {"wdm", SPECIAL_CASE, "SET_A(wdm(GET_A, GET_X));"},
191
  {"xba", SPECIAL_CASE,
192
   "if (GET_XBIT==0) { SET_A(((GET_A >> 8) & 0xff) | ((GET_A & 0xff)<<8));} else { int t = GET_A; SET_A(GET_B); SET_B(t);}; SET_NBIT_8(GET_A); SET_ZBIT_8(GET_A);"},
193
  {"xce", SPECIAL_CASE, "{ int t = GET_E; SET_E(GET_CBIT); SET_CBIT(GET_E);if (GET_E) { SET_MBIT(1); SET_XBIT(1);}}; goto top;"},
194
  0};
195
 
196
struct ainfo alist[] =
197
{
198
  {"#a", "IMMTOA", "#$0", "M==0 ? 2:1", "M==0 ? %sR_W65_ABS16 : %sR_W65_ABS8",   "lval = GET_PBRPC; INC_PC(GET_MBIT ? 1:2); ", 0},
199
  {"#c", "IMMCOP", "#$0", "1", "%sR_W65_ABS8",   "lval = GET_PBRPC; INC_PC(1); ", 0},
200
  {"#i", "IMMTOI", "#$0", "X==0 ? 2:1", "X==0 ? %sR_W65_ABS16 : %sR_W65_ABS8",   "lval = GET_PBRPC; INC_PC(GET_XBIT ? 1:2);", 0},
201
  {"A", "ACC", "a", "0", 0, "*FAIL**", 0},
202
  {"r", "PC_REL", "$0", "1", "%sR_W65_PCR8",   "lval = GET_PBR_HIGH + (0xffff &(fetch8sext(GET_PBRPC) + GET_PC + 1)); INC_PC(1);", 0},
203
  {"rl", "PC_REL_LONG", "$0", "2", "%sR_W65_PCR16",   "lval = GET_PBR_HIGH + (0xffff & (fetch16 (GET_PBRPC) + GET_PC + 2)); INC_PC(2);", 0},
204
  {"i", "IMPLIED", "", "0", "", 0},
205
  {"s", "STACK", "", "0", "", 0},
206
  {"d", "DIR", "<$0", "1", "%sR_W65_ABS8",   "lval = fetch8(GET_PBRPC) + GET_D; INC_PC(1);", 1},
207
  {"d,x", "DIR_IDX_X", "<$0,x", "1", "%sR_W65_ABS8",   "lval = fetch8(GET_PBRPC) + GET_X+ GET_D; INC_PC(1);", 1},
208
  {"d,y", "DIR_IDX_Y", "<$0,y", "1", "%sR_W65_ABS8",   "lval = fetch8(GET_PBRPC) + GET_Y + GET_D; INC_PC(1);", 1},
209
  {"(d)", "DIR_IND", "(<$0)", "1", "%sR_W65_ABS8",   "lval = GET_DBR_HIGH + (0xffff & fetch16(fetch8(GET_PBRPC) + GET_D));INC_PC(1);",1},
210
  {"(d,x)", "DIR_IDX_IND_X", "(<$0,x)", "1", "%sR_W65_ABS8",   "lval = GET_DBR_HIGH + (0xffff & (fetch8 (GET_PBRPC) + GET_D + GET_X)) ; INC_PC(1);",1},
211
  {"(d),y", "DIR_IND_IDX_Y", "(<$0),y", "1", "%sR_W65_ABS8",   "lval = fetch16(fetch8(GET_PBRPC) + GET_D) + GET_Y  + GET_DBR_HIGH;INC_PC(1);",1},
212
  {"[d]", "DIR_IND_LONG", "[$0]", "1", "%sR_W65_ABS8",   "lval = fetch24(GET_D + fetch8(GET_PBRPC));INC_PC(1);",1},
213
 
214
  {"[d],y", "DIR_IND_IDX_Y_LONG", "[$0],y", "1", "%sR_W65_ABS8",   "lval = fetch24(fetch8(GET_PBRPC) + GET_D) + GET_Y;INC_PC(1);",1},
215
 
216
  {"a", "ABS", "!$0", "2", "%sR_W65_ABS16",   "lval = fetch16(GET_PBRPC) + GET_DBR_HIGH; INC_PC(2) ; ",1},
217
  {"a,x", "ABS_IDX_X", "!$0,x", "2", "%sR_W65_ABS16",   "lval = fetch16(GET_PBRPC) + GET_DBR_HIGH + GET_X; INC_PC(2); ",1},
218
  {"a,y", "ABS_IDX_Y", "!$0,y", "2", "%sR_W65_ABS16",   "lval = fetch16(GET_PBRPC) + GET_DBR_HIGH + GET_Y; INC_PC(2); ", 1},
219
  {"al", "ABS_LONG", ">$0", "3", "%sR_W65_ABS24",   "lval = fetch24(GET_PBRPC); INC_PC(3);\nl=1;\n", 1},
220
  {"[a]", "ABS_IND_LONG", "[>$0]", "2", "%sR_W65_ABS16",   "lval = fetch24(fetch16(GET_PBRPC)); INC_PC(2);", 1},
221
  {"al,x", "ABS_LONG_IDX_X", ">$0,x", "3", "%sR_W65_ABS24",   "lval = fetch24(GET_PBRPC) + GET_X; INC_PC(3);", 1},
222
  {"d,s", "STACK_REL", "$0,s", "1", "%sR_W65_ABS8",   "lval = fetch8(GET_PBRPC) + GET_S; INC_PC(1);", 0},
223
  {"(d,s),y", "STACK_REL_INDX_IDX", "($0,s),y", "1", "%sR_W65_ABS8",   "lval = fetch16(fetch8(GET_PBRPC) + GET_S) + GET_DBR_HIGH + GET_Y;INC_PC(1);",0},
224
  {"(a)", "ABS_IND", "($0)", "2", "%sR_W65_ABS16",   "lval = fetch16(GET_PBRPC) + GET_DBR_HIGH; INC_PC(2);", 1},
225
  {"(a,x)", "ABS_IND_IDX", "($0,x)", "2", "%sR_W65_ABS16",
226
     "lval = fetch16((0xffff & (fetch16(GET_PBRPC) + GET_X )) + GET_PBR_HIGH) + GET_PBR_HIGH;INC_PC(2);",1},
227
  {"xyz", "BLOCK_MOVE", "", "2", "", 0},
228
  0};
229
 
230
 
231
struct opinfo optable[257] =
232
{
233
  {0x00, "brk", "s"},
234
  {0x01, "ora", "(d,x)"},
235
  {0x02, "cop", "#c"},
236
  {0x03, "ora", "d,s"},
237
  {0x04, "tsb", "d"},
238
  {0x05, "ora", "d"},
239
  {0x06, "asl", "d"},
240
  {0x07, "ora", "[d]"},
241
  {0x08, "php", "s"},
242
  {0x09, "ora", "#a"},
243
  {0x0a, "asl", "A"},
244
  {0x0b, "phd", "s"},
245
  {0x0c, "tsb", "a"},
246
  {0x0d, "ora", "a"},
247
  {0x0e, "asl", "a"},
248
  {0x0f, "ora", "al"},
249
  {0x10, "bpl", "r"},
250
  {0x11, "ora", "(d),y"},
251
  {0x12, "ora", "(d)"},
252
  {0x13, "ora", "(d,s),y"},
253
  {0x14, "trb", "d"},
254
  {0x15, "ora", "d,x"},
255
  {0x16, "asl", "d,x"},
256
  {0x17, "ora", "[d],y"},
257
  {0x18, "clc", "i"},
258
  {0x19, "ora", "a,y"},
259
  {0x1a, "inc", "A"},
260
  {0x1b, "tcs", "i"},
261
  {0x1c, "trb", "a"},
262
  {0x1d, "ora", "a,x"},
263
  {0x1e, "asl", "a,x"},
264
  {0x1f, "ora", "al,x"},
265
  {0x20, "jsr", "a"},
266
  {0x21, "and", "(d,x)"},
267
  {0x22, "jsr", "al"},
268
  {0x23, "and", "d,s"},
269
  {0x24, "bit", "(d)"},
270
  {0x25, "and", "d"},
271
  {0x26, "rol", "d"},
272
  {0x27, "and", "[d]"},
273
  {0x28, "plp", "s"},
274
  {0x29, "and", "#a"},
275
  {0x2a, "rol", "A"},
276
  {0x2b, "pld", "s"},
277
  {0x2c, "bit", "a"},
278
  {0x2d, "and", "a"},
279
  {0x2e, "rol", "a"},
280
  {0x2f, "and", "al"},
281
  {0x30, "bmi", "r"},
282
  {0x31, "and", "(d),y"},
283
  {0x32, "and", "(d)"},
284
  {0x33, "and", "(d,s),y"},
285
  {0x34, "bit", "(d,x)"},
286
  {0x35, "and", "d,x"},
287
  {0x36, "rol", "d,x"},
288
  {0x37, "and", "[d],y"},
289
  {0x38, "sec", "i"},
290
  {0x39, "and", "a,y"},
291
  {0x3a, "dec", "A"},
292
  {0x3b, "tsc", "i"},
293
  {0x3c, "bit", "a,x"},
294
  {0x3d, "and", "a,x"},
295
  {0x3e, "rol", "a,x"},
296
  {0x3f, "and", "al,x"},
297
  {0x40, "rti", "s"},
298
  {0x41, "eor", "(d,x)"},
299
  {0x42, "wdm", "i"},
300
  {0x43, "eor", "d,s"},
301
  {0x44, "mvp", "xyz"},
302
  {0x45, "eor", "d"},
303
  {0x46, "lsr", "d"},
304
  {0x47, "eor", "[d]"},
305
  {0x48, "pha", "s"},
306
  {0x49, "eor", "#a"},
307
  {0x4a, "lsr", "A"},
308
  {0x4b, "phk", "s"},
309
  {0x4c, "jmp", "a"},
310
  {0x4d, "eor", "a"},
311
  {0x4e, "lsr", "a"},
312
  {0x4f, "eor", "al"},
313
  {0x50, "bvc", "r"},
314
  {0x51, "eor", "(d),y"},
315
  {0x52, "eor", "(d)"},
316
  {0x53, "eor", "(d,s),y"},
317
  {0x54, "mvn", "xyz"},
318
  {0x55, "eor", "d,x"},
319
  {0x56, "lsr", "d,x"},
320
  {0x57, "eor", "[d],y"},
321
  {0x58, "cli", "i"},
322
  {0x59, "eor", "a,y"},
323
  {0x5a, "phy", "s"},
324
  {0x5b, "tcd", "i"},
325
  {0x5c, "jmp", "al"},
326
  {0x5d, "eor", "a,x"},
327
  {0x5e, "lsr", "a,x"},
328
  {0x5f, "eor", "al,x"},
329
  {0x60, "rts", "s"},
330
  {0x61, "adc", "(d,x)"},
331
  {0x62, "per", "rl"},
332
  {0x63, "adc", "d,s"},
333
  {0x64, "stz", "d"},
334
  {0x65, "adc", "d"},
335
  {0x66, "ror", "d"},
336
  {0x67, "adc", "[d]"},
337
  {0x68, "pla", "s"},
338
  {0x69, "adc", "#a"},
339
  {0x6a, "ror", "A"},
340
  {0x6b, "rtl", "s"},
341
  {0x6c, "jmp", "(a)"},
342
  {0x6d, "adc", "a"},
343
  {0x6e, "ror", "a"},
344
  {0x6f, "adc", "al"},
345
  {0x70, "bvs", "r"},
346
  {0x71, "adc", "(d),y"},
347
  {0x72, "adc", "(d)"},
348
  {0x73, "adc", "(d,s),y"},
349
  {0x74, "stz", "d,x"},
350
  {0x75, "adc", "d,x"},
351
  {0x76, "ror", "d,x"},
352
  {0x77, "adc", "[d],y"},
353
  {0x78, "sei", "i"},
354
  {0x79, "adc", "a,y"},
355
  {0x7a, "ply", "s"},
356
  {0x7b, "tdc", "i"},
357
  {0x7c, "jmp", "(a,x)"},
358
  {0x7d, "adc", "a,x"},
359
  {0x7e, "ror", "a,x"},
360
  {0x7f, "adc", "al,x"},
361
  {0x80, "bra", "r"},
362
  {0x81, "sta", "(d,x)"},
363
  {0x82, "brl", "rl"},
364
  {0x83, "sta", "d,s"},
365
  {0x84, "sty", "d"},
366
  {0x85, "sta", "d"},
367
  {0x86, "stx", "d"},
368
  {0x87, "sta", "[d]"},
369
  {0x88, "dey", "i"},
370
  {0x89, "bit", "#a"},
371
  {0x8a, "txa", "i"},
372
  {0x8b, "phb", "s"},
373
  {0x8c, "sty", "a"},
374
  {0x8d, "sta", "a"},
375
  {0x8e, "stx", "a"},
376
  {0x8f, "sta", "al"},
377
  {0x90, "bcc", "r"},
378
  {0x91, "sta", "(d),y"},
379
  {0x92, "sta", "(d)"},
380
  {0x93, "sta", "(d,s),y"},
381
  {0x94, "sty", "d,x"},
382
  {0x95, "sta", "d,x"},
383
  {0x96, "stx", "d,x"},
384
  {0x97, "sta", "[d],y"},
385
  {0x98, "tya", "i"},
386
  {0x99, "sta", "a,y"},
387
  {0x9a, "txs", "i"},
388
  {0x9b, "txy", "i"},
389
  {0x9c, "stz", "a"},
390
  {0x9d, "sta", "a,x"},
391
  {0x9e, "stz", "a,x"},
392
  {0x9f, "sta", "al,x"},
393
  {0xa0, "ldy", "#i"},
394
  {0xa1, "lda", "(d,x)"},
395
  {0xa2, "ldx", "#i"},
396
  {0xa3, "lda", "d,s"},
397
  {0xa4, "ldy", "d"},
398
  {0xa5, "lda", "d"},
399
  {0xa6, "ldx", "d"},
400
  {0xa7, "lda", "[d]"},
401
  {0xa8, "tay", "i"},
402
  {0xa9, "lda", "#a"},
403
  {0xaa, "tax", "i"},
404
  {0xab, "plb", "s"},
405
  {0xac, "ldy", "a"},
406
  {0xad, "lda", "a"},
407
  {0xae, "ldx", "a"},
408
  {0xaf, "lda", "al"},
409
  {0xb0, "bcs", "r"},
410
  {0xb1, "lda", "(d),y"},
411
  {0xb2, "lda", "(d)"},
412
  {0xb3, "lda", "(d,s),y"},
413
  {0xb4, "ldy", "d,x"},
414
  {0xb5, "lda", "d,x"},
415
  {0xb6, "ldx", "d,y"},
416
  {0xb7, "lda", "[d],y"},
417
  {0xb8, "clv", "i"},
418
  {0xb9, "lda", "a,y"},
419
  {0xba, "tsx", "i"},
420
  {0xbb, "tyx", "i"},
421
  {0xbc, "ldy", "a,x"},
422
  {0xbd, "lda", "a,x"},
423
  {0xbe, "ldx", "a,y"},
424
  {0xbf, "lda", "al,x"},
425
  {0xc0, "cpy", "#i"},
426
  {0xc1, "cmp", "(d,x)"},
427
  {0xc2, "rep", "#c"},
428
  {0xc3, "cmp", "d,s"},
429
  {0xc4, "cpy", "d"},
430
  {0xc5, "cmp", "d"},
431
  {0xc6, "dec", "d"},
432
  {0xc7, "cmp", "[d]"},
433
  {0xc8, "iny", "i"},
434
  {0xc9, "cmp", "#a"},
435
  {0xca, "dex", "i"},
436
  {0xcb, "wai", "i"},
437
  {0xcc, "cpy", "a"},
438
  {0xcd, "cmp", "a"},
439
  {0xce, "dec", "a"},
440
  {0xcf, "cmp", "al"},
441
  {0xd0, "bne", "r"},
442
  {0xd1, "cmp", "(d),y"},
443
  {0xd2, "cmp", "(d)"},
444
  {0xd3, "cmp", "(d,s),y"},
445
  {0xd4, "pei", "d"},
446
  {0xd5, "cmp", "d,x"},
447
  {0xd6, "dec", "d,x"},
448
  {0xd7, "cmp", "[d],y"},
449
  {0xd8, "cld", "i"},
450
  {0xd9, "cmp", "a,y"},
451
  {0xda, "phx", "s"},
452
  {0xdb, "stp", "i"},
453
  {0xdc, "jmp", "[a]"},
454
  {0xdd, "cmp", "a,x"},
455
  {0xde, "dec", "a,x"},
456
  {0xdf, "cmp", "al,x"},
457
  {0xe0, "cpx", "#i"},
458
  {0xe1, "sbc", "(d,x)"},
459
  {0xe2, "sep", "#c"},
460
  {0xe3, "sbc", "d,s"},
461
  {0xe4, "cpx", "d"},
462
  {0xe5, "sbc", "d"},
463
  {0xe6, "inc", "d"},
464
  {0xe7, "sbc", "[d]"},
465
  {0xe8, "inx", "i"},
466
  {0xe9, "sbc", "#a"},
467
  {0xea, "nop", "i"},
468
  {0xeb, "xba", "i"},
469
  {0xec, "cpx", "a"},
470
  {0xed, "sbc", "a"},
471
  {0xee, "inc", "a"},
472
  {0xef, "sbc", "al"},
473
  {0xf0, "beq", "r"},
474
  {0xf1, "sbc", "(d),y"},
475
  {0xf2, "sbc", "(d)"},
476
  {0xf3, "sbc", "(d,s),y"},
477
  {0xf4, "pea", "a"},
478
  {0xf5, "sbc", "d,x"},
479
  {0xf6, "inc", "d,x"},
480
  {0xf7, "sbc", "[d],y"},
481
  {0xf8, "sed", "i"},
482
  {0xf9, "sbc", "a,y"},
483
  {0xfa, "plx", "s"},
484
  {0xfb, "xce", "i"},
485
  {0xfc, "jsr", "(a,x)"},
486
  {0xfd, "sbc", "a,x"},
487
  {0xfe, "inc", "a,x"},
488
  {0xff, "sbc", "al,x"},
489
  0};
490
 
491
 
492
int pfunc(a,b)
493
struct opinfo *a;
494
struct opinfo *b;
495
{
496
return strcmp(a->mode, b->mode);
497
 
498
}
499
static void
500
dump_table ()
501
{
502
  int x;
503
  int y;
504
  printf ("  |");
505
  for (x = 0; x < 16; x++)
506
    {
507
      printf ("   %x   |", x);
508
    }
509
  printf ("\n");
510
  printf ("  |");
511
  for (x = 0; x < 16; x++)
512
    {
513
      printf ("-------|");
514
    }
515
  printf ("\n");
516
 
517
  for (y = 0; y < 16; y++)
518
    {
519
      printf ("%x |", y);
520
      for (x = 0; x < 16; x++)
521
        {
522
          struct opinfo *p = &optable[y * 16 + x];
523
          if (p->opcode)
524
            {
525
              printf ("%-7s", p->opcode);
526
            }
527
          else
528
            {
529
              printf ("*******");
530
            }
531
          printf ("|");
532
        }
533
      printf ("\n");
534
      printf ("  |");
535
 
536
      for (x = 0; x < 16; x++)
537
        {
538
          struct opinfo *p = &optable[y * 16 + x];
539
          if (p->mode)
540
            {
541
              printf ("%-7s", p->mode);
542
            }
543
          else
544
            {
545
              printf ("*******");
546
            }
547
          printf ("|");
548
        }
549
      printf ("\n");
550
      printf ("  |");
551
      for (x = 0; x < 16; x++)
552
        {
553
          printf ("-------|");
554
        }
555
 
556
 
557
      printf ("\n");
558
    }
559
}
560
 
561
dt ()
562
{
563
#if 0
564
  int i;
565
  for (i = 0; i < 256; i++)
566
    {
567
      struct opinfo *p = &optable[i];
568
      printf ("/* %02x */ ", i);
569
      if (p->opcode)
570
        printf ("{\"%s\",\"%s\",%d,%d},", p->opcode->name, p->addr->name);
571
 
572
      printf ("\n");
573
    }
574
#endif
575
 
576
}
577
static
578
void
579
init_table ()
580
{
581
  int i;
582
  for (i = 0; i < 256; i++)
583
    {
584
      struct opinfo *p = optable + i;
585
      struct ainfo *a;
586
      struct oinfo *o;
587
      for (a = alist; a->name; a++)
588
        {
589
          if (strcmp (a->name, p->mode) == 0)
590
            {
591
              p->ai = a;
592
              goto done;
593
            }
594
        }
595
      printf ("bad %x\n", i);
596
    done:;
597
      for (o = olist; o->name; o++)
598
        {
599
          if (strcmp (o->name, p->opcode) == 0)
600
            {
601
              p->oi = o;
602
              goto doneo;
603
            }
604
        }
605
      printf ("bad %x\n", i);
606
    doneo:;
607
 
608
    }
609
}
610
 
611
/* Dump the opcodes sorted by name */
612
static
613
void
614
assembler_table (as)
615
{
616
  int i;
617
  struct oinfo *o;
618
  struct ainfo *a;
619
  int n = 0;
620
  /* Step through the sorted list of opnames */
621
  printf ("                     /* WDC 65816 Assembler opcode table */\n");
622
  printf ("                     /*   (generated by the program sim/w65/gencode -a) */\n");
623
 
624
  for (a = alist; a->name; a++)
625
    {
626
      printf ("#define ADDR_%-20s%d\t /* %-7s */\n", a->enumname, ++n, a->name);
627
    }
628
 
629
  printf ("struct opinfo {\n\tint val;\n\tint code;\n\tchar *name;\n\tint amode;\n};\n");
630
 
631
  printf ("struct opinfo optable[257]={\n");
632
  if (as)
633
    {
634
      i = 1;
635
      for (o = olist; o->name; o++)
636
        {
637
          printf ("#define O_%s %d\n", o->name, i++);
638
        }
639
 
640
      qsort (optable, 256, sizeof (struct opinfo), pfunc);
641
 
642
      printf ("#ifdef DEFINE_TABLE\n");
643
      for (o = olist; o->name; o++)
644
        {
645
 
646
          for (i = 0; i < 256; i++)
647
            {
648
              struct opinfo *p = optable + i;
649
 
650
              if (p->oi == o)
651
                {
652
                  /* This opcode is of the right name */
653
                  printf ("\t{0x%02X,\tO_%s,\t\"%s\",\tADDR_%s},\n", p->code, p->oi->name, p->oi->name, p->ai->enumname);
654
                }
655
            }
656
        }
657
    }
658
  else
659
    {
660
      for (i = 0; i < 256; i++)
661
        {
662
          struct opinfo *p = optable + i;
663
          printf ("\t{0x%02X,\t\"%s\",\tADDR_%s},\n", i, p->oi->name, p->ai->enumname);
664
        }
665
    }
666
 
667
  printf ("0};\n");
668
  printf ("#endif\n");
669
 
670
 
671
  /* Generate the operand disassembly case list */
672
 
673
  printf ("#define DISASM()\\\n");
674
  {
675
    struct ainfo *a;
676
    for (a = alist; a->name; a++)
677
      {
678
        printf ("  case ADDR_%s:\\\n\t", a->enumname);
679
        if (strcmp (a->enumname, "BLOCK_MOVE") == 0)
680
          {
681
            printf ("args[0] = (asR_W65_ABS16 >>8) &0xff;\\\n");
682
            printf ("\targs[1] = ( asR_W65_ABS16 & 0xff);\\\n");
683
            printf ("\tprint_operand (0,\"\t$0,$1\",args);\\\n");
684
          }
685
        else if (a->reloc0 == 0)
686
          {
687
            printf ("print_operand (0, \"\t%s\", 0);\\\n", a->disasmstring );
688
          }
689
        else if (strlen (a->reloc0))
690
          {
691
            printf ("args[0] = ");
692
            printf (a->reloc0, "as","as");
693
            printf (";\\\n");
694
            printf ("\tprint_operand (%d, \"\t%s\", args);\\\n",
695
                    a->regflag,
696
                    a->disasmstring);
697
          }
698
 
699
        printf ("\tsize += %s;\\\n\tbreak;\\\n", a->sizer);
700
      }
701
  }
702
 
703
  printf ("\n");
704
 
705
  /* Generate the operand size and type case list */
706
 
707
  printf ("#define GETINFO(size,type,pcrel)\\\n");
708
  {
709
    struct ainfo *a;
710
    for (a = alist; a->name; a++)
711
      {
712
        printf ("\tcase ADDR_%s: ", a->enumname);
713
        printf ("size = %s;type=", a->sizer);
714
        if (a->reloc0 && strlen (a->reloc0))
715
          {
716
            printf (a->reloc0, "", "");
717
          }
718
        else
719
          printf ("-1");
720
        printf (";pcrel=%d;", a->name[0] == 'P');
721
        printf ("break;\\\n");
722
      }
723
  }
724
  printf ("\n");
725
}
726
 
727
 
728
/* Write out examples of each opcode */
729
static
730
void
731
test_table ()
732
{
733
  struct opinfo *o;
734
  for (o = optable; o->opcode; o++)
735
    {
736
      printf ("\t%s\t", o->opcode);
737
      printf (o->ai->disasmstring, 0x6543210, 0x6543210);
738
      printf ("\n");
739
    }
740
 
741
}
742
 
743
static void
744
op_table ()
745
{
746
  struct opinfo *o;
747
  int i = 0;
748
  /* Write four optables, M=0,1 X=0,1 */
749
 
750
  for (o = optable; o->opcode; o++)
751
    {
752
      printf ("{0x%02x, \"%s\", \"%s\"\t},\n",
753
              i++,
754
              o->opcode,
755
              o->mode);
756
    }
757
}
758
 
759
int worked_out_lval;
760
static void
761
genfetch (amode, size)
762
     struct ainfo *amode;
763
     int size;
764
{
765
  if (amode->howlval)
766
    {
767
      if (strcmp (amode->name, "A") == 0)
768
        {
769
          /* Can't get the lval for the accumulator */
770
          printf ("src = GET_A;\n");
771
        }
772
      else
773
        {
774
          printf ("%s\n", amode->howlval);
775
worked_out_lval = 1;
776
          if (size == 0)
777
            {
778
              printf ("src = fetch16 (lval);\n");
779
            }
780
          else
781
            {
782
              printf ("src = fetch8 (lval);\n");
783
            }
784
        }
785
    }
786
 
787
}
788
 
789
static void
790
genstore (amode, size)
791
     struct ainfo *amode;
792
     int size;
793
{
794
  if (amode->howlval)
795
    {
796
      if (strcmp (amode->name, "A") == 0)
797
        {
798
          /* Can't get the lval for the accumulator */
799
          printf ("SET_A (src);\n");
800
        }
801
      else
802
        {
803
          if (!worked_out_lval)
804
            printf ("%s\n", amode->howlval);
805
          if (size == 0)
806
            {
807
              printf ("store16(lval, src);\n");
808
            }
809
          else
810
            {
811
              printf ("store8(lval, src);\n");
812
            }
813
        }
814
    }
815
}
816
/* Generate the code to simulate the instructions */
817
static void
818
code_table ()
819
{
820
  struct opinfo *o;
821
  int x, m;
822
  printf("#include \"interp.h\"\n");
823
 
824
  for (x = 0; x < 2; x++) {
825
    for (m = 0; m < 2; m++) {
826
      printf("ifunc_X%d_M%d() {\n",x,m);
827
      printf("#undef GET_MBIT\n");
828
      printf("#undef GET_XBIT\n");
829
      printf("#define GET_XBIT %d\n", x);
830
      printf("#define GET_MBIT %d\n", m);
831
      printf("STARTFUNC();\n");
832
      printf("do { register opcode = fetch8(GET_PBRPC); insts++; INC_PC(1);\n");
833
      printf ("switch (opcode) {\n");
834
      for (o = optable; o->opcode; o++)
835
        {
836
          printf ("             /* %s %s */\n", o->opcode, o->ai->name);
837
          printf ("case 0x%02x:\n", o->code);
838
          printf ("{\n");
839
          printf ("int l ;\n");
840
          printf ("register int src;\n");
841
          printf ("register int lval;\n");
842
worked_out_lval = 0;
843
          switch (o->oi->howsrc)
844
            {
845
            case POP_M:
846
              if (m == 0)
847
                printf ("POP16 (src);");
848
              else
849
                printf ("POP8(src);");
850
              break;
851
            case POP_X:
852
              if (x == 0)
853
                printf ("POP16 (src);");
854
              else
855
                printf ("POP8 (src);");
856
              break;
857
            case POP_8:
858
              printf ("POP8 (src);");
859
              break;
860
            case POP_16:
861
              printf ("POP16 (src);");
862
              break;
863
 
864
            case STANDARD_PC_GET:
865
              printf ("%s\n", o->ai->howlval);
866
              break;
867
 
868
            case GET_M:
869
              genfetch (o->ai, m);
870
              break;
871
            case G2_GET:
872
              genfetch (o->ai, m);
873
              break;
874
            case GET_X:
875
              genfetch (o->ai, x);
876
              break;
877
            case BRANCH:
878
              printf ("%s", o->ai->howlval);
879
              break;
880
            case COP_GET:
881
              genfetch(o->ai,1);
882
              break;
883
            case STORE_X:
884
            case STORE_M:
885
              ;
886
            }
887
 
888
          switch (o->oi->howsrc)
889
            {
890
            case BRANCH:
891
              printf ("if (%s) { SET_ONLY_PC(lval);} ", o->oi->howto);
892
              break;
893
            case SPECIAL_CASE:
894
            case GET_M:
895
            case GET_X:
896
            case STORE_X:
897
            case STANDARD_PC_GET:
898
            case G2_GET:
899
            case PUSH_16:
900
            case PUSH_8:
901
            case PUSH_M:
902
            case PUSH_X:
903
            case POP_16:
904
            case POP_8:
905
            case POP_M:
906
            case POP_X:
907
            case COP_GET:
908
            case STORE_M:
909
              printf ("%s", o->oi->howto);
910
              break;
911
            }
912
 
913
          switch (o->oi->howsrc)
914
            {
915
            case STORE_M:
916
              genstore (o->ai, m);
917
              break;
918
            case STORE_X:
919
              genstore (o->ai, x);
920
              break;
921
            case PUSH_M:
922
              if (m == 0)
923
                printf ("PUSH16 (src);");
924
              else
925
                printf ("PUSH8(src);");
926
              break;
927
            case PUSH_X:
928
              if (x == 0)
929
                printf ("PUSH16 (src);");
930
              else
931
                printf ("PUSH8 (src);");
932
              break;
933
            case PUSH_8:
934
              printf ("PUSH8 (src);");
935
              break;
936
            case PUSH_16:
937
              printf ("PUSH16 (src);");
938
              break;
939
            case G2_GET:
940
              genstore (o->ai, x, m);
941
              break;
942
            }
943
          printf ("}\n");
944
 
945
          printf ("break;\n");
946
        }
947
      printf ("}\n}\n");
948
      printf("while (!saved_state.exception);\n");
949
      printf("#undef GET_MBIT\n");
950
      printf("#undef GET_XBIT\n");
951
      printf("#define GET_MBIT (the_mbit)\n");
952
      printf("#define GET_XBIT (the_xbit)\n");
953
 
954
      printf("ENDFUNC();\n");
955
      printf("}");
956
    }
957
  }
958
}
959
 
960
int
961
main (ac, av)
962
     char **av;
963
{
964
  init_table ();
965
 
966
  if (ac > 1)
967
    {
968
      if (av[1][1] == 'a')
969
        {
970
          assembler_table (1);
971
        }
972
      if (av[1][1] == 't')
973
        {
974
          test_table ();
975
        }
976
      if (av[1][1] == 'o')
977
        {
978
          op_table ();
979
        }
980
      if (av[1][1] == 'c')
981
        {
982
          code_table ();
983
        }
984
    }
985
  else
986
    dump_table ();
987
 
988
  dt ();
989
 
990
  return 0;
991
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.