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