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