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