1 /* Simulator definitions
2 
3    Copyright (c) 1993-1997,
4    Robert M Supnik, 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 #ifndef _INCLUDED_sim_defs
27 #define _INCLUDED_sim_defs 1
28 
29 #include <stddef.h>
30 #include <stdlib.h>
31 #include <stdio.h>
32 #include <string.h>
33 #include <errno.h>
34 #ifdef SUNOS
35 #include <unistd.h>
36 #endif
37 
38 #ifndef TRUE
39 #define TRUE		1
40 #define FALSE		0
41 #endif
42 
43 /* Length specific integer declarations */
44 
45 #define int8		char
46 #define int16		short
47 #define int32		int
48 /* #define int64	long */
49 typedef int		t_stat;				/* status */
50 typedef int32		t_addr;				/* address */
51 #if defined (int64)
52 typedef unsigned int64	t_value;			/* value */
53 #else
54 typedef unsigned int32	t_value;
55 #endif
56 
57 /* System independent definitions */
58 
59 typedef int32		t_mtrlnt;			/* magtape rec lnt */
60 #define FLIP_SIZE	(1 << 16)			/* flip buf size */
61 #define CBUFSIZE	128				/* string buf size */
62 
63 /* Simulator status codes
64 
65    0			ok
66    1 - (SCPE_BASE - 1)	simulator specific
67    SCPE_BASE - n	general
68 */
69 
70 #define SCPE_OK		0				/* normal return */
71 #define SCPE_BASE	32				/* base for messages */
72 #define SCPE_NXM	(SCPE_BASE + 0)			/* nxm */
73 #define SCPE_UNATT	(SCPE_BASE + 1)			/* no file */
74 #define SCPE_IOERR 	(SCPE_BASE + 2)			/* I/O error */
75 #define SCPE_CSUM	(SCPE_BASE + 3)			/* loader cksum */
76 #define SCPE_FMT	(SCPE_BASE + 4)			/* loader format */
77 #define SCPE_NOATT	(SCPE_BASE + 5)			/* not attachable */
78 #define SCPE_OPENERR	(SCPE_BASE + 6)			/* open error */
79 #define SCPE_MEM	(SCPE_BASE + 7)			/* alloc error */
80 #define SCPE_ARG	(SCPE_BASE + 8)			/* argument error */
81 #define SCPE_STEP	(SCPE_BASE + 9)			/* step expired */
82 #define SCPE_UNK	(SCPE_BASE + 10)		/* unknown command */
83 #define SCPE_RO		(SCPE_BASE + 11)		/* read only */
84 #define SCPE_INCOMP	(SCPE_BASE + 12)		/* incomplete */
85 #define SCPE_STOP	(SCPE_BASE + 13)		/* sim stopped */
86 #define SCPE_EXIT	(SCPE_BASE + 14)		/* sim exit */
87 #define SCPE_TTIERR	(SCPE_BASE + 15)		/* console tti err */
88 #define SCPE_TTOERR	(SCPE_BASE + 16)		/* console tto err */
89 #define SCPE_EOF	(SCPE_BASE + 17)		/* end of file */
90 #define SCPE_REL	(SCPE_BASE + 18)		/* relocation error */
91 #define SCPE_NOPARAM	(SCPE_BASE + 19)		/* no parameters */
92 #define SCPE_ALATT	(SCPE_BASE + 20)		/* already attached */
93 #define SCPE_KFLAG	01000				/* tti data flag */
94 
95 /* Print value format codes */
96 
97 #define PV_RZRO		0				/* right, zero fill */
98 #define PV_RSPC		1				/* right, space fill */
99 #define PV_LEFT		2				/* left justify */
100 
101 /* Default timing parameters */
102 
103 #define KBD_POLL_WAIT	5000				/* keyboard poll */
104 #define SERIAL_IN_WAIT	100				/* serial in time */
105 #define SERIAL_OUT_WAIT	10				/* serial output */
106 #define NOQUEUE_WAIT	10000				/* min check time */
107 
108 /* Convert switch letter to bit mask */
109 
110 #define SWMASK(x) (1u << (((int) (x)) - ((int) 'A')))
111 
112 /* String match */
113 
114 #define MATCH_CMD(ptr,cmd) strncmp ((ptr), (cmd), strlen (ptr))
115 
116 /* Device data structure */
117 
118 struct device {
119 	char		*name;				/* name */
120 	struct unit 	*units;				/* units */
121 	struct reg	*registers;			/* registers */
122 	struct mtab	*modifiers;			/* modifiers */
123 	int		numunits;			/* #units */
124 	int		aradix;				/* address radix */
125 	int		awidth;				/* address width */
126 	int		aincr;				/* addr increment */
127 	int		dradix;				/* data radix */
128 	int		dwidth;				/* data width */
129 	t_stat		(*examine)();			/* examine routine */
130 	t_stat		(*deposit)();			/* deposit routine */
131 	t_stat		(*reset)();			/* reset routine */
132 	t_stat		(*boot)();			/* boot routine */
133 	t_stat		(*attach)();			/* attach routine */
134 	t_stat		(*detach)();			/* detach routine */
135 };
136 
137 /* Unit data structure
138 
139    Parts of the unit structure are device specific, that is, they are
140    not referenced by the simulator control package and can be freely
141    used by device simulators.  Fields starting with 'buf', and flags
142    starting with 'UF', are device specific.  The definitions given here
143    are for a typical sequential device.
144 */
145 
146 struct unit {
147 	struct unit	*next;				/* next active */
148 	t_stat		(*action)();			/* action routine */
149 	char		*filename;			/* open file name */
150 	FILE		*fileref;			/* file reference */
151 	void		*filebuf;			/* memory buffer */
152 	t_addr		hwmark;				/* high water mark */
153 	int32		time;				/* time out */
154 	int32		flags;				/* flags */
155 	t_addr		capac;				/* capacity */
156 	t_addr		pos;				/* file position */
157 	int32		buf;				/* buffer */
158 	int32		wait;				/* wait */
159 	int32		u3;				/* device specific */
160 	int32		u4;				/* device specific */
161 };
162 
163 /* Unit flags */
164 
165 #define UNIT_ATTABLE	000001				/* attachable */
166 #define UNIT_RO		000002				/* read only */
167 #define UNIT_FIX	000004				/* fixed capacity */
168 #define UNIT_SEQ	000010				/* sequential */
169 #define UNIT_ATT	000020				/* attached */
170 #define UNIT_BINK	000040				/* K = power of 2 */
171 #define UNIT_BUFABLE	000100				/* bufferable */
172 #define UNIT_MUSTBUF	000200				/* must buffer */
173 #define UNIT_BUF	000400				/* buffered */
174 #define UNIT_DISABLE	001000				/* disable-able */
175 #define UNIT_DIS	002000				/* disabled */
176 #define UNIT_V_UF	11				/* device specific */
177 
178 /* Register data structure */
179 
180 struct reg {
181 	char		*name;				/* name */
182 	void		*loc;				/* location */
183 	int		radix;				/* radix */
184 	int		width;				/* width */
185 	int		offset;				/* starting bit */
186 	int		depth;				/* save depth */
187 	int32		flags;				/* flags */
188 };
189 
190 #define REG_FMT		003				/* see PV_x */
191 #define REG_RO		004				/* read only */
192 #define REG_HIDDEN	010				/* hidden */
193 #define REG_NZ		020				/* must be non-zero */
194 #define REG_HRO		(REG_RO + REG_HIDDEN)		/* hidden, read only */
195 
196 /* Command table */
197 
198 struct ctab {
199 	char		*name;				/* name */
200 	t_stat		(*action)();			/* action routine */
201 	int		arg;				/* argument */
202 };
203 
204 /* Modifier table */
205 
206 struct mtab {
207 	int32		mask;				/* mask */
208 	int32		match;				/* match */
209 	char		*pstring;			/* print string */
210 	char		*mstring;			/* match string */
211 	t_stat		(*valid)();			/* validation routine */
212 };
213 
214 /* The following macros define structure contents */
215 
216 #define UDATA(act,fl,cap) NULL,act,NULL,NULL,NULL,0,0,(fl),(cap),0,0
217 
218 #if defined (__STDC__) || defined (_WIN32)
219 #define ORDATA(nm,loc,wd) #nm, &(loc), 8, (wd), 0, 1
220 #define DRDATA(nm,loc,wd) #nm, &(loc), 10, (wd), 0, 1
221 #define HRDATA(nm,loc,wd) #nm, &(loc), 16, (wd), 0, 1
222 #define FLDATA(nm,loc,pos) #nm, &(loc), 2, 1, (pos), 1
223 #define GRDATA(nm,loc,rdx,wd,pos) #nm, &(loc), (rdx), (wd), (pos), 1
224 #define BRDATA(nm,loc,rdx,wd,dep) #nm, (loc), (rdx), (wd), 0, (dep)
225 #else
226 #define ORDATA(nm,loc,wd) "nm", &(loc), 8, (wd), 0, 1
227 #define DRDATA(nm,loc,wd) "nm", &(loc), 10, (wd), 0, 1
228 #define HRDATA(nm,loc,wd) "nm", &(loc), 16, (wd), 0, 1
229 #define FLDATA(nm,loc,pos) "nm", &(loc), 2, 1, (pos), 1
230 #define GRDATA(nm,loc,rdx,wd,pos) "nm", &(loc), (rdx), (wd), (pos), 1
231 #define BRDATA(nm,loc,rdx,wd,dep) "nm", (loc), (rdx), (wd), 0, (dep)
232 #endif
233 
234 /* Typedefs for principal structures */
235 
236 typedef struct device DEVICE;
237 typedef struct unit UNIT;
238 typedef struct reg REG;
239 typedef struct ctab CTAB;
240 typedef struct mtab MTAB;
241 
242 /* Function prototypes */
243 
244 #if defined (SCP)					/* defining routine? */
245 #define EXTERN
246 #else							/* referencing routine */
247 #define EXTERN extern
248 #endif
249 
250 EXTERN t_stat sim_process_event (void);
251 EXTERN t_stat sim_activate (UNIT *uptr, int32 interval);
252 EXTERN t_stat sim_cancel (UNIT *uptr);
253 EXTERN int32 sim_is_active (UNIT *uptr);
254 EXTERN double sim_gtime (void);
255 EXTERN t_stat attach_unit (UNIT *uptr, char *cptr);
256 EXTERN t_stat detach_unit (UNIT *uptr);
257 EXTERN t_stat reset_all (int start_device);
258 EXTERN size_t fxread (void *bptr, size_t size, size_t count, FILE *fptr);
259 EXTERN size_t fxwrite (void *bptr, size_t size, size_t count, FILE *fptr);
260 EXTERN t_stat get_yn (char *ques, t_stat deflt);
261 EXTERN char *get_glyph (char *iptr, char *optr, char mchar);
262 EXTERN t_value get_uint (char *cptr, int radix, t_value max, t_stat *status);
263 
264 #endif /* !_INCLUDED_sim_defs */
265