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