-
Notifications
You must be signed in to change notification settings - Fork 4
/
Dasm68000.h
427 lines (402 loc) · 16.1 KB
/
Dasm68000.h
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
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
/***************************************************************************
* dasmfw -- Disassembler Framework *
* *
* 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 2 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, write to the Free Software *
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
***************************************************************************/
/*****************************************************************************/
/* Dasm68000.h : definition of the Dasm68000 class */
/*****************************************************************************/
#ifndef __Dasm68000_h_defined__
#define __Dasm68000_h_defined__
#include "Disassembler.h"
/*****************************************************************************/
/* Dasm68000 : class for a Motorola 68000 processor */
/*****************************************************************************/
class Dasm68000 :
public Disassembler
{
public:
Dasm68000(Application *pApp);
virtual ~Dasm68000(void);
// Overrides
public:
// return processor long name
virtual string GetName() { return "Motorola 68000"; }
// return whether big- or little-endian
virtual Endian GetEndianness() { return BigEndian; }
// return bus width
virtual int GetBusWidth(int bus = BusCode) { (void)bus; return 24; }
// return code bits
virtual int GetCodeBits() { return 32; }
// return code pointer size in bytes
virtual int GetCodePtrSize() { return 4; }
// return highest possible code address
virtual cadr_t GetHighestCodeAddr() { return 0xffffff; }
// return data bits
virtual int GetDataBits() { return 16; }
// return data pointer size in bytes
virtual int GetDataPtrSize() { return 4; }
// return highest possible data address
virtual dadr_t GetHighestDataAddr() { return 0xffffff; }
// Options handler
protected:
int Set68000Option(string name, string value);
string Get68000Option(string name);
// the real disassembler activities
protected:
// parse data area for labels
virtual adr_t ParseData(adr_t addr, int bus = BusCode);
// parse instruction at given memory address for labels
virtual adr_t ParseCode(adr_t addr, int bus = BusCode);
// pass back correct mnemonic and parameters for a label
virtual bool DisassembleLabel(Label *label, string &slabel, string &smnemo, string &sparm, int bus = BusCode);
// pass back correct mnemonic and parameters for a DefLabel
virtual bool DisassembleDefLabel(DefLabel *label, string &slabel, string &smnemo, string &sparm, int bus = BusCode);
// disassemble data area at given memory address
virtual adr_t DisassembleData(adr_t addr, adr_t end, uint32_t flags, string &smnemo, string &sparm, int maxparmlen, int bus = BusCode);
// disassemble instruction at given memory address
virtual adr_t DisassembleCode(adr_t addr, string &smnemo, string &sparm, int bus = BusCode);
public:
// Initialize parsing
virtual bool InitParse(int bus = BusCode);
// pass back disassembler-specific state changes before/after a disassembly line
virtual bool DisassembleChanges(adr_t addr, adr_t prevaddr, adr_t prevsz, bool bAfterLine, vector<LineChange> &changes, int bus = BusCode);
// create hex / ASCII representation of the current area
virtual bool DisassembleHexAsc(adr_t addr, adr_t len, adr_t max, string &sHex, string &sAsc, int bus = BusCode)
{
// 68000 displays hex in word-sized quantities instead of bytes
sAsc = "\'";
adr_t i;
for (i = 0; i < len; i++)
{
uint8_t c = GetUByte(addr + i, bus);
sHex += sformat("%02X%s", c, (i & 1) ? " " : "");
sAsc += (isprint(c)) ? c : '.';
}
sAsc += '\'';
for (; i < max; i++)
{
sHex += (i & 1) ? " " : " ";
sAsc += ' ';
}
return true;
}
protected:
virtual bool String2Number(string s, adr_t &value);
virtual string Number2String(adr_t value, int nDigits, adr_t addr, int bus = BusCode);
virtual string Address2String(adr_t addr, int bus = BusCode)
{ (void)bus; return sformat("%s%06x", hdrHex.c_str(), addr); }
protected:
enum OpType
{
optype_unknown,
optype_01,
optype_02,
optype_03,
optype_04,
optype_05,
optype_06,
optype_07,
optype_08,
optype_09,
optype_10,
optype_11,
optype_12,
optype_13,
optype_14,
optype_15,
optype_16,
optype_17,
optype_18,
optype_19,
optype_20,
optype_21,
optype_22,
optype_23,
optype_24,
optype_25,
optype_26,
optype_27,
optype_28,
optype_29,
OpType68000_count
};
enum Mnemonics68000
{
_equ,
_org,
_phase,
_dephase,
_end,
_ill, /* illegal */
_abcd,
_adda,
_addi,
_addq,
_addx,
_add,
_and,
_andi,
_asl,
_asr,
_bcc,
_bchg,
_bclr,
_bcs,
_beq,
_bge,
_bgt,
_bhi,
_ble,
_bls,
_blt,
_bmi,
_bne,
_bpl,
_bra,
_bset,
_bsr,
_btst,
_bvc,
_bvs,
_chk,
_clr,
_cmp,
_cmpa,
_cmpi,
_cmpm,
_dbcc,
_dbcs,
_dbeq,
_dbf,
_dbge,
_dbgt,
_dbhi,
_dble,
_dbls,
_dblt,
_dbmi,
_dbne,
_dbpl,
_dbt,
_dbvc,
_dbvs,
_divs,
_divu,
_eor,
_eori,
_exg,
_ext,
_jmp,
_jsr,
_lea,
_link,
_lsl,
_lsr,
_move,
_move_b,
_move_w,
_move_l,
_movem,
_movep_w,
_movep_l,
_moveq,
_muls,
_mulu,
_nbcd,
_neg,
_negx,
_nop,
_not,
_or,
_ori,
_pea,
_reset,
_rol,
_ror,
_roxl,
_roxr,
_rte,
_rtr,
_rts,
_sbcd,
_scc,
_scs,
_seq,
_sf,
_sge,
_sgt,
_shi,
_sle,
_sls,
_slt,
_smi,
_sne,
_spl,
_st,
_stop,
_sub,
_suba,
_subi,
_subq,
_subx,
_svc,
_svs,
_swap,
_tas,
_trap,
_trapv,
_tst,
_unlk,
// Pseudo-Ops:
_dc,
_rmb,
mnemo68000_count
};
struct OpDef
{
Mnemonics68000 mnemo; /* mnemonic */
uint16_t op_code; /* base op code */
uint16_t mask; /* mask to remove variable data */
OpType ot; /* op type */
};
enum
{
optblSize = 143
};
enum Reg68000
{
_unkr,
_a0,
_a1,
_a2,
_a3,
_a4,
_a5,
_a6,
_a7,
_d0,
_d1,
_d2,
_d3,
_d4,
_d5,
_d6,
_d7,
_pc,
_ccr,
_sr,
_usp,
reg68000_count
};
static OpDef OpTable[optblSize];
static OpCode opcodes[mnemo68000_count];
uint8_t *otIndex;
static const char *regnames[reg68000_count];
#if 1
string asmtype; /* assembler type */
#else
bool gas; /* flag whether GNU assembler output */
#endif
bool useFCC;
bool closeCC;
// TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST
bool showInstTypes;
string sExtByte, sExtShort, sExtWord, sExtLong, sExtQuad;
string hdrHex, hdrDec, hdrOct, hdrBin;
protected:
virtual void SetAsmType(string &newType);
virtual adr_t ParseEffectiveAddress(adr_t instaddr, adr_t addr, uint16_t ea, int16_t index, int op_mode);
virtual adr_t ParseOptype01(adr_t instaddr, adr_t addr, uint16_t code, int optable_index);
virtual adr_t ParseOptype02(adr_t instaddr, adr_t addr, uint16_t code, int optable_index);
virtual adr_t ParseOptype03(adr_t instaddr, adr_t addr, uint16_t code, int optable_index);
virtual adr_t ParseOptype04(adr_t instaddr, adr_t addr, uint16_t code, int optable_index);
virtual adr_t ParseOptype05(adr_t instaddr, adr_t addr, uint16_t code, int optable_index);
virtual adr_t ParseOptype06(adr_t instaddr, adr_t addr, uint16_t code, int optable_index);
virtual adr_t ParseOptype07(adr_t instaddr, adr_t addr, uint16_t code, int optable_index);
virtual adr_t ParseOptype08(adr_t instaddr, adr_t addr, uint16_t code, int optable_index);
virtual adr_t ParseOptype09(adr_t instaddr, adr_t addr, uint16_t code, int optable_index);
virtual adr_t ParseOptype10(adr_t instaddr, adr_t addr, uint16_t code, int optable_index);
virtual adr_t ParseOptype11(adr_t instaddr, adr_t addr, uint16_t code, int optable_index);
virtual adr_t ParseOptype12(adr_t instaddr, adr_t addr, uint16_t code, int optable_index);
virtual adr_t ParseOptype13(adr_t instaddr, adr_t addr, uint16_t code, int optable_index);
virtual adr_t ParseOptype14(adr_t instaddr, adr_t addr, uint16_t code, int optable_index);
virtual adr_t ParseOptype15(adr_t instaddr, adr_t addr, uint16_t code, int optable_index);
virtual adr_t ParseOptype16(adr_t instaddr, adr_t addr, uint16_t code, int optable_index);
virtual adr_t ParseOptype17(adr_t instaddr, adr_t addr, uint16_t code, int optable_index);
virtual adr_t ParseOptype18(adr_t instaddr, adr_t addr, uint16_t code, int optable_index);
virtual adr_t ParseOptype19(adr_t instaddr, adr_t addr, uint16_t code, int optable_index);
virtual adr_t ParseOptype20(adr_t instaddr, adr_t addr, uint16_t code, int optable_index);
virtual adr_t ParseOptype21(adr_t instaddr, adr_t addr, uint16_t code, int optable_index);
virtual adr_t ParseOptype22(adr_t instaddr, adr_t addr, uint16_t code, int optable_index);
virtual adr_t ParseOptype23(adr_t instaddr, adr_t addr, uint16_t code, int optable_index);
virtual adr_t ParseOptype24(adr_t instaddr, adr_t addr, uint16_t code, int optable_index);
virtual adr_t ParseOptype25(adr_t instaddr, adr_t addr, uint16_t code, int optable_index);
virtual adr_t ParseOptype26(adr_t instaddr, adr_t addr, uint16_t code, int optable_index);
virtual adr_t ParseOptype27(adr_t instaddr, adr_t addr, uint16_t code, int optable_index);
virtual adr_t ParseOptype28(adr_t instaddr, adr_t addr, uint16_t code, int optable_index);
virtual adr_t ParseOptype29(adr_t instaddr, adr_t addr, uint16_t code, int optable_index);
virtual const char *GetAddrReg(int i);
virtual const char *GetDataReg(int i);
virtual const char *GetSizeSuffix(int sizeCode);
virtual int GetEffectiveAddressRegNum(uint16_t ea);
virtual adr_t DisassembleEffectiveAddress(adr_t instaddr, adr_t addr, string &s, uint16_t ea, int16_t index, int op_mode);
virtual adr_t DisassembleOptype01(adr_t instaddr, adr_t addr, uint16_t code, int optable_index, string &smnemo, string &sparm);
virtual adr_t DisassembleOptype02(adr_t instaddr, adr_t addr, uint16_t code, int optable_index, string &smnemo, string &sparm);
virtual adr_t DisassembleOptype03(adr_t instaddr, adr_t addr, uint16_t code, int optable_index, string &smnemo, string &sparm);
virtual adr_t DisassembleOptype04(adr_t instaddr, adr_t addr, uint16_t code, int optable_index, string &smnemo, string &sparm);
virtual adr_t DisassembleOptype05(adr_t instaddr, adr_t addr, uint16_t code, int optable_index, string &smnemo, string &sparm);
virtual adr_t DisassembleOptype06(adr_t instaddr, adr_t addr, uint16_t code, int optable_index, string &smnemo, string &sparm);
virtual adr_t DisassembleOptype07(adr_t instaddr, adr_t addr, uint16_t code, int optable_index, string &smnemo, string &sparm);
virtual adr_t DisassembleOptype08(adr_t instaddr, adr_t addr, uint16_t code, int optable_index, string &smnemo, string &sparm);
virtual adr_t DisassembleOptype09(adr_t instaddr, adr_t addr, uint16_t code, int optable_index, string &smnemo, string &sparm);
virtual adr_t DisassembleOptype10(adr_t instaddr, adr_t addr, uint16_t code, int optable_index, string &smnemo, string &sparm);
virtual adr_t DisassembleOptype11(adr_t instaddr, adr_t addr, uint16_t code, int optable_index, string &smnemo, string &sparm);
virtual adr_t DisassembleOptype12(adr_t instaddr, adr_t addr, uint16_t code, int optable_index, string &smnemo, string &sparm);
virtual adr_t DisassembleOptype13(adr_t instaddr, adr_t addr, uint16_t code, int optable_index, string &smnemo, string &sparm);
virtual adr_t DisassembleOptype14(adr_t instaddr, adr_t addr, uint16_t code, int optable_index, string &smnemo, string &sparm);
virtual adr_t DisassembleOptype15(adr_t instaddr, adr_t addr, uint16_t code, int optable_index, string &smnemo, string &sparm);
virtual adr_t DisassembleOptype16(adr_t instaddr, adr_t addr, uint16_t code, int optable_index, string &smnemo, string &sparm);
virtual adr_t DisassembleOptype17(adr_t instaddr, adr_t addr, uint16_t code, int optable_index, string &smnemo, string &sparm);
virtual adr_t DisassembleOptype18(adr_t instaddr, adr_t addr, uint16_t code, int optable_index, string &smnemo, string &sparm);
virtual adr_t DisassembleOptype19(adr_t instaddr, adr_t addr, uint16_t code, int optable_index, string &smnemo, string &sparm);
virtual adr_t DisassembleOptype20(adr_t instaddr, adr_t addr, uint16_t code, int optable_index, string &smnemo, string &sparm);
virtual adr_t DisassembleOptype21(adr_t instaddr, adr_t addr, uint16_t code, int optable_index, string &smnemo, string &sparm);
virtual adr_t DisassembleOptype22(adr_t instaddr, adr_t addr, uint16_t code, int optable_index, string &smnemo, string &sparm);
virtual adr_t DisassembleOptype23(adr_t instaddr, adr_t addr, uint16_t code, int optable_index, string &smnemo, string &sparm);
virtual adr_t DisassembleOptype24(adr_t instaddr, adr_t addr, uint16_t code, int optable_index, string &smnemo, string &sparm);
virtual adr_t DisassembleOptype25(adr_t instaddr, adr_t addr, uint16_t code, int optable_index, string &smnemo, string &sparm);
virtual adr_t DisassembleOptype26(adr_t instaddr, adr_t addr, uint16_t code, int optable_index, string &smnemo, string &sparm);
virtual adr_t DisassembleOptype27(adr_t instaddr, adr_t addr, uint16_t code, int optable_index, string &smnemo, string &sparm);
virtual adr_t DisassembleOptype28(adr_t instaddr, adr_t addr, uint16_t code, int optable_index, string &smnemo, string &sparm);
virtual adr_t DisassembleOptype29(adr_t instaddr, adr_t addr, uint16_t code, int optable_index, string &smnemo, string &sparm);
};
// to my understanding, an 68008 is a crippled 68000 with either 20 or 22 bits address bus
class Dasm68008 :
public Dasm68000
{
public:
Dasm68008(Application *pApp);
virtual ~Dasm68008(void);
// Overrides
public:
// return processor long name
virtual string GetName() { return "Motorola 68008"; }
// return highest possible code address
virtual cadr_t GetHighestCodeAddr() { return 0x3fffff; }
// return highest possible data address
virtual dadr_t GetHighestDataAddr() { return 0x3fffff; }
};
#endif // __Dasm68000_h_defined__