First Commit of my working state
[simh.git] / HP2100 / hp2100_defs.h
1 /* hp2100_defs.h: HP 2100 simulator definitions
2
3 Copyright (c) 1993-2008, Robert M. Supnik
4
5 Permission is hereby granted, free of charge, to any person obtaining a
6 copy of this software and associated documentation files (the "Software"),
7 to deal in the Software without restriction, including without limitation
8 the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 and/or sell copies of the Software, and to permit persons to whom the
10 Software is furnished to do so, subject to the following conditions:
11
12 The above copyright notice and this permission notice shall be included in
13 all copies or substantial portions of the Software.
14
15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 ROBERT M SUPNIK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19 IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
22 Except as contained in this notice, the name of Robert M Supnik shall not
23 be used in advertising or otherwise to promote the sale, use or other dealings
24 in this Software without prior written authorization from Robert M Supnik.
25
26 24-Apr-08 JDB Added I_MRG_I, I_JSB, I_JSB_I, and I_JMP instruction masks
27 14-Apr-08 JDB Changed TMR_MUX to TMR_POLL for idle support
28 Added POLLMODE, sync_poll() declaration
29 Added I_MRG, I_ISZ, I_IOG, I_STF, and I_SFS instruction masks
30 07-Dec-07 JDB Added BACI device
31 10-Nov-07 JDB Added 16/32-bit unsigned-to-signed conversions
32 11-Jan-07 JDB Added 12578A DMA byte packing to DMA structure
33 28-Dec-06 JDB Added CRS backplane signal as I/O pseudo-opcode
34 Added DMASK32 32-bit mask value
35 21-Dec-06 JDB Changed MEM_ADDR_OK for 21xx loader support
36 12-Sep-06 JDB Define NOTE_IOG to recalc interrupts after instr exec
37 Rename STOP_INDINT to NOTE_INDINT (not a stop condition)
38 30-Dec-04 JDB Added IBL_DS_HEAD head number mask
39 19-Nov-04 JDB Added STOP_OFFLINE, STOP_PWROFF stop codes
40 25-Apr-04 RMS Added additional IBL definitions
41 Added DMA EDT I/O pseudo-opcode
42 25-Apr-03 RMS Revised for extended file support
43 24-Oct-02 RMS Added indirect address interrupt
44 08-Feb-02 RMS Added DMS definitions
45 01-Feb-02 RMS Added terminal multiplexor support
46 16-Jan-02 RMS Added additional device support
47 30-Nov-01 RMS Added extended SET/SHOW support
48 15-Oct-00 RMS Added dynamic device numbers
49 14-Apr-99 RMS Changed t_addr to unsigned
50
51 The author gratefully acknowledges the help of Jeff Moffat in answering
52 questions about the HP2100; and of Dave Bryan in adding features and
53 correcting errors throughout the simulator.
54 */
55 #ifndef _HP2100_DEFS_H_
56 #define _HP2100_DEFS_H_ 0
57
58 #include "sim_defs.h" /* simulator defns */
59
60 /* Simulator stop and notification codes */
61
62 #define STOP_RSRV 1 /* must be 1 */
63 #define STOP_IODV 2 /* must be 2 */
64 #define STOP_HALT 3 /* HALT */
65 #define STOP_IBKPT 4 /* breakpoint */
66 #define STOP_IND 5 /* indirect loop */
67 #define NOTE_INDINT 6 /* indirect intr */
68 #define STOP_NOCONN 7 /* no connection */
69 #define STOP_OFFLINE 8 /* device offline */
70 #define STOP_PWROFF 9 /* device powered off */
71 #define NOTE_IOG 10 /* I/O instr executed */
72
73 #define ABORT_PRO 1 /* protection abort */
74
75 /* Memory */
76
77 #define MEMSIZE (cpu_unit.capac) /* actual memory size */
78 #define MEM_ADDR_OK(x) (((uint32) (x)) < fwanxm)
79 #define VA_N_SIZE 15 /* virtual addr size */
80 #define VASIZE (1 << VA_N_SIZE)
81 #define VAMASK 077777 /* virt addr mask */
82 #define PA_N_SIZE 20 /* phys addr size */
83 #define PASIZE (1 << PA_N_SIZE)
84 #define PAMASK (PASIZE - 1) /* phys addr mask */
85
86 /* Architectural constants */
87
88 #define SIGN32 020000000000 /* 32b sign */
89 #define DMASK32 037777777777 /* 32b data mask/maximum value */
90 #define DMAX32 017777777777 /* 32b maximum signed value */
91 #define SIGN 0100000 /* 16b sign */
92 #define DMASK 0177777 /* 16b data mask/maximum value */
93 #define DMAX 0077777 /* 16b maximum signed value */
94 #define DMASK8 0377 /* 8b data mask/maximum value */
95 #define AR ABREG[0] /* A = reg 0 */
96 #define BR ABREG[1] /* B = reg 1 */
97
98 /* Portable conversions (sign-extension, unsigned-to-signed) */
99
100 #define SEXT(x) ((int32) (((x) & SIGN)? ((x) | ~DMASK): ((x) & DMASK)))
101
102 #define INT16(u) ((u) > DMAX ? (-(int16) (DMASK - (u)) - 1) : (int16) (u))
103 #define INT32(u) ((u) > DMAX32 ? (-(int32) (DMASK32 - (u)) - 1) : (int32) (u))
104
105 /* Memory reference instructions */
106
107 #define I_IA 0100000 /* indirect address */
108 #define I_AB 0004000 /* A/B select */
109 #define I_CP 0002000 /* current page */
110 #define I_DISP 0001777 /* page displacement */
111 #define I_PAGENO 0076000 /* page number */
112
113 /* Other instructions */
114
115 #define I_NMRMASK 0172000 /* non-mrf opcode */
116 #define I_SRG 0000000 /* shift */
117 #define I_ASKP 0002000 /* alter/skip */
118 #define I_EXTD 0100000 /* extend */
119 #define I_IO 0102000 /* I/O */
120 #define I_CTL 0004000 /* CTL on/off */
121 #define I_HC 0001000 /* hold/clear */
122 #define I_DEVMASK 0000077 /* device mask */
123 #define I_GETIOOP(x) (((x) >> 6) & 07) /* I/O sub op */
124
125 /* Instruction masks */
126
127 #define I_MRG 0074000 /* MRG instructions */
128 #define I_MRG_I (I_MRG | I_IA) /* MRG indirect instruction group */
129 #define I_JSB 0014000 /* JSB instruction */
130 #define I_JSB_I (I_JSB | I_IA) /* JSB,I instruction */
131 #define I_JMP 0024000 /* JMP instruction */
132 #define I_ISZ 0034000 /* ISZ instruction */
133
134 #define I_IOG 0107700 /* I/O group instruction */
135 #define I_SFS 0102300 /* SFS instruction */
136 #define I_STF 0102100 /* STF instruction */
137
138 /* DMA channels */
139
140 #define DMA_OE 020000000000 /* byte packing odd/even flag */
141 #define DMA1_STC 0100000 /* DMA - issue STC */
142 #define DMA1_PB 0040000 /* DMA - pack bytes */
143 #define DMA1_CLC 0020000 /* DMA - issue CLC */
144 #define DMA2_OI 0100000 /* DMA - output/input */
145
146 struct DMA { /* DMA channel */
147 uint32 cw1; /* device select */
148 uint32 cw2; /* direction, address */
149 uint32 cw3; /* word count */
150 uint32 latency; /* 1st cycle delay */
151 uint32 packer; /* byte-packer holding reg */
152 };
153
154 /* Memory management */
155
156 #define VA_N_OFF 10 /* offset width */
157 #define VA_M_OFF ((1 << VA_N_OFF) - 1) /* offset mask */
158 #define VA_GETOFF(x) ((x) & VA_M_OFF)
159 #define VA_N_PAG (VA_N_SIZE - VA_N_OFF) /* page width */
160 #define VA_V_PAG (VA_N_OFF)
161 #define VA_M_PAG ((1 << VA_N_PAG) - 1)
162 #define VA_GETPAG(x) (((x) >> VA_V_PAG) & VA_M_PAG)
163
164 /* Maps */
165
166 #define MAP_NUM 4 /* num maps */
167 #define MAP_LNT (1 << VA_N_PAG) /* map length */
168 #define MAP_MASK ((MAP_NUM * MAP_LNT) - 1)
169 #define SMAP 0 /* system map */
170 #define UMAP (SMAP + MAP_LNT) /* user map */
171 #define PAMAP (UMAP + MAP_LNT) /* port A map */
172 #define PBMAP (PAMAP + MAP_LNT) /* port B map */
173
174 /* DMS map entries */
175
176 #define MAP_V_RPR 15 /* read prot */
177 #define MAP_V_WPR 14 /* write prot */
178 #define RD (1 << MAP_V_RPR)
179 #define WR (1 << MAP_V_WPR)
180 #define MAP_MBZ 0036000 /* must be zero */
181 #define MAP_N_PAG (PA_N_SIZE - VA_N_OFF) /* page width */
182 #define MAP_V_PAG (VA_N_OFF)
183 #define MAP_M_PAG ((1 << MAP_N_PAG) - 1)
184 #define MAP_GETPAG(x) (((x) & MAP_M_PAG) << MAP_V_PAG)
185
186 /* Map status register */
187
188 #define MST_ENBI 0100000 /* mem enb @ int */
189 #define MST_UMPI 0040000 /* usr map @ int */
190 #define MST_ENB 0020000 /* mem enb */
191 #define MST_UMP 0010000 /* usr map */
192 #define MST_PRO 0004000 /* protection */
193 #define MST_FLT 0002000 /* fence comp */
194 #define MST_FENCE 0001777 /* base page fence */
195
196 /* Map violation register */
197
198 #define MVI_V_RPR 15 /* must be same as */
199 #define MVI_V_WPR 14 /* MAP_V_xPR */
200 #define MVI_RPR (1 << MVI_V_RPR) /* rd viol */
201 #define MVI_WPR (1 << MVI_V_WPR) /* wr viol */
202 #define MVI_BPG 0020000 /* base page viol */
203 #define MVI_PRV 0010000 /* priv viol */
204 #define MVI_MEB 0000200 /* me bus enb @ viol */
205 #define MVI_MEM 0000100 /* mem enb @ viol */
206 #define MVI_UMP 0000040 /* usr map @ viol */
207 #define MVI_PAG 0000037 /* pag sel */
208
209 /* Timers */
210
211 #define TMR_CLK 0 /* clock */
212 #define TMR_POLL 1 /* input polling */
213
214 #define POLL_RATE 100 /* poll 100 times per second */
215 #define POLL_WAIT 15800 /* initial poll ~ 10 msec. */
216
217 typedef enum { INITIAL, SERVICE } POLLMODE; /* poll synchronization modes */
218
219 /* I/O sub-opcodes */
220
221 #define ioHLT 0 /* halt */
222 #define ioFLG 1 /* set/clear flag */
223 #define ioSFC 2 /* skip on flag clear */
224 #define ioSFS 3 /* skip on flag set */
225 #define ioMIX 4 /* merge into A/B */
226 #define ioLIX 5 /* load into A/B */
227 #define ioOTX 6 /* output from A/B */
228 #define ioCTL 7 /* set/clear control */
229 #define ioEDT 8 /* DMA: end data transfer */
230 #define ioCRS 9 /* control reset ("CLC 0") */
231
232 /* I/O devices - fixed assignments */
233
234 #define CPU 000 /* interrupt control */
235 #define OVF 001 /* overflow */
236 #define DMALT0 002 /* DMA 0 alternate */
237 #define DMALT1 003 /* DMA 1 alternate */
238 #define PWR 004 /* power fail */
239 #define PRO 005 /* parity/mem protect */
240 #define DMA0 006 /* DMA channel 0 */
241 #define DMA1 007 /* DMA channel 1 */
242 #define VARDEV (DMA1 + 1) /* start of var assign */
243 #define M_NXDEV (INT_M (CPU) | INT_M (OVF) | \
244 INT_M (DMALT0) | INT_M (DMALT1))
245 #define M_FXDEV (M_NXDEV | INT_M (PWR) | INT_M (PRO) | \
246 INT_M (DMA0) | INT_M (DMA1))
247
248 /* I/O devices - variable assignment defaults */
249
250 #define PTR 010 /* 12597A-002 paper tape reader */
251 #define TTY 011 /* 12531C teleprinter */
252 #define PTP 012 /* 12597A-005 paper tape punch */
253 #define CLK 013 /* 12539C time-base generator */
254 #define LPS 014 /* 12653A line printer */
255 #define LPT 015 /* 12845A line printer */
256 #define MTD 020 /* 12559A data */
257 #define MTC 021 /* 12559A control */
258 #define DPD 022 /* 12557A data */
259 #define DPC 023 /* 12557A control */
260 #define DQD 024 /* 12565A data */
261 #define DQC 025 /* 12565A control */
262 #define DRD 026 /* 12610A data */
263 #define DRC 027 /* 12610A control */
264 #define MSD 030 /* 13181A data */
265 #define MSC 031 /* 13181A control */
266 #define IPLI 032 /* 12566B link in */
267 #define IPLO 033 /* 12566B link out */
268 #define DS 034 /* 13037A control */
269 #define BACI 035 /* 12966A Buffered Async Comm Interface */
270 #define MUXL 040 /* 12920A lower data */
271 #define MUXU 041 /* 12920A upper data */
272 #define MUXC 042 /* 12920A control */
273
274 /* IBL assignments */
275
276 #define IBL_V_SEL 14 /* ROM select */
277 #define IBL_M_SEL 03
278 #define IBL_PTR 0000000 /* PTR */
279 #define IBL_DP 0040000 /* disk: DP */
280 #define IBL_DQ 0060000 /* disk: DQ */
281 #define IBL_MS 0100000 /* option 0: MS */
282 #define IBL_DS 0140000 /* option 1: DS */
283 #define IBL_MAN 0010000 /* RPL/man boot */
284 #define IBL_V_DEV 6 /* dev in <11:6> */
285 #define IBL_OPT 0000070 /* options in <5:3> */
286 #define IBL_DP_REM 0000001 /* DP removable */
287 #define IBL_DS_HEAD 0000003 /* DS head number */
288 #define IBL_LNT 64 /* boot length */
289 #define IBL_MASK (IBL_LNT - 1) /* boot length mask */
290 #define IBL_DPC (IBL_LNT - 2) /* DMA ctrl word */
291 #define IBL_END (IBL_LNT - 1) /* last location */
292
293 /* Dynamic device information table */
294
295 typedef struct {
296 uint32 devno; /* device number */
297 uint32 cmd; /* saved command */
298 uint32 ctl; /* saved control */
299 uint32 flg; /* saved flag */
300 uint32 fbf; /* saved flag buf */
301 uint32 srq; /* saved svc req */
302 int32 (*iot)(int32 op, int32 ir, int32 dat); /* I/O routine */
303 } DIB;
304
305 /* I/O macros */
306
307 #define INT_V(x) ((x) & 037) /* device bit pos */
308 #define INT_M(x) (1u << INT_V (x)) /* device bit mask */
309 #define setCMD(D) dev_cmd[(D)/32] = dev_cmd[(D)/32] | INT_M ((D))
310 #define clrCMD(D) dev_cmd[(D)/32] = dev_cmd[(D)/32] & ~INT_M (D)
311 #define setCTL(D) dev_ctl[(D)/32] = dev_ctl[(D)/32] | INT_M ((D))
312 #define clrCTL(D) dev_ctl[(D)/32] = dev_ctl[(D)/32] & ~INT_M (D)
313 #define setFBF(D) dev_fbf[(D)/32] = dev_fbf[(D)/32] | INT_M (D)
314 #define clrFBF(D) dev_fbf[(D)/32] = dev_fbf[(D)/32] & ~INT_M (D)
315 #define setFLG(D) dev_flg[(D)/32] = dev_flg[(D)/32] | INT_M (D); \
316 setFBF(D)
317 #define clrFLG(D) dev_flg[(D)/32] = dev_flg[(D)/32] & ~INT_M (D); \
318 clrFBF(D)
319 #define setFSR(D) dev_flg[(D)/32] = dev_flg[(D)/32] | INT_M (D); \
320 setFBF(D); setSRQ(D)
321 #define clrFSR(D) dev_flg[(D)/32] = dev_flg[(D)/32] & ~INT_M (D); \
322 clrFBF(D); clrSRQ(D)
323 #define setSRQ(D) dev_srq[(D)/32] = dev_srq[(D)/32] | INT_M ((D))
324 #define clrSRQ(D) dev_srq[(D)/32] = dev_srq[(D)/32] & ~INT_M (D)
325 #define CMD(D) ((dev_cmd[(D)/32] >> INT_V (D)) & 1)
326 #define CTL(D) ((dev_ctl[(D)/32] >> INT_V (D)) & 1)
327 #define FLG(D) ((dev_flg[(D)/32] >> INT_V (D)) & 1)
328 #define FBF(D) ((dev_fbf[(D)/32] >> INT_V (D)) & 1)
329 #define SRQ(D) ((dev_srq[(D)/32] >> INT_V (D)) & 1)
330
331 #define IOT_V_REASON 16
332 #define IORETURN(f,v) ((f)? (v): SCPE_OK) /* stop on error */
333
334 /* Function prototypes */
335
336 int32 sync_poll (POLLMODE poll_mode);
337 t_stat ibl_copy (const uint16 pboot[IBL_LNT], int32 dev);
338 t_stat hp_setdev (UNIT *uptr, int32 val, char *cptr, void *desc);
339 t_stat hp_showdev (FILE *st, UNIT *uptr, int32 val, void *desc);
340 void hp_enbdis_pair (DEVICE *ccp, DEVICE *dcp);
341 t_stat fprint_sym (FILE *ofile, t_addr addr, t_value *val, UNIT *uptr, int32 sw);
342
343 #endif