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