1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 #ifndef DPS8_H
24 # define DPS8_H
25
26 # include <stdio.h>
27 # include <stdbool.h>
28 # include <errno.h>
29 # include <inttypes.h>
30 # include <sys/stat.h>
31 # include <sys/time.h>
32 # include <setjmp.h>
33
34 # if (defined(__APPLE__) && defined(__MACH__)) || defined(__ANDROID__)
35 # include <libgen.h>
36 # endif
37
38 typedef int64_t __int64_t;
39
40 # ifdef NEED_128
41 typedef struct { uint64_t h; uint64_t l; } x__uint128_t;
42 typedef struct { int64_t h; uint64_t l; } x__int128_t;
43 # define construct_128(h, l) ((uint128) { (h), (l) })
44 # define construct_s128(h, l) ((int128) { (h), (l) })
45 # endif
46
47
48 # define QUIET_UNUSED
49
50
51 # ifndef TESTING
52 # define SPEED
53 # endif
54
55
56
57 # define DISC_DELAY 200
58
59
60
61
62
63 # ifdef PANEL68
64 # define PNL(x) x
65 # else
66 # define PNL(x)
67 # endif
68
69 # define L68_(x) if (cpu.tweaks.l68_mode) { x }
70 # define DPS8M_(x) if (! cpu.tweaks.l68_mode) { x }
71
72
73 # ifdef TESTING
74 # define IF1 if (cpu.tweaks.isolts_mode)
75 # else
76 # define IF1 if (0)
77 # endif
78
79
80 # define HEX_MODE
81
82
83
84
85
86
87
88
89
90 # define TR_WORK_EXEC
91
92
93 # if defined(THREADZ) || defined(LOCKLESS)
94 # define vol volatile
95 # else
96 # define vol
97 # endif
98
99 # ifndef NEED_128
100 # ifdef PRIu64
101 # undef PRIu64
102 # endif
103 # ifndef PRIu64
104 # define PRIu64 "llu"
105 # endif
106 # ifdef PRId64
107 # undef PRId64
108 # endif
109 # ifndef PRId64
110 # define PRId64 "lld"
111 # endif
112 # ifdef PRIo64
113 # undef PRIo64
114 # endif
115 # ifndef PRIo64
116 # ifdef __HAIKU__
117 # define PRIo64 "lo"
118 # undef llo
119 # define llo "lo"
120 # else
121 # define PRIo64 "llo"
122 # endif
123 # endif
124 # endif
125
126 # include "sim_defs.h"
127 # include "sim_tape.h"
128
129
130 # ifdef __MINGW32__
131 # include <stdint.h>
132 typedef t_uint64 u_int64_t;
133 # endif
134 # ifdef __HAIKU__
135 # include <stdint.h>
136 typedef long int64;
137 typedef unsigned long uint64;
138 # endif
139 # ifndef __HAIKU__
140 typedef t_uint64 uint64;
141 # endif
142 # ifndef _AIX
143 # ifndef __HAIKU__
144 typedef t_int64 int64;
145 # endif
146 # else
147 typedef long int64;
148 # endif
149
150
151
152 typedef uint8 word1;
153 typedef uint8 word2;
154 typedef uint8 word3;
155 typedef uint8 word4;
156 typedef uint8 word5;
157 typedef uint8 word6;
158 typedef uint8 word7;
159 typedef uint8 word8;
160 typedef int8 word8s;
161 typedef uint16 word9;
162 typedef uint16 word10;
163 typedef uint16 word11;
164 typedef uint16 word12;
165 typedef int16 word12s;
166 typedef uint16 word13;
167 typedef uint16 word14;
168 typedef uint16 word15;
169 typedef uint16 word16;
170 typedef uint32 word17;
171 typedef uint32 word18;
172 typedef uint32 word19;
173 typedef int32 word18s;
174 typedef uint32 word20;
175 typedef int32 word20s;
176 typedef uint32 word21;
177 typedef uint32 word22;
178 typedef uint32 word23;
179 typedef uint32 word24;
180 typedef uint32 word27;
181 typedef int32 word27s;
182 typedef uint32 word28;
183 typedef uint32 word32;
184 typedef uint64 word34;
185 typedef uint64 word36;
186 typedef uint64 word37;
187 typedef uint64 word38;
188 typedef int64 word38s;
189 typedef int64 word36s;
190 # ifndef NEED_128
191 typedef __uint128_t word72;
192 typedef __int128_t word72s;
193 typedef __uint128_t word73;
194 typedef __uint128_t word74;
195 typedef __uint128_t uint128;
196 typedef __int128_t int128;
197 # else
198 typedef x__uint128_t word72;
199 typedef x__int128_t word72s;
200 typedef x__uint128_t word73;
201 typedef x__uint128_t word74;
202 typedef x__uint128_t uint128;
203 typedef x__int128_t int128;
204 # endif
205
206 typedef word36 float36;
207 typedef word72 float72;
208
209 typedef unsigned int uint;
210
211 # include "dps8_simh.h"
212 # include "dps8_sys.h"
213 # include "dps8_math128.h"
214 # include "dps8_hw_consts.h"
215 # include "dps8_em_consts.h"
216
217 # define SETF(flags, x) flags = ((flags) | (x))
218 # define CLRF(flags, x) flags = ((flags) & ~(x))
219 # define TSTF(flags, x) (((flags) & (x)) ? 1 : 0)
220 # define SCF(cond, flags, x) { if (cond) SETF((flags), x); else CLRF((flags), x); }
221
222 # define SETBIT(dst, bitno) ((dst) | (1LLU << (bitno)))
223 # define CLRBIT(dst, bitno) ((dst) & ~(1LLU << (bitno)))
224 # define TSTBIT(dst, bitno) (((dst) & (1LLU << (bitno))) ? 1: 0)
225
226 typedef enum
227 {
228 UNKNOWN_CYCLE = 0,
229 OPERAND_STORE,
230 OPERAND_READ,
231 INDIRECT_WORD_FETCH,
232 RTCD_OPERAND_FETCH,
233 INSTRUCTION_FETCH,
234 APU_DATA_READ,
235 APU_DATA_STORE,
236 ABSA_CYCLE,
237 # ifdef LOCKLESS
238 OPERAND_RMW,
239 APU_DATA_RMW,
240 # endif
241 } processor_cycle_type;
242
243 # ifndef LOCKLESS
244 # define OPERAND_RMW OPERAND_READ
245 # define APU_DATA_RMW APU_DATA_READ
246 # endif
247
248 # ifndef EIS_PTR4
249
250 typedef enum
251 {
252 UnknownMAT = 0,
253 OperandRead,
254 OperandWrite,
255 viaPR
256 } MemoryAccessType;
257 # endif
258
259
260 # define GETCHAR(src, pos) (word6)(((word36)src >> (word36)((5 - pos) * 6)) & 077)
261
262 # define GETBYTE(src, pos) (word9)(((word36)src >> (word36)((3 - pos) * 9)) & 0777)
263
264 # ifdef NEED_128
265 # define YPAIRTO72(ypair) construct_128 ((ypair[0] >> 28) & MASK8, \
266 ((ypair[0] & MASK28) << 36) | \
267 (ypair[1] & MASK36));
268 # else
269 # define YPAIRTO72(ypair) (((((word72)(ypair[0] & DMASK)) << 36) | \
270 (ypair[1] & DMASK)) & MASK72)
271 # endif
272
273 # define GET_TALLY(src) (((src) >> 6) & MASK12)
274 # define GET_DELTA(src) ((src) & MASK6)
275
276 # ifndef max
277 # define max(a,b) max2((a),(b))
278 # endif
279 # define max2(a,b) ((a) > (b) ? (a) : (b))
280 # define max3(a,b,c) max((a), max((b),(c)))
281
282 # ifndef min
283 # define min(a,b) min2((a),(b))
284 # endif
285 # define min2(a,b) ((a) < (b) ? (a) : (b))
286 # define min3(a,b,c) min((a), min((b),(c)))
287
288
289 typedef enum
290 {
291 READ_OPERAND = (1U << 0),
292 STORE_OPERAND = (1U << 1),
293 # define RMW (READ_OPERAND | STORE_OPERAND)
294 READ_YPAIR = (1U << 2),
295 STORE_YPAIR = (1U << 3),
296 READ_YBLOCK8 = (1U << 4),
297 NO_RPT = (1U << 5),
298
299 NO_RPL = (1U << 7),
300
301 READ_YBLOCK16 = (1U << 8),
302 STORE_YBLOCK16 = (1U << 9),
303 TRANSFER_INS = (1U << 10),
304 TSPN_INS = (1U << 11),
305 CALL6_INS = (1U << 12),
306 PREPARE_CA = (1U << 13),
307 STORE_YBLOCK8 = (1U << 14),
308 IGN_B29 = (1U << 15),
309 NO_TAG = (1U << 16),
310 PRIV_INS = (1U << 17),
311 NO_BAR = (1U << 18),
312
313 NO_XED = (1U << 20),
314
315
316
317 # define EOP_ALPHA 1U
318
319
320 EOP1_ALPHA = (EOP_ALPHA << 21),
321 EOP1_MASK = (3U << 21),
322 # define EOP1_SHIFT 21
323
324
325 EOP2_ALPHA = (EOP_ALPHA << 23),
326 EOP2_MASK = (3U << 23),
327 # define EOP2_SHIFT 23
328
329
330 EOP3_ALPHA = (EOP_ALPHA << 25),
331 EOP3_MASK = (3U << 25),
332 # define EOP3_SHIFT 25
333
334 READ_YBLOCK32 = (1U << 27),
335 STORE_YBLOCK32 = (1U << 28),
336 } opc_flag;
337
338
339 enum opc_mod
340 {
341 NO_DU = (1U << 0),
342 NO_DL = (1U << 1),
343 # define NO_DUDL (NO_DU | NO_DL)
344
345 NO_CI = (1U << 2),
346 NO_SC = (1U << 3),
347 NO_SCR = (1U << 4),
348 # define NO_CSS (NO_CI | NO_SC | NO_SCR)
349
350 # define NO_DLCSS (NO_DU | NO_CSS)
351 # define NO_DDCSS (NO_DUDL | NO_CSS)
352
353 ONLY_AU_QU_AL_QL_XN = (1U << 5)
354 };
355
356
357
358
359
360 # define IS_NONE(tag) (!(tag))
361
362 # define IS_DD(tag) ((_TM(tag) != 040U) && \
363 ((_TD(tag) == 003U) || (_TD(tag) == 007U)))
364
365 # define IS_CSS(tag) ((_TM(tag) == 040U) && \
366 ((_TD(tag) == 050U) || (_TD(tag) == 052U) || \
367 (_TD(tag) == 045U)))
368 # define IS_DDCSS(tag) (IS_DD(tag) || IS_CSS(tag))
369
370 # define IS_DCSS(tag) (((_TM(tag) != 040U) && (_TD(tag) == 007U)) || IS_CSS(tag))
371
372
373
374
375
376
377 enum reg_use { is_WRD = 0174000,
378 is_9 = 0274000,
379 is_6 = 0334000,
380 is_4 = 0354000,
381 is_1 = 0364000,
382 is_DU = 04000,
383 is_OU = 02000,
384 ru_A = 02000 | 01000,
385 ru_Q = 02000 | 0400,
386 ru_X0 = 02000 | 0200,
387 ru_X1 = 02000 | 0100,
388 ru_X2 = 02000 | 040,
389 ru_X3 = 02000 | 020,
390 ru_X4 = 02000 | 010,
391 ru_X5 = 02000 | 04,
392 ru_X6 = 02000 | 02,
393 ru_X7 = 02000 | 01,
394 ru_none = 02000 | 0 };
395
396
397 # define ru_AQ (ru_A | ru_Q)
398 # define ru_Xn(n) (1 << (7 - (n)))
399
400
401 struct opcode_s {
402 const char *mne;
403 opc_flag flags;
404 enum opc_mod mods;
405 uint ndes;
406 enum reg_use reg_use;
407 };
408
409
410
411
412 # define Y(i) (i & MASKHI18)
413
414 # define OPSX(i) ((i & 0007000LLU) >> 9)
415
416 # define X(i) (i & 07U)
417
418 enum { OP_1 = 00001U,
419 OP_E = 00002U,
420 OP_BAR = 00003U,
421 OP_IC = 00004U,
422 OP_A = 00005U,
423 OP_Q = 00006U,
424 OP_AQ = 00007U,
425 OP_IR = 00010U,
426 OP_TR = 00011U,
427 OP_REGS = 00012U,
428
429
430 OP_CPR = 00021U,
431 OP_DBR = 00022U,
432 OP_PTP = 00023U,
433 OP_PTR = 00024U,
434 OP_RA = 00025U,
435 OP_SDP = 00026U,
436 OP_SDR = 00027U,
437
438 OP_X = 01000U
439 };
440
441 enum eCAFoper {
442 unknown = 0,
443 readCY,
444 writeCY,
445 rmwCY,
446
447
448
449
450
451
452
453 prepareCA,
454 };
455 typedef enum eCAFoper eCAFoper;
456
457 # define READOP(i) ((bool) (i->info->flags & \
458 (READ_OPERAND | \
459 READ_YPAIR | \
460 READ_YBLOCK8 | \
461 READ_YBLOCK16 | \
462 READ_YBLOCK32)))
463
464 # define WRITEOP(i) ((bool) (i->info->flags & \
465 (STORE_OPERAND | \
466 STORE_YPAIR | \
467 STORE_YBLOCK8 | \
468 STORE_YBLOCK16 | \
469 STORE_YBLOCK32)))
470
471
472 # define RMWOP(i) ((bool) READOP(i) && WRITEOP(i))
473
474 # define TRANSOP(i) ((bool) (i->info->flags & (TRANSFER_INS) ))
475
476
477
478
479
480
481
482
483 enum
484 {
485 CTA9 = 0U,
486 CTA6 = 1U,
487 CTA4 = 2U,
488 CTAILL = 3U
489 };
490
491
492 enum
493 {
494 CTN9 = 0U,
495 CTN4 = 1U
496 };
497
498
499
500 enum
501 {
502 CSFL = 0U,
503 CSLS = 1U,
504 CSTS = 2U,
505 CSNS = 3U
506 };
507
508 enum
509 {
510
511
512
513
514 MFkAR = 0x40U,
515
516
517
518
519
520
521 MFkRL = 0x20U,
522
523
524
525
526 MFkID = 0x10U,
527
528 MFkREGMASK = 0xfU
529 };
530
531
532
533 typedef enum
534 {
535 eisUnknown = 0,
536 eisTA = 1,
537 eisTN = 2,
538 eisBIT = 3
539 } eisDataType;
540
541 typedef enum
542 {
543 eRWreadBit = 0,
544 eRWwriteBit
545 } eRW;
546
547
548
549 # define ARRAY_SIZE(a) ( sizeof(a) / sizeof((a)[0]) )
550
551 # undef FREE
552 # ifdef TESTING
553 # define FREE(p) free(p)
554 # else
555 # define FREE(p) do \
556 { \
557 free((p)); \
558 (p) = NULL; \
559 } while(0)
560 # endif
561
562 # if defined (__MINGW64__) || \
563 defined (__MINGW32__) || \
564 defined (__GNUC__) || \
565 defined (__clang_version__)
566 # define NO_RETURN __attribute__ ((noreturn))
567 # define UNUSED __attribute__ ((unused))
568 # else
569 # define NO_RETURN
570 # define UNUSED
571 # endif
572
573 # define MAX_DEV_NAME_LEN 64
574
575
576 # ifdef TESTING
577 void * trealloc(void *ptr, size_t size);
578 # endif
579
580
581 # ifndef __CYGWIN__
582 # if defined( __MINGW32__ ) || defined( __MINGW64__ ) || defined( CROSS_MINGW32 ) || defined( CROSS_MINGW64 )
583 # define WIN_STDIO 1
584 # endif
585 # endif
586
587 #endif