home *** CD-ROM | disk | FTP | other *** search
/ minnie.tuhs.org / unixen.tar / unixen / PDP-11 / Boot_Images / 2.11_on_rl02 / pdpsim.tz / pdpsim / sim_defs.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-01-29  |  6.7 KB  |  214 lines

  1. /* Simulator definitions
  2.  
  3.    Copyright (c) 1993, 1994, 1995, 1996, Robert M Supnik,
  4.    Digital Equipment Corporation
  5.    Commercial use prohibited
  6.  
  7.    The interface between the simulator control package (SCP) and the
  8.    simulator consists of the following routines and data structures
  9.  
  10.     sim_name        simulator name string
  11.     sim_devices[]        array of pointers to simulated devices
  12.     sim_PC            pointer to saved PC register descriptor
  13.     sim_interval        simulator interval to next event
  14.     sim_stop_messages[]    array of pointers to stop messages
  15.     sim_instr()        instruction execution routine
  16.     sim_load()        binary loader routine
  17.     sim_emax        maximum number of words in an instruction
  18.  
  19.    In addition, the simulator must supply routines to print and parse
  20.    architecture specific formats
  21.  
  22.     print_sym        print symbolic output
  23.     parse_sym        parse symbolic input
  24. */
  25.  
  26. #include <stddef.h>
  27. #include <stdlib.h>
  28. #include <stdio.h>
  29. #include <string.h>
  30. #include <errno.h>
  31.  
  32. #ifndef TRUE
  33. #define TRUE        1
  34. #define FALSE        0
  35. #endif
  36.  
  37. /* Simulator status codes
  38.  
  39.    0            ok
  40.    1 - (SCPE_BASE - 1)    simulator specific
  41.    SCPE_BASE - n    general
  42. */
  43.  
  44. #define SCPE_OK        0                /* normal return */
  45. #define SCPE_BASE    32                /* base for messages */
  46. #define SCPE_NXM    (SCPE_BASE + 0)            /* nxm */
  47. #define SCPE_UNATT    (SCPE_BASE + 1)            /* no file */
  48. #define SCPE_IOERR     (SCPE_BASE + 2)            /* I/O error */
  49. #define SCPE_CSUM    (SCPE_BASE + 3)            /* loader cksum */
  50. #define SCPE_FMT    (SCPE_BASE + 4)            /* loader format */
  51. #define SCPE_NOATT    (SCPE_BASE + 5)            /* not attachable */
  52. #define SCPE_OPENERR    (SCPE_BASE + 6)            /* open error */
  53. #define SCPE_MEM    (SCPE_BASE + 7)            /* alloc error */
  54. #define SCPE_ARG    (SCPE_BASE + 8)            /* argument error */
  55. #define SCPE_STEP    (SCPE_BASE + 9)            /* step expired */
  56. #define SCPE_UNK    (SCPE_BASE + 10)        /* unknown command */
  57. #define SCPE_RO        (SCPE_BASE + 11)        /* read only */
  58. #define SCPE_INCOMP    (SCPE_BASE + 12)        /* incomplete */
  59. #define SCPE_STOP    (SCPE_BASE + 13)        /* sim stopped */
  60. #define SCPE_EXIT    (SCPE_BASE + 14)        /* sim exit */
  61. #define SCPE_TTIERR    (SCPE_BASE + 15)        /* console tti err */
  62. #define SCPE_TTOERR    (SCPE_BASE + 16)        /* console tto err */
  63. #define SCPE_EOF    (SCPE_BASE + 17)        /* end of file */
  64. #define SCPE_REL    (SCPE_BASE + 18)        /* relocation error */
  65. #define SCPE_NOPARAM    (SCPE_BASE + 19)        /* no parameters */
  66. #define SCPE_ALATT    (SCPE_BASE + 20)        /* already attached */
  67. #define SCPE_KFLAG    01000                /* tti data flag */
  68.  
  69. /* Constants */
  70.  
  71. #define CBUFSIZE    128                /* string buf size */
  72. #define PV_RZRO        0                /* right, zero fill */
  73. #define PV_RSPC        1                /* right, space fill */
  74. #define PV_LEFT        2                /* left justify */
  75.  
  76. /* Default timing parameters */
  77.  
  78. #define KBD_POLL_WAIT    5000                /* keyboard poll */
  79. #define SERIAL_IN_WAIT    100                /* serial in time */
  80. #define SERIAL_OUT_WAIT    10                /* serial output */
  81. #define NOQUEUE_WAIT    10000                /* min check time */
  82.  
  83. /* Convert switch letter to bit mask */
  84.  
  85. #define SWMASK(x) (1u << (((int) (x)) - ((int) 'A')))
  86.  
  87. /* String match */
  88.  
  89. #define MATCH_CMD(ptr,cmd) strncmp ((ptr), (cmd), strlen (ptr))
  90.  
  91. /* Device data structure */
  92.  
  93. struct device {
  94.     char        *name;                /* name */
  95.     struct unit     *units;                /* units */
  96.     struct reg    *registers;            /* registers */
  97.     struct mtab    *modifiers;            /* modifiers */
  98.     int        numunits;            /* #units */
  99.     int        aradix;                /* address radix */
  100.     int        awidth;                /* address width */
  101.     int        aincr;                /* addr increment */
  102.     int        dradix;                /* data radix */
  103.     int        dwidth;                /* data width */
  104.     int        (*examine)();            /* examine routine */
  105.     int        (*deposit)();            /* deposit routine */
  106.     int        (*reset)();            /* reset routine */
  107.     int        (*boot)();            /* boot routine */
  108.     int        (*attach)();            /* attach routine */
  109.     int        (*detach)();            /* detach routine */
  110. };
  111.  
  112. /* Unit data structure
  113.  
  114.    Parts of the unit structure are device specific, that is, they are
  115.    not referenced by the simulator control package and can be freely
  116.    used by device simulators.  Fields starting with 'buf', and flags
  117.    starting with 'UF', are device specific.  The definitions given here
  118.    are for a typical sequential device.
  119. */
  120.  
  121. struct unit {
  122.     struct unit    *next;                /* next active */
  123.     int        (*action)();            /* action routine */
  124.     char        *filename;            /* open file name */
  125.     FILE        *fileref;            /* file reference */
  126.     void        *filebuf;            /* memory buffer */
  127.     int        hwmark;                /* high water mark */
  128.     int        time;                /* time out */
  129.     int        flags;                /* flags */
  130.     int        capac;                /* capacity */
  131.     int        pos;                /* file position */
  132.     int        buf;                /* buffer */
  133.     int        wait;                /* wait */
  134.     int        u3;                /* device specific */
  135.     int        u4;                /* device specific */
  136. };
  137.  
  138. /* Unit flags */
  139.  
  140. #define UNIT_ATTABLE    000001                /* attachable */
  141. #define UNIT_RO        000002                /* read only */
  142. #define UNIT_FIX    000004                /* fixed capacity */
  143. #define UNIT_SEQ    000010                /* sequential */
  144. #define UNIT_ATT    000020                /* attached */
  145. /* unused        000040 */
  146. #define UNIT_BUFABLE    000100                /* bufferable */
  147. #define UNIT_MUSTBUF    000200                /* must buffer */
  148. #define UNIT_BUF    000400                /* buffered */
  149. #define UNIT_V_UF    9                /* device specific */
  150.  
  151. /* Register data structure */
  152.  
  153. struct reg {
  154.     char        *name;                /* name */
  155.     void        *loc;                /* location */
  156.     int        radix;                /* radix */
  157.     int        width;                /* width */
  158.     int        offset;                /* starting bit */
  159.     int        depth;                /* save depth */
  160.     int        flags;                /* flags */
  161. };
  162.  
  163. #define REG_FMT        003                /* see PV_x */
  164. #define REG_RO        004                /* read only */
  165. #define REG_HIDDEN    010                /* hidden */
  166. #define REG_NZ        020                /* must be non-zero */
  167. #define REG_HRO        (REG_RO + REG_HIDDEN)        /* hidden, read only */
  168.  
  169. /* Command table */
  170.  
  171. struct ctab {
  172.     char        *name;                /* name */
  173.     int        (*action)();            /* action routine */
  174.     int        arg;                /* argument */
  175. };
  176.  
  177. /* Modifier table */
  178.  
  179. struct mtab {
  180.     int        mask;                /* mask */
  181.     int        match;                /* match */
  182.     char        *pstring;            /* print string */
  183.     char        *mstring;            /* match string */
  184.     int        (*valid)();            /* validation routine */
  185. };
  186.  
  187. /* The following macros define structure contents */
  188.  
  189. #define UDATA(act,fl,cap) NULL,act,NULL,NULL,NULL,0,0,(fl),(cap),0,0
  190.  
  191. #ifndef __STDC__
  192. #define ORDATA(nm,loc,wd) "nm", &(loc), 8, (wd), 0, 1
  193. #define DRDATA(nm,loc,wd) "nm", &(loc), 10, (wd), 0, 1
  194. #define HRDATA(nm,loc,wd) "nm", &(loc), 16, (wd), 0, 1
  195. #define FLDATA(nm,loc,pos) "nm", &(loc), 2, 1, (pos), 1
  196. #define GRDATA(nm,loc,rdx,wd,pos) "nm", &(loc), (rdx), (wd), (pos), 1
  197. #define BRDATA(nm,loc,rdx,wd,dep) "nm", (loc), (rdx), (wd), 0, (dep)
  198. #else
  199. #define ORDATA(nm,loc,wd) #nm, &(loc), 8, (wd), 0, 1
  200. #define DRDATA(nm,loc,wd) #nm, &(loc), 10, (wd), 0, 1
  201. #define HRDATA(nm,loc,wd) #nm, &(loc), 16, (wd), 0, 1
  202. #define FLDATA(nm,loc,pos) #nm, &(loc), 2, 1, (pos), 1
  203. #define GRDATA(nm,loc,rdx,wd,pos) #nm, &(loc), (rdx), (wd), (pos), 1
  204. #define BRDATA(nm,loc,rdx,wd,dep) #nm, (loc), (rdx), (wd), 0, (dep)
  205. #endif
  206.  
  207. /* Typedefs for principal structures */
  208.  
  209. typedef struct device DEVICE;
  210. typedef struct unit UNIT;
  211. typedef struct reg REG;
  212. typedef struct ctab CTAB;
  213. typedef struct mtab MTAB;
  214.