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

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