M68kException.java
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19: package xeij;
20:
21: import java.lang.*;
22:
23: public class M68kException extends Exception {
24:
25: public static final boolean M6E_DEBUG_ERROR = false;
26:
27:
28: public static final int M6E_INSTRUCTION_BREAK_POINT = -1;
29: public static final int M6E_WAIT_EXCEPTION = -2;
30:
31:
32:
33:
34: public static final int M6E_RESET_INITIAL_SSP = 0;
35: public static final int M6E_RESET_INITIAL_PC = 1;
36: public static final int M6E_ACCESS_FAULT = 2;
37: public static final int M6E_ADDRESS_ERROR = 3;
38: public static final int M6E_ILLEGAL_INSTRUCTION = 4;
39: public static final int M6E_DIVIDE_BY_ZERO = 5;
40: public static final int M6E_CHK_INSTRUCTION = 6;
41: public static final int M6E_TRAPV_INSTRUCTION = 7;
42: public static final int M6E_PRIVILEGE_VIOLATION = 8;
43: public static final int M6E_TRACE = 9;
44: public static final int M6E_LINE_1010_EMULATOR = 10;
45: public static final int M6E_LINE_1111_EMULATOR = 11;
46: public static final int M6E_FP_UNIMPLEMENTED_INSTRUCTION = 11;
47: public static final int M6E_FP_DISABLED = 11;
48: public static final int M6E_EMULATOR_INTERRUPT = 12;
49: public static final int M6E_COPROCESSOR_PROTOCOL_VIOLATION = 13;
50: public static final int M6E_FORMAT_ERROR = 14;
51: public static final int M6E_UNINITIALIZED_INTERRUPT = 15;
52: public static final int M6E_SPURIOUS_INTERRUPT = 24;
53: public static final int M6E_LEVEL_1_INTERRUPT_AUTOVECTOR = 25;
54: public static final int M6E_LEVEL_2_INTERRUPT_AUTOVECTOR = 26;
55: public static final int M6E_LEVEL_3_INTERRUPT_AUTOVECTOR = 27;
56: public static final int M6E_LEVEL_4_INTERRUPT_AUTOVECTOR = 28;
57: public static final int M6E_LEVEL_5_INTERRUPT_AUTOVECTOR = 29;
58: public static final int M6E_LEVEL_6_INTERRUPT_AUTOVECTOR = 30;
59: public static final int M6E_LEVEL_7_INTERRUPT_AUTOVECTOR = 31;
60: public static final int M6E_TRAP_0_INSTRUCTION_VECTOR = 32;
61: public static final int M6E_TRAP_1_INSTRUCTION_VECTOR = 33;
62: public static final int M6E_TRAP_2_INSTRUCTION_VECTOR = 34;
63: public static final int M6E_TRAP_3_INSTRUCTION_VECTOR = 35;
64: public static final int M6E_TRAP_4_INSTRUCTION_VECTOR = 36;
65: public static final int M6E_TRAP_5_INSTRUCTION_VECTOR = 37;
66: public static final int M6E_TRAP_6_INSTRUCTION_VECTOR = 38;
67: public static final int M6E_TRAP_7_INSTRUCTION_VECTOR = 39;
68: public static final int M6E_TRAP_8_INSTRUCTION_VECTOR = 40;
69: public static final int M6E_TRAP_9_INSTRUCTION_VECTOR = 41;
70: public static final int M6E_TRAP_10_INSTRUCTION_VECTOR = 42;
71: public static final int M6E_TRAP_11_INSTRUCTION_VECTOR = 43;
72: public static final int M6E_TRAP_12_INSTRUCTION_VECTOR = 44;
73: public static final int M6E_TRAP_13_INSTRUCTION_VECTOR = 45;
74: public static final int M6E_TRAP_14_INSTRUCTION_VECTOR = 46;
75: public static final int M6E_TRAP_15_INSTRUCTION_VECTOR = 47;
76: public static final int M6E_FP_BRANCH_SET_UNORDERED = 48;
77: public static final int M6E_FP_INEXACT_RESULT = 49;
78:
79: public static final int M6E_FP_DIVIDE_BY_ZERO = 50;
80: public static final int M6E_FP_UNDERFLOW = 51;
81:
82: public static final int M6E_FP_OPERAND_ERROR = 52;
83:
84: public static final int M6E_FP_OVERFLOW = 53;
85:
86: public static final int M6E_FP_SIGNALING_NAN = 54;
87:
88: public static final int M6E_FP_UNSUPPORTED_DATA_TYPE = 55;
89:
90:
91: public static final int M6E_MMU_CONFIGULATION_ERROR = 56;
92: public static final int M6E_MMU_ILLEGAL_OPERATION_ERROR = 57;
93: public static final int M6E_MMU_ACCESS_LEVEL_VIOLATION = 58;
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104: public static final int M6E_UNIMPLEMENTED_EFFECTIVE = 60;
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125: public static final int M6E_UNIMPLEMENTED_INSTRUCTION = 61;
126:
127: public static final String[] M6E_ERROR_NAME = {
128: "undefined exception #0",
129: "undefined exception #1",
130: "Access fault",
131: "Address error",
132: "Illegal instruction",
133: "Divide by zero",
134: "CHK instruction",
135: "Trapv instruction",
136: "Privilege violation",
137: "Trace",
138: "Line 1010 emulator",
139: "Line 1111 emulator",
140: "Emulator interrupt",
141: "Coprocessor protocol violation",
142: "Format error",
143: "Uninitialized interrupt",
144: "undefined exception #16",
145: "undefined exception #17",
146: "undefined exception #18",
147: "undefined exception #19",
148: "undefined exception #20",
149: "undefined exception #21",
150: "undefined exception #22",
151: "undefined exception #23",
152: "Spurious interrupt",
153: "Level 1 interrupt autovector",
154: "Level 2 interrupt autovector",
155: "Level 3 interrupt autovector",
156: "Level 4 interrupt autovector",
157: "Level 5 interrupt autovector",
158: "Level 6 interrupt autovector",
159: "Level 7 interrupt autovector",
160: "TRAP #0 instruction vector",
161: "TRAP #1 instruction vector",
162: "TRAP #2 instruction vector",
163: "TRAP #3 instruction vector",
164: "TRAP #4 instruction vector",
165: "TRAP #5 instruction vector",
166: "TRAP #6 instruction vector",
167: "TRAP #7 instruction vector",
168: "TRAP #8 instruction vector",
169: "TRAP #9 instruction vector",
170: "TRAP #10 instruction vector",
171: "TRAP #11 instruction vector",
172: "TRAP #12 instruction vector",
173: "TRAP #13 instruction vector",
174: "TRAP #14 instruction vector",
175: "TRAP #15 instruction vector",
176: "FP branch/set on unordered ",
177: "FP inexact result",
178: "FP divide by zero",
179: "FP underflow",
180: "FP operand error",
181: "FP overflow",
182: "FP signaling NAN",
183: "FP unsupported data type",
184: "MMU configulation error",
185: "MMU illegal operation error",
186: "MMU access level violation",
187: "undefined exception #59",
188: "Unimplemented effective address",
189: "Unimplemented instruction",
190: "undefined exception #62",
191: "undefined exception #63",
192: };
193:
194: public static M68kException m6eSignal;
195: public static int m6eNumber;
196: public static int m6eAddress;
197: public static int m6eDirection;
198: public static int m6eSize;
199:
200:
201:
202:
203:
204:
205:
206:
207:
208:
209:
210:
211:
212:
213:
214:
215:
216: public static final int M6E_FSLW_MISALIGNED = 1 << 27;
217: public static final int M6E_FSLW_LOCKED = 1 << 25;
218: public static final int M6E_FSLW_READ_AND_WRITE = 3 << 23;
219: public static final int M6E_FSLW_RW_WRITE = 1 << 23;
220: public static final int M6E_FSLW_RW_READ = 2 << 23;
221: public static final int M6E_FSLW_RW_MODIFY = 3 << 23;
222: public static final int M6E_FSLW_TRANSFER_SIZE = 3 << 21;
223: public static final int M6E_FSLW_SIZE_LONG = 0 << 21;
224: public static final int M6E_FSLW_SIZE_BYTE = 1 << 21;
225: public static final int M6E_FSLW_SIZE_WORD = 2 << 21;
226: public static final int M6E_FSLW_SIZE_QUAD = 3 << 21;
227: public static final int M6E_FSLW_TRANSFER_TYPE = 3 << 19;
228: public static final int M6E_FSLW_TT_NORMAL = 0 << 19;
229: public static final int M6E_FSLW_TT_MOVE16 = 1 << 19;
230: public static final int M6E_FSLW_TT_ALTERNATE = 2 << 19;
231: public static final int M6E_FSLW_TT_ACKNOWLEDGE = 3 << 19;
232: public static final int M6E_FSLW_TRANSFER_MODIFIER = 7 << 16;
233: public static final int M6E_FSLW_TM_CACHE_PUSH = 0 << 16;
234: public static final int M6E_FSLW_TM_USER_DATA = 1 << 16;
235: public static final int M6E_FSLW_TM_USER_CODE = 2 << 16;
236: public static final int M6E_FSLW_TM_MMU_DATA = 3 << 16;
237: public static final int M6E_FSLW_TM_MMU_CODE = 4 << 16;
238: public static final int M6E_FSLW_TM_SUPER_DATA = 5 << 16;
239: public static final int M6E_FSLW_TM_SUPER_CODE = 6 << 16;
240: public static final int M6E_FSLW_TM_DATA = 1 << 16;
241: public static final int M6E_FSLW_TM_CODE = 2 << 16;
242: public static final int M6E_FSLW_TM_SUPERVISOR = 4 << 16;
243: public static final int M6E_FSLW_INSTRUCTION = 1 << 15;
244: public static final int M6E_FSLW_IOMA_FIRST = 0 << 15 | 0 << 27;
245: public static final int M6E_FSLW_IOMA_SECOND = 0 << 15 | 1 << 27;
246: public static final int M6E_FSLW_IOMA_OPWORD = 1 << 15 | 0 << 27;
247: public static final int M6E_FSLW_IOMA_EXWORD = 1 << 15 | 1 << 27;
248: public static final int M6E_FSLW_PUSH_BUFFER = 1 << 14;
249: public static final int M6E_FSLW_STORE_BUFFER = 1 << 13;
250: public static final int M6E_FSLW_ROOT_DESCRIPTOR = 1 << 12;
251: public static final int M6E_FSLW_POINTER_DESCRIPTOR = 1 << 11;
252: public static final int M6E_FSLW_INDIRECT_LEVEL = 1 << 10;
253: public static final int M6E_FSLW_PAGE_FAULT = 1 << 9;
254: public static final int M6E_FSLW_SUPERVISOR_PROTECT = 1 << 8;
255: public static final int M6E_FSLW_WRITE_PROTECT = 1 << 7;
256: public static final int M6E_FSLW_TABLE_SEARCH = 1 << 6;
257: public static final int M6E_FSLW_BUS_ERROR_ON_READ = 1 << 5;
258: public static final int M6E_FSLW_BUS_ERROR_ON_WRITE = 1 << 4;
259: public static final int M6E_FSLW_TRANSPARENT = 1 << 3;
260: public static final int M6E_FSLW_BRANCH_PREDICTION = 1 << 2;
261: public static final int M6E_FSLW_SOFTWARE_EMULATION = 1 << 0;
262:
263: public static int m6eFSLW;
264:
265:
266:
267:
268:
269:
270:
271:
272:
273:
274: public static long m6eIncremented;
275:
276: public static final String[] M6E_FSLW_TEXT_IOMA = {
277: "IO=0,MA=0 First access of a misaligned transfer or only access of an aligned transfer",
278: "IO=0,MA=1 Second or later access of a misaligned transfer",
279: "IO=1,MA=0 Instruction opword fetch",
280: "IO=1,MA=1 Fetch of an extension word",
281: };
282: public static final String[] M6E_FSLW_TEXT_LK = {
283: "LK=0 Not locked",
284: "LK=1 Locked",
285: };
286: public static final String[] M6E_FSLW_TEXT_RW = {
287: "RW=0 Undefined, reserved",
288: "RW=1 Write",
289: "RW=2 Read",
290: "RW=3 Read-Modify-Write",
291: };
292: public static final String[] M6E_FSLW_TEXT_SIZE = {
293: "SIZE=0 Byte",
294: "SIZE=1 Word",
295: "SIZE=2 Long",
296: "SIZE=3 Double precision or MOVE16",
297: };
298: public static final String[] M6E_FSLW_TEXT_TT = {
299: "TT=0 Normal access",
300: "TT=1 MOVE16 access",
301: "TT=2 Alternate or debug access",
302: "TT=3 Acknowledge or LPSTOP broadcast",
303: };
304: public static final String[] M6E_FSLW_TEXT_TM = {
305: "TM=0 Data cache push access",
306: "TM=1 User data or MOVE16 access",
307: "TM=2 User code access",
308: "TM=3 MMU table search data access",
309: "TM=4 MMU table search code access",
310: "TM=5 Supervisor data access",
311: "TM=6 Supervisor code access",
312: "TM=7 Reserved",
313:
314:
315:
316:
317:
318:
319:
320:
321: };
322: public static final String[] M6E_FSLW_TEXT_CAUSE = {
323: "SEE=1 Software emulation error",
324: "",
325: "BPE=1 Branch prediction error",
326: "TTR=1 TTR hit",
327: "WE=1 Bus error on write",
328: "RE=1 Bus error on read",
329: "TWE=1 Bus error on table search",
330: "WP=1 Write protect",
331: "SP=1 Supervisor protect",
332: "PF=1 Page fault",
333: "IL=1 Indirect level fault",
334: "PTB=1 Pointer B fault",
335: "PTA=1 Pointer A fault",
336: "SBE=1 Store buffer bus error",
337: "PBE=1 Push buffer bus error",
338: };
339:
340: public static String m6eToString6 () {
341: StringBuilder sb = new StringBuilder ();
342: int supervisor = m6eFSLW & M6E_FSLW_TM_SUPERVISOR;
343: int instruction = m6eFSLW & M6E_FSLW_TM_CODE;
344: if (0 <= m6eNumber && m6eNumber < M6E_ERROR_NAME.length) {
345: sb.append (M6E_ERROR_NAME[m6eNumber]);
346: } else {
347: sb.append ("undefined exception #").append (m6eNumber);
348: }
349: XEiJ.fmtHex8 (sb.append (" at PC=$"), XEiJ.regPC0).append ("($");
350: int pa = MC68060.mmuTranslatePeek (XEiJ.regPC0, supervisor, 1);
351: if ((XEiJ.regPC0 ^ pa) == 1) {
352: sb.append ("????????");
353: } else {
354: XEiJ.fmtHex8 (sb, pa);
355: }
356: XEiJ.fmtHex4 (sb.append ("), SR=$"), XEiJ.regSRT1 | XEiJ.regSRS | XEiJ.regSRI | XEiJ.regCCR);
357:
358:
359: if (0b0011011101000000000000000000000000000000000000000000000000000000L << m6eNumber < 0L) {
360: if ((m6eFSLW & (M6E_FSLW_BUS_ERROR_ON_READ | M6E_FSLW_BUS_ERROR_ON_WRITE)) != 0) {
361: XEiJ.fmtHex8 (sb.append ("\n Fault or effective address is EA=($"), m6eAddress).append (')');
362: } else {
363: XEiJ.fmtHex8 (sb.append ("\n Fault or effective address is EA=$"), m6eAddress).append ("($");
364: pa = MC68060.mmuTranslatePeek (m6eAddress, supervisor, instruction);
365: if ((m6eAddress ^ pa) == 1) {
366: sb.append ("????????");
367: } else {
368: XEiJ.fmtHex8 (sb, pa);
369: }
370: sb.append (')');
371: }
372: }
373: if (m6eNumber == M6E_ACCESS_FAULT) {
374: XEiJ.fmtHex8 (sb.append ("\n Fault status long word is FSLW=$"), m6eFSLW);
375: sb.append ("\n Fault was caused by:");
376: for (int i = 14; i >= 0; i--) {
377: if ((m6eFSLW & (1 << i)) != 0) {
378: sb.append ("\n ").append (M6E_FSLW_TEXT_CAUSE[i]);
379: }
380: }
381: sb.append ("\n Fault occured on:\n ")
382: .append (M6E_FSLW_TEXT_IOMA[(m6eFSLW & M6E_FSLW_INSTRUCTION) >>> 15 - 1 | (m6eFSLW & M6E_FSLW_MISALIGNED) >>> 27])
383: .append ("\n ").append (M6E_FSLW_TEXT_LK[(m6eFSLW & M6E_FSLW_LOCKED) >>> 25])
384: .append ("\n ").append (M6E_FSLW_TEXT_RW[(m6eFSLW & M6E_FSLW_READ_AND_WRITE) >>> 23])
385: .append ("\n ").append (M6E_FSLW_TEXT_SIZE[(m6eFSLW & M6E_FSLW_TRANSFER_SIZE) >>> 21])
386: .append ("\n ").append (M6E_FSLW_TEXT_TT[(m6eFSLW & M6E_FSLW_TRANSFER_TYPE) >>> 19])
387: .append ("\n ").append (M6E_FSLW_TEXT_TM[(m6eFSLW & M6E_FSLW_TRANSFER_MODIFIER) >>> 16]);
388: }
389: return sb.toString ();
390: }
391:
392: }
393:
394:
395: