First Commit of my working state
[simh.git] / Interdata / id_defs.h
1 /* id_defs.h: Interdata 16b/32b simulator definitions
2
3 Copyright (c) 2000-2006, 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 be
23 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 The author gratefully acknowledges the help of Carl Friend and Al Kossow,
27 who provided key documents about the Interdata product line.
28
29 09-Mar-06 RMS Increased register sets to architectural limit
30 25-Jan-04 RMS Removed local logging support
31 22-Sep-03 RMS Added additional instruction decode types
32 21-Jun-03 RMS Changed subroutine argument for ARM compiler conflict
33 25-Apr-03 RMS Revised for extended file support
34 28-Feb-03 RMS Changed magtape device default to 0x85
35 */
36
37 #ifndef _ID_DEFS_H_
38 #define _ID_DEFS_H_ 0
39
40 #include "sim_defs.h" /* simulator defns */
41
42 /* Simulator stop codes */
43
44 #define STOP_RSRV 1 /* undef instr */
45 #define STOP_HALT 2 /* HALT */
46 #define STOP_IBKPT 3 /* breakpoint */
47 #define STOP_WAIT 4 /* wait */
48 #define STOP_VFU 5 /* runaway VFU */
49
50 /* Memory */
51
52 #define PAWIDTH16 16
53 #define PAWIDTH16E 18
54 #define PAWIDTH32 20
55 #define MAXMEMSIZE16 (1u << PAWIDTH16) /* max mem size, 16b */
56 #define MAXMEMSIZE16E (1u << PAWIDTH16E) /* max mem size, 16b E */
57 #define MAXMEMSIZE32 (1u << PAWIDTH32) /* max mem size, 32b */
58 #define PAMASK16 (MAXMEMSIZE16 - 1) /* phys mem mask */
59 #define PAMASK16E (MAXMEMSIZE16E - 1)
60 #define PAMASK32 (MAXMEMSIZE32 - 1)
61
62 #define MEMSIZE (cpu_unit.capac) /* act memory size */
63 #define MEM_ADDR_OK(x) (((uint32) (x)) < MEMSIZE)
64
65 /* Single precision floating point registers */
66
67 #if defined (IFP_IN_MEM)
68 #define ReadFReg(r) (fp_in_hwre? \
69 F[(r) >> 1]: ReadF (((r) << 1) & ~3, P))
70 #define WriteFReg(r,v) if (fp_in_hwre) F[(r) >> 1] = (v); \
71 else WriteF (((r) << 1) & ~3, (v), P)
72 #else
73 #define ReadFReg(r) (F[(r) >> 1])
74 #define WriteFReg(r,v) F[(r) >> 1] = (v)
75 #endif
76
77 /* Double precision floating point registers */
78
79 typedef struct {
80 uint32 h; /* high 32b */
81 uint32 l; /* low 32b */
82 } dpr_t;
83
84 /* Architectural constants */
85
86 #define VAMASK16 (0xFFFF) /* 16b virt addr */
87 #define VAMASK32 (0x000FFFFF) /* 32b virt addr */
88
89 #define SIGN8 0x80 /* 8b sign bit */
90 #define DMASK8 0xFF /* 8b data mask */
91 #define MMASK8 0x7F /* 8b magnitude mask */
92 #define SIGN16 0x8000 /* 16b sign bit */
93 #define DMASK16 0xFFFF /* 16b data mask */
94 #define MMASK16 0x7FFF /* 16b magnitude mask */
95 #define SIGN32 0x80000000 /* 32b sign bit */
96 #define DMASK32 0xFFFFFFFF /* 32b data mask */
97 #define MMASK32 0x7FFFFFFF /* 32b magn mask */
98
99 #define CC_C 0x8 /* carry */
100 #define CC_V 0x4 /* overflow */
101 #define CC_G 0x2 /* greater than */
102 #define CC_L 0x1 /* less than */
103 #define CC_MASK (CC_C | CC_V | CC_G | CC_L)
104
105 #define PSW_WAIT 0x8000 /* wait */
106 #define PSW_EXI 0x4000 /* ext intr enable */
107 #define PSW_MCI 0x2000 /* machine check enable */
108 #define PSW_AFI 0x1000 /* arith fault enb */
109 #define PSW_AIO 0x0800 /* auto I/O int enable */
110 #define PSW_FPF 0x0400 /* flt fault enb, 16b */
111 #define PSW_REL 0x0400 /* reloc enb, 32b */
112 #define PSW_SQI 0x0200 /* sys q int enable */
113 #define PSW_PRO 0x0100 /* protect mode */
114 #define PSW_V_MAP 4 /* mem map, 16b */
115 #define PSW_M_MAP 0xF
116 #define PSW_MAP (PSW_M_MAP << PSW_V_MAP)
117 #define PSW_V_REG 4 /* reg set, 32b */
118 #define PSW_M_REG 0xF
119 #define PSW_ID4 0xF40F /* I3, I4 PSW */
120 #define PSW_x16 0xFF0F /* 7/16, 8/16 PSW */
121 #define PSW_816E 0xFFFF /* 8/16E PSW */
122 #define PSW_x32 0xFFFF /* 7/32, 8/32 PSW */
123
124 #define MCKOPSW 0x20 /* mchk old PSW, 32b */
125 #define FPFPSW 0x28 /* flt fault PSW, 16b */
126 #define ILOPSW 0x30 /* ill op PSW */
127 #define MCKPSW 0x38 /* mach chk PSW */
128 #define EXIPSW 0x40 /* ext intr PSW, 16b */
129 #define AFIPSW 0x48 /* arith flt PSW */
130 #define SQP 0x80 /* system queue ptr */
131 #define SQIPSW 0x82 /* sys q int PSW, 16b */
132 #define SQOP 0x8A /* sys q ovf ptr, 16b */
133 #define SQVPSW 0x8C /* sys q ovf PSW, 16b */
134 #define SQTPSW 0x88 /* sys q int PSW, 32b */
135 #define MPRPSW 0x90 /* mprot int PSW, 32b */
136 #define SVCAP 0x94 /* svc arg ptr, 16b */
137 #define SVOPS 0x96 /* svc old PS, 16b */
138 #define SVOPC 0x98 /* svc old PC, 16b */
139 #define SVNPS32 0x98 /* svc new PS, 32b */
140 #define SVNPS 0x9A /* svc new PS, 16b */
141 #define SVNPC 0x9C /* svc new PC */
142 #define INTSVT 0xD0 /* int service table */
143
144 #define AL_DEV 0x78 /* autoload: dev */
145 #define AL_IOC 0x79 /* command */
146 #define AL_DSKU 0x7A /* disk unit */
147 #define AL_DSKT 0x7B /* disk type */
148 #define AL_DSKC 0x7C /* disk ctrl */
149 #define AL_SCH 0x7D /* sel chan */
150 #define AL_EXT 0x7E /* OS extension */
151 #define AL_BUF 0x80 /* buffer start */
152
153 #define Q16_SLT 0 /* list: # slots */
154 #define Q16_USD 1 /* # in use */
155 #define Q16_TOP 2 /* current top */
156 #define Q16_BOT 3 /* next bottom */
157 #define Q16_BASE 4 /* base of q */
158 #define Q16_SLNT 2 /* slot length */
159
160 #define Q32_SLT 0 /* list: # slots */
161 #define Q32_USD 2 /* # in use */
162 #define Q32_TOP 4 /* current top */
163 #define Q32_BOT 6 /* next bottom */
164 #define Q32_BASE 8 /* base of q */
165 #define Q32_SLNT 4 /* slot length */
166
167 /* CPU event flags */
168
169 #define EV_MAC 0x01 /* MAC interrupt */
170 #define EV_BLK 0x02 /* block I/O in prog */
171 #define EV_INT 0x04 /* interrupt pending */
172 #define EV_WAIT 0x08 /* wait state pending */
173
174 /* Block I/O state */
175
176 struct BlockIO {
177 uint32 dfl; /* devno, flags */
178 uint32 cur; /* current addr */
179 uint32 end; /* end addr */
180 };
181
182 #define BL_RD 0x8000 /* block read */
183 #define BL_LZ 0x4000 /* skip 0's */
184
185 /* Instruction decode ROM, for all, 16b, 32b */
186
187 #define OP_UNDEF 0x0000 /* undefined */
188 #define OP_NO 0x0001 /* all: short or fp rr */
189 #define OP_RR 0x0002 /* all: reg-reg */
190 #define OP_RS 0x0003 /* 16b: reg-storage */
191 #define OP_RI1 0x0003 /* 32b: reg-imm 16b */
192 #define OP_RX 0x0004 /* all: reg-mem */
193 #define OP_RXB 0x0005 /* all: reg-mem, rd BY */
194 #define OP_RXH 0x0006 /* all: reg-mem, rd HW */
195 #define OP_RXF 0x0007 /* 32b: reg-mem, rd FW */
196 #define OP_RI2 0x0008 /* 32b: reg-imm 32b */
197 #define OP_MASK 0x000F
198
199 #define OP_ID4 0x0010 /* 16b: ID4 */
200 #define OP_716 0x0020 /* 16b: 7/16 */
201 #define OP_816 0x0040 /* 16b: 8/16 */
202 #define OP_816E 0x0080 /* 16b: 8/16E */
203
204 #define OP_DPF 0x4000 /* all: hwre FP */
205 #define OP_PRV 0x8000 /* all: privileged */
206
207 #define OP_TYPE(x) (decrom[(x)] & OP_MASK)
208 #define OP_DPFP(x) (decrom[(x)] & OP_DPF)
209
210 /* Device information block */
211
212 typedef struct {
213 uint32 dno; /* device number */
214 int32 sch; /* sch */
215 uint32 irq; /* interrupt */
216 uint8 *tplte; /* template */
217 uint32 (*iot)(uint32 d, uint32 o, uint32 dat);
218 void (*ini)(t_bool f);
219 } DIB;
220
221 #define TPL_END 0xFF /* template end */
222
223 /* Device select return codes */
224
225 #define BY 0 /* 8b only */
226 #define HW 1 /* 8b/16b */
227
228 /* I/O operations */
229
230 #define IO_ADR 0x0 /* address select */
231 #define IO_RD 0x1 /* read byte */
232 #define IO_RH 0x2 /* read halfword */
233 #define IO_WD 0x3 /* write byte */
234 #define IO_WH 0x4 /* write halfword */
235 #define IO_OC 0x5 /* output command */
236 #define IO_SS 0x6 /* sense status */
237
238 /* Device command byte */
239
240 #define CMD_V_INT 6 /* interrupt control */
241 #define CMD_M_INT 0x3
242 #define CMD_IENB 1 /* enable */
243 #define CMD_IDIS 2 /* disable */
244 #define CMD_IDSA 3 /* disarm */
245 #define CMD_GETINT(x) (((x) >> CMD_V_INT) & CMD_M_INT)
246
247 /* Device status byte */
248
249 #define STA_BSY 0x8 /* busy */
250 #define STA_EX 0x4 /* examine status */
251 #define STA_EOM 0x2 /* end of medium */
252 #define STA_DU 0x1 /* device unavailable */
253
254 /* Default device numbers */
255
256 #define DEV_LOW 0x01 /* lowest intr dev */
257 #define DEV_MAX 0xFF /* highest intr dev */
258 #define DEVNO (DEV_MAX + 1) /* number of devices */
259 #define d_DS 0x01 /* display, switches */
260 #define d_TT 0x02 /* teletype */
261 #define d_PT 0x03 /* reader */
262 #define d_CD 0x04 /* card reader */
263 #define d_TTP 0x10 /* PAS as console */
264 #define d_PAS 0x10 /* first PAS */
265 #define o_PASX 0x01 /* offset to xmt */
266 #define d_LPT 0x62 /* line printer */
267 #define d_PIC 0x6C /* interval timer */
268 #define d_LFC 0x6D /* line freq clk */
269 #define d_MT 0x85 /* magtape */
270 #define o_MT0 0x10
271 #define d_DPC 0xB6 /* disk controller */
272 #define o_DP0 0x10
273 #define o_DPF 0x01 /* offset to fixed */
274 #define d_FD 0xC1 /* floppy disk */
275 #define d_SCH 0xF0 /* selector chan */
276 #define d_IDC 0xFB /* MSM disk ctrl */
277 #define o_ID0 0x01
278
279 /* Interrupts
280
281 To make interrupt flags independent of device numbers, each device is
282 assigned an interrupt flag in one of four interrupt words
283
284 word 0 DMA devices
285 word 1 programmed I/O devices
286 word 2-3 PAS devices
287
288 Devices are identified by a level and a bit within a level. Priorities
289 run low to high in the array, right to left within words
290 */
291
292 #define INTSZ 4 /* interrupt words */
293 #define SCH_NUMCH 4 /* #channels */
294 #define ID_NUMDR 4 /* # MSM drives */
295 #define DP_NUMDR 4 /* # DPC drives */
296 #define MT_NUMDR 4 /* # MT drives */
297
298 /* Word 0, DMA devices */
299
300 #define i_SCH 0 /* highest priority */
301 #define i_IDC (i_SCH + SCH_NUMCH) /* MSM disk ctrl */
302 #define i_DPC (i_IDC + ID_NUMDR + 1) /* cartridge disk ctrl */
303 #define i_MT (i_DPC + DP_NUMDR + 1) /* magtape */
304
305 #define l_SCH 0
306 #define l_IDC 0
307 #define l_DPC 0
308 #define l_MT 0
309
310 #define v_SCH (l_SCH * 32) + i_SCH
311 #define v_IDC (l_IDC * 32) + i_IDC
312 #define v_DPC (l_DPC * 32) + i_DPC
313 #define v_MT (l_MT * 32) + i_MT
314
315 /* Word 1, programmed I/O devices */
316
317 #define i_PIC 0 /* precision clock */
318 #define i_LFC 1 /* line clock */
319 #define i_FD 2 /* floppy disk */
320 #define i_CD 3 /* card reader */
321 #define i_LPT 4 /* line printer */
322 #define i_PT 5 /* paper tape */
323 #define i_TT 6 /* teletype */
324 #define i_DS 7 /* display */
325 #define i_TTP 10 /* PAS console */
326
327 #define l_PIC 1
328 #define l_LFC 1
329 #define l_FD 1
330 #define l_CD 1
331 #define l_LPT 1
332 #define l_PT 1
333 #define l_TT 1
334 #define l_DS 1
335 #define l_TTP 1
336
337 #define v_PIC (l_PIC * 32) + i_PIC
338 #define v_LFC (l_LFC * 32) + i_LFC
339 #define v_FD (l_FD * 32) + i_FD
340 #define v_CD (l_CD * 32) + i_CD
341 #define v_LPT (l_LPT * 32) + i_LPT
342 #define v_PT (l_PT * 32) + i_PT
343 #define v_TT (l_TT * 32) + i_TT
344 #define v_DS (l_DS * 32) + i_DS
345 #define v_TTP (l_TTP * 32) + i_TTP
346
347 /* Word 2-3, PAS devices */
348
349 #define i_PAS 0
350 #define l_PAS 2
351 #define v_PAS (l_PAS * 32) + i_PAS
352 #define v_PASX (v_PAS + 1) /* offset to xmt */
353
354 /* I/O macros */
355
356 #define SET_INT(v) int_req[(v) >> 5] = int_req[(v) >> 5] | (1u << ((v) & 0x1F))
357 #define CLR_INT(v) int_req[(v) >> 5] = int_req[(v) >> 5] & ~(1u << ((v) & 0x1F))
358 #define SET_ENB(v) int_enb[(v) >> 5] = int_enb[(v) >> 5] | (1u << ((v) & 0x1F))
359 #define CLR_ENB(v) int_enb[(v) >> 5] = int_enb[(v) >> 5] & ~(1u << ((v) & 0x1F))
360
361 #define IORETURN(f,v) ((f)? (v): SCPE_OK) /* stop on error */
362
363 /* Device accessible macro */
364
365 #define DEV_ACC(d) (dev_tab[d] && !sch_blk (d))
366
367 /* Automatic I/O channel programs, 16b */
368
369 #define CCB16_CHN -4 /* chain */
370 #define CCB16_DEV -2 /* dev no */
371 #define CCB16_STS -1 /* status */
372 #define CCB16_CCW 0 /* cmd wd */
373 #define CCB16_STR 2 /* start */
374 #define CCB16_END 4 /* end */
375 #define CCB16_IOC 6 /* OC byte */
376 #define CCB16_TRM 7 /* term byte */
377
378 #define CCW16_INIT 0x8000 /* init */
379 #define CCW16_NOP 0x4000 /* nop */
380 #define CCW16_V_FNC 12 /* function */
381 #define CCW16_M_FNC 0x3
382 #define CCW16_FNC(x) (((x) >> CCW16_V_FNC) & CCW16_M_FNC)
383 #define CCW16_RD 0 /* read */
384 #define CCW16_WR 1 /* write */
385 #define CCW16_DMT 2 /* dec mem */
386 #define CCW16_NUL 3 /* null */
387 #define CCW16_TRM 0x0400 /* term char */
388 #define CCW16_Q 0x0200 /* queue */
389 #define CCW16_HI 0x0100 /* queue hi */
390 #define CCW16_OC 0x0080 /* OC */
391 #define CCW16_CHN 0x0020 /* chain */
392 #define CCW16_CON 0x0010 /* continue */
393 #define CCW16_V_BPI 0 /* bytes per int */
394 #define CCW16_M_BPI 0xF
395 #define CCW16_BPI(x) (((x) >> CCW16_V_BPI) & CCW16_M_BPI)
396
397 /* Automatic I/O channel programs, 32b */
398
399 #define CCB32_CCW 0 /* cmd wd */
400 #define CCB32_B0C 2 /* buf 0 cnt */
401 #define CCB32_B0E 4 /* buf 0 end */
402 #define CCB32_CHK 8 /* check word */
403 #define CCB32_B1C 10 /* buf 1 cnt */
404 #define CCB32_B1E 12 /* buf 1 end */
405 #define CCB32_TAB 16 /* trans table */
406 #define CCB32_SUB 20 /* subroutine */
407
408 #define CCW32_V_STA 8 /* status */
409 #define CCW32_M_STA 0xFF
410 #define CCW32_STA(x) (((x) >> CCW32_V_STA) & CCW32_M_STA)
411 #define CCW32_EXE 0x80 /* execute */
412 #define CCW32_CRC 0x10
413 #define CCW32_B1 0x08 /* buffer 1 */
414 #define CCW32_WR 0x04 /* write */
415 #define CCW32_TL 0x02 /* translate */
416 #define CCW32_FST 0x01 /* fast mode */
417
418 /* MAC, 32b */
419
420 #define P 0 /* physical */
421 #define VE 1 /* virtual inst */
422 #define VR 2 /* virtual read */
423 #define VW 3 /* virtual write */
424
425 #define MAC_BASE 0x300 /* MAC base */
426 #define MAC_STA 0x340 /* MAC status */
427 #define MAC_LNT 16
428 #define VA_V_OFF 0 /* offset */
429 #define VA_M_OFF 0xFFFF
430 #define VA_GETOFF(x) (((x) >> VA_V_OFF) & VA_M_OFF)
431 #define VA_V_SEG 16 /* segment */
432 #define VA_M_SEG 0xF
433 #define VA_GETSEG(x) (((x) >> VA_V_SEG) & VA_M_SEG)
434
435 #define SRF_MASK 0x000FFF00 /* base mask */
436 #define SRL_MASK 0x0FF00000 /* limit mask */
437 #define GET_SRL(x) ((((x) & SRL_MASK) >> 12) + 0x100)
438 #define SR_EXP 0x80 /* execute prot */
439 #define SR_WPI 0x40 /* wr prot int */
440 #define SR_WRP 0x20 /* wr prot */
441 #define SR_PRS 0x10 /* present */
442 #define SR_MASK (SRF_MASK|SRL_MASK|SR_EXP|SR_WPI|SR_WRP|SR_PRS)
443
444 #define MACS_L 0x10 /* limit viol */
445 #define MACS_NP 0x08 /* not present */
446 #define MACS_WP 0x04 /* write prot */
447 #define MACS_WI 0x02 /* write int */
448 #define MACS_EX 0x01 /* exec prot */
449
450 /* Miscellaneous */
451
452 #define TMR_LFC 0 /* LFC = timer 0 */
453 #define TMR_PIC 1 /* PIC = timer 1 */
454 #define LPT_WIDTH 132
455 #define VFU_LNT 132
456 #define MIN(x,y) (((x) < (y))? (x): (y))
457 #define MAX(x,y) (((x) > (y))? (x): (y))
458
459 /* Function prototypes */
460
461 int32 int_chg (uint32 irq, int32 dat, int32 armdis);
462 int32 io_2b (int32 val, int32 pos, int32 old);
463 uint32 IOReadB (uint32 loc);
464 void IOWriteB (uint32 loc, uint32 val);
465 uint32 IOReadH (uint32 loc);
466 void IOWriteH (uint32 loc, uint32 val);
467 uint32 ReadF (uint32 loc, uint32 rel);
468 void WriteF (uint32 loc, uint32 val, uint32 rel);
469 uint32 IOReadBlk (uint32 loc, uint32 cnt, uint8 *buf);
470 uint32 IOWriteBlk (uint32 loc, uint32 cnt, uint8 *buf);
471 void sch_adr (uint32 ch, uint32 dev);
472 t_bool sch_actv (uint32 sch, uint32 devno);
473 void sch_stop (uint32 sch);
474 uint32 sch_wrmem (uint32 sch, uint8 *buf, uint32 cnt);
475 uint32 sch_rdmem (uint32 sch, uint8 *buf, uint32 cnt);
476 t_stat set_sch (UNIT *uptr, int32 val, char *cptr, void *desc);
477 t_stat set_dev (UNIT *uptr, int32 val, char *cptr, void *desc);
478 t_stat show_sch (FILE *st, UNIT *uptr, int32 val, void *desc);
479 t_stat show_dev (FILE *st, UNIT *uptr, int32 val, void *desc);
480
481 #endif