First Commit of my working state
[simh.git] / VAX / vax_defs.h
1 /* vax_defs.h: VAX architecture definitions file
2
3 Copyright (c) 1998-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 Stephen Shirron, Antonio
27 Carlini, and Kevin Peterson in providing specifications for the Qbus VAX's
28
29 09-May-06 RMS Added system PTE ACV error code
30 03-May-06 RMS Added EDITPC get/put cc's macros
31 03-Nov-05 RMS Added 780 stop codes
32 22-Jul-05 RMS Fixed warning from Solaris C (from Doug Gwyn)
33 02-Sep-04 RMS Added octa specifier definitions
34 30-Aug-04 RMS Added octa, h_floating instruction definitions
35 24-Aug-04 RMS Added compatibility mode definitions
36 18-Apr-04 RMS Added octa, fp, string definitions
37 19-May-03 RMS Revised for new conditional compilation scheme
38 14-Jul-02 RMS Added infinite loop message
39 30-Apr-02 RMS Added CLR_TRAPS macro
40 */
41
42 #ifndef _VAX_DEFS_H
43 #define _VAX_DEFS_H 0
44
45 #ifndef VM_VAX
46 #define VM_VAX 0
47 #endif
48
49 #include "sim_defs.h"
50 #include <setjmp.h>
51
52 /* Stops and aborts */
53
54 #define STOP_HALT 1 /* halt */
55 #define STOP_IBKPT 2 /* breakpoint */
56 #define STOP_CHMFI 3 /* chg mode IS */
57 #define STOP_ILLVEC 4 /* illegal vector */
58 #define STOP_INIE 5 /* exc in intexc */
59 #define STOP_PPTE 6 /* proc pte in Px */
60 #define STOP_UIPL 7 /* undefined IPL */
61 #define STOP_RQ 8 /* fatal RQ err */
62 #define STOP_LOOP 9 /* infinite loop */
63 #define STOP_SANITY 10 /* sanity timer exp */
64 #define STOP_SWDN 11 /* software done (780) */
65 #define STOP_BOOT 12 /* reboot (780) */
66 #define STOP_UNKNOWN 13 /* unknown reason */
67 #define STOP_UNKABO 14 /* unknown abort */
68 #define ABORT_INTR -1 /* interrupt */
69 #define ABORT_MCHK (-SCB_MCHK) /* machine check */
70 #define ABORT_RESIN (-SCB_RESIN) /* rsvd instruction */
71 #define ABORT_RESAD (-SCB_RESAD) /* rsvd addr mode */
72 #define ABORT_RESOP (-SCB_RESOP) /* rsvd operand */
73 #define ABORT_CMODE (-SCB_CMODE) /* comp mode fault */
74 #define ABORT_ARITH (-SCB_ARITH) /* arithmetic trap */
75 #define ABORT_ACV (-SCB_ACV) /* access violation */
76 #define ABORT_TNV (-SCB_TNV) /* transl not vaid */
77 #define ABORT(x) longjmp (save_env, (x)) /* abort */
78 #define RSVD_INST_FAULT ABORT (ABORT_RESIN)
79 #define RSVD_ADDR_FAULT ABORT (ABORT_RESAD)
80 #define RSVD_OPND_FAULT ABORT (ABORT_RESOP)
81 #define FLT_OVFL_FAULT p1 = FLT_OVRFLO, ABORT (ABORT_ARITH)
82 #define FLT_DZRO_FAULT p1 = FLT_DIVZRO, ABORT (ABORT_ARITH)
83 #define FLT_UNFL_FAULT p1 = FLT_UNDFLO, ABORT (ABORT_ARITH)
84 #define CMODE_FAULT(cd) p1 = (cd), ABORT (ABORT_CMODE)
85 #define MACH_CHECK(cd) p1 = (cd), ABORT (ABORT_MCHK)
86
87 /* Recovery queue */
88
89 #define RQ_RN 0xF /* register */
90 #define RQ_V_LNT 4 /* length */
91 #define RQ_M_LNT 0x7 /* 0,1,2,3,4 */
92 #define RQ_DIR 0x800 /* 0 = -, 1 = + */
93 #define RQ_REC(d,r) (((d) << RQ_V_LNT) | (r))
94 #define RQ_GETRN(x) ((x) & RQ_RN)
95 #define RQ_GETLNT(x) (((x) >> RQ_V_LNT) & RQ_M_LNT)
96
97 /* Address space */
98
99 #define VAMASK 0xFFFFFFFF /* virt addr mask */
100 #define PAWIDTH 30 /* phys addr width */
101 #define PASIZE (1 << PAWIDTH) /* phys addr size */
102 #define PAMASK (PASIZE - 1) /* phys addr mask */
103 #define IOPAGE (1 << (PAWIDTH - 1)) /* start of I/O page */
104
105 /* Architectural constants */
106
107 #define BMASK 0x000000FF /* byte */
108 #define BSIGN 0x00000080
109 #define WMASK 0x0000FFFF /* word */
110 #define WSIGN 0x00008000
111 #define LMASK 0xFFFFFFFF /* longword */
112 #define LSIGN 0x80000000
113 #define FPSIGN 0x00008000 /* floating point */
114 #define L_BYTE 1 /* bytes per */
115 #define L_WORD 2 /* data type */
116 #define L_LONG 4
117 #define L_QUAD 8
118 #define L_OCTA 16
119 #define NUM_INST 512 /* one byte+two byte */
120 #define MAX_SPEC 6 /* max spec/instr */
121
122 /* Floating point formats */
123
124 #define FD_V_EXP 7 /* f/d exponent */
125 #define FD_M_EXP 0xFF
126 #define FD_BIAS 0x80 /* f/d bias */
127 #define FD_EXP (FD_M_EXP << FD_V_EXP)
128 #define FD_HB (1 << FD_V_EXP) /* f/d hidden bit */
129 #define FD_GUARD (15 - FD_V_EXP) /* # guard bits */
130 #define FD_GETEXP(x) (((x) >> FD_V_EXP) & FD_M_EXP)
131
132 #define G_V_EXP 4 /* g exponent */
133 #define G_M_EXP 0x7FF
134 #define G_BIAS 0x400 /* g bias */
135 #define G_EXP (G_M_EXP << G_V_EXP)
136 #define G_HB (1 << G_V_EXP) /* g hidden bit */
137 #define G_GUARD (15 - G_V_EXP) /* # guard bits */
138 #define G_GETEXP(x) (((x) >> G_V_EXP) & G_M_EXP)
139
140 #define H_V_EXP 0 /* h exponent */
141 #define H_M_EXP 0x7FFF
142 #define H_BIAS 0x4000 /* h bias */
143 #define H_EXP (H_M_EXP << H_V_EXP)
144 #define H_HB (1 << H_V_EXP) /* h hidden bit */
145 #define H_GUARD (15 - H_V_EXP) /* # guard bits */
146 #define H_GETEXP(x) (((x) >> H_V_EXP) & H_M_EXP)
147
148 /* Memory management modes */
149
150 #define KERN 0
151 #define EXEC 1
152 #define SUPV 2
153 #define USER 3
154
155 /* Register and stack aliases */
156
157 #define nAP 12
158 #define nFP 13
159 #define nSP 14
160 #define nPC 15
161 #define AP R[nAP]
162 #define FP R[nFP]
163 #define SP R[nSP]
164 #define PC R[nPC]
165 #define RGMASK 0xF
166 #define KSP STK[KERN]
167 #define ESP STK[EXEC]
168 #define SSP STK[SUPV]
169 #define USP STK[USER]
170 #define IS STK[4]
171
172 /* PSL, PSW, and condition codes */
173
174 #define PSL_V_CM 31 /* compatibility mode */
175 #define PSL_CM (1u << PSL_V_CM)
176 #define PSL_V_TP 30 /* trace pending */
177 #define PSL_TP (1 << PSL_V_TP)
178 #define PSL_V_FPD 27 /* first part done */
179 #define PSL_FPD (1 << PSL_V_FPD)
180 #define PSL_V_IS 26 /* interrupt stack */
181 #define PSL_IS (1 << PSL_V_IS)
182 #define PSL_V_CUR 24 /* current mode */
183 #define PSL_V_PRV 22 /* previous mode */
184 #define PSL_M_MODE 0x3 /* mode mask */
185 #define PSL_CUR (PSL_M_MODE << PSL_V_CUR)
186 #define PSL_PRV (PSL_M_MODE << PSL_V_PRV)
187 #define PSL_V_IPL 16 /* int priority lvl */
188 #define PSL_M_IPL 0x1F
189 #define PSL_IPL (PSL_M_IPL << PSL_V_IPL)
190 #define PSL_IPL1 (0x01 << PSL_V_IPL)
191 #define PSL_IPL1F (0x1F << PSL_V_IPL)
192 #define PSL_MBZ (0x30200000 | PSW_MBZ) /* must be zero */
193 #define PSW_MBZ 0xFF00 /* must be zero */
194 #define PSW_DV 0x80 /* dec ovflo enable */
195 #define PSW_FU 0x40 /* flt undflo enable */
196 #define PSW_IV 0x20 /* int ovflo enable */
197 #define PSW_T 0x10 /* trace enable */
198 #define CC_N 0x08 /* negative */
199 #define CC_Z 0x04 /* zero */
200 #define CC_V 0x02 /* overflow */
201 #define CC_C 0x01 /* carry */
202 #define CC_MASK (CC_N | CC_Z | CC_V | CC_C)
203 #define PSL_GETCUR(x) (((x) >> PSL_V_CUR) & PSL_M_MODE)
204 #define PSL_GETPRV(x) (((x) >> PSL_V_PRV) & PSL_M_MODE)
205 #define PSL_GETIPL(x) (((x) >> PSL_V_IPL) & PSL_M_IPL)
206
207 /* Software interrupt summary register */
208
209 #define SISR_MASK 0xFFFE
210 #define SISR_2 (1 << 2)
211
212 /* AST register */
213
214 #define AST_MASK 7
215 #define AST_MAX 4
216
217 /* Virtual address */
218
219 #define VA_N_OFF 9 /* offset size */
220 #define VA_PAGSIZE (1u << VA_N_OFF) /* page size */
221 #define VA_M_OFF ((1u << VA_N_OFF) - 1) /* offset mask */
222 #define VA_V_VPN VA_N_OFF /* vpn start */
223 #define VA_N_VPN (31 - VA_N_OFF) /* vpn size */
224 #define VA_M_VPN ((1u << VA_N_VPN) - 1) /* vpn mask */
225 #define VA_S0 (1u << 31) /* S0 space */
226 #define VA_P1 (1u << 30) /* P1 space */
227 #define VA_N_TBI 12 /* TB index size */
228 #define VA_TBSIZE (1u << VA_N_TBI) /* TB size */
229 #define VA_M_TBI ((1u << VA_N_TBI) - 1) /* TB index mask */
230 #define VA_GETOFF(x) ((x) & VA_M_OFF)
231 #define VA_GETVPN(x) (((x) >> VA_V_VPN) & VA_M_VPN)
232 #define VA_GETTBI(x) ((x) & VA_M_TBI)
233
234 /* PTE */
235
236 #define PTE_V_V 31 /* valid */
237 #define PTE_V (1u << PTE_V_V)
238 #define PTE_V_ACC 27 /* access */
239 #define PTE_M_ACC 0xF
240 #define PTE_ACC (PTE_M_ACC << PTE_V_ACC)
241 #define PTE_V_M 26 /* modified */
242 #define PTE_M (1u << PTE_V_M)
243 #define PTE_GETACC(x) (((x) >> PTE_V_ACC) & PTE_M_ACC)
244
245 /* TLB entry */
246
247 #define TLB_V_RACC 0 /* rd acc field */
248 #define TLB_V_WACC 4 /* wr acc field */
249 #define TLB_M_ACC 0xF
250 #define TLB_RACC (TLB_M_ACC << TLB_V_RACC)
251 #define TLB_WACC (TLB_M_ACC << TLB_V_WACC)
252 #define TLB_V_M 8 /* m bit */
253 #define TLB_M (1u << TLB_V_M)
254 #define TLB_N_PFN (PAWIDTH - VA_N_OFF) /* ppfn size */
255 #define TLB_M_PFN ((1u << TLB_N_PFN) - 1) /* ppfn mask */
256 #define TLB_PFN (TLB_M_PFN << VA_V_VPN)
257
258 /* Traps and interrupt requests */
259
260 #define TIR_V_IRQL 0 /* int request lvl */
261 #define TIR_V_TRAP 5 /* trap requests */
262 #define TIR_M_TRAP 07
263 #define TIR_TRAP (TIR_M_TRAP << TIR_V_TRAP)
264 #define TRAP_INTOV (1 << TIR_V_TRAP) /* integer overflow */
265 #define TRAP_DIVZRO (2 << TIR_V_TRAP) /* divide by zero */
266 #define TRAP_FLTOVF (3 << TIR_V_TRAP) /* flt overflow */
267 #define TRAP_FLTDIV (4 << TIR_V_TRAP) /* flt/dec div by zero */
268 #define TRAP_FLTUND (5 << TIR_V_TRAP) /* flt underflow */
269 #define TRAP_DECOVF (6 << TIR_V_TRAP) /* decimal overflow */
270 #define TRAP_SUBSCR (7 << TIR_V_TRAP) /* subscript range */
271 #define SET_TRAP(x) trpirq = (trpirq & PSL_M_IPL) | (x)
272 #define CLR_TRAPS trpirq = trpirq & ~TIR_TRAP
273 #define SET_IRQL trpirq = (trpirq & TIR_TRAP) | eval_int ()
274 #define GET_TRAP(x) (((x) >> TIR_V_TRAP) & TIR_M_TRAP)
275 #define GET_IRQL(x) (((x) >> TIR_V_IRQL) & PSL_M_IPL)
276
277 /* Floating point fault parameters */
278
279 #define FLT_OVRFLO 0x8 /* flt overflow */
280 #define FLT_DIVZRO 0x9 /* flt div by zero */
281 #define FLT_UNDFLO 0xA /* flt underflow */
282
283 /* Compatability mode fault parameters */
284
285 #define CMODE_RSVI 0x0 /* reserved instr */
286 #define CMODE_BPT 0x1 /* BPT */
287 #define CMODE_IOT 0x2 /* IOT */
288 #define CMODE_EMT 0x3 /* EMT */
289 #define CMODE_TRAP 0x4 /* TRAP */
290 #define CMODE_ILLI 0x5 /* illegal instr */
291 #define CMODE_ODD 0x6 /* odd address */
292
293 /* EDITPC suboperators */
294
295 #define EO_END 0x00 /* end */
296 #define EO_END_FLOAT 0x01 /* end float */
297 #define EO_CLR_SIGNIF 0x02 /* clear signif */
298 #define EO_SET_SIGNIF 0x03 /* set signif */
299 #define EO_STORE_SIGN 0x04 /* store sign */
300 #define EO_LOAD_FILL 0x40 /* load fill */
301 #define EO_LOAD_SIGN 0x41 /* load sign */
302 #define EO_LOAD_PLUS 0x42 /* load sign if + */
303 #define EO_LOAD_MINUS 0x43 /* load sign if - */
304 #define EO_INSERT 0x44 /* insert */
305 #define EO_BLANK_ZERO 0x45 /* blank zero */
306 #define EO_REPL_SIGN 0x46 /* replace sign */
307 #define EO_ADJUST_LNT 0x47 /* adjust length */
308 #define EO_FILL 0x80 /* fill */
309 #define EO_MOVE 0x90 /* move */
310 #define EO_FLOAT 0xA0 /* float */
311 #define EO_RPT_MASK 0x0F /* rpt mask */
312 #define EO_RPT_FLAG 0x80 /* rpt flag */
313
314 /* EDITPC R2 packup parameters */
315
316 #define ED_V_CC 16 /* condition codes */
317 #define ED_M_CC 0xFF
318 #define ED_CC (ED_M_CC << ED_V_CC)
319 #define ED_V_SIGN 8 /* sign */
320 #define ED_M_SIGN 0xFF
321 #define ED_SIGN (ED_M_SIGN << ED_V_SIGN)
322 #define ED_V_FILL 0 /* fill */
323 #define ED_M_FILL 0xFF
324 #define ED_FILL (ED_M_FILL << ED_V_FILL)
325 #define ED_GETCC(x) (((x) >> ED_V_CC) & CC_MASK)
326 #define ED_GETSIGN(x) (((x) >> ED_V_SIGN) & ED_M_SIGN)
327 #define ED_GETFILL(x) (((x) >> ED_V_FILL) & ED_M_FILL)
328 #define ED_PUTCC(r,x) (((r) & ~ED_CC) | (((x) << ED_V_CC) & ED_CC))
329 #define ED_PUTSIGN(r,x) (((r) & ~ED_SIGN) | (((x) << ED_V_SIGN) & ED_SIGN))
330 #define ED_PUTFILL(r,x) (((r) & ~ED_FILL) | (((x) << ED_V_FILL) & ED_FILL))
331
332 /* SCB offsets */
333
334 #define SCB_MCHK 0x04 /* machine chk */
335 #define SCB_KSNV 0x08 /* ker stk invalid */
336 #define SCB_PWRFL 0x0C /* power fail */
337 #define SCB_RESIN 0x10 /* rsvd/priv instr */
338 #define SCB_XFC 0x14 /* XFC instr */
339 #define SCB_RESOP 0x18 /* rsvd operand */
340 #define SCB_RESAD 0x1C /* rsvd addr mode */
341 #define SCB_ACV 0x20 /* ACV */
342 #define SCB_TNV 0x24 /* TNV */
343 #define SCB_TP 0x28 /* trace pending */
344 #define SCB_BPT 0x2C /* BPT instr */
345 #define SCB_CMODE 0x30 /* comp mode fault */
346 #define SCB_ARITH 0x34 /* arith fault */
347 #define SCB_CHMK 0x40 /* CHMK */
348 #define SCB_CHME 0x44 /* CHME */
349 #define SCB_CHMS 0x48 /* CHMS */
350 #define SCB_CHMU 0x4C /* CHMU */
351 #define SCB_CRDERR 0x54 /* CRD err intr */
352 #define SCB_MEMERR 0x60 /* mem err intr */
353 #define SCB_IPLSOFT 0x80 /* software intr */
354 #define SCB_INTTIM 0xC0 /* timer intr */
355 #define SCB_EMULATE 0xC8 /* emulation */
356 #define SCB_EMULFPD 0xCC /* emulation, FPD */
357 #define SCB_CSI 0xF0 /* constor input */
358 #define SCB_CSO 0xF4 /* constor output */
359 #define SCB_TTI 0xF8 /* console input */
360 #define SCB_TTO 0xFC /* console output */
361 #define SCB_INTR 0x100 /* hardware intr */
362
363 #define IPL_HLTPIN 0x1F /* halt pin IPL */
364 #define IPL_MEMERR 0x1D /* mem err IPL */
365 #define IPL_CRDERR 0x1A /* CRD err IPL */
366
367 /* Interrupt and exception types */
368
369 #define IE_SVE -1 /* severe exception */
370 #define IE_EXC 0 /* normal exception */
371 #define IE_INT 1 /* interrupt */
372
373 /* Decode ROM: opcode entry */
374
375 #define DR_F 0x80 /* FPD ok flag */
376 #define DR_NSPMASK 0x07 /* #specifiers */
377 #define DR_V_USPMASK 4
378 #define DR_M_USPMASK 0x70 /* #spec, sym_ */
379 #define DR_GETNSP(x) ((x) & DR_NSPMASK)
380 #define DR_GETUSP(x) (((x) >> DR_V_USPMASK) & DR_M_USPMASK)
381
382 /* Decode ROM: specifier entry */
383
384 #define DR_ACMASK 0x300 /* type */
385 #define DR_SPFLAG 0x008 /* special decode */
386 #define DR_LNMASK 0x007 /* length mask */
387 #define DR_LNT(x) (1 << (x & DR_LNMASK)) /* disp to lnt */
388
389 /* Decode ROM: length */
390
391 #define DR_BYTE 0x000 /* byte */
392 #define DR_WORD 0x001 /* word */
393 #define DR_LONG 0x002 /* long */
394 #define DR_QUAD 0x003 /* quad */
395 #define DR_OCTA 0x004 /* octa */
396
397 /* Decode ROM: operand type */
398
399 #define SH0 0x000 /* short literal */
400 #define SH1 0x010
401 #define SH2 0x020
402 #define SH3 0x030
403 #define IDX 0x040 /* indexed */
404 #define GRN 0x050 /* register */
405 #define RGD 0x060 /* register def */
406 #define ADC 0x070 /* autodecrement */
407 #define AIN 0x080 /* autoincrement */
408 #define AID 0x090 /* autoinc def */
409 #define BDP 0x0A0 /* byte disp */
410 #define BDD 0x0B0 /* byte disp def */
411 #define WDP 0x0C0 /* word disp */
412 #define WDD 0x0D0 /* word disp def */
413 #define LDP 0x0E0 /* long disp */
414 #define LDD 0x0F0 /* long disp def */
415
416 /* Decode ROM: access type */
417
418 #define DR_R 0x000 /* read */
419 #define DR_M 0x100 /* modify */
420 #define DR_A 0x200 /* address */
421 #define DR_W 0x300 /* write */
422
423 /* Decode ROM: access type and length */
424
425 #define RB (DR_R|DR_BYTE)
426 #define RW (DR_R|DR_WORD)
427 #define RL (DR_R|DR_LONG)
428 #define RQ (DR_R|DR_QUAD)
429 #define RO (DR_R|DR_OCTA)
430 #define MB (DR_M|DR_BYTE)
431 #define MW (DR_M|DR_WORD)
432 #define ML (DR_M|DR_LONG)
433 #define MQ (DR_M|DR_QUAD)
434 #define MO (DR_M|DR_OCTA)
435 #define AB (DR_A|DR_BYTE)
436 #define AW (DR_A|DR_WORD)
437 #define AL (DR_A|DR_LONG)
438 #define AQ (DR_A|DR_QUAD)
439 #define AO (DR_A|DR_OCTA)
440 #define WB (DR_W|DR_BYTE)
441 #define WW (DR_W|DR_WORD)
442 #define WL (DR_W|DR_LONG)
443 #define WQ (DR_W|DR_QUAD)
444 #define WO (DR_W|DR_OCTA)
445
446 /* Special dispatches.
447
448 vb = variable bit field, treated as wb except for register
449 rf = f_floating, treated as rl except for short literal
450 rd = d_floating, treated as rq except for short literal
451 rg = g_floating, treated as rq except for short literal
452 rh = h_floating, treated as ro except for short literal
453 bb = branch byte displacement
454 bw = branch word displacement
455
456 Length field must be correct
457 */
458
459 #define VB (DR_SPFLAG|WB) /* .vb */
460 #define RF (DR_SPFLAG|RL) /* .rf */
461 #define RD (DR_SPFLAG|RQ) /* .rd */
462 #define RG (DR_SPFLAG|MQ) /* .rg */
463 #define RH (DR_SPFLAG|RO) /* .rh */
464 #define BB (DR_SPFLAG|WB|6) /* byte branch */
465 #define BW (DR_SPFLAG|WB|7) /* word branch */
466
467 /* Probe results and memory management fault codes */
468
469 #define PR_ACV 0 /* ACV */
470 #define PR_LNV 1 /* length viol */
471 #define PR_PACV 2 /* pte ACV (780) */
472 #define PR_PLNV 3 /* pte len viol */
473 #define PR_TNV 4 /* TNV */
474 /* #define PR_TB 5 /* impossible */
475 #define PR_PTNV 6 /* pte TNV */
476 #define PR_OK 7 /* ok */
477 #define MM_PARAM(w,p) (((w)? 4: 0) | ((p) & 3)) /* fault param */
478
479 /* Memory management errors */
480
481 #define MM_WRITE 4 /* write */
482 #define MM_EMASK 3 /* against probe */
483
484 /* Privileged registers */
485
486 #define MT_KSP 0
487 #define MT_ESP 1
488 #define MT_SSP 2
489 #define MT_USP 3
490 #define MT_IS 4
491 #define MT_P0BR 8
492 #define MT_P0LR 9
493 #define MT_P1BR 10
494 #define MT_P1LR 11
495 #define MT_SBR 12
496 #define MT_SLR 13
497 #define MT_PCBB 16
498 #define MT_SCBB 17
499 #define MT_IPL 18
500 #define MT_ASTLVL 19
501 #define MT_SIRR 20
502 #define MT_SISR 21
503 #define MT_ICCS 24
504 #define MT_NICR 25
505 #define MT_ICR 26
506 #define MT_TODR 27
507 #define MT_CSRS 28
508 #define MT_CSRD 29
509 #define MT_CSTS 30
510 #define MT_CSTD 31
511 #define MT_RXCS 32
512 #define MT_RXDB 33
513 #define MT_TXCS 34
514 #define MT_TXDB 35
515 #define MT_MAPEN 56
516 #define MT_TBIA 57
517 #define MT_TBIS 58
518 #define MT_PME 61
519 #define MT_SID 62
520 #define MT_TBCHK 63
521
522 #define BR_MASK 0xFFFFFFFC
523 #define LR_MASK 0x003FFFFF
524
525 /* Opcodes */
526
527 enum opcodes {
528 HALT, NOP, REI, BPT, RET, RSB, LDPCTX, SVPCTX,
529 CVTPS, CVTSP, INDEX, CRC, PROBER, PROBEW, INSQUE, REMQUE,
530 BSBB, BRB, BNEQ, BEQL, BGTR, BLEQ, JSB, JMP,
531 BGEQ, BLSS, BGTRU, BLEQU, BVC, BVS, BGEQU, BLSSU,
532 ADDP4, ADDP6, SUBP4, SUBP6, CVTPT, MULP, CVTTP, DIVP,
533 MOVC3, CMPC3, SCANC, SPANC, MOVC5, CMPC5, MOVTC, MOVTUC,
534 BSBW, BRW, CVTWL, CVTWB, MOVP, CMPP3, CVTPL, CMPP4,
535 EDITPC, MATCHC, LOCC, SKPC, MOVZWL, ACBW, MOVAW, PUSHAW,
536 ADDF2, ADDF3, SUBF2, SUBF3, MULF2, MULF3, DIVF2, DIVF3,
537 CVTFB, CVTFW, CVTFL, CVTRFL, CVTBF, CVTWF, CVTLF, ACBF,
538 MOVF, CMPF, MNEGF, TSTF, EMODF, POLYF, CVTFD,
539 ADAWI = 0x58, INSQHI = 0x5C, INSQTI, REMQHI, REMQTI,
540 ADDD2, ADDD3, SUBD2, SUBD3, MULD2, MULD3, DIVD2, DIVD3,
541 CVTDB, CVTDW, CVTDL, CVTRDL, CVTBD, CVTWD, CVTLD, ACBD,
542 MOVD, CMPD, MNEGD, TSTD, EMODD, POLYD, CVTDF,
543 ASHL = 0x78, ASHQ, EMUL, EDIV, CLRQ, MOVQ, MOVAQ, PUSHAQ,
544 ADDB2, ADDB3, SUBB2, SUBB3, MULB2, MULB3, DIVB2, DIVB3,
545 BISB2, BISB3, BICB2, BICB3, XORB2, XORB3, MNEGB, CASEB,
546 MOVB, CMPB, MCOMB, BITB, CLRB, TSTB, INCB, DECB,
547 CVTBL, CVTBW, MOVZBL, MOVZBW, ROTL, ACBB, MOVAB, PUSHAB,
548 ADDW2, ADDW3, SUBW2, SUBW3, MULW2, MULW3, DIVW2, DIVW3,
549 BISW2, BISW3, BICW2, BICW3, XORW2, XORW3, MNEGW, CASEW,
550 MOVW, CMPW, MCOMW, BITW, CLRW, TSTW, INCW, DECW,
551 BISPSW, BICPSW, POPR, PUSHR, CHMK, CHME, CHMS, CHMU,
552 ADDL2, ADDL3, SUBL2, SUBL3, MULL2, MULL3, DIVL2, DIVL3,
553 BISL2, BISL3, BICL2, BICL3, XORL2, XORL3, MNEGL, CASEL,
554 MOVL, CMPL, MCOML, BITL, CLRL, TSTL, INCL, DECL,
555 ADWC, SBWC, MTPR, MFPR, MOVPSL, PUSHL, MOVAL, PUSHAL,
556 BBS, BBC, BBSS, BBCS, BBSC, BBCC, BBSSI, BBCCI,
557 BLBS, BLBC, FFS, FFC, CMPV, CMPZV, EXTV, EXTZV,
558 INSV, ACBL, AOBLSS, AOBLEQ, SOBGEQ, SOBGTR, CVTLB, CVTLW,
559 ASHP, CVTLP, CALLG, CALLS, XFC, CVTDH = 0x132, CVTGF = 0x133,
560 ADDG2 = 0x140, ADDG3, SUBG2, SUBG3, MULG2, MULG3, DIVG2, DIVG3,
561 CVTGB, CVTGW, CVTGL, CVTRGL, CVTBG, CVTWG, CVTLG, ACBG,
562 MOVG, CMPG, MNEGG, TSTG, EMODG, POLYG, CVTGH,
563 ADDH2 = 0x160, ADDH3, SUBH2, SUBH3, MULH2, MULH3, DIVH2, DIVH3,
564 CVTHB, CVTHW, CVTHL, CVTRHL, CVTBH, CVTWH, CVTLH, ACBH,
565 MOVH, CMPH, MNEGH, TSTH, EMODH, POLYH, CVTHG,
566 CLRO = 0x17C, MOVO, MOVAO, PUSHAO,
567 CVTFH = 0x198, CVTFG = 0x199,
568 CVTHF = 0x1F6, CVTHD = 0x1F7 };
569
570 /* Repeated operations */
571
572 #define SXTB(x) (((x) & BSIGN)? ((x) | ~BMASK): ((x) & BMASK))
573 #define SXTW(x) (((x) & WSIGN)? ((x) | ~WMASK): ((x) & WMASK))
574 #define SXTBW(x) (((x) & BSIGN)? ((x) | (WMASK - BMASK)): ((x) & BMASK))
575 #define SXTL(x) (((x) & LSIGN)? ((x) | ~LMASK): ((x) & LMASK))
576 #define INTOV if (PSL & PSW_IV) SET_TRAP (TRAP_INTOV)
577 #define V_INTOV cc = cc | CC_V; INTOV
578 #define NEG(x) ((~(x) + 1) & LMASK)
579
580 /* Istream access */
581
582 #define PCQ_SIZE 64 /* must be 2**n */
583 #define PCQ_MASK (PCQ_SIZE - 1)
584 #define PCQ_ENTRY pcq[pcq_p = (pcq_p - 1) & PCQ_MASK] = fault_PC
585 #define GET_ISTR(d,l) d = get_istr (l, acc)
586 #define BRANCHB(d) PCQ_ENTRY, PC = PC + SXTB (d), FLUSH_ISTR
587 #define BRANCHW(d) PCQ_ENTRY, PC = PC + SXTW (d), FLUSH_ISTR
588 #define JUMP(d) PCQ_ENTRY, PC = (d), FLUSH_ISTR
589 #define CMODE_JUMP(d) PCQ_ENTRY, PC = (d)
590 #define SETPC(d) PC = (d), FLUSH_ISTR
591 #define FLUSH_ISTR ibcnt = 0, ppc = -1
592
593 /* Character string instructions */
594
595 #define STR_V_DPC 24 /* delta PC */
596 #define STR_M_DPC 0xFF
597 #define STR_V_CHR 16 /* char argument */
598 #define STR_M_CHR 0xFF
599 #define STR_LNMASK 0xFFFF /* string length */
600 #define STR_GETDPC(x) (((x) >> STR_V_DPC) & STR_M_DPC)
601 #define STR_GETCHR(x) (((x) >> STR_V_CHR) & STR_M_CHR)
602 #define STR_PACK(m,x) ((((PC - fault_PC) & STR_M_DPC) << STR_V_DPC) | \
603 (((m) & STR_M_CHR) << STR_V_CHR) | ((x) & STR_LNMASK))
604
605 /* Read and write */
606
607 #define RA (acc)
608 #define WA ((acc) << TLB_V_WACC)
609 #define ACC_MASK(x) (1 << (x))
610 #define TLB_ACCR(x) (ACC_MASK (x) << TLB_V_RACC)
611 #define TLB_ACCW(x) (ACC_MASK (x) << TLB_V_WACC)
612 #define REF_V 0
613 #define REF_P 1
614
615 /* Condition code macros */
616
617 #define CC_ZZ1P cc = CC_Z | (cc & CC_C)
618
619 #define CC_IIZZ_B(r) \
620 if ((r) & BSIGN) cc = CC_N; \
621 else if ((r) == 0) cc = CC_Z; \
622 else cc = 0
623 #define CC_IIZZ_W(r) \
624 if ((r) & WSIGN) cc = CC_N; \
625 else if ((r) == 0) cc = CC_Z; \
626 else cc = 0
627 #define CC_IIZZ_L(r) \
628 if ((r) & LSIGN) cc = CC_N; \
629 else if ((r) == 0) cc = CC_Z; \
630 else cc = 0
631 #define CC_IIZZ_Q(rl,rh) \
632 if ((rh) & LSIGN) cc = CC_N; \
633 else if (((rl) | (rh)) == 0) cc = CC_Z; \
634 else cc = 0
635 #define CC_IIZZ_FP CC_IIZZ_W
636
637 #define CC_IIZP_B(r) \
638 if ((r) & BSIGN) cc = CC_N | (cc & CC_C); \
639 else if ((r) == 0) cc = CC_Z | (cc & CC_C); \
640 else cc = cc & CC_C
641 #define CC_IIZP_W(r) \
642 if ((r) & WSIGN) cc = CC_N | (cc & CC_C); \
643 else if ((r) == 0) cc = CC_Z | (cc & CC_C); \
644 else cc = cc & CC_C
645 #define CC_IIZP_L(r) \
646 if ((r) & LSIGN) cc = CC_N | (cc & CC_C); \
647 else if ((r) == 0) cc = CC_Z | (cc & CC_C); \
648 else cc = cc & CC_C
649 #define CC_IIZP_Q(rl,rh) \
650 if ((rh) & LSIGN) cc = CC_N | (cc & CC_C); \
651 else if (((rl) | (rh)) == 0) cc = CC_Z | (cc & CC_C); \
652 else cc = cc & CC_C
653 #define CC_IIZP_O(rl,rm2,rm1,rh) \
654 if ((rh) & LSIGN) cc = CC_N | (cc & CC_C); \
655 else if (((rl) | (rm2) | (rm1) | (rh)) == 0) cc = CC_Z | (cc & CC_C); \
656 else cc = cc & CC_C
657 #define CC_IIZP_FP CC_IIZP_W
658
659 #define V_ADD_B(r,s1,s2) \
660 if (((~(s1) ^ (s2)) & ((s1) ^ (r))) & BSIGN) { V_INTOV; }
661 #define V_ADD_W(r,s1,s2) \
662 if (((~(s1) ^ (s2)) & ((s1) ^ (r))) & WSIGN) { V_INTOV; }
663 #define V_ADD_L(r,s1,s2) \
664 if (((~(s1) ^ (s2)) & ((s1) ^ (r))) & LSIGN) { V_INTOV; }
665 #define C_ADD(r,s1,s2) \
666 if (((uint32) r) < ((uint32) s2)) cc = cc | CC_C
667
668 #define CC_ADD_B(r,s1,s2) \
669 CC_IIZZ_B (r); \
670 V_ADD_B (r, s1, s2); \
671 C_ADD (r, s1, s2)
672 #define CC_ADD_W(r,s1,s2) \
673 CC_IIZZ_W (r); \
674 V_ADD_W (r, s1, s2); \
675 C_ADD (r, s1, s2)
676 #define CC_ADD_L(r,s1,s2) \
677 CC_IIZZ_L (r); \
678 V_ADD_L (r, s1, s2); \
679 C_ADD (r, s1, s2)
680
681 #define V_SUB_B(r,s1,s2) \
682 if ((((s1) ^ (s2)) & (~(s1) ^ (r))) & BSIGN) { V_INTOV; }
683 #define V_SUB_W(r,s1,s2) \
684 if ((((s1) ^ (s2)) & (~(s1) ^ (r))) & WSIGN) { V_INTOV; }
685 #define V_SUB_L(r,s1,s2) \
686 if ((((s1) ^ (s2)) & (~(s1) ^ (r))) & LSIGN) { V_INTOV; }
687 #define C_SUB(r,s1,s2) \
688 if (((uint32) s2) < ((uint32) s1)) cc = cc | CC_C
689
690 #define CC_SUB_B(r,s1,s2) \
691 CC_IIZZ_B (r); \
692 V_SUB_B (r, s1, s2); \
693 C_SUB (r, s1, s2)
694 #define CC_SUB_W(r,s1,s2) \
695 CC_IIZZ_W (r); \
696 V_SUB_W (r, s1, s2); \
697 C_SUB (r, s1, s2)
698 #define CC_SUB_L(r,s1,s2) \
699 CC_IIZZ_L (r); \
700 V_SUB_L (r, s1, s2); \
701 C_SUB (r, s1, s2)
702
703 #define CC_CMP_B(s1,s2) \
704 if (SXTB (s1) < SXTB (s2)) cc = CC_N; \
705 else if ((s1) == (s2)) cc = CC_Z; \
706 else cc = 0; \
707 if (((uint32) s1) < ((uint32) s2)) cc = cc | CC_C
708 #define CC_CMP_W(s1,s2) \
709 if (SXTW (s1) < SXTW (s2)) cc = CC_N; \
710 else if ((s1) == (s2)) cc = CC_Z; \
711 else cc = 0; \
712 if (((uint32) s1) < ((uint32) s2)) cc = cc | CC_C
713 #define CC_CMP_L(s1,s2) \
714 if ((s1) < (s2)) cc = CC_N; \
715 else if ((s1) == (s2)) cc = CC_Z; \
716 else cc = 0; \
717 if (((uint32) s1) < ((uint32) s2)) cc = cc | CC_C
718
719 /* Model dependent definitions */
720
721 #if defined (VAX_780)
722 #include "vax780_defs.h"
723 #else
724 #include "vaxmod_defs.h"
725 #endif
726
727 #endif /* _VAX_DEFS_H */