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
|
// license:BSD-3-Clause
// copyright-holders:Patrick Mackinlay
#pragma once
#ifndef __CLIPPER_H__
#define __CLIPPER_H__
// enumerate registers
enum clipper_registers
{
CLIPPER_R0, CLIPPER_R1, CLIPPER_R2, CLIPPER_R3, CLIPPER_R4, CLIPPER_R5, CLIPPER_R6, CLIPPER_R7,
CLIPPER_R8, CLIPPER_R9, CLIPPER_R10, CLIPPER_R11, CLIPPER_R12, CLIPPER_R13, CLIPPER_R14, CLIPPER_R15,
CLIPPER_F0, CLIPPER_F1, CLIPPER_F2, CLIPPER_F3, CLIPPER_F4, CLIPPER_F5, CLIPPER_F6, CLIPPER_F7,
CLIPPER_F8, CLIPPER_F9, CLIPPER_F10, CLIPPER_F11, CLIPPER_F12, CLIPPER_F13, CLIPPER_F14, CLIPPER_F15,
CLIPPER_PSW, CLIPPER_SSW,
CLIPPER_PC
};
enum clipper_addressing_modes
{
ADDR_MODE_PC32 = 0x10,
ADDR_MODE_ABS32 = 0x30,
ADDR_MODE_REL32 = 0x60,
ADDR_MODE_PC16 = 0x90,
ADDR_MODE_REL12 = 0xa0,
ADDR_MODE_ABS16 = 0xb0,
ADDR_MODE_PCX = 0xd0,
ADDR_MODE_RELX = 0xe0
};
#define PSW(mask) (m_psw & PSW_##mask)
#define SSW(mask) (m_ssw & SSW_##mask)
// macros for setting psw flags
#define FLAGS(C,V,Z,N) \
m_psw = (m_psw & ~(PSW_C | PSW_V | PSW_Z | PSW_N)) | (((C) << 3) | ((V) << 2) | ((Z) << 1) | ((N) << 0));
#define FLAGS_CV(C,V) \
m_psw = (m_psw & ~(PSW_C | PSW_V)) | (((C) << 3) | ((V) << 2));
#define FLAGS_ZN(Z,N) \
m_psw = (m_psw & ~(PSW_Z | PSW_N)) | (((Z) << 1) | ((N) << 0));
// over/underflow for addition/subtraction from here: http://stackoverflow.com/questions/199333/how-to-detect-integer-overflow-in-c-c
#define OF_ADD(a, b) ((b > 0) && (a > INT_MAX - b))
#define UF_ADD(a, b) ((b < 0) && (a < INT_MIN - b))
#define OF_SUB(a, b) ((b < 0) && (a > INT_MAX + b))
#define UF_SUB(a, b) ((b > 0) && (a < INT_MIN + b))
// CLIPPER logic for carry and overflow flags
#define C_ADD(a, b) ((uint32_t)a + (uint32_t)b < (uint32_t)a)
#define V_ADD(a, b) (OF_ADD((int32_t)a, (int32_t)b) || UF_ADD((int32_t)a, (int32_t)b))
#define C_SUB(a, b) ((uint32_t)a < (uint32_t)b)
#define V_SUB(a, b) (OF_SUB((int32_t)a, (int32_t)b) || UF_SUB((int32_t)a, (int32_t)b))
enum clipper_psw
{
PSW_N = 0x00000001, // negative
PSW_Z = 0x00000002, // zero
PSW_V = 0x00000004, // overflow
PSW_C = 0x00000008, // carry out or borrow in
PSW_FX = 0x00000010, // floating inexact
PSW_FU = 0x00000020, // floating underflow
PSW_FD = 0x00000040, // floating divide by zero
PSW_FV = 0x00000080, // floating overflow
PSW_FI = 0x00000100, // floating invalid operation
PSW_EFX = 0x00000200, // enable floating inexact trap
PSW_EFU = 0x00000400, // enable floating underflow trap
PSW_EFD = 0x00000800, // enable floating divide by zero trap
PSW_EFV = 0x00001000, // enable floating overflow trap
PSW_EFI = 0x00002000, // enable floating invalid operation trap
PSW_EFT = 0x00004000, // enable floating trap
PSW_FR = 0x00018000, // floating rounding mode (2 bits)
PSW_GAP = 0x000e0000, // unused (3 bits)
PSW_DSP = 0x00300000, // c400 - delay slot pointer (2 bits)
PSW_BIG = 0x00400000, // c400 - big endian (hardware)
PSW_T = 0x00800000, // trace trap
PSW_CTS = 0x0f000000, // cpu trap status (4 bits)
PSW_MTS = 0xf0000000 // memory trap status (4 bits)
};
enum clipper_ssw
{
SSW_IN = 0x0000000f, // interrupt number (4 bits)
SSW_IL = 0x000000f0, // interrupt level (4 bits)
SSW_EI = 0x00000100, // enable interrupts
SSW_ID = 0x0001fe00, // cpu rev # and type (8 bits)
SSW_GAP = 0x003e0000, // unused (5 bits)
SSW_FRD = 0x00400000, // floating registers dirty
SSW_TP = 0x00800000, // trace trap pending
SSW_ECM = 0x01000000, // enabled corrected memory error
SSW_DF = 0x02000000, // fpu disabled
SSW_M = 0x04000000, // mapped mode
SSW_KU = 0x08000000, // user protect key
SSW_UU = 0x10000000, // user data mode
SSW_K = 0x20000000, // protect key
SSW_U = 0x40000000, // user mode
SSW_P = 0x80000000, // previous mode
};
// branch conditions
enum clipper_branch_conditions
{
BRANCH_T = 0x0,
BRANCH_LT = 0x1,
BRANCH_LE = 0x2,
BRANCH_EQ = 0x3,
BRANCH_GT = 0x4,
BRANCH_GE = 0x5,
BRANCH_NE = 0x6,
BRANCH_LTU = 0x7,
BRANCH_LEU = 0x8,
BRANCH_GTU = 0x9,
BRANCH_GEU = 0xa,
BRANCH_V = 0xb,
BRANCH_NV = 0xc,
BRANCH_N = 0xd,
BRANCH_NN = 0xe,
BRANCH_FN = 0xf
};
enum clipper_exception_vectors
{
// data memory trap group
EXCEPTION_D_CORRECTED_MEMORY_ERROR = 0x108,
EXCEPTION_D_UNCORRECTABLE_MEMORY_ERROR = 0x110,
EXCEPTION_D_ALIGNMENT_FAULT = 0x120,
EXCEPTION_D_PAGE_FAULT = 0x128,
EXCEPTION_D_READ_PROTECT_FAULT = 0x130,
EXCEPTION_D_WRITE_PROTECT_FAULT = 0x138,
// floating-point arithmetic trap group
EXCEPTION_FLOATING_INEXACT = 0x180,
EXCEPTION_FLOATING_UNDERFLOW = 0x188,
EXCEPTION_FLOATING_DIVIDE_BY_ZERO = 0x190,
EXCEPTION_FLOATING_OVERFLOW = 0x1a0,
EXCEPTION_FLOATING_INVALID_OPERATION = 0x1c0,
// integer arithmetic trap group
EXCEPTION_INTEGER_DIVIDE_BY_ZERO = 0x208,
// instruction memory trap group
EXCEPTION_I_CORRECTED_MEMORY_ERROR = 0x288,
EXCEPTION_I_UNCORRECTABLE_MEMORY_ERROR = 0x290,
EXCEPTION_I_ALIGNMENT_FAULT = 0x2a0,
EXCEPTION_I_PAGE_FAULT = 0x2a8,
EXCEPTION_I_EXECUTE_PROTECT_FAULT = 0x2b0,
// illegal operation trap group
EXCEPTION_ILLEGAL_OPERATION = 0x300,
EXCEPTION_PRIVILEGED_INSTRUCTION = 0x308,
// diagnostic trap group
EXCEPTION_TRACE = 0x380,
// supervisor calls (0x400-0x7f8)
EXCEPTION_SUPERVISOR_CALL_BASE = 0x400,
// prioritized interrupts (0x800-0xff8)
EXCEPTION_INTERRUPT_BASE = 0x800,
};
enum clipper_cpu_trap_sources
{
CTS_NO_CPU_TRAP = 0 << 24,
CTS_DIVIDE_BY_ZERO = 2 << 24,
CTS_ILLEGAL_OPERATION = 4 << 24,
CTS_PRIVILEGED_INSTRUCTION = 5 << 24,
CTS_TRACE_TRAP = 7 << 24,
};
enum clipper_memory_trap_sources
{
MTS_NO_MEMORY_TRAP = 0 << 28,
MTS_CORRECTED_MEMORY_ERROR = 1 << 28,
MTS_UNCORRECTABLE_MEMORY_ERROR = 2 << 28,
MTS_ALIGNMENT_FAULT = 4 << 28,
MTS_PAGE_FAULT = 5 << 28,
MTS_READ_OR_EXECUTE_PROTECT_FAULT = 6 << 28,
MTS_WRITE_PROTECT_FAULT = 7 << 28,
};
class clipper_device : public cpu_device
{
public:
clipper_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock);
protected:
// device-level overrides
virtual void device_start() override;
virtual void device_reset() override;
// device_execute_interface overrides
virtual uint32_t execute_min_cycles() const override { return 1; };
virtual uint32_t execute_max_cycles() const override { return 1; }; // FIXME: don't know, especially macro instructions
virtual uint32_t execute_input_lines() const override { return 2; }; // number of input/interrupt lines (irq/nmi)
virtual void execute_run() override;
virtual void execute_set_input(int inputnum, int state) override;
// device_memory_interface overrides
virtual const address_space_config *memory_space_config(address_spacenum spacenum = AS_0) const override;
// device_state_interface overrides
#if 0
virtual void state_import(const device_state_entry &entry) override;
virtual void state_export(const device_state_entry &entry) override;
#endif
virtual void state_string_export(const device_state_entry &entry, std::string &str) const override;
// device_disasm_interface overrides
virtual uint32_t disasm_min_opcode_bytes() const override { return 2; } // smallest instruction
virtual uint32_t disasm_max_opcode_bytes() const override { return 8; } // largest instruction
virtual offs_t disasm_disassemble(std::ostream &stream, offs_t pc, const uint8_t *oprom, const uint8_t *opram, uint32_t options) override;
// core registers
uint32_t m_pc;
uint32_t m_psw;
uint32_t m_ssw;
// integer registers
int32_t *m_r; // active registers
int32_t m_ru[16]; // user registers
int32_t m_rs[16]; // supervisor registers
// floating registers
double m_f[16];
private:
address_space_config m_program_config;
address_space *m_program;
direct_read_data *m_direct;
int m_icount;
int m_interrupt_cycles;
int m_irq;
int m_nmi;
struct
{
// decoded operand information
union {
int32_t imm;
uint32_t r2 : 4;
uint16_t macro;
} op;
// total size of instruction in bytes
uint32_t size;
// computed effective address
uint32_t address;
} m_info;
void clipper_device::decode_instruction(uint16_t insn);
int clipper_device::execute_instruction(uint16_t insn);
// condition code evaluation
void clipper_device::evaluate_cc2f(double v0, double v1);
bool clipper_device::evaluate_branch(uint32_t condition);
uint32_t clipper_device::intrap(uint32_t vector, uint32_t pc, uint32_t cts = CTS_NO_CPU_TRAP, uint32_t mts = MTS_NO_MEMORY_TRAP);
};
extern const device_type CLIPPER;
#endif /* __CLIPPER_H__ */
|