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