summaryrefslogtreecommitdiffstatshomepage
path: root/src/emu/cpu/arc/arcdasm.c
blob: 27bcf5f54dc1722234db40d56b040dac0a6ec329 (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
/*********************************\

 ARCtangent (A4? A5?) disassembler

\*********************************/

#include "emu.h"
#include <stdarg.h>

static char *output;

static void ATTR_PRINTF(1,2) print(const char *fmt, ...)
{
	va_list vl;

	va_start(vl, fmt);
	vsprintf(output, fmt, vl);
	va_end(vl);
}

/*****************************************************************************/



/*****************************************************************************/

static const char *basic[0x20] =
{
	/* 00 */ "LD r+r",
	/* 01 */ "LD r+o",
	/* 02 */ "ST r+o",
	/* 03 */ "extended",
	/* 04 */ "B",
	/* 05 */ "BLcc",
	/* 06 */ "LPcc",
	/* 07 */ "Jcc JLcc",
	/* 08 */ "ADD",
	/* 09 */ "ADC",
	/* 0a */ "SUB",
	/* 0b */ "SBC",
	/* 0c */ "AND",
	/* 0d */ "OR",
	/* 0e */ "BIC",
	/* 0f */ "XOR",
	/* 10 */ "ASL",
	/* 11 */ "LSR",
	/* 12 */ "ASR",
	/* 13 */ "ROR",
	/* 14 */ "MUL64",
	/* 15 */ "MULU64",
	/* 16 */ "undefined",
	/* 17 */ "undefined",
	/* 18 */ "undefined",
	/* 19 */ "undefined",
	/* 1a */ "undefined",
	/* 1b */ "undefined",
	/* 1c */ "undefined",
	/* 1d */ "undefined",
	/* 1e */ "MAX",
	/* 1f */ "MIN"
};

static const char *conditions[0x20] =
{
	/* 00 */ "AL", // (aka RA         - Always)
	/* 01 */ "EQ", // (aka Z          - Zero
	/* 02 */ "NE", // (aka NZ         - Non-Zero)
	/* 03 */ "PL", // (aka P          - Positive)
	/* 04 */ "MI", // (aka N          - Negative)
	/* 05 */ "CS", // (aka C,  LO     - Carry set / Lower than) (unsigned)
	/* 06 */ "CC", // (aka CC, NC, HS - Carry Clear / Higher or Same) (unsigned) 
	/* 07 */ "VS", // (aka V          - Overflow set)
	/* 08 */ "VC", // (aka NV         - Overflow clear)
	/* 09 */ "GT", // (               - Greater than) (signed)
	/* 0a */ "GE", // (               - Greater than or Equal) (signed)
	/* 0b */ "LT", // (               - Less than) (signed)
	/* 0c */ "LE", // (               - Less than or Equal) (signed)
	/* 0d */ "HI", // (               - Higher than) (unsigned)
	/* 0e */ "LS", // (               - Lower or Same) (unsigned)
	/* 0f */ "PNZ",// (               - Positive non-0 value)
	/* 10 */ "0x10 Reserved", // possible CPU implementation specifics
	/* 11 */ "0x11 Reserved",
	/* 12 */ "0x12 Reserved",
	/* 13 */ "0x13 Reserved",
	/* 14 */ "0x14 Reserved",
	/* 15 */ "0x15 Reserved",
	/* 16 */ "0x16 Reserved",
	/* 17 */ "0x17 Reserved",
	/* 18 */ "0x18 Reserved",
	/* 19 */ "0x19 Reserved",
	/* 1a */ "0x1a Reserved",
	/* 1b */ "0x1b Reserved",
	/* 1c */ "0x1c Reserved",
	/* 1d */ "0x1d Reserved",
	/* 1e */ "0x1e Reserved",
	/* 1f */ "0x1f Reserved"
};

static const char *delaytype[0x4] =
{
	"ND", // NO DELAY - execute next instruction only when NOT jumping
	"D",  // always execute next instruction
	"JD", // only execute next instruction when jumping
	"Res!", // reserved / invalid
};

#define ARC_CONDITION ((op & 0x0000001f) >> 0 )

// used in jumps
#define ARC_BRANCH_DELAY     ((op & 0x00000060) >> 5 ) // aka NN
#define ARC_BRANCH_ADDR      ((op & 0x07ffff80) >> 7 ) // aka L

#define ARC_OPERATION ((op & 0xf8000000) >> 27) // aka QQQQQ

CPU_DISASSEMBLE(arc)
{
	UINT32 op = oprom[0] | (oprom[1] << 8) | (oprom[2] << 16) | (oprom[3] << 24);
	op = BIG_ENDIANIZE_INT32(op);

	output = buffer;

	UINT8 opcode = ARC_OPERATION;

	switch (opcode)
	{
		case 0x04:
		print("%s(%s)(%s) %08x", basic[opcode], conditions[ARC_CONDITION], delaytype[ARC_BRANCH_DELAY], (ARC_BRANCH_ADDR<<2)+pc+4);
		break;
	
		default:
		print("%s (%08x)", basic[opcode], op &~ 0xf8000000);
		break;
	}



	return 4 | DASMFLAG_SUPPORTED;
}