-
Notifications
You must be signed in to change notification settings - Fork 42
/
Copy path32016.h
369 lines (308 loc) · 6.47 KB
/
32016.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
/*
* NS32K CPU defines
*/
/*
* Public interface
*/
extern void ns32016_reset(void);
extern void ns32016_init(void);
extern void ns32016_ShowRegs(unsigned Options);
extern void ns32016_reset_addr(uint32_t StartAddress);
extern void ns32016_exec(int tstates);
extern void ns32016_close(void);
extern void ns32016_build_matrix(void);
extern void ns32016_set_irq(unsigned mask);
extern void ns32016_trace(unsigned onoff);
/*
* Platform provided
*/
extern uint8_t ns32016_read8(uint32_t addr);
extern uint8_t ns32016_read8_debug(uint32_t addr);
extern void ns32016_write8(uint32_t addr, uint8_t val);
#ifdef _NS32K_PRIV
// Some meaningful memory sizes
#define K128 0x0020000
#define K256 0x0040000
#define K512 0x0080000
#define K640 0x00A0000
#define MEG1 0x0100000
#define MEG2 0x0200000
#define MEG4 0x0400000
#define MEG8 0x0800000
#define MEG15 0x0F00000
#define MEG16 0x1000000
#define MEM_MASK 0xFFFFFF
#define BIT(in) (1u <<(in))
#define TEST(in) ((in) ? 1u : 0u)
#define C_FLAG PR.PSR.c_flag
#define T_FLAG PR.PSR.t_flag
#define L_FLAG PR.PSR.l_flag
#define V_FLAG PR.PSR.v_flag
#define F_FLAG PR.PSR.f_flag
#define Z_FLAG PR.PSR.z_flag
#define N_FLAG PR.PSR.n_flag
#define U_FLAG PR.PSR.u_flag
#define S_FLAG PR.PSR.s_flag
#define P_FLAG PR.PSR.p_flag
#define I_FLAG PR.PSR.i_flag
enum Formats {
Format0,
Format1,
Format2,
Format3,
Format4,
Format5,
Format6,
Format7,
Format8,
Format9,
Format10,
Format11,
Format12,
Format13,
Format14,
FormatCount,
FormatBad = 0xFF
};
enum RegType {
Integer,
SinglePrecision,
DoublePrecision
};
#define GET_PRECISION(in) ((in) ? SinglePrecision : DoublePrecision)
#define GET_F_SIZE(in) ((in) ? sz32 : sz64)
enum OpTypes {
Memory,
Register,
TOS,
OpImmediate
};
enum Operands {
R0,
R1,
R2,
R3,
R4,
R5,
R6,
R7,
R0_Offset,
R1_Offset,
R2_Offset,
R3_Offset,
R4_Offset,
R5_Offset,
R6_Offset,
R7_Offset,
FrameRelative,
StackRelative,
StaticRelative,
IllegalOperand,
Immediate,
Absolute,
External,
TopOfStack,
FpRelative,
SpRelative,
SbRelative,
PcRelative,
EaPlusRn,
EaPlus2Rn,
EaPlus4Rn,
EaPlus8Rn
};
enum OperandsPostitions {
Oper1,
Oper2
};
enum DataSize {
szVaries = 0,
sz8 = 1,
sz16 = 2,
Translating = 3,
sz32 = 4,
sz64 = 8,
};
typedef union {
uint8_t Op[4];
uint32_t Whole;
} OperandSizeType;
#define WriteSize OpSize.Op[2]
typedef union {
struct {
unsigned c_flag:1; // 0x0001
unsigned t_flag:1; // 0x0002
unsigned l_flag:1; // 0x0004
unsigned Bit3:1; // 0x0008
unsigned v_flag:1; // 0x0010
unsigned f_flag:1; // 0x0020
unsigned z_flag:1; // 0x0040
unsigned n_flag:1; // 0x0080
unsigned u_flag:1; // 0x0100
unsigned s_flag:1; // 0x0200
unsigned p_flag:1; // 0x0400
unsigned i_flag:1; // 0x0800
unsigned NU:20;
};
struct {
uint8_t lsb;
uint8_t msb;
uint8_t byte3;
uint8_t byte4;
};
uint32_t Whole;
} PsrType;
#define PrivilegedPSR(in) (BIT(in) & (BIT(0xE) | BIT(0xC) | BIT(0xC) | BIT(0xB) | BIT(0x4) | BIT(0x3) | BIT(0x2) | BIT(0x1)))
typedef union {
struct {
unsigned i_flag:1; // 0x0001
unsigned fpu_flag:1; // 0x0002
unsigned m_flag:1; // 0x0004
unsigned c_flag:1; // 0x0008
unsigned not_used:4; // 0x00X0
unsigned de_flag:1; // 0x0100
unsigned dc_flag:1; // 0x0200
unsigned ldc_flag:1; // 0x0400
unsigned ic_flag:1; // 0x0800
unsigned lic_flag:1; // 0x2000
unsigned pf_flag:1; // 0x0400
unsigned NU:18;
};
struct {
uint8_t lsb;
uint8_t msb;
uint8_t byte3;
uint8_t byte4;
};
uint32_t Whole;
} CfgType;
typedef union {
struct {
uint16_t Lower;
uint16_t Upper;
};
uint32_t Whole;
} T16In32;
// Floating point registers
// 0 F0:L F0:F
// 1 F0:L F1:F
// 2 F1:L
// 3 F1:L
// 4 F2:L F2:F
// 5 F2:L F3:F
// 6 F3:L
// 7 F3:L
// 8 F4:L F4:F
// 9 F4:L F5:F
// 10 F5:L
// 11 F5:L
// 12 F6:L F6:F
// 13 F6:L F7:F
// 14 F7:L
// 15 F7:L
typedef union {
float fr32[16];
double fr64[8];
uint32_t u32[16];
uint64_t u64[8];
} FloatingPointRegisters;
typedef union {
double f64;
uint64_t u64;
int64_t s64;
} Temp64Type;
typedef union {
float f32;
uint32_t u32;
int32_t s32;
} Temp32Type;
typedef union {
struct {
uint32_t UPSR;
uint32_t DCR;
uint32_t BPC;
uint32_t DSR;
uint32_t CAR;
uint32_t NotUsed_0101;
uint32_t NotUsed_0110;
uint32_t NotUsed_0111;
uint32_t FP;
uint32_t SP;
uint32_t SB;
uint32_t USP;
CfgType CFG;
PsrType PSR;
uint32_t INTBASE;
T16In32 MOD;
};
uint32_t Direct[16];
} ProcessorRegisters;
#define fp PR.FP
#define sb PR.SB
#define psr PR.PSR.Whole
#define psr_lsb PR.PSR.lsb
#define intbase PR.INTBASE
#define mod PR.MOD.Whole
#define nscfg PR.CFG
typedef union {
struct {
unsigned OpType:5;
unsigned RegType:3;
unsigned IdxReg:3;
unsigned IdxType:5;
};
struct {
uint8_t LowerByte;
uint8_t UpperByte;
};
uint16_t Whole;
} RegLKU;
extern uint32_t sp[2];
#define STACK_P sp[S_FLAG]
//#define STACK_P PR.SP
#define SET_SP(in) STACK_P = (in); PrintSP("Set SP:");
#define INC_SP(in) STACK_P += (in); PrintSP("Inc SP:");
#define DEC_SP(in) STACK_P -= (in); PrintSP("Dec SP:");
#define GET_SP() STACK_P
extern const uint32_t OpSizeLookup[6];
#define SET_OP_SIZE(in) OpSize.Whole = OpSizeLookup[(in) & 0x03]
#define SET_FOP_SIZE(in) OpSize.Whole = OpSizeLookup[0x04 | ((in) & 0x01)]
enum StringBits {
Translation = 15,
Backwards = 16,
UntilMatch = 17,
WhileMatch = 18
};
extern void ns32016_init();
extern void ns32016_ShowRegs(uint32_t Option);
extern void ns32016_reset_addr(uint32_t StartAddress);
extern void ns32016_exec();
extern void ns32016_build_matrix();
extern uint32_t ns32016_get_pc();
extern uint32_t ns32016_get_startpc();
extern void ns32016_set_pc(uint32_t value);
extern void BreakPoint(uint32_t pc, uint32_t opcode);
extern int32_t GetDisplacement(uint32_t * pPC);
extern ProcessorRegisters PR;
extern uint32_t r[8];
extern RegLKU Regs[2];
extern OperandSizeType FredSize;
extern void ShowRegisterWrite(RegLKU RegIn, uint32_t Value);
extern const uint8_t FormatSizes[FormatCount + 1];
//#define SHOW_STACK
#ifdef SHOW_STACK
#define PrintSP(str) PiTRACE("(%u) %s %06"PRIX32"\n", __LINE__, (str), GET_SP())
#else
#define PrintSP(str)
#endif
#define READ_PC_BYTE() read_x8(pc++)
#define SIGN_EXTEND(size, reg) \
if ((size == sz8) && (reg & 0x80)) { \
reg |= 0xFFFFFF00; \
} else if ((size == sz16) && (reg & 0x8000)) { \
reg |= 0xFFFF0000; \
}
#define NIBBLE_EXTEND(reg) \
if (reg & 0x08) \
reg |= 0xFFFFFFF0u;
#endif