1 /* i7094_defs.h: IBM 7094 simulator definitions
2 
3    Copyright (c) 2003-2011, 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    This simulator incorporates prior work by Paul Pierce, Dave Pitts, and Rob
27    Storey.  Tom Van Vleck, Stan Dunten, Jerry Saltzer, and other CTSS veterans
28    helped to reconstruct the CTSS hardware RPQ's.  Dave Pitts gets special
29    thanks for patiently coaching me through IBSYS debug.
30 
31    25-Mar-11    RMS     Updated SDC mask based on 7230 documentation
32    22-May-10    RMS     Added check for 64b addresses
33 
34 */
35 
36 #ifndef _I7094_DEFS_H_
37 #define _I7094_DEFS_H_  0
38 
39 #include "sim_defs.h"                                   /* simulator defns */
40 
41 #if defined(USE_ADDR64)
42 #error "7094 does not support 64b addresses!"
43 #endif
44 
45 /* Simulator stop codes */
46 
47 #define STOP_HALT       1                               /* halted */
48 #define STOP_IBKPT      2                               /* breakpoint */
49 #define STOP_ILLEG      3                               /* illegal instr */
50 #define STOP_DIVCHK     4                               /* divide check */
51 #define STOP_XEC        5                               /* XCT loop */
52 #define STOP_ASTOP      6                               /* address stop */
53 #define STOP_NXCHN      7                               /* nx channel */
54 #define STOP_7909       8                               /* ill inst to 7909 */
55 #define STOP_NT7909     9                               /* ill inst to !7909 */
56 #define STOP_NXDEV      10                              /* nx device */
57 #define STOP_ILLCHI     11                              /* illegal channel op */
58 #define STOP_WRP        12                              /* write protect */
59 #define STOP_ILLIOP     13                              /* illegal I/O op */
60 #define STOP_INVFMT     14                              /* invalid disk format */
61 #define STOP_NOIFREE    15                              /* 7750: no buf for inp */
62 #define STOP_NOOFREE    16                              /* 7750: no buf for out */
63 #define STOP_INVLIN     17                              /* 7750: invalid line# */
64 #define STOP_INVMSG     18                              /* 7750: invalid message */
65 #define STOP_CHBKPT     19                              /* channel breakpoint */
66 
67 /* Simulator error codes */
68 
69 #define ERR_STALL       40                              /* stall */
70 #define ERR_ENDRC       41                              /* end rec */
71 #define ERR_NRCF        42                              /* no record found */
72 
73 /* Instruction history - flags in left half of pc entry */
74 
75 #define HIST_PC         0x04000000                      /* CPU */
76 #define HIST_V_CH       28                              /* chan + 1 */
77 #define HIST_M_CH       0xF
78 #define HIST_CH(x)      (((x) >> HIST_V_CH) & HIST_M_CH)
79 
80 typedef struct {
81     uint32              pc;
82     uint32              ea;
83     uint32              rpt;
84     t_uint64    ir;
85     t_uint64    ac;
86     t_uint64    mq;
87     t_uint64    si;
88     t_uint64    opnd;
89     } InstHistory;
90 
91 /* Architectural constants */
92 
93 #define A704_SIZE       14                              /* addr width, 704 mode */
94 #define ASIZE           15                              /* inst addr width */
95 #define PASIZE          16                              /* phys addr width */
96 #define STDMEMSIZE      (1u << ASIZE)                   /* standard memory */
97 #define MAXMEMSIZE      (1u << PASIZE)                  /* maximum memory */
98 #define A704_MASK       ((1u << A704_SIZE) - 1)
99 #define PAMASK          ((1u << PASIZE) - 1)
100 #define MEMSIZE         (cpu_unit.capac)
101 #define BCORE_V         (ASIZE)                         /* (CTSS) A/B core sel */
102 #define BCORE_BASE      (1u << BCORE_V)                 /* (CTSS) B core base */
103 
104 /* Traps */
105 
106 #define TRAP_STD_SAV    000000                          /* trap save location */
107 #define TRAP_TRA_PC     000001                          /* trap PC: transfer */
108 #define TRAP_STR_PC     000002                          /* trap PC: STR */
109 #define TRAP_FP_PC      000010                          /* trap PC: flt point */
110 #define TRAP_PROT_SAV   000032                          /* protection trap save */
111 #define TRAP_PROT_PC    000033                          /* protection trap PC */
112 #define TRAP_704_SAV    040000                          /* 704 compat trap */
113 #define TRAP_SEL_PC     040001                          /* 704 trap PC: select */
114 #define TRAP_CPY_PC     040002                          /* 704 trap PC: copy */
115 
116 #define TRAP_F_MQ       000001                          /* MQ error */
117 #define TRAP_F_AC       000002                          /* AC error */
118 #define TRAP_F_OVF      000004                          /* overflow */
119 #define TRAP_F_SGL      000010                          /* single precision */
120 #define TRAP_F_DVC      000020                          /* fake: divide check */
121 #define TRAP_F_ODD      000040                          /* odd address */
122 #define TRAP_F_BDATA    020000                          /* (CTSS) data B core */
123 #define TRAP_F_BINST    040000                          /* (CTSS) inst B core */
124 
125 /* Integer */
126 
127 #define DMASK           0777777777777                   /* data mask */
128 #define SIGN            0400000000000                   /* sign */
129 #define MMASK           0377777777777                   /* magnitude mask */
130 #define LMASK           0777777000000                   /* left mask */
131 #define RMASK           0000000777777                   /* right mask */
132 #define PMASK           0700000000000                   /* prefix */
133 #define XMASK           0077777000000                   /* decrement */
134 #define TMASK           0000000700000                   /* tag */
135 #define AMASK           0000000077777                   /* address */
136 #define SCMASK          0000000000377                   /* shift count mask */
137 #define B1              0200000000000                   /* bit 1 */
138 #define B9              0000400000000                   /* bit 9 */
139 
140 /* Accumulator is actually 38b wide */
141 
142 #define AC_S            02000000000000                  /* sign */
143 #define AC_Q            01000000000000                  /* Q */
144 #define AC_P            00400000000000                  /* P */
145 #define AC_MMASK        01777777777777                  /* Q+P+magnitude */
146 
147 /* Floating point */
148 
149 #define FP_N_FR         27                              /* fraction bits */
150 #define FP_FMASK        ((1u << FP_N_FR) - 1)
151 #define FP_N_DFR        54                              /* double fraction bits */
152 #define FP_DFMASK       ((((t_uint64) 1) << FP_N_DFR) - 1)
153 #define FP_FNORM        (((t_uint64) 1u) << (FP_N_DFR - 1))     /* normalized bit */
154 #define FP_FCRY         (((t_uint64) 1u) << FP_N_DFR)   /* fraction carry */
155 #define FP_BIAS         0200                            /* exponent bias */
156 #define FP_V_CH         (FP_N_FR)                       /* exponent */
157 #define FP_M_CH         0377                            /* SR char mask */
158 #define FP_M_ACCH       01777                           /* AC char mask incl Q,P */
159 
160 /* Instruction format */
161 
162 #define INST_T_DEC      0300000000000                   /* if nz, takes decr */
163 #define INST_T_CXR1     0000000100000                   /* if nz, update XR1 */
164 #define INST_V_OPD      33                              /* decrement opcode */
165 #define INST_M_OPD      07
166 #define INST_V_DEC      18                              /* decrement */
167 #define INST_M_DEC      077777
168 #define INST_V_OPC      24                              /* normal opcode */
169 #define INST_M_OPC      0777
170 #define INST_V_IND      22                              /* indirect */
171 #define INST_IND        (3 << INST_V_IND)
172 #define INST_V_CCNT     18                              /* convert count */
173 #define INST_M_CCNT     0377
174 #define INST_V_VCNT     18                              /* vlm/vdh count */
175 #define INST_M_VCNT     077
176 #define INST_V_TAG      15                              /* index */
177 #define INST_M_TAG      07
178 #define INST_V_ADDR     0
179 #define INST_M_ADDR     077777
180 #define INST_V_4B		0
181 #define INST_M_4B		017
182 
183 #define GET_OPD(x)      ((uint32) (((x) >> INST_V_OPD) & INST_M_OPD))
184 #define GET_DEC(x)      ((uint32) (((x) >> INST_V_DEC) & INST_M_DEC))
185 #define GET_OPC(x)      (((uint32) (((x) >> INST_V_OPC) & INST_M_OPC)) | \
186                      (((x) & SIGN)? 01000: 0))
187 #define TST_IND(x)      (((x) & INST_IND) == INST_IND)
188 #define GET_CCNT(x)     ((uint32) (((x) >> INST_V_CCNT) & INST_M_CCNT))
189 #define GET_VCNT(x)     ((uint32) (((x) >> INST_V_VCNT) & INST_M_VCNT))
190 #define GET_TAG(x)      ((uint32) (((x) >> INST_V_TAG) & INST_M_TAG))
191 
192 /* Instruction decode flags */
193 
194 #define I_4X            0x01                            /* 7040, 7044 */
195 #define I_9X            0x02                            /* 7090, 7094, CTSS */
196 #define I_94            0x04                            /* 7094, CTSS */
197 #define I_CT            0x08                            /* CTSS */
198 #define I_MODEL         0x0F                            /* option mask */
199 #define I_X             0x10                            /* indexed */
200 #define I_N             0x20                            /* indirect */
201 #define I_R             0x40                            /* read */
202 #define I_D             0x80                            /* double read */
203 
204 #define I_XN            (I_X|I_N)
205 #define I_XNR           (I_X|I_N|I_R)
206 #define I_XND           (I_X|I_N|I_D)
207 
208 /* Memory protection (CTSS) */
209 
210 #define VA_V_OFF        0                               /* offset in block */
211 #define VA_N_OFF        8                               /* width of offset */
212 #define VA_M_OFF        ((1u << VA_N_OFF) - 1)
213 #define VA_OFF          (VA_M_OFF << VA_V_OFF)
214 #define VA_V_BLK        (VA_N_OFF)                      /* block */
215 #define VA_N_BLK        (ASIZE - VA_N_OFF)              /* width of block */
216 #define VA_M_BLK        ((1u << VA_N_BLK) - 1)
217 #define VA_BLK          (VA_M_BLK << VA_V_BLK)
218 
219 /* Unsigned operations */
220 
221 #define NEG(x)          (~(x) + 1)
222 #define BIT_TST(w,b)    (((w) >> (b)) & 1)
223 
224 /* Device information block */
225 
226 typedef struct {
227     t_stat              (*chsel)(uint32 ch, uint32 sel, uint32 u);
228     t_stat              (*write)(uint32 ch, t_uint64 val, uint32 flags);
229     } DIB;
230 
231 /* BCD digits */
232 
233 #define BCD_MASK        017
234 #define BCD_ZERO        012
235 #define BCD_ONE         001
236 #define BCD_TWO         002
237 #define BCD_AT          014
238 
239 /* Channels */
240 
241 #define NUM_CHAN        8                               /* # channels */
242 #define CH_A            0                               /* channel A */
243 #define CH_B            1
244 #define CH_C            2
245 #define CH_D            3
246 #define CH_E            4
247 #define CH_F            5
248 #define CH_G            6
249 #define CH_H            7
250 
251 #define REQ_CH(x)       (1u << (x))
252 
253 /* All channel commands */
254 
255 #define CHI_IND         0000000400000                   /* ch inst indirect */
256 
257 /* Channel selects - all channels */
258 
259 #define CHSL_RDS        0001                            /* data selects */
260 #define CHSL_WRS        0002
261 #define CHSL_SNS        0003
262 #define CHSL_CTL        0004
263 #define CHSL_FMT        0005
264 #define CHSL_WEF        0010                            /* non-data selects */
265 #define CHSL_WBT        0011                            /* 704X only */
266 #define CHSL_BSR        0012
267 #define CHSL_BSF        0013
268 #define CHSL_REW        0014
269 #define CHSL_RUN        0015
270 #define CHSL_SDN        0016
271 #define CHSL_2ND        0020                            /* second state */
272 #define CHSL_3RD        0040                            /* etc */
273 #define CHSL_4TH        0060
274 #define CHSL_5TH        0100
275 #define CHSL_NDS        0010                            /* non-data sel flag */
276 #define CHSL_NUM        16
277 
278 /* Channel commands - 7607/7289 - S12'19 */
279 
280 #define CH6I_NST        0000000200000                   /* ch inst no store */
281 
282 #define CH6_IOCD        000
283 #define CH6_TCH         002
284 #define CH6_IORP        004
285 #define CH6_IORT        006
286 #define CH6_IOCP        010
287 #define CH6_IOCT        012
288 #define CH6_IOSP        014
289 #define CH6_IOST        016
290 #define CH6_OPMASK      016                             /* without nostore */
291 #define TCH_LIMIT       5                               /* TCH autoresolve limit */
292 
293 /* Channel data flags - 7607 */
294 
295 #define CH6DF_EOR       1                               /* end of record */
296 #define CH6DF_VLD       2                               /* input valid */
297 
298 /* Channel commands - 7909 - S123'19 */
299 
300 #define CH9_WTR         000
301 #define CH9_XMT         001
302 #define CH9_TCH         004
303 #define CH9_LIPT        005
304 #define CH9_CTL         010
305 #define CH9_CTLR        011
306 #define CH9_CTLW        012
307 #define CH9_SNS         013
308 #define CH9_LAR         014
309 #define CH9_SAR         015
310 #define CH9_TWT         016
311 #define CH9_CPYP        020
312 #define CH9_CPYD        024
313 #define CH9_TCM         025
314 #define CH9_LIP         031
315 #define CH9_TDC         032
316 #define CH9_LCC         033
317 #define CH9_SMS         034
318 #define CH9_ICC         035
319 #define CH9_ICCA        037                             /* ignores bit <3> */
320 #define CH9_OPMASK      037
321 
322 /* Channel data flags - 7909 */
323 
324 #define CH9DF_STOP      1                               /* stop */
325 #define CH9DF_VLD       2                               /* input valid */
326 
327 /* Extended parts of the command come from the decrement, stored in ch_wc */
328 
329 #define CH9D_V_MASK     0                               /* condition mask */
330 #define CH9D_M_MASK     077
331 #define CH9D_V_COND     12                              /* condition select */
332 #define CH9D_M_COND     07
333 #define CH9D_MASK(x)    (((x) >> CH9D_V_MASK) & CH9D_M_MASK)
334 #define CH9D_COND(x)    (((x) >> CH9D_V_COND) & CH9D_M_COND)
335 
336 #define CH9D_NST        020000                          /* no store */
337 #define CH9D_B11        000100
338 
339 /* Or from the effective address, stored in ch_ca */
340 
341 #define CH9A_V_LCC      0                               /* counter */
342 #define CH9A_M_LCC      077
343 #define CH9A_V_SMS      0                               /* system mask */
344 #define CH9A_M_SMS      0177
345 #define CH9A_LCC(x)     (((x) >> CH9A_V_LCC) & CH9A_M_LCC)
346 #define CH9A_SMS(x)     (((x) >> CH9A_V_SMS) & CH9A_M_SMS)
347 
348 /* Channel states - common */
349 
350 #define CHXS_IDLE       0                               /* idle */
351 #define CHXS_DSX        1                               /* executing */
352 
353 /* Channel states - 7607/7289 */
354 
355 #define CH6S_PNDS       2                               /* polling NDS */
356 #define CH6S_PDS        3                               /* polling DS */
357 #define CH6S_NDS        4                               /* nds, executing */
358 #define CH6S_DSW        5                               /* ds, chan wait */
359 
360 /* Channel traps - 7909 has only CMD (== TWT) */
361 
362 #define CHTR_V_CME      0                               /* cmd/eof enable */
363 #define CHTR_V_CLK      17                              /* clock */
364 #define CHTR_V_TRC      18                              /* tape check */
365 #define CHTR_V_TWT      (CHTR_V_CME)
366 #define CHTR_CLK_SAV    006                             /* clock */
367 #define CHTR_CHA_SAV    012                             /* start of chan block */
368 #define CHTR_F_CMD      1                               /* CMD flag (in decr) */
369 #define CHTR_F_TRC      2                               /* TRC flag (in decr) */
370 #define CHTR_F_EOF      4                               /* EOF flag (in decr) */
371 
372 /* Channel interrupts - 7909 only */
373 
374 #define CHINT_CHA_SAV   042                             /* start of chan block */
375 
376 /* Channel interrupt conditions - 7909 only */
377 
378 #define CHINT_ADPC      001                             /* adapter check */
379 #define CHINT_ATN2      002                             /* attention 2 - ni */
380 #define CHINT_ATN1      004                             /* attention 1 */
381 #define CHINT_UEND      010                             /* unusual end */
382 #define CHINT_SEQC      020                             /* sequence check */
383 #define CHINT_IOC       040                             /* IO check */
384 
385 /* Channel SMS flags - 7909 only */
386 
387 #define CHSMS_SEL2      0001                            /* select 2nd - ni */
388 #define CHSMS_IATN2     0002                            /* inhibit atn2 - ni */
389 #define CHSMS_IATN1     0004                            /* inhibit atn1 */
390 #define CHSMS_IUEND     0010                            /* inhibit uend */
391 #define CHSMS_BCD       0020                            /* BCD conversion - ni */
392 #define CHSMS_RBCK      0040                            /* read backwards - ni */
393 #define CHSMS_ENCI      0100                            /* enable noncon - ni */
394 
395 /* Channel flags (7607 in right half, 7909 in left half) */
396 
397 #define CHF_CMD         00000000001                     /* cmd done */
398 #define CHF_TWT         (CHF_CMD)
399 #define CHF_TRC         00000000002                     /* tape check */
400 #define CHF_EOF         00000000004                     /* end of file */
401 #define CHF_BOT         00000000010                     /* beginning of tape */
402 #define CHF_EOT         00000000020                     /* end of tape */
403 #define CHF_LDW         00000000040                     /* LCH waiting */
404 #define CHF_EOR         00000000100                     /* end of record */
405 #define CHF_IRQ         00001000000                     /* intr request */
406 #define CHF_INT         00002000000                     /* intr in prog */
407 #define CHF_WRS         00004000000                     /* write */
408 #define CHF_RDS         00010000000                     /* read */
409 #define CHF_PWR         00020000000                     /* prepare to write */
410 #define CHF_PRD         00040000000                     /* prepare to read */
411 #define CHF_V_COND      24                              /* cond register */
412 #define CHF_M_COND      077
413 #define  CHF_ADPC       (CHINT_ADPC << CHF_V_COND)      /* adapter check */
414 #define  CHF_ATN2       (CHINT_ATN2 << CHF_V_COND)      /* attention 2 */
415 #define  CHF_ATN1       (CHINT_ATN1 << CHF_V_COND)      /* attention 1 */
416 #define  CHF_UEND       (CHINT_UEND << CHF_V_COND)      /* unusual end */
417 #define  CHF_SEQC       (CHINT_SEQC << CHF_V_COND)      /* sequence check */
418 #define  CHF_IOC        (CHINT_IOC << CHF_V_COND)       /* IO check */
419 #define CHF_V_LCC       30                              /* loop ctrl counter */
420 #define CHF_M_LCC       077
421 
422 #define CHF_CLR_7909    07775000177                     /* 7909 clear flags */
423 #define CHF_SDC_7909    07777600000                     /* 7909 SDC flags */
424 
425 /* Channel characteristics (in dev.flags) */
426 
427 #define DEV_7909        (1u << (DEV_V_UF + 0))
428 #define DEV_7289        (1u << (DEV_V_UF + 1))
429 #define DEV_CDLP        (1u << (DEV_V_UF + 2))
430 #define DEV_7750        (1u << (DEV_V_UF + 3))
431 #define DEV_7631        (1u << (DEV_V_UF + 4))
432 
433 /* Unit addresses - 7607/7289 only */
434 
435 #define U_V_CH          9                               /* channel number */
436 #define U_M_CH          077
437 #define U_V_UNIT        0
438 #define U_M_UNIT        0777
439 #define GET_U_CH(x)     (((((uint32) (x)) >> U_V_CH) & U_M_CH) - 1)
440 #define GET_U_UNIT(x)   ((((uint32) (x)) >> U_V_UNIT) & U_M_UNIT)
441 
442 #define U_MTBCD         0201                            /* BCD tape */
443 #define U_MTBIN         0221                            /* binary tape */
444 #define U_CDR           0321                            /* card reader */
445 #define U_CDP           0341                            /* card punch */
446 #define U_LPBCD         0361                            /* BCD print */
447 #define U_LPBIN         0362                            /* binary print */
448 #define U_DRM           0330                            /* 7320A drum */
449 
450 #define MT_NUMDR        10
451 
452 /* CTSS Chronolog clock */
453 
454 #define CHRONO_CH       (CH_A)                          /* channel A */
455 #define CHRONO_UNIT     (7)                             /* unit 7 */
456 
457 /* Interval timer */
458 
459 #define CLK_CTR         05                              /* counter */
460 #define CLK_TPS         60                              /* 60Hz */
461 #define TMR_CLK         0                               /* use timer 0 */
462 #define TMR_COM         1                               /* 7750 timer */
463 
464 /* Function prototypes and macros */
465 
466 #define ReadP(p)        M[p]
467 #define WriteP(p,d)     M[p] = d
468 
469 void cpu_ent_hist (uint32 pc, uint32 ea, t_uint64 ir, t_uint64 opnd);
470 t_stat ch_show_chan (FILE *st, UNIT *uptr, int32 val, void *desc);
471 t_stat ch6_end_nds (uint32 ch);
472 uint32 ch6_set_flags (uint32 ch, uint32 unit, uint32 flags);
473 t_stat ch6_err_disc (uint32 ch, uint32 unit, uint32 flags);
474 t_stat ch6_req_rd (uint32 ch, uint32 unit, t_uint64 val, uint32 flags);
475 t_stat ch6_req_wr (uint32 ch, uint32 unit);
476 t_bool ch6_qconn (uint32 ch, uint32 unit);
477 t_stat ch9_req_rd (uint32 ch, t_uint64 val);
478 void ch9_set_atn (uint32 ch);
479 void ch9_set_ioc (uint32 ch);
480 void ch9_set_end (uint32 ch, uint32 ireq);
481 t_bool ch9_qconn (uint32 ch);
482 void ch_set_map (void);
483 t_bool ch_qidle (void);
484 
485 #endif
486