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
|
// license:GPL-2.0+
// copyright-holders:Segher Boessenkool, David Haywood
/*****************************************************************************
SunPlus µ'nSP disassembler
Copyright 2008-2017 Segher Boessenkool <segher@kernel.crashing.org>
Licensed under the terms of the GNU GPL, version 2
http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
*****************************************************************************/
#include "emu.h"
#include "unspdasm.h"
char const* const unsp_disassembler::regs[] =
{
"sp", "r1", "r2", "r3", "r4", "bp", "sr", "pc"
};
char const* const unsp_disassembler::bitops[] =
{
"tstb", "setb", "clrb", "invb"
};
char const* const unsp_disassembler::signmodes[] =
{
"uu", "us", "su?", "ss" // su? might be invalid
};
char const* const unsp_disassembler::lsft[] =
{
"asr", "asror", "lsl", "lslor", "lsr", "lsror", "rol", "ror"
};
char const* const unsp_disassembler::extregs[] =
{
"r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15"
};
// TODO: use alu_op_start-like formatting
char const* const unsp_disassembler::aluops[] =
{
"add","adc","sub","sbc","cmp","(invalid)","neg","--","xor","load","or","and","test","store","(invalid)","(invalid)"
};
char const* const unsp_disassembler::forms[] =
{
"[%s]", "[%s--]", "[%s++]", "[++%s]"
};
u32 unsp_disassembler::opcode_alignment() const
{
return 1;
}
void unsp_disassembler::print_alu_op_start(std::ostream &stream, uint8_t op0, uint8_t opA)
{
static const char* const alu_op_start[] =
{
"%s += ",
"%s += ", // with carry
"%s -= ",
"%s -= ", // with carry
"cmp %s, ",
"<BAD>",
"%s =- ", // neg
"<BAD>",
"%s ^= ",
"%s = ", // load
"%s |= ",
"%s &= ",
"test %s, ",
"store", // syntax changes
"<BAD>", // bad
"<BAD>", // bad
};
util::stream_format(stream, alu_op_start[op0], regs[opA]);
}
void unsp_disassembler::print_alu_op3(std::ostream &stream, uint8_t op0, uint8_t opB)
{
static const char* const alu_op3[] =
{
"%s + ",
"%s + ", // with carry
"%s - ",
"%s - ", // with carry
"cmp %s, ",
"<BAD>",
"-", // neg
"<BAD>",
"%s ^ ",
"", // load
"%s | ",
"%s & ",
"test %s, ",
"store", // syntax changes
"<BAD>",
"<BAD>",
};
util::stream_format(stream, alu_op3[op0], regs[opB]);
}
void unsp_disassembler::print_mul(std::ostream& stream, uint16_t op)
{
int rs = (op & 0x0007) >> 0;
// (op & 0x0078) >> 3; fixed 0001
// (op & 0x0080) >> 7; fixed 0
int srd = (op & 0x0100) >> 8;
int rd = (op & 0x0e00) >> 9;
int srs = (op & 0x1000) >> 12;
// (op & 0xe000) >> 13; fixed 111
int sign = (srs << 1) | srd;
util::stream_format(stream, "MR = %s*%s, %s", regs[rd], regs[rs], signmodes[sign] );
}
void unsp_disassembler::print_muls(std::ostream& stream, uint16_t op)
{
int rs = (op & 0x0007) >> 0;
int size = (op & 0x0078) >> 3;
// (op & 0x0080) >> 7; fixed 1
int srd = (op & 0x0100) >> 8;
int rd = (op & 0x0e00) >> 9;
int srs = (op & 0x1000) >> 12;
// (op & 0xe000) >> 13; fixed 111
int sign = (srs << 1) | srd;
if (size == 0) size = 16;
util::stream_format(stream, "MR = [%s]*[%s], %s, %d", regs[rd], regs[rs], signmodes[sign], size );
}
void unsp_disassembler::print_alu_op_end(std::ostream &stream, uint8_t op0)
{
if (op0 == 1 || op0 == 3)
util::stream_format(stream, ", carry");
}
void unsp_disassembler::print_indirect_op(std::ostream &stream, uint8_t opN, uint8_t opB)
{
if (opN & 4)
util::stream_format(stream, "ds:");
util::stream_format(stream, forms[opN & 3], regs[opB]);
}
offs_t unsp_disassembler::disassemble_code(std::ostream &stream, offs_t pc, uint16_t op, uint16_t ximm, const data_buffer &opcodes)
{
uint32_t len = 1;
// all-zero and all-one are invalid insns:
if (op == 0 || op == 0xffff)
{
util::stream_format(stream, "--");
return UNSP_DASM_OK;
}
uint8_t op0 = (op >> 12);
if (op0 == 0xf)
return disassemble_fxxx_group(stream, pc, op, ximm, opcodes);
uint8_t opA = (op >> 9) & 7;
uint8_t op1 = (op >> 6) & 7;
if (op0 < 15 && opA == 7 && op1 < 2)
return disassemble_jumps(stream, pc, op);
if (op0 == 0xe)
return disassemble_exxx_group(stream, pc, op, ximm);
return disassemble_remaining(stream, pc, op, ximm, opcodes);
}
offs_t unsp_disassembler::disassemble(std::ostream &stream, offs_t pc, const data_buffer &opcodes, const data_buffer ¶ms)
{
uint16_t op = opcodes.r16(pc);
uint16_t imm16 = opcodes.r16(pc+1);
return disassemble_code(stream, pc, op, imm16, opcodes);
}
|