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