root/src/simh/sim_defs.h

/* [previous][next][first][last][top][bottom][index][help] */

INCLUDED FROM


   1 /*
   2  * sim_defs.h: simulator definitions
   3  *
   4  * vim: filetype=c:tabstop=4:ai:expandtab
   5  * SPDX-License-Identifier: MIT
   6  * scspell-id: ae37b35b-f62a-11ec-8c79-80ee73e9b8e7
   7  *
   8  * ---------------------------------------------------------------------------
   9  *
  10  * Copyright (c) 1993-2008 Robert M. Supnik
  11  * Copyright (c) 2021-2023 The DPS8M Development Team
  12  *
  13  * Permission is hereby granted, free of charge, to any person obtaining a
  14  * copy of this software and associated documentation files (the "Software"),
  15  * to deal in the Software without restriction, including without limitation
  16  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  17  * and/or sell copies of the Software, and to permit persons to whom the
  18  * Software is furnished to do so, subject to the following conditions:
  19  *
  20  * The above copyright notice and this permission notice shall be included in
  21  * all copies or substantial portions of the Software.
  22  *
  23  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  24  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  25  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
  26  * ROBERT M SUPNIK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  27  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
  28  * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  29  * SOFTWARE.
  30  *
  31  * Except as contained in this notice, the name of Robert M. Supnik shall not
  32  * be used in advertising or otherwise to promote the sale, use or other
  33  * dealings in this Software without prior written authorization from
  34  * Robert M. Supnik.
  35  *
  36  * ---------------------------------------------------------------------------
  37  */
  38 
  39 /*
  40  * The interface between the simulator control package (SCP) and the
  41  * simulator consists of the following routines and data structures
  42  *
  43  *      sim_name                simulator name string
  44  *      sim_devices[]           array of pointers to simulated devices
  45  *      sim_PC                  pointer to saved PC register descriptor
  46  *      sim_interval            simulator interval to next event
  47  *      sim_stop_messages[]     array of pointers to stop messages
  48  *      sim_instr()             instruction execution routine
  49  *      sim_emax                maximum number of words in an instruction
  50  *
  51  * In addition, the simulator must supply routines to print and parse
  52  * architecture specific formats
  53  *
  54  *      print_sym               print symbolic output
  55  *      parse_sym               parse symbolic input
  56  */
  57 
  58 #ifndef SIM_DEFS_H_
  59 # define SIM_DEFS_H_    0
  60 
  61 # include <stddef.h>
  62 # include <stdlib.h>
  63 # include <stdio.h>
  64 # if defined(_MSC_VER) && (_MSC_VER < 1900)
  65 #  define snprintf _snprintf
  66 # endif
  67 # include <stdarg.h>
  68 # include <string.h>
  69 # include <errno.h>
  70 # include <limits.h>
  71 
  72 # ifdef _WIN32
  73 #  include <winsock2.h>
  74 #  undef PACKED                       /* avoid macro name collision */
  75 #  undef ERROR                        /* avoid macro name collision */
  76 #  undef MEM_MAPPED                   /* avoid macro name collision */
  77 #  include <process.h>
  78 # endif
  79 
  80 # include <sys/param.h>               /* MAXPATHLEN */
  81 
  82 /* avoid macro names collisions */
  83 # ifdef MAX
  84 #  undef MAX
  85 # endif
  86 # ifdef MIN
  87 #  undef MIN
  88 # endif
  89 # ifdef PMASK
  90 #  undef PMASK
  91 # endif
  92 # ifdef RS
  93 #  undef RS
  94 # endif
  95 # ifdef PAGESIZE
  96 #  undef PAGESIZE
  97 # endif
  98 
  99 # ifndef TRUE
 100 #  define TRUE            1
 101 #  undef FALSE
 102 #  define FALSE           0
 103 # endif
 104 
 105 /*
 106  * SCP API shim.
 107  *
 108  * The SCP API for version 4.0 introduces a number of "pointer-to-const"
 109  * parameter qualifiers that were not present in the 3.x versions.  To maintain
 110  * compatibility with the earlier versions, the new qualifiers are expressed as
 111  * "CONST" rather than "const".  This allows macro removal of the qualifiers
 112  * when compiling for SIMH 3.x.
 113  */
 114 
 115 # ifndef CONST
 116 #  define CONST const
 117 # endif
 118 
 119 /* Length specific integer declarations */
 120 
 121 typedef signed char     int8;
 122 typedef signed short    int16;
 123 typedef signed int      int32;
 124 typedef unsigned char   uint8;
 125 typedef unsigned short  uint16;
 126 typedef unsigned int    uint32;
 127 typedef int             t_stat;                         /* status */
 128 typedef int             t_bool;                         /* boolean */
 129 
 130 /* 64b integers */
 131 
 132 # if defined (__GNUC__)                                  /* GCC */
 133 typedef signed long long        t_int64;
 134 typedef unsigned long long      t_uint64;
 135 # elif defined (_WIN32)                                  /* Windows */
 136 typedef signed __int64          t_int64;
 137 typedef unsigned __int64        t_uint64;
 138 # else                                                   /* default */
 139 #  define t_int64                 signed long long
 140 #  define t_uint64                unsigned long long
 141 # endif                                                  /* end 64b */
 142 # include <stdint.h>
 143 # ifndef INT64_C
 144 #  define INT64_C(x)      x ## LL
 145 # endif
 146 
 147 typedef t_int64         t_svalue;                       /* signed value */
 148 typedef t_uint64        t_value;                        /* value */
 149 typedef uint32          t_addr;
 150 # define T_ADDR_W        32
 151 # define T_ADDR_FMT      ""
 152 
 153 # if defined (_WIN32)
 154 #  undef vsnprintf
 155 #  define vsnprintf _vsnprintf
 156 # endif
 157 # define STACKBUFSIZE 2048
 158 
 159 # if defined (_WIN32) /* Actually, a GCC issue */
 160 #  define LL_FMT "I64"
 161 # else
 162 #  define LL_FMT "ll"
 163 # endif
 164 
 165 # if defined (_WIN32)
 166 #  define NULL_DEVICE "NUL:"
 167 # else
 168 #  define NULL_DEVICE "/dev/null"
 169 # endif
 170 
 171 /* Stubs for inlining */
 172 
 173 # if defined(_MSC_VER)
 174 #  define SIM_INLINE _inline
 175 # elif defined(__GNUC__) || defined(__clang_version__) || defined(__xlc__)
 176 #  define SIM_INLINE inline
 177 # else
 178 #  define SIM_INLINE
 179 # endif
 180 
 181 /* System independent definitions */
 182 
 183 # define FLIP_SIZE       (1 << 16)                       /* flip buf size */
 184 # if !defined (PATH_MAX)                                 /* usually in limits */
 185 #  define PATH_MAX        512
 186 # endif
 187 # if (PATH_MAX >= 128)
 188 #  define CBUFSIZE        (4096 + PATH_MAX)                /* string buf size */
 189 # else
 190 #  define CBUFSIZE        4224
 191 # endif
 192 
 193 /* Breakpoint spaces definitions */
 194 
 195 # define SIM_BKPT_N_SPC  (1 << (32 - SIM_BKPT_V_SPC))    /* max number spaces */
 196 # define SIM_BKPT_V_SPC  (BRK_TYP_MAX + 1)               /* location in arg */
 197 
 198 /* Extended switch definitions (bits >= 26) */
 199 
 200 # define SIM_SW_HIDE     (1u << 26)                      /* enable hiding */
 201 # define SIM_SW_REST     (1u << 27)                      /* attach/restore */
 202 # define SIM_SW_REG      (1u << 28)                      /* register value */
 203 # define SIM_SW_STOP     (1u << 29)                      /* stop message */
 204 # define SIM_SW_SHUT     (1u << 30)                      /* shutdown */
 205 
 206 /*
 207  * Simulator status codes
 208  *
 209  * 0                    ok
 210  * 1 - (SCPE_BASE - 1)  simulator specific
 211  * SCPE_BASE - n        general
 212  */
 213 
 214 # define SCPE_OK         0                               /* normal return */
 215 # define SCPE_BASE       64                              /* base for messages */
 216 # define SCPE_NXM        (SCPE_BASE + 0)                 /* nxm */
 217 # define SCPE_UNATT      (SCPE_BASE + 1)                 /* no file */
 218 # define SCPE_IOERR      (SCPE_BASE + 2)                 /* I/O error */
 219 # define SCPE_CSUM       (SCPE_BASE + 3)                 /* loader cksum */
 220 # define SCPE_FMT        (SCPE_BASE + 4)                 /* loader format */
 221 # define SCPE_NOATT      (SCPE_BASE + 5)                 /* not attachable */
 222 # define SCPE_OPENERR    (SCPE_BASE + 6)                 /* open error */
 223 # define SCPE_MEM        (SCPE_BASE + 7)                 /* alloc error */
 224 # define SCPE_ARG        (SCPE_BASE + 8)                 /* argument error */
 225 # define SCPE_STEP       (SCPE_BASE + 9)                 /* step expired */
 226 # define SCPE_UNK        (SCPE_BASE + 10)                /* unknown command */
 227 # define SCPE_RO         (SCPE_BASE + 11)                /* read only */
 228 # define SCPE_INCOMP     (SCPE_BASE + 12)                /* incomplete */
 229 # define SCPE_STOP       (SCPE_BASE + 13)                /* sim stopped */
 230 # define SCPE_EXIT       (SCPE_BASE + 14)                /* sim exit */
 231 # define SCPE_TTIERR     (SCPE_BASE + 15)                /* console tti err */
 232 # define SCPE_TTOERR     (SCPE_BASE + 16)                /* console tto err */
 233 # define SCPE_EOF        (SCPE_BASE + 17)                /* end of file */
 234 # define SCPE_REL        (SCPE_BASE + 18)                /* relocation error */
 235 # define SCPE_NOPARAM    (SCPE_BASE + 19)                /* no parameters */
 236 # define SCPE_ALATT      (SCPE_BASE + 20)                /* already attached */
 237 # define SCPE_TIMER      (SCPE_BASE + 21)                /* hwre timer err */
 238 # define SCPE_SIGERR     (SCPE_BASE + 22)                /* signal err */
 239 # define SCPE_TTYERR     (SCPE_BASE + 23)                /* tty setup err */
 240 # define SCPE_SUB        (SCPE_BASE + 24)                /* subscript err */
 241 # define SCPE_NOFNC      (SCPE_BASE + 25)                /* func not imp */
 242 # define SCPE_UDIS       (SCPE_BASE + 26)                /* unit disabled */
 243 # define SCPE_NORO       (SCPE_BASE + 27)                /* rd only not ok */
 244 # define SCPE_INVSW      (SCPE_BASE + 28)                /* invalid switch */
 245 # define SCPE_MISVAL     (SCPE_BASE + 29)                /* missing value */
 246 # define SCPE_2FARG      (SCPE_BASE + 30)                /* too few arguments */
 247 # define SCPE_2MARG      (SCPE_BASE + 31)                /* too many arguments */
 248 # define SCPE_NXDEV      (SCPE_BASE + 32)                /* nx device */
 249 # define SCPE_NXUN       (SCPE_BASE + 33)                /* nx unit */
 250 # define SCPE_NXREG      (SCPE_BASE + 34)                /* nx register */
 251 # define SCPE_NXPAR      (SCPE_BASE + 35)                /* nx parameter */
 252 # define SCPE_NEST       (SCPE_BASE + 36)                /* nested DO */
 253 # define SCPE_IERR       (SCPE_BASE + 37)                /* internal error */
 254 # define SCPE_MTRLNT     (SCPE_BASE + 38)                /* tape rec lnt error */
 255 # define SCPE_LOST       (SCPE_BASE + 39)                /* Telnet conn lost */
 256 # define SCPE_TTMO       (SCPE_BASE + 40)                /* Telnet conn timeout */
 257 # define SCPE_STALL      (SCPE_BASE + 41)                /* Telnet conn stall */
 258 # define SCPE_AFAIL      (SCPE_BASE + 42)                /* assert failed */
 259 # define SCPE_INVREM     (SCPE_BASE + 43)                /* invalid remote console command */
 260 # define SCPE_NOTATT     (SCPE_BASE + 44)                /* not attached */
 261 # define SCPE_EXPECT     (SCPE_BASE + 45)                /* expect matched */
 262 # define SCPE_REMOTE     (SCPE_BASE + 46)                /* remote console command */
 263 
 264 # define SCPE_MAX_ERR    (SCPE_BASE + 47)                /* Maximum SCPE Error Value */
 265 # define SCPE_KFLAG      0x1000                          /* tti data flag */
 266 # define SCPE_BREAK      0x2000                          /* tti break flag */
 267 # define SCPE_NOMESSAGE  0x10000000                      /* message display suppression flag */
 268 # define SCPE_BARE_STATUS(stat) ((stat) & ~(SCPE_NOMESSAGE|SCPE_KFLAG|SCPE_BREAK))
 269 
 270 /* Print value format codes */
 271 
 272 # define PV_RZRO         0                               /* right, zero fill */
 273 # define PV_RSPC         1                               /* right, space fill */
 274 # define PV_RCOMMA       2                               /* right, space fill. Comma separate every 3 */
 275 # define PV_LEFT         3                               /* left justify */
 276 
 277 /* Default timing parameters */
 278 
 279 # define KBD_POLL_WAIT   5000                            /* keyboard poll */
 280 # define KBD_MAX_WAIT    500000
 281 # define SERIAL_IN_WAIT  100                             /* serial in time */
 282 # define SERIAL_OUT_WAIT 100                             /* serial output */
 283 # define NOQUEUE_WAIT    1000000                         /* min check time */
 284 # define KBD_LIM_WAIT(x) (((x) > KBD_MAX_WAIT)? KBD_MAX_WAIT: (x))
 285 # define KBD_WAIT(w,s)   ((w)? w: KBD_LIM_WAIT (s))
 286 
 287 /* Convert switch letter to bit mask */
 288 
 289 # define SWMASK(x) (1u << (((int) (x)) - ((int) 'A')))
 290 
 291 /* String match - at least one character required */
 292 
 293 # define MATCH_CMD(ptr,cmd) ((NULL == (ptr)) || (!*(ptr)) || strncmp ((ptr), (cmd), strlen (ptr)))
 294 
 295 /* End of Linked List/Queue value                           */
 296 /* Chosen for 2 reasons:                                    */
 297 /*     1 - to not be NULL, this allowing the NULL value to  */
 298 /*         indicate inclusion on a list                     */
 299 /* and                                                      */
 300 /*     2 - to not be a valid/possible pointer (alignment)   */
 301 # define QUEUE_LIST_END ((UNIT *)1)
 302 
 303 /* Typedefs for principal structures */
 304 
 305 typedef struct DEVICE DEVICE;
 306 typedef struct UNIT UNIT;
 307 typedef struct REG REG;
 308 typedef struct CTAB CTAB;
 309 typedef struct C1TAB C1TAB;
 310 typedef struct SHTAB SHTAB;
 311 typedef struct MTAB MTAB;
 312 typedef struct SCHTAB SCHTAB;
 313 typedef struct BRKTAB BRKTAB;
 314 typedef struct BRKTYPTAB BRKTYPTAB;
 315 typedef struct EXPTAB EXPTAB;
 316 typedef struct EXPECT EXPECT;
 317 typedef struct SEND SEND;
 318 typedef struct DEBTAB DEBTAB;
 319 typedef struct FILEREF FILEREF;
 320 typedef struct BITFIELD BITFIELD;
 321 
 322 typedef t_stat (*ACTIVATE_API)(UNIT *unit, int32 interval);
 323 
 324 /* Device data structure */
 325 
 326 struct DEVICE {
 327     const char          *name;                          /* name */
 328     UNIT                *units;                         /* units */
 329     REG                 *registers;                     /* registers */
 330     MTAB                *modifiers;                     /* modifiers */
 331     uint32              numunits;                       /* #units */
 332     uint32              aradix;                         /* address radix */
 333     uint32              awidth;                         /* address width */
 334     uint32              aincr;                          /* addr increment */
 335     uint32              dradix;                         /* data radix */
 336     uint32              dwidth;                         /* data width */
 337     t_stat              (*examine)(t_value *v, t_addr a, UNIT *up,
 338                             int32 sw);                  /* examine routine */
 339     t_stat              (*deposit)(t_value v, t_addr a, UNIT *up,
 340                             int32 sw);                  /* deposit routine */
 341     t_stat              (*reset)(DEVICE *dp);           /* reset routine */
 342     t_stat              (*boot)(int32 u, DEVICE *dp);
 343                                                         /* boot routine */
 344     t_stat              (*attach)(UNIT *up, CONST char *cp);
 345                                                         /* attach routine */
 346     t_stat              (*detach)(UNIT *up);            /* detach routine */
 347     void                *ctxt;                          /* context */
 348     uint32              flags;                          /* flags */
 349     uint32              dctrl;                          /* debug control */
 350     DEBTAB              *debflags;                      /* debug flags */
 351     t_stat              (*msize)(UNIT *up, int32 v, CONST char *cp, void *dp);
 352                                                         /* mem size routine */
 353     char                *lname;                         /* logical name */
 354     t_stat              (*help)(FILE *st, DEVICE *dptr,
 355                             UNIT *uptr, int32 flag, const char *cptr);
 356                                                         /* help */
 357     t_stat              (*attach_help)(FILE *st, DEVICE *dptr,
 358                             UNIT *uptr, int32 flag, const char *cptr);
 359                                                         /* attach help */
 360     void *help_ctx;                                     /* Context available to help routines */
 361     const char          *(*description)(DEVICE *dptr);  /* Device Description */
 362     BRKTYPTAB           *brk_types;                     /* Breakpoint types */
 363     };
 364 
 365 /* Device flags */
 366 
 367 # define DEV_V_DIS       0                               /* dev disabled */
 368 # define DEV_V_DISABLE   1                               /* dev disable-able */
 369 # define DEV_V_DYNM      2                               /* mem size dynamic */
 370 # define DEV_V_DEBUG     3                               /* debug capability */
 371 # define DEV_V_TYPE      4                               /* Attach type */
 372 # define DEV_S_TYPE      3                               /* Width of Type Field */
 373 # define DEV_V_SECTORS   7                               /* Unit Capacity is in 512byte sectors */
 374 # define DEV_V_DONTAUTO  8                               /* Do not auto detach already attached units */
 375 # define DEV_V_FLATHELP  9                               /* Use traditional (unstructured) help */
 376 # define DEV_V_NOSAVE    10                              /* Don't save device state */
 377 # define DEV_V_UF_31     12                              /* user flags, V3.1 */
 378 # define DEV_V_UF        16                              /* user flags */
 379 # define DEV_V_RSV       31                              /* reserved */
 380 
 381 # define DEV_DIS         (1 << DEV_V_DIS)                /* device is currently disabled */
 382 # define DEV_DISABLE     (1 << DEV_V_DISABLE)            /* device can be set enabled or disabled */
 383 # define DEV_DYNM        (1 << DEV_V_DYNM)               /* device requires call on msize routine to change memory size */
 384 # define DEV_DEBUG       (1 << DEV_V_DEBUG)              /* device supports SET DEBUG command */
 385 # define DEV_SECTORS     (1 << DEV_V_SECTORS)            /* capacity is 512 byte sectors */
 386 # define DEV_DONTAUTO    (1 << DEV_V_DONTAUTO)           /* Do not auto detach already attached units */
 387 # define DEV_FLATHELP    (1 << DEV_V_FLATHELP)           /* Use traditional (unstructured) help */
 388 # define DEV_NOSAVE      (1 << DEV_V_NOSAVE)             /* Don't save device state */
 389 # define DEV_NET         0                               /* Deprecated - meaningless */
 390 
 391 # define DEV_TYPEMASK    (((1 << DEV_S_TYPE) - 1) << DEV_V_TYPE)
 392 # define DEV_DISK        (1 << DEV_V_TYPE)               /* sim_disk Attach */
 393 # define DEV_TAPE        (2 << DEV_V_TYPE)               /* sim_tape Attach */
 394 # define DEV_MUX         (3 << DEV_V_TYPE)               /* sim_tmxr Attach */
 395 # define DEV_ETHER       (4 << DEV_V_TYPE)               /* Ethernet Device */
 396 # define DEV_DISPLAY     (5 << DEV_V_TYPE)               /* Display Device */
 397 # define DEV_TYPE(dptr)  ((dptr)->flags & DEV_TYPEMASK)
 398 
 399 # define DEV_UFMASK_31   (((1u << DEV_V_RSV) - 1) & ~((1u << DEV_V_UF_31) - 1))
 400 # define DEV_UFMASK      (((1u << DEV_V_RSV) - 1) & ~((1u << DEV_V_UF) - 1))
 401 # define DEV_RFLAGS      (DEV_UFMASK|DEV_DIS)            /* restored flags */
 402 
 403 /* Unit data structure
 404 
 405    Parts of the unit structure are device specific, that is, they are
 406    not referenced by the simulator control package and can be freely
 407    used by device simulators.  Fields starting with 'buf', and flags
 408    starting with 'UF', are device specific.  The definitions given here
 409    are for a typical sequential device.
 410 */
 411 
 412 struct UNIT {
 413     UNIT                *next;                          /* next active */
 414     t_stat              (*action)(UNIT *up);            /* action routine */
 415     char                *filename;                      /* open file name */
 416     FILE                *fileref;                       /* file reference */
 417     void                *filebuf;                       /* memory buffer */
 418     uint32              hwmark;                         /* high water mark */
 419     int32               time;                           /* time out */
 420     uint32              flags;                          /* flags */
 421     uint32              dynflags;                       /* dynamic flags */
 422     t_addr              capac;                          /* capacity */
 423     t_addr              pos;                            /* file position */
 424     void                (*io_flush)(UNIT *up);          /* io flush routine */
 425     uint32              iostarttime;                    /* I/O start time */
 426     int32               buf;                            /* buffer */
 427     int32               wait;                           /* wait */
 428     int32               u3;                             /* device specific */
 429     int32               u4;                             /* device specific */
 430     int32               u5;                             /* device specific */
 431     int32               u6;                             /* device specific */
 432     void                *up7;                           /* device specific */
 433     void                *up8;                           /* device specific */
 434     void                *tmxr;                          /* TMXR linkage */
 435     void                (*cancel)(UNIT *);
 436     };
 437 
 438 /* Unit flags */
 439 
 440 # define UNIT_V_UF_31    12              /* dev spec, V3.1 */
 441 # define UNIT_V_UF       16              /* device specific */
 442 # define UNIT_V_RSV      31              /* reserved!! */
 443 
 444 # define UNIT_ATTABLE    0000001         /* attachable */
 445 # define UNIT_RO         0000002         /* read only */
 446 # define UNIT_FIX        0000004         /* fixed capacity */
 447 # define UNIT_SEQ        0000010         /* sequential */
 448 # define UNIT_ATT        0000020         /* attached */
 449 # define UNIT_BINK       0000040         /* K = power of 2 */
 450 # define UNIT_BUFABLE    0000100         /* bufferable */
 451 # define UNIT_MUSTBUF    0000200         /* must buffer */
 452 # define UNIT_BUF        0000400         /* buffered */
 453 # define UNIT_ROABLE     0001000         /* read only ok */
 454 # define UNIT_DISABLE    0002000         /* disable-able */
 455 # define UNIT_DIS        0004000         /* disabled */
 456 # define UNIT_IDLE       0040000         /* idle eligible */
 457 
 458 /* Unused/meaningless flags */
 459 # define UNIT_TEXT       0000000         /* text mode - no effect */
 460 
 461 # define UNIT_UFMASK_31  (((1u << UNIT_V_RSV) - 1) & ~((1u << UNIT_V_UF_31) - 1))
 462 # define UNIT_UFMASK     (((1u << UNIT_V_RSV) - 1) & ~((1u << UNIT_V_UF) - 1))
 463 # define UNIT_RFLAGS     (UNIT_UFMASK|UNIT_DIS)          /* restored flags */
 464 
 465 /* Unit dynamic flags (dynflags) */
 466 
 467 /* These flags are only set dynamically */
 468 
 469 # define UNIT_ATTMULT    0000001         /* Allow multiple attach commands */
 470 # define UNIT_TM_POLL    0000002         /* TMXR Polling unit */
 471 # define UNIT_NO_FIO     0000004         /* fileref is NOT a FILE * */
 472 # define UNIT_DISK_CHK   0000010         /* disk data debug checking (sim_disk) */
 473 # define UNIT_TMR_UNIT   0000020         /* Unit registered as a calibrated timer */
 474 # define UNIT_V_DF_TAPE  5               /* Bit offset for Tape Density reservation */
 475 # define UNIT_S_DF_TAPE  3               /* Bits Reserved for Tape Density */
 476 
 477 struct BITFIELD {
 478     const char      *name;                              /* field name */
 479     uint32          offset;                             /* starting bit */
 480     uint32          width;                              /* width */
 481     const char      **valuenames;                       /* map of values to strings */
 482     const char      *format;                            /* value format string */
 483     };
 484 
 485 /* Register data structure */
 486 
 487 struct REG {
 488     CONST char          *name;                          /* name */
 489     void                *loc;                           /* location */
 490     uint32              radix;                          /* radix */
 491     uint32              width;                          /* width */
 492     uint32              offset;                         /* starting bit */
 493     uint32              depth;                          /* save depth */
 494     const char          *desc;                          /* description */
 495     BITFIELD            *fields;                        /* bit fields */
 496     uint32              flags;                          /* flags */
 497     uint32              qptr;                           /* circ q ptr */
 498     size_t              str_size;                       /* structure size */
 499     };
 500 
 501 /* Register flags */
 502 
 503 # define REG_FMT         00003                           /* see PV_x */
 504 # define REG_RO          00004                           /* read only */
 505 # define REG_HIDDEN      00010                           /* hidden */
 506 # define REG_NZ          00020                           /* must be non-zero */
 507 # define REG_UNIT        00040                           /* in unit struct */
 508 # define REG_STRUCT      00100                           /* in structure array */
 509 # define REG_CIRC        00200                           /* circular array */
 510 # define REG_VMIO        00400                           /* use VM data print/parse */
 511 # define REG_VMAD        01000                           /* use VM addr print/parse */
 512 # define REG_FIT         02000                           /* fit access to size */
 513 # define REG_HRO         (REG_RO | REG_HIDDEN)           /* hidden, read only */
 514 
 515 # define REG_V_UF        16                              /* device specific */
 516 # define REG_UFMASK      (~((1u << REG_V_UF) - 1))       /* user flags mask */
 517 # define REG_VMFLAGS     (REG_VMIO | REG_UFMASK)         /* call VM routine if any of these are set */
 518 
 519 /* Command tables, base and alternate formats */
 520 
 521 struct CTAB {
 522     const char          *name;                          /* name */
 523     t_stat              (*action)(int32 flag, CONST char *cptr);
 524                                                         /* action routine */
 525     int32               arg;                            /* argument */
 526     const char          *help;                          /* help string/structured locator */
 527     const char          *help_base;                     /* structured help base*/
 528     void                (*message)(const char *unechoed_cmdline, t_stat stat);
 529                                                         /* message printing routine */
 530     };
 531 
 532 struct C1TAB {
 533     const char          *name;                          /* name */
 534     t_stat              (*action)(DEVICE *dptr, UNIT *uptr,
 535                             int32 flag, CONST char *cptr);/* action routine */
 536     int32               arg;                            /* argument */
 537     const char          *help;                          /* help string */
 538     };
 539 
 540 struct SHTAB {
 541     const char          *name;                          /* name */
 542     t_stat              (*action)(FILE *st, DEVICE *dptr,
 543                             UNIT *uptr, int32 flag, CONST char *cptr);
 544     int32               arg;                            /* argument */
 545     const char          *help;                          /* help string */
 546     };
 547 
 548 /* Modifier table - only extended entries have disp, reg, or flags */
 549 
 550 struct MTAB {
 551     uint32              mask;                           /* mask */
 552     uint32              match;                          /* match */
 553     const char          *pstring;                       /* print string */
 554     const char          *mstring;                       /* match string */
 555     t_stat              (*valid)(UNIT *up, int32 v, CONST char *cp, void *dp);
 556                                                         /* validation routine */
 557     t_stat              (*disp)(FILE *st, UNIT *up, int32 v, CONST void *dp);
 558                                                         /* display routine */
 559     void                *desc;                          /* value descriptor */
 560                                                         /* REG * if MTAB_VAL */
 561                                                         /* int * if not */
 562     const char          *help;                          /* help string */
 563     };
 564 
 565 /* mtab mask flag bits */
 566 /* NOTE: MTAB_VALR and MTAB_VALO are only used to display help */
 567 # define MTAB_XTD        (1u << UNIT_V_RSV)              /* ext entry flag */
 568 # define MTAB_VDV        (0001 | MTAB_XTD)               /* valid for dev */
 569 # define MTAB_VUN        (0002 | MTAB_XTD)               /* valid for unit */
 570 # define MTAB_VALR       (0004 | MTAB_XTD)               /* takes a value (required) */
 571 # define MTAB_VALO       (0010 | MTAB_XTD)               /* takes a value (optional) */
 572 # define MTAB_NMO        (0020 | MTAB_XTD)               /* only if named */
 573 # define MTAB_NC         (0040 | MTAB_XTD)               /* no UC conversion */
 574 # define MTAB_QUOTE      (0100 | MTAB_XTD)               /* quoted string */
 575 # define MTAB_SHP        (0200 | MTAB_XTD)               /* show takes parameter */
 576 # define MODMASK(mptr,flag) (((mptr)->mask & (uint32)(flag)) == (uint32)(flag))/* flag mask test */
 577 
 578 /* Search table */
 579 
 580 struct SCHTAB {
 581     int32               logic;                          /* logical operator */
 582     int32               boolop;                         /* boolean operator */
 583     uint32              count;                          /* value count in mask and comp arrays */
 584     t_value             *mask;                          /* mask for logical */
 585     t_value             *comp;                          /* comparison for boolean */
 586     };
 587 
 588 /* Breakpoint table */
 589 
 590 struct BRKTAB {
 591     t_addr              addr;                           /* address */
 592     uint32              typ;                            /* mask of types */
 593 # define BRK_TYP_USR_TYPES       ((1 << ('Z'-'A'+1)) - 1)/* all types A-Z */
 594 # define BRK_TYP_DYN_STEPOVER    (SWMASK ('Z'+1))
 595 # define BRK_TYP_DYN_USR         (SWMASK ('Z'+2))
 596 # define BRK_TYP_DYN_ALL         (BRK_TYP_DYN_USR|BRK_TYP_DYN_STEPOVER) /* Mask of All Dynamic types */
 597 # define BRK_TYP_TEMP            (SWMASK ('Z'+3))        /* Temporary (one-shot) */
 598 # define BRK_TYP_MAX             (('Z'-'A')+3)           /* Maximum breakpoint type */
 599     int32               cnt;                            /* proceed count */
 600     char                *act;                           /* action string */
 601     double              time_fired[SIM_BKPT_N_SPC];     /* instruction count when match occurred */
 602     BRKTAB *next;                                       /* list with same address value */
 603     };
 604 
 605 /* Breakpoint table */
 606 
 607 struct BRKTYPTAB {
 608     uint32      btyp;                                   /* type mask */
 609     const char *desc;                                   /* description */
 610     };
 611 # define BRKTYPE(typ,descrip) {SWMASK(typ), descrip}
 612 
 613 /* Expect rule */
 614 
 615 struct EXPTAB {
 616     uint8               *match;                         /* match string */
 617     uint32              size;                           /* match string size */
 618     char                *match_pattern;                 /* match pattern for format */
 619     int32               cnt;                            /* proceed count */
 620     int32               switches;                       /* flags */
 621 # define EXP_TYP_PERSIST         (SWMASK ('P'))      /* rule persists after match, default is once a rule matches, it is removed */
 622 # define EXP_TYP_CLEARALL        (SWMASK ('C'))      /* clear all rules after matching this rule, default is to once a rule matches, it is removed */
 623 # define EXP_TYP_REGEX           (SWMASK ('R'))      /* rule pattern is a regular expression */
 624 # define EXP_TYP_REGEX_I         (SWMASK ('I'))      /* regular expression pattern matching should be case independent */
 625 # define EXP_TYP_TIME            (SWMASK ('T'))      /* halt delay is in microseconds instead of instructions */
 626     char                *act;                           /* action string */
 627     };
 628 
 629 /* Expect Context */
 630 
 631 struct EXPECT {
 632     DEVICE              *dptr;                          /* Device (for Debug) */
 633     uint32              dbit;                           /* Debugging Bit */
 634     EXPTAB              *rules;                         /* match rules */
 635     int32               size;                           /* count of match rules */
 636     uint32              after;                          /* delay before halting */
 637     uint8               *buf;                           /* buffer of output data which has produced */
 638     uint32              buf_ins;                        /* buffer insertion point for the next output data */
 639     uint32              buf_size;                       /* buffer size */
 640     };
 641 
 642 /* Send Context */
 643 
 644 struct SEND {
 645     uint32              delay;                          /* instruction delay between sent data */
 646 # define SEND_DEFAULT_DELAY  1000                        /* default delay instruction count */
 647     DEVICE              *dptr;                          /* Device (for Debug) */
 648     uint32              dbit;                           /* Debugging Bit */
 649     uint32              after;                          /* instruction delay before sending any data */
 650     double              next_time;                      /* execution time when next data can be sent */
 651     uint8               *buffer;                        /* buffer */
 652     size_t              bufsize;                        /* buffer size */
 653     int32               insoff;                         /* insert offset */
 654     int32               extoff;                         /* extra offset */
 655     };
 656 
 657 /* Debug table */
 658 
 659 struct DEBTAB {
 660     const char          *name;                          /* control name */
 661     uint32              mask;                           /* control bit */
 662     const char          *desc;                          /* description */
 663     };
 664 
 665 /* Deprecated Debug macros.  Use sim_debug() */
 666 
 667 # define DEBUG_PRS(d)    (sim_deb && d.dctrl)
 668 # define DEBUG_PRD(d)    (sim_deb && d->dctrl)
 669 # define DEBUG_PRI(d,m)  (sim_deb && (d.dctrl & (m)))
 670 # define DEBUG_PRJ(d,m)  (sim_deb && ((d)->dctrl & (m)))
 671 
 672 # define SIM_DBG_EVENT       0x10000
 673 # define SIM_DBG_ACTIVATE    0x20000
 674 # define SIM_DBG_AIO_QUEUE   0x40000
 675 
 676 /* File Reference */
 677 struct FILEREF {
 678     char                name[CBUFSIZE];                 /* file name */
 679     FILE                *file;                          /* file handle */
 680     int32               refcount;                       /* reference count */
 681     };
 682 
 683 /*
 684    The following macros exist to help populate structure contents
 685 
 686    They are dependent on the declaration order of the fields
 687    of the structures they exist to populate.
 688 
 689  */
 690 
 691 # define UDATA(act,fl,cap) NULL,act,NULL,NULL,NULL,0,0,(fl),0,(cap),0,NULL,0,0
 692 
 693 # if defined (__STDC__) || defined (_WIN32) /* Variants which depend on how macro arguments are converted to strings */
 694 /* Generic Register declaration for all fields.
 695    If the register structure is extended, this macro will be retained and a
 696    new macro will be provided that populates the new register structure */
 697 #  define REGDATA(nm,loc,rdx,wd,off,dep,desc,flds,fl,qptr,siz) \
 698     #nm, &(loc), (rdx), (wd), (off), (dep), (desc), (flds), (fl), (qptr), (siz)
 699 /* Right Justified Octal Register Data */
 700 #  define ORDATA(nm,loc,wd) #nm, &(loc), 8, (wd), 0, 1, NULL, NULL
 701 /* Right Justified Decimal Register Data */
 702 #  define DRDATA(nm,loc,wd) #nm, &(loc), 10, (wd), 0, 1, NULL, NULL
 703 /* Right Justified Hexadecimal Register Data */
 704 #  define HRDATA(nm,loc,wd) #nm, &(loc), 16, (wd), 0, 1, NULL, NULL
 705 /* Right Justified Binary Register Data */
 706 #  define BINRDATA(nm,loc,wd) #nm, &(loc), 2, (wd), 0, 1, NULL, NULL
 707 /* One-bit binary flag at an arbitrary offset in a 32-bit word Register */
 708 #  define FLDATA(nm,loc,pos) #nm, &(loc), 2, 1, (pos), 1, NULL, NULL
 709 /* Arbitrary location and Radix Register */
 710 #  define GRDATA(nm,loc,rdx,wd,pos) #nm, &(loc), (rdx), (wd), (pos), 1, NULL, NULL
 711 /* Arrayed register whose data is kept in a standard C array Register */
 712 #  define BRDATA(nm,loc,rdx,wd,dep) #nm, (loc), (rdx), (wd), 0, (dep), NULL, NULL
 713 /* Same as above, but with additional description initializer */
 714 #  define ORDATAD(nm,loc,wd,desc) #nm, &(loc), 8, (wd), 0, 1, (desc), NULL
 715 #  define DRDATAD(nm,loc,wd,desc) #nm, &(loc), 10, (wd), 0, 1, (desc), NULL
 716 #  define HRDATAD(nm,loc,wd,desc) #nm, &(loc), 16, (wd), 0, 1, (desc), NULL
 717 #  define BINRDATAD(nm,loc,wd,desc) #nm, &(loc), 2, (wd), 0, 1, (desc), NULL
 718 #  define FLDATAD(nm,loc,pos,desc) #nm, &(loc), 2, 1, (pos), 1, (desc), NULL
 719 #  define GRDATAD(nm,loc,rdx,wd,pos,desc) #nm, &(loc), (rdx), (wd), (pos), 1, (desc), NULL
 720 #  define BRDATAD(nm,loc,rdx,wd,dep,desc) #nm, (loc), (rdx), (wd), 0, (dep), (desc), NULL
 721 /* Same as above, but with additional description initializer, and bitfields */
 722 #  define ORDATADF(nm,loc,wd,desc,flds) #nm, &(loc), 8, (wd), 0, 1, (desc), (flds)
 723 #  define DRDATADF(nm,loc,wd,desc,flds) #nm, &(loc), 10, (wd), 0, 1, (desc), (flds)
 724 #  define HRDATADF(nm,loc,wd,desc,flds) #nm, &(loc), 16, (wd), 0, 1, (desc), (flds)
 725 #  define BINRDATADF(nm,loc,wd) #nm, &(loc), 2, (wd), 0, 1, NULL, NULL
 726 #  define FLDATADF(nm,loc,pos,desc,flds) #nm, &(loc), 2, 1, (pos), 1, (desc), (flds)
 727 #  define GRDATADF(nm,loc,rdx,wd,pos,desc,flds) #nm, &(loc), (rdx), (wd), (pos), 1, (desc), (flds)
 728 #  define BRDATADF(nm,loc,rdx,wd,dep,desc,flds) #nm, (loc), (rdx), (wd), 0, (dep), (desc), (flds)
 729 #  define BIT(nm)              {#nm, 0xffffffff, 1}             /* Single Bit definition */
 730 #  define BITNC                {"",  0xffffffff, 1}             /* Don't care Bit definition */
 731 #  define BITF(nm,sz)          {#nm, 0xffffffff, sz}            /* Bit Field definition */
 732 #  define BITNCF(sz)           {"",  0xffffffff, sz}            /* Don't care Bit Field definition */
 733 #  define BITFFMT(nm,sz,fmt)   {#nm, 0xffffffff, sz, NULL, #fmt}/* Bit Field definition with Output format */
 734 #  define BITFNAM(nm,sz,names) {#nm, 0xffffffff, sz, names}     /* Bit Field definition with value->name map */
 735 # else /* For non-STD-C compiler which can't stringify macro arguments with # */
 736 #  define REGDATA(nm,loc,rdx,wd,off,dep,desc,flds,fl,qptr,siz) \
 737     "nm", &(loc), (rdx), (wd), (off), (dep), (desc), (flds), (fl), (qptr), (siz)
 738 #  define ORDATA(nm,loc,wd) "nm", &(loc), 8, (wd), 0, 1, NULL, NULL
 739 #  define DRDATA(nm,loc,wd) "nm", &(loc), 10, (wd), 0, 1, NULL, NULL
 740 #  define HRDATA(nm,loc,wd) "nm", &(loc), 16, (wd), 0, 1, NULL, NULL
 741 #  define BINRDATA(nm,loc,wd) "nm", &(loc), 2, (wd), 0, 1, NULL, NULL
 742 #  define FLDATA(nm,loc,pos) "nm", &(loc), 2, 1, (pos), 1, NULL, NULL
 743 #  define GRDATA(nm,loc,rdx,wd,pos) "nm", &(loc), (rdx), (wd), (pos), 1, NULL, NULL
 744 #  define BRDATA(nm,loc,rdx,wd,dep) "nm", (loc), (rdx), (wd), 0, (dep), NULL, NULL
 745 #  define ORDATAD(nm,loc,wd,desc) "nm", &(loc), 8, (wd), 0, 1, (desc), NULL
 746 #  define DRDATAD(nm,loc,wd,desc) "nm", &(loc), 10, (wd), 0, 1, (desc), NULL
 747 #  define HRDATAD(nm,loc,wd,desc) "nm", &(loc), 16, (wd), 0, 1, (desc), NULL
 748 #  define BINRDATAD(nm,loc,wd,desc) "nm", &(loc), 2, (wd), 0, 1, (desc), NULL
 749 #  define FLDATAD(nm,loc,pos,desc) "nm", &(loc), 2, 1, (pos), 1, (desc), NULL
 750 #  define GRDATAD(nm,loc,rdx,wd,pos,desc) "nm", &(loc), (rdx), (wd), (pos), 1, (desc), NULL
 751 #  define BRDATAD(nm,loc,rdx,wd,dep,desc) "nm", (loc), (rdx), (wd), 0, (dep), (desc), NULL
 752 #  define ORDATADF(nm,loc,wd,desc,flds) "nm", &(loc), 8, (wd), 0, 1, (desc), (flds)
 753 #  define DRDATADF(nm,loc,wd,desc,flds) "nm", &(loc), 10, (wd), 0, 1, (desc), (flds)
 754 #  define HRDATADF(nm,loc,wd,desc,flds) "nm", &(loc), 16, (wd), 0, 1, (desc), (flds)
 755 #  define BINRDATADF(nm,loc,wd,desc,flds) "nm", &(loc), 2, (wd), 0, 1, (desc), (flds)
 756 #  define FLDATADF(nm,loc,pos,desc,flds) "nm", &(loc), 2, 1, (pos), 1, (desc), (flds)
 757 #  define GRDATADF(nm,loc,rdx,wd,pos,desc,flds) "nm", &(loc), (rdx), (wd), (pos), 1, (desc), (flds)
 758 #  define BRDATADF(nm,loc,rdx,wd,dep,desc,flds) "nm", (loc), (rdx), (wd), 0, (dep), (desc), (flds)
 759 #  define BIT(nm)              {"nm", 0xffffffff, 1}              /* Single Bit definition */
 760 #  define BITNC                {"",   0xffffffff, 1}              /* Don't care Bit definition */
 761 #  define BITF(nm,sz)          {"nm", 0xffffffff, sz}             /* Bit Field definition */
 762 #  define BITNCF(sz)           {"",   0xffffffff, sz}             /* Don't care Bit Field definition */
 763 #  define BITFFMT(nm,sz,fmt)   {"nm", 0xffffffff, sz, NULL, "fmt"}/* Bit Field definition with Output format */
 764 #  define BITFNAM(nm,sz,names) {"nm", 0xffffffff, sz, names}      /* Bit Field definition with value->name map */
 765 # endif
 766 # define ENDBITS {NULL}  /* end of bitfield list */
 767 
 768 /* Arrayed register whose data is part of the UNIT structure */
 769 # define URDATA(nm,loc,rdx,wd,off,dep,fl) \
 770     REGDATA(nm,(loc),(rdx),(wd),(off),(dep),NULL,NULL,((fl) | REG_UNIT),0,0)
 771 /* Arrayed register whose data is part of an arbitrary structure */
 772 # define STRDATA(nm,loc,rdx,wd,off,dep,siz,fl) \
 773     REGDATA(nm,(loc),(rdx),(wd),(off),(dep),NULL,NULL,((fl) | REG_STRUCT),0,(siz))
 774 /* Same as above, but with additional description initializer */
 775 # define URDATAD(nm,loc,rdx,wd,off,dep,fl,desc) \
 776     REGDATA(nm,(loc),(rdx),(wd),(off),(dep),(desc),NULL,((fl) | REG_UNIT),0,0)
 777 # define STRDATAD(nm,loc,rdx,wd,off,dep,siz,fl,desc) \
 778     REGDATA(nm,(loc),(rdx),(wd),(off),(dep),(desc),NULL,((fl) | REG_STRUCT),0,(siz))
 779 /* Same as above, but with additional description initializer, and bitfields */
 780 # define URDATADF(nm,loc,rdx,wd,off,dep,fl,desc,flds) \
 781     REGDATA(nm,(loc),(rdx),(wd),(off),(dep),(desc),(flds),((fl) | REG_UNIT),0,0)
 782 # define STRDATADF(nm,loc,rdx,wd,off,dep,siz,fl,desc,flds) \
 783     REGDATA(nm,(loc),(rdx),(wd),(off),(dep),(desc),(flds),((fl) | REG_STRUCT),0,(siz))
 784 
 785 /* Function prototypes */
 786 
 787 # include "scp.h"
 788 # include "sim_console.h"
 789 # include "sim_timer.h"
 790 # include "sim_fio.h"
 791 
 792 # undef FREE
 793 # ifdef TESTING
 794 #  define FREE(p) free(p)
 795 # else
 796 #  define FREE(p) do  \
 797   {                   \
 798     free((p));        \
 799     (p) = NULL;       \
 800   } while(0)
 801 # endif /* ifdef TESTING */
 802 
 803 /* Consistent PATH_MAX */
 804 
 805 # ifndef MAXPATHLEN
 806 #  if defined(PATH_MAX) && PATH_MAX > 1024
 807 #   define MAXPATHLEN PATH_MAX
 808 #  else
 809 #   define MAXPATHLEN 1024
 810 #  endif /* if defined(PATH_MAX) && PATH_MAX > 1024 */
 811 # endif /* ifndef MAXPATHLEN */
 812 
 813 # ifndef PATH_MAX
 814 #  define PATH_MAX MAXPATHLEN
 815 # endif /* ifndef PATH_MAX */
 816 
 817 /* Macro to ALWAYS execute the specified expression and fail if it evaluates to false. */
 818 
 819 /* This replaces any references to "assert()" which should never be invoked */
 820 /* with an expression which causes side effects (i.e. must be executed for */
 821 /* the program to work correctly) */
 822 
 823 # define ASSURE(_Expression) while (!(_Expression)) {fprintf(stderr, "%s failed at %s line %d\n", #_Expression, __FILE__, __LINE__);  \
 824                                                     sim_printf("%s failed at %s line %d\n", #_Expression, __FILE__, __LINE__);       \
 825                                                     abort();}
 826 
 827 #endif

/* [previous][next][first][last][top][bottom][index][help] */