1 /*
2 * vim: filetype=c:tabstop=4:ai:expandtab
3 * SPDX-License-Identifier: ICU
4 * SPDX-License-Identifier: Multics
5 * scspell-id: 4182f303-f62e-11ec-9475-80ee73e9b8e7
6 *
7 * ---------------------------------------------------------------------------
8 *
9 * Copyright (c) 2007-2013 Michael Mondy
10 * Copyright (c) 2012-2016 Harry Reed
11 * Copyright (c) 2013-2016 Charles Anthony
12 * Copyright (c) 2017 Michal Tomek
13 * Copyright (c) 2021-2026 The DPS8M Development Team
14 *
15 * This software is made available under the terms of the ICU License.
16 * See the LICENSE.md file at the top-level directory of this distribution.
17 *
18 * ---------------------------------------------------------------------------
19 *
20 * This source file may contain code comments that adapt, include, and/or
21 * incorporate Multics program code and/or documentation distributed under
22 * the Multics License. In the event of any discrepancy between code
23 * comments herein and the original Multics materials, the original Multics
24 * materials should be considered authoritative unless otherwise noted.
25 * For more details and historical background, see the LICENSE.md file at
26 * the top-level directory of this distribution.
27 *
28 * ---------------------------------------------------------------------------
29 */
30
31 #include <stdio.h>
32
33 #include "dps8.h"
34 #include "dps8_sys.h"
35 #include "dps8_iom.h"
36 #include "dps8_cable.h"
37 #include "dps8_cpu.h"
38 #include "dps8_faults.h"
39 #include "dps8_scu.h"
40 #include "dps8_append.h"
41 #include "dps8_ins.h"
42 #include "dps8_utils.h"
43 #if defined(THREADZ) || defined(LOCKLESS)
44 # include "threadz.h"
45 #endif
46
47 #define DBG_CTR cpu.cycleCnt
48
49 /*
50 * FAULT RECOGNITION
51 * For the discussion following, the term "function" is defined as a major processor functional
52 * cycle. Examples are: APPEND CYCLE, CA CYCLE, INSTRUCTION FETCH CYCLE, OPERAND STORE CYCLE,
53 * DIVIDE EXECUTION CYCLE. Some of these cycles are discussed in various sections of this manual.
54 * Faults in groups 1 and 2 cause the processor to abort all functions immediately by entering a
55 * FAULT CYCLE. Faults in group 3 cause the processor to "close out" current functions without
56 * taking any irrevocable action (such as setting PTW.U in an APPEND CYCLE or modifying an
57 * indirect word in a CA CYCLE), then to discard any pending functions (such as an APPEND CYCLE
58 * needed during a CA CYCLE), and to enter a FAULT CYCLE. Faults in group 4 cause the processor
59 * to suspend overlapped operation, to complete current and pending functions for the current
60 * instruction, and then to enter a FAULT CYCLE. Faults in groups 5 or 6 are normally detected
61 * during virtual address formation and instruction decode. These faults cause the processor to
62 * suspend overlapped operation, to complete the current and pending instructions, and to enter
63 * a FAULT CYCLE. If a fault in a higher priority group is generated by the execution of the
64 * current or pending instructions, that higher priority fault will take precedence and the
65 * group 5 or 6 fault will be lost. If a group 5 or 6 fault is detected during execution of the
66 * current instruction (e.g., an access violation, out of segment bounds, fault during certain
67 * interruptible EIS instructions), the instruction is considered "complete" upon detection of
68 * the fault. Faults in group 7 are held and processed (with interrupts) at the completion of
69 * the current instruction pair. Group 7 faults are inhibitable by setting bit 28 of the
70 * instruction word. Faults in groups 3 through 6 must wait for the system controller to
71 * acknowledge the last access request before entering the FAULT CYCLE.
72 */
73
74 /*
75 * Table 7-1. List of Faults
76 *
77 * Decimal fault Octal (1) Fault Fault name Priority Group
78 * number fault address mnemonic
79 * 0 ; 0 ; sdf ; Shutdown ; 27 ; 7
80 * 1 ; 2 ; str ; Store ; 10 ; 4
81 * 2 ; 4 ; mme ; Master mode entry 1 ; 11 ; 5
82 * 3 ; 6 ; f1 ; Fault tag 1 ; 17 ; 5
83 * 4 ; 10 ; tro ; Timer runout ; 26 ; 7
84 * 5 ; 12 ; cmd ; Command ; 9 ; 4
85 * 6 ; 14 ; drl ; Derail ; 15 ; 5
86 * 7 ; 16 ; luf ; Lockup ; 5 ; 4
87 * 8 ; 20 ; con ; Connect ; 25 ; 7
88 * 9 ; 22 ; par ; Parity ; 8 ; 4
89 * 10 ; 24 ; ipr ; Illegal procedure ; 16 ; 5
90 * 11 ; 26 ; onc ; Operation not complete ; 4 ; 2
91 * 12 ; 30 ; suf ; Startup ; 1 ; 1
92 * 13 ; 32 ; ofl ; Overflow ; 7 ; 3
93 * 14 ; 34 ; div ; Divide check ; 6 ; 3
94 * 15 ; 36 ; exf ; Execute ; 2 ; 1
95 * 16 ; 40 ; df0 ; Directed fault 0 ; 20 ; 6
96 * 17 ; 42 ; df1 ; Directed fault 1 ; 21 ; 6
97 * 18 ; 44 ; df2 ; Directed fault 2 ; 22 ; 6
98 * 19 ; 46 ; df3 ; Directed fault 3 ; 23 ; 6
99 * 20 ; 50 ; acv ; Access violation ; 24 ; 6
100 * 21 ; 52 ; mme2 ; Master mode entry 2 ; 12 ; 5
101 * 22 ; 54 ; mme3 ; Master mode entry 3 ; 13 ; 5
102 * 23 ; 56 ; mme4 ; Master mode entry 4 ; 14 ; 5
103 * 24 ; 60 ; f2 ; Fault tag 2 ; 18 ; 5
104 * 25 ; 62 ; f3 ; Fault tag 3 ; 19 ; 5
105 * 26 ; 64 ; ; Unassigned ; ;
106 * 27 ; 66 ; ; Unassigned ; ;
107 */
108
109 #if !defined(QUIET_UNUSED)
110 static dps8faults _faultsP[] = { // sorted by priority
111 // number address mnemonic name Priority Group
112 { 12, 030, "suf", "Startup", 1, 1, false },
113 { 15, 036, "exf", "Execute", 2, 1, false },
114 { 31, 076, "trb", "Trouble", 3, 2, false },
115 { 11, 026, "onc", "Operation not complete", 4, 2, false },
116 { 7, 016, "luf", "Lockup", 5, 4, false },
117 { 14, 034, "div", "Divide check", 6, 3, false },
118 { 13, 032, "ofl", "Overflow", 7, 3, false },
119 { 9, 022, "par", "Parity", 8, 4, false },
120 { 5, 012, "cmd", "Command", 9, 4, false },
121 { 1, 2, "str", "Store", 10, 4, false },
122 { 2, 4, "mme", "Master mode entry 1", 11, 5, false },
123 { 21, 052, "mme2", "Master mode entry 2", 12, 5, false },
124 { 22, 054, "mme3", "Master mode entry 3", 13, 5, false },
125 { 23, 056, "mme4", "Master mode entry 4", 14, 5, false },
126 { 6, 014, "drl", "Derail", 15, 5, false },
127 { 10, 024, "ipr", "Illegal procedure", 16, 5, false },
128 { 3, 06, "f1", "Fault tag 1", 17, 5, false },
129 { 24, 060, "f2", "Fault tag 2", 18, 5, false },
130 { 25, 062, "f3", "Fault tag 3", 19, 5, false },
131 { 16, 040, "df0", "Directed fault 0", 20, 6, false },
132 { 17, 042, "df1", "Directed fault 1", 21, 6, false },
133 { 18, 044, "df2", "Directed fault 2", 22, 6, false },
134 { 19, 046, "df3", "Directed fault 3", 23, 6, false },
135 { 20, 050, "acv", "Access violation", 24, 6, false },
136 { 8, 020, "con", "Connect", 25, 7, false },
137 { 4, 010, "tro", "Timer runout", 26, 7, false },
138 { 0, 0, "sdf", "Shutdown", 27, 7, false },
139 { 26, 064, "???", "Unassigned", -1, -1, false },
140 { 27, 066, "???", "Unassigned", -1, -1, false },
141 { -1, -1, NULL, NULL, -1, -1, false }
142 };
143
144 static dps8faults _faults[] = { // sorted by number
145 // number address mnemonic name Priority Group
146 { 0, 0, "sdf", "Shutdown", 27, 7, false },
147 { 1, 2, "str", "Store", 10, 4, false },
148 { 2, 4, "mme", "Master mode entry 1", 11, 5, false },
149 { 3, 06, "f1", "Fault tag 1", 17, 5, false },
150 { 4, 010, "tro", "Timer runout", 26, 7, false },
151 { 5, 012, "cmd", "Command", 9, 4, false },
152 { 6, 014, "drl", "Derail", 15, 5, false },
153 { 7, 016, "luf", "Lockup", 5, 4, false },
154 { 8, 020, "con", "Connect", 25, 7, false },
155 { 9, 022, "par", "Parity", 8, 4, false },
156 { 10, 024, "ipr", "Illegal procedure", 16, 5, false },
157 { 11, 026, "onc", "Operation not complete", 4, 2, false },
158 { 12, 030, "suf", "Startup", 1, 1, false },
159 { 13, 032, "ofl", "Overflow", 7, 3, false },
160 { 14, 034, "div", "Divide check", 6, 3, false },
161 { 15, 036, "exf", "Execute", 2, 1, false },
162 { 16, 040, "df0", "Directed fault 0", 20, 6, false },
163 { 17, 042, "df1", "Directed fault 1", 21, 6, false },
164 { 18, 044, "df2", "Directed fault 2", 22, 6, false },
165 { 19, 046, "df3", "Directed fault 3", 23, 6, false },
166 { 20, 050, "acv", "Access violation", 24, 6, false },
167 { 21, 052, "mme2", "Master mode entry 2", 12, 5, false },
168 { 22, 054, "mme3", "Master mode entry 3", 13, 5, false },
169 { 23, 056, "mme4", "Master mode entry 4", 14, 5, false },
170 { 24, 060, "f2", "Fault tag 2", 18, 5, false },
171 { 25, 062, "f3", "Fault tag 3", 19, 5, false },
172 { 26, 064, "???", "Unassigned", -1, -1, false },
173 { 27, 066, "???", "Unassigned", -1, -1, false },
174 { 28, 070, "???", "Unassigned", -1, -1, false },
175 { 29, 072, "???", "Unassigned", -1, -1, false },
176 { 30, 074, "???", "Unassigned", -1, -1, false },
177 { 31, 076, "trb", "Trouble", 3, 2, false },
178 { -1, -1, NULL, NULL, -1, -1, false }
179 };
180 #endif /* if !defined(QUIET_UNUSED) */
181
182 char * faultNames [N_FAULTS] =
183 {
184 "Shutdown",
185 "Store",
186 "Master mode entry 1",
187 "Fault tag 1",
188 "Timer runout",
189 "Command",
190 "Derail",
191 "Lockup",
192 "Connect",
193 "Parity",
194 "Illegal procedure",
195 "Operation not complete",
196 "Startup",
197 "Overflow",
198 "Divide check",
199 "Execute",
200 "Directed fault 0",
201 "Directed fault 1",
202 "Directed fault 2",
203 "Directed fault 3",
204 "Access violation",
205 "Master mode entry 2",
206 "Master mode entry 3",
207 "Master mode entry 4",
208 "Fault tag 2",
209 "Fault tag 3",
210 "Unassigned 26",
211 "Unassigned 27",
212 "Unassigned 28",
213 "Unassigned 29",
214 "Unassigned 30",
215 "Trouble"
216 };
217 //bool pending_fault = false; // true when a fault has been signalled, but not processed
218
219 #if !defined(QUIET_UNUSED)
220 static bool port_interrupts[8] = { false, false, false, false, false, false, false, false };
221 #endif /* if !defined(QUIET_UNUSED) */
222
223 //-----------------------------------------------------------------------------
224 // *** Constants, unchanging lookup tables, etc
225
226 #if !defined (QUIET_UNUSED)
227 static int fault2group[32] = {
228 // from AL39, page 7-3
229 7, 4, 5, 5, 7, 4, 5, 4,
230 7, 4, 5, 2, 1, 3, 3, 1,
231 6, 6, 6, 6, 6, 5, 5, 5,
232 5, 5, 0, 0, 0, 0, 0, 2
233 };
234
235 static int fault2prio[32] = {
236 // from AL39, page 7-3
237 27, 10, 11, 17, 26, 9, 15, 5,
238 25, 8, 16, 4, 1, 7, 6, 2,
239 20, 21, 22, 23, 24, 12, 13, 14,
240 18, 19, 0, 0, 0, 0, 0, 3
241 };
242 #endif /* if !defined(QUIET_UNUSED) */
243
244 /*
245 * fault handler(s).
246 */
247
248 #if defined(TESTING)
249 // We stash a few things for debugging; they are accessed by emCall.
250 static word18 fault_ic;
251 static word15 fault_psr;
252 static char fault_msg [1024];
253
254 void emCallReportFault (void)
/* ![[previous]](../icons/n_left.png)
![[next]](../icons/right.png)
![[first]](../icons/n_first.png)
![[last]](../icons/last.png)
![[top]](../icons/top.png)
![[bottom]](../icons/bottom.png)
![[index]](../icons/index.png)
*/
255 {
256 cpu_state_t * cpup = _cpup;
257 sim_printf ("fault report:\r\n");
258 sim_printf (" fault number %d (%o)\r\n", cpu . faultNumber, cpu . faultNumber);
259 sim_printf (" subfault number %llu (%llo)\r\n", (unsigned long long) cpu.subFault.bits,
260 (unsigned long long)cpu.subFault.bits);
261 sim_printf (" faulting address %05o:%06o\r\n", fault_psr, fault_ic);
262 sim_printf (" msg %s\r\n", fault_msg);
263 }
264 #endif /* if defined(TESTING) */
265
266 void clearFaultCycle (cpu_state_t * cpup)
/* ![[previous]](../icons/left.png)
![[next]](../icons/right.png)
![[first]](../icons/first.png)
![[last]](../icons/last.png)
![[top]](../icons/top.png)
![[bottom]](../icons/bottom.png)
![[index]](../icons/index.png)
*/
267 {
268 cpu . bTroubleFaultCycle = false;
269 }
270
271 /*
272
273 Faults in groups 1 and 2 cause the processor to abort all functions immediately
274 by entering a FAULT CYCLE.
275
276 Faults in group 3 cause the processor to "close out" current functions without
277 taking any irrevocable action (such as setting PTW.U in an APPEND CYCLE or
278 modifying an indirect word in a CA CYCLE), then to discard any pending
279 functions (such as an APPEND CYCLE needed during a CA CYCLE), and to enter a
280 FAULT CYCLE.
281
282 Faults in group 4 cause the processor to suspend overlapped operation, to
283 complete current and pending functions for the current instruction, and then to
284 enter a FAULT CYCLE.
285
286 Faults in groups 5 or 6 are normally detected during virtual address formation
287 and instruction decode. These faults cause the processor to suspend overlapped
288 operation, to complete the current and pending instructions, and to enter a
289 FAULT CYCLE. If a fault in a higher priority group is generated by the
290 execution of the current or pending instructions, that higher priority fault
291 will take precedence and the group 5 or 6 fault will be lost. If a group 5 or 6
292 fault is detected during execution of the current instruction (e.g., an access
293 violation, out of segment bounds, fault during certain interruptible EIS
294 instructions), the instruction is considered "complete" upon detection of the
295 fault.
296
297 Faults in group 7 are held and processed (with interrupts) at the completion
298 of the current instruction pair.
299
300 Group 7 faults are inhibitable by setting bit 28 of the instruction word.
301
302 Faults in groups 3 through 6 must wait for the system controller to acknowledge
303 the last access request before entering the FAULT CYCLE.
304
305 After much rumination here are my thoughts for fault processing .....
306
307 For now, at least, we must remember a few things:
308
309 1) We only have 1 cpu so we have few & limited async faults - shutdown, TRO,
310 etc.
311 2) We have no overlapping instruction execution
312 3) Because of 2) we have no pending instructions
313 4) We have no system controller to wait for
314
315 Group 1 & 2 faults can be processed immediately and then proceed to next
316 instruction as long as no transfer prevents us from returning from the XED pair.
317
318 Group 3 faults will probably also execute immediately since a G3 fault causes
319 "the processor to "close out" current functions without taking any irrevocable
320 action (such as setting PTW.U in an APPEND CYCLE or modifying an indirect word
321 in a CA CYCLE), then to discard any pending functions (such as an APPEND CYCLE
322 needed during a CA CYCLE), and to enter a FAULT CYCLE."
323
324 Group 4 faults will probably also execute immediately since a G4 fault causes
325 "the processor to suspend overlapped operation, to complete current and pending
326 functions for the current instruction, and then to enter a FAULT CYCLE."
327
328 Group 5 & 6 faults will probably also execute immediately because "if a group 5
329 or 6 fault is detected during execution of the current instruction (e.g., an
330 access violation, out of segment bounds, fault during certain interruptible EIS
331 instructions), the instruction is considered "complete" upon detection of the
332 fault." However, remember "If a fault in a higher priority group is generated
333 by the execution of the current or pending instructions, that higher priority
334 fault will take precedence and the group 5 or 6 fault will be lost. If a group
335 5 or 6 fault is detected during execution of the current instruction (e.g., an
336 access violation, out of segment bounds, fault during certain interruptible EIS
337 instructions), the instruction is considered "complete" upon detection of the
338 fault."
339
340 For further justification of immediate execution since "Faults in groups 3
341 through 6 must wait for the system controller to acknowledge the last access
342 request before entering the FAULT CYCLE."
343
344 Group 7 faults will be processed after next even instruction decode instruction
345 decode, but before instruction execution. In this way we can actually use
346 bit-28 tp inhibit interrupts
347
348 */
349
350 #if defined(LOOPTRC)
351 # include <time.h>
352 void elapsedtime (void);
353 #endif /* if defined(LOOPRTC) */
354
355 // SCU word 1 IACHN, the processor port of a system controller illegal
356 // action: the DPS8 reports it; an L68 does not (SM781-SM784 add the port
357 // to the expected fault data only when RSW 2 says DPS8; SM783 10A)
358 static word3 ia_port (cpu_state_t * cpup)
/* ![[previous]](../icons/left.png)
![[next]](../icons/right.png)
![[first]](../icons/first.png)
![[last]](../icons/last.png)
![[top]](../icons/top.png)
![[bottom]](../icons/bottom.png)
![[index]](../icons/index.png)
*/
359 {
360 return cpu.tweaks.l68_mode ? 0 : cpu.neaPort;
361 }
362
363 #if !defined(NEED_128)
364 const _fault_subtype fst_zero = (_fault_subtype) {.bits=0};
365 const _fault_subtype fst_acv9 = (_fault_subtype) {.fault_acv_subtype=ACV9};
366 const _fault_subtype fst_acv15 = (_fault_subtype) {.fault_acv_subtype=ACV15};
367 const _fault_subtype fst_ill_mod = (_fault_subtype) {.fault_ipr_subtype=FR_ILL_MOD};
368 const _fault_subtype fst_ill_proc = (_fault_subtype) {.fault_ipr_subtype=FR_ILL_PROC};
369 const _fault_subtype fst_ill_dig = (_fault_subtype) {.fault_ipr_subtype=FR_ILL_DIG};
370 const _fault_subtype fst_ill_op = (_fault_subtype) {.fault_ipr_subtype=FR_ILL_OP};
371 const _fault_subtype fst_str_oob = (_fault_subtype) {.fault_str_subtype=flt_str_oob};
372 const _fault_subtype fst_str_nea = (_fault_subtype) {.fault_str_subtype=flt_str_nea};
373 const _fault_subtype fst_str_ptr = (_fault_subtype) {.fault_str_subtype=flt_str_ill_ptr};
374 const _fault_subtype fst_cmd_lprpn = (_fault_subtype) {.fault_cmd_subtype=flt_cmd_lprpn_bits};
375 const _fault_subtype fst_cmd_ctl = (_fault_subtype) {.fault_cmd_subtype=flt_cmd_not_control};
376 const _fault_subtype fst_onc_nem = (_fault_subtype) {.fault_onc_subtype=flt_onc_nem};
377 #endif /* if !defined(NEED_128) */
378 // CANFAULT
379 void doFault (_fault faultNumber, _fault_subtype subFault,
/* ![[previous]](../icons/left.png)
![[next]](../icons/right.png)
![[first]](../icons/first.png)
![[last]](../icons/last.png)
![[top]](../icons/top.png)
![[bottom]](../icons/bottom.png)
![[index]](../icons/index.png)
*/
380 const char * faultMsg)
381 {
382 cpu_state_t * cpup = _cpup;
383
384 #if defined(LOOPTRC)
385 if (faultNumber == FAULT_TRO)
386 {
387 elapsedtime ();
388 sim_printf (" TRO PSR:IC %05o:%06o\r\n", cpu.PPR.PSR, cpu.PPR.IC);
389 }
390 else if (faultNumber == FAULT_ACV)
391 {
392 elapsedtime ();
393 sim_printf (" ACV %012llo PSR:IC %05o:%06o\r\n", subFault.bits, cpu.PPR.PSR, cpu.PPR.IC);
394 }
395 #endif /* if defined(LOOPRTC) */
396 //if (current_running_cpu_idx)
397 //sim_printf ("Fault %d(0%0o), sub %ld(0%lo), dfc %c, '%s'\r\n",
398 //faultNumber, faultNumber, subFault, subFault,
399 //cpu . bTroubleFaultCycle ? 'Y' : 'N', faultMsg);
400 //if (current_running_cpu_idx)
401 //sim_printf ("xde %d xdo %d\r\n", cpu.cu.xde, cpu.cu.xdo);
402 sim_debug (DBG_FAULT, & cpu_dev,
403 "Fault %d(0%0o), sub %"PRIu64"(0%"PRIo64"), dfc %c, '%s'\r\n",
404 faultNumber, faultNumber, subFault.bits, subFault.bits,
405 cpu . bTroubleFaultCycle ? 'Y' : 'N', faultMsg);
406 #if defined(PROFILER)
407 # if !defined(GNU_ATOMICS)
408 # error PROFILER requires GNU_ATOMICS
409 # endif /* if !defined(GNU_ATOMICS) */
410 //__atomic_add_fetch (& cpu.faults[faultNumber], 1u, __ATOMIC_ACQUIRE);
411 (void)atomic_fetch_add_explicit(&cpu.faults[faultNumber], 1u, memory_order_acquire);
412 #endif /* if defined(PROFILER) */
413 #if defined(TESTING)
414 HDBGFault (faultNumber, subFault, faultMsg, "");
415 #endif /* if defined(TESTING) */
416 #if !defined(SPEED)
417 if_sim_debug (DBG_FAULT, & cpu_dev)
418 traceInstruction (DBG_FAULT);
419 #endif /* if !defined(SPEED) */
420
421 PNL (cpu.DACVpDF = faultNumber >= FAULT_DF0 && faultNumber <= FAULT_ACV;)
422
423 #if defined(TESTING)
424 // some debugging support stuff
425 fault_psr = cpu . PPR.PSR;
426 fault_ic = cpu . PPR.IC;
427 strcpy (fault_msg, faultMsg);
428 #endif /* if defined(TESTING) */
429
430 //if (faultNumber < 0 || faultNumber > 31)
431 if (faultNumber & ~037U) // quicker?
432 {
433 sim_printf ("fault(out-of-range): %d %llo '%s'\r\n",
434 faultNumber, (unsigned long long)subFault.bits,
435 faultMsg ? faultMsg : "?");
436 sim_warn ("fault out-of-range\r\n");
437 faultNumber = FAULT_TRB; // XXX Really? this is a simulator bug, not a trouble fault
438 }
439
440 cpu.faultNumber = faultNumber;
441 cpu.subFault = subFault;
442 cpu.faultCnt [faultNumber] ++;
443
444 // A fault abandons any cache read or scpr store in progress
445 cpu.cacheFetch = false;
446 cpu.cacheDirReadout = false;
447
448 // "The occurrence of a fault or interrupt sets the cache-to-register mode bit to OFF." a:AL39/cmr1
449 CPTUR (cptUseCMR);
450 cpu.CMR.csh_reg = 0;
451
452 // Increment FCT
453
454 word3 FCT = cpu.cu.APUCycleBits & MASK3;
455 FCT = (FCT + 1u) & MASK3;
456 cpu.cu.APUCycleBits = (word12) ((cpu.cu.APUCycleBits & 07770) | FCT);
457
458 // Set fault register bits
459
460 CPTUR (cptUseFR);
461 if (faultNumber == FAULT_IPR)
462 {
463
464
465
466
467
468
469
470
471
472
473 cpu . faultRegister [0] |= subFault.bits;
474
475 }
476 else if (faultNumber == FAULT_ONC && subFault.fault_onc_subtype == flt_onc_nem)
477 {
478 cpu . faultRegister [0] |= FR_NEM;
479 }
480 else if (faultNumber == FAULT_STR)
481 {
482 if (subFault.fault_str_subtype == flt_str_oob)
483 cpu . faultRegister [0] |= FR_OOB;
484 //else if (subFault.fault_str_subtype == flt_str_ill_ptr)
485 //cpu . faultRegister [0] |= ?; // XXX
486 // L68: a store fault for a nonexistent address sets fault
487 // register bit 4 (PM776 06A, L68 only: "bit four of the fault
488 // register s/b set indicating non-existent address store
489 // fault"). Not known for the DPS8/M, which the page skips.
490 else if (subFault.fault_str_subtype == flt_str_nea &&
491 cpu.tweaks.l68_mode)
492 cpu . faultRegister [0] |= FR_NEM;
493 }
494 else if (faultNumber == FAULT_CON)
495 {
496 switch (subFault.fault_con_subtype)
497 {
498 case con_a:
499 cpu . faultRegister [0] |= FR_CON_A;
500 break;
501 case con_b:
502 cpu . faultRegister [0] |= FR_CON_B;
503 break;
504 case con_c:
505 cpu . faultRegister [0] |= FR_CON_C;
506 break;
507 case con_d:
508 cpu . faultRegister [0] |= FR_CON_D;
509 break;
510 default:
511 sim_warn ("FAULT_CON can't map port %lo\r\n", (long unsigned) subFault.fault_con_subtype);
512 break;
513 }
514 }
515
516 // Set cu word1 fault bits
517
518 cpu . cu . IRO_ISN = 0;
519 cpu . cu . OEB_IOC = 0;
520 cpu . cu . EOFF_IAIM = 0;
521 cpu . cu . ORB_ISP = 0;
522 cpu . cu . ROFF_IPR = 0;
523 cpu . cu . OWB_NEA = 0;
524 cpu . cu . WOFF_OOB = 0;
525 cpu . cu . NO_GA = 0;
526 cpu . cu . OCB = 0;
527 cpu . cu . OCALL = 0;
528 cpu . cu . BOC = 0;
529 DPS8M_ (cpu . cu . PTWAM_ER = 0;)
530 cpu . cu . CRT = 0;
531 cpu . cu . RALR = 0;
532 cpu . cu . SDWAM_ER = 0;
533 cpu . cu . OOSB = 0;
534 cpu . cu . PARU = 0;
535 cpu . cu . PARL = 0;
536 cpu . cu . ONC1 = 0;
537 cpu . cu . ONC2 = 0;
538 cpu . cu . IA = 0;
539 cpu . cu . IACHN = 0;
540 cpu . cu . CNCHN = (faultNumber == FAULT_CON) ? subFault.fault_con_subtype & MASK3 : 0;
541
542 // Set control unit 'fault occurred during instruction fetch' flag
543 cpu . cu . FIF = cpu . cycle == FETCH_cycle ? 1 : 0;
544 cpu . cu . FI_ADDR = (word5) faultNumber;
545
546 // L68 CU overlap: once an odd instruction's operand cycle has started,
547 // the control unit has fetched the next pair, so a fault in it (directed
548 // fault, ACV, ...) stores that pair's odd word as SCU word 7 (PA870 01A,
549 // 02A); an MME or derail faults at decode, before that (PA885 01A)
550 cpu.l68OddFault = cpu.tweaks.l68_mode && cpu.cycle == EXEC_cycle &&
551 (cpu.PPR.IC & 1) && cpu.l68PairValid &&
552 ! (cpu.cu.xde || cpu.cu.xdo || cpu.cu.rpt ||
553 cpu.cu.rd || cpu.cu.rl) &&
554 faultNumber != FAULT_MME && faultNumber != FAULT_MME2 &&
555 faultNumber != FAULT_MME3 && faultNumber != FAULT_MME4 &&
556 faultNumber != FAULT_DRL;
557
558 // A fault in the append cycle of an instruction fetch, before the
559 // final address (an SDW or PTW fetch), adds PI-AP to the APU status
560 // (PA885 06A: PI-AP+PTW)
561 if (cpu.cycle == FETCH_cycle && (cpu.cu.APUCycleBits & 03700) &&
562 ! (cpu.cu.APUCycleBits & 00070))
563 cpu.cu.APUCycleBits |= 04000;
564
565 // XXX Under what conditions should this be set?
566 // Assume no
567 // Reading Multics source, it seems like Multics is setting this bit; I'm going
568 // to assume that the h/w also sets it to 0, and the s/w has to explicitly set it on.
569 cpu . cu . rfi = 0;
570 if (cpu.lufRFI) // T&D: lockup on a transfer, g7 fault at a fetch
571 {
572 cpu.cu.rfi = 1;
573 cpu.lufRFI = false;
574 }
575 // A fault during an instruction fetch reports "refetch this
576 // instruction" as well (PA885 10A, PA865 03A, PA885 06A); RCU of a FIF
577 // fault refetches in any case
578 cpu.scuRFI = cpu.cu.FIF;
579
580 // A fault in the first repetition, before the instruction completes,
581 // leaves the Xn the repetition set up unchanged (PA885 06B)
582 if (cpu.rptXnSaved)
583 {
584 if (faultNumber != FAULT_OFL && faultNumber != FAULT_DIV)
585 {
586 cpu.rX[cpu.rptXn] = cpu.rptXnOld;
587 // dps8m turned repeat_first off before this repetition began;
588 // turn it back on, so that the safe-stored RF is on and the
589 // restart does the first repetition again (Xn + offset). With
590 // RF off, rcu would treat this as a later repetition and add
591 // the delta to the restored Xn, so the repetition and the
592 // rest of the repeat would use addresses one delta too high.
593 cpu.cu.repeat_first = 1;
594 }
595 cpu.rptXnSaved = false;
596 }
597 // Likewise a later repetition: the delta dps8m added ahead for the
598 // instructions not yet completed (PA885 06D)
599 if ((cpu.cu.rpt || cpu.cu.rd) && cpu.cycle == EXEC_cycle &&
600 faultNumber != FAULT_OFL && faultNumber != FAULT_DIV)
601 for (int k = 0; k < 2; k ++)
602 if (cpu.rptUndo[k])
603 cpu.rX[cpu.rptUndo[k] - 1] =
604 (cpu.rX[cpu.rptUndo[k] - 1] - cpu.cu.delta) & AMASK;
605 cpu.rptUndo[0] = cpu.rptUndo[1] = 0;
606
607 // A fault fetching the instruction(s) an rpt/rpd/rpl repeats is
608 // reported as a fault of the repeat instruction: the IC back at it
609 // (the word before), the repeat not started, RFI on (PA885 06A; the
610 // ISOLTS SCU rewrite table has the same expected data)
611 if (cpu.cycle == FETCH_cycle && cpu.cu.repeat_first &&
612 (cpu.cu.rpt || cpu.cu.rd || cpu.cu.rl))
613 {
614 cpu.PPR.IC = (cpu.PPR.IC - 1) & MASK18;
615 cpu.cu.repeat_first = 0;
616 cpu.cu.rpt = 0;
617 cpu.cu.rd = 0;
618 cpu.cu.rl = 0;
619 cpu.scuRFI = true;
620 }
621
622 // Try to decide if this a MIF fault (fault during EIS instruction)
623 // EIS instructions are not used in fault/interrupt pairs, so the
624 // only time an EIS instruction could be executing is during EXEC_cycle.
625 // I am also assuming that only multi-word EIS instructions are of interest.
626 // Testing faultNumber fixes ISOLTS 890-04a
627 // fixes 890-04a and 791 / 792
628 SC_I_MIF (cpu.cycle == EXEC_cycle &&
629 (cpu.currentInstruction.info->ndes > 0 ||
630 (faultNumber == FAULT_IPR && (subFault.fault_ipr_subtype & FR_ILL_OP_CONST) &&
631 cpu.currentInstruction.opcodeX &&
632 (cpu.currentInstruction.opcode & 0410) == 0)));
633 sim_debug (DBG_TRACEEXT, & cpu_dev, "MIF %o\r\n", TST_I_MIF);
634
635 // An overflow fault at the close-out of an EIS instruction reports
636 // MIF and RFI. The T&D PAS executive (pm061 L20202) takes
637 // MIF+RFI+^FIF as "instruction completed" and resumes after it;
638 // with RFI off it resumes at the instruction, which overflows
639 // again (PS810 01L). Multics's fim sets rfi+if itself, and RCU of
640 // an overflow fault resumes after the instruction regardless.
641 if (faultNumber == FAULT_OFL && TST_I_MIF)
642 cpu.scuRFI = true;
643
644
645
646
647
648
649
650
651
652
653
654
655 if (faultNumber == FAULT_ACV)
656 {
657 // This is annoyingly inefficient since the subFault value
658 // is bitwise the same as the upper half of CU word1;
659 // if the upper half were not broken out, then this would be
660 // cpu . cu . word1_upper_half = subFault.
661
662 if (subFault.fault_acv_subtype & ACV0)
663 cpu . cu . IRO_ISN = 1;
664 if (subFault.fault_acv_subtype & ACV1)
665 cpu . cu . OEB_IOC = 1;
666 if (subFault.fault_acv_subtype & ACV2)
667 cpu . cu . EOFF_IAIM = 1;
668 if (subFault.fault_acv_subtype & ACV3)
669 cpu . cu . ORB_ISP = 1;
670 if (subFault.fault_acv_subtype & ACV4)
671 cpu . cu . ROFF_IPR = 1;
672 if (subFault.fault_acv_subtype & ACV5)
673 cpu . cu . OWB_NEA = 1;
674 if (subFault.fault_acv_subtype & ACV6)
675 cpu . cu . WOFF_OOB = 1;
676 if (subFault.fault_acv_subtype & ACV7)
677 cpu . cu . NO_GA = 1;
678 if (subFault.fault_acv_subtype & ACV8)
679 cpu . cu . OCB = 1;
680 if (subFault.fault_acv_subtype & ACV9)
681 cpu . cu . OCALL = 1;
682 if (subFault.fault_acv_subtype & ACV10)
683 cpu . cu . BOC = 1;
684 if (subFault.fault_acv_subtype & ACV11)
685 cpu . cu . PTWAM_ER = 1;
686 if (subFault.fault_acv_subtype & ACV12)
687 cpu . cu . CRT = 1;
688 if (subFault.fault_acv_subtype & ACV13)
689 cpu . cu . RALR = 1;
690 if (subFault.fault_acv_subtype & ACV14)
691 cpu . cu . SDWAM_ER = 1;
692 if (subFault.fault_acv_subtype & ACV15)
693 cpu . cu . OOSB = 1;
694 }
695 else if (faultNumber == FAULT_STR)
696 {
697 if (subFault.fault_str_subtype == flt_str_oob)
698 cpu . cu . WOFF_OOB = 1;
699 //else if (subFault.fault_str_subtype == flt_str_ill_ptr)
700 //cpu . cu . ??? = 1; // XXX
701 else if (subFault.fault_str_subtype == flt_str_nea)
702 {
703 // T&D (SM781 13A): an address in a port's window but beyond
704 // the SCU's store: the SCU reports illegal action 02 on the
705 // port (IACHN). In no port's window, the CPU reports it with
706 // OWB/NEA (PA885 10B).
707 if (cpu.tweaks.tandd_mode && ! cpu.neaNoPort)
708 {
709 cpu.cu.IA = 02;
710 cpu.cu.IACHN = ia_port (cpup);
711 }
712 else
713 cpu . cu . OWB_NEA = 1;
714 }
715 else if (subFault.fault_str_subtype == flt_str_nrdy)
716 {
717 cpu.cu.IA = 013; // store unit not ready (T&D)
718 cpu.cu.IACHN = ia_port (cpup);
719 }
720 }
721 else if (faultNumber == FAULT_PAR && subFault.bits)
722 {
723 // T&D: system controller illegal action code (sdpap/separ, bad
724 // parity read); 0100/0200: the processor saw it in the upper/lower
725 // word. No illegal action (processor only): no port.
726 cpu.cu.IA = (word4) (subFault.bits & 017);
727 cpu.cu.IACHN = cpu.cu.IA ? ia_port (cpup) : 0;
728 if (subFault.bits & 0100)
729 cpu.cu.PARU = 1;
730 if (subFault.bits & 0200)
731 cpu.cu.PARL = 1;
732 // Cache parity (PM893 06; 04000: found by the cache): the processor
733 // parity bits PARU/PARL are fault register bits 7/8; 01000/02000
734 // are the cache's storage (bit 33) and block load (bit 35) errors.
735 if (subFault.bits & 07000)
736 {
737 if (subFault.bits & 0100)
738 cpu.faultRegister [0] |= ((word36) 1) << (35 - 7);
739 if (subFault.bits & 0200)
740 cpu.faultRegister [0] |= ((word36) 1) << (35 - 8);
741 if (subFault.bits & 01000)
742 cpu.faultRegister [0] |= ((word36) 1) << (35 - 33);
743 if (subFault.bits & 02000)
744 cpu.faultRegister [0] |= ((word36) 1) << (35 - 35);
745 }
746 }
747 else if (faultNumber == FAULT_IPR)
748 {
749 if (subFault.fault_ipr_subtype & FR_ILL_OP_CONST)
750 cpu . cu . OEB_IOC = 1;
751 if (subFault.fault_ipr_subtype & FR_ILL_MOD_CONST)
752 cpu . cu . EOFF_IAIM = 1;
753 if (subFault.fault_ipr_subtype & FR_ILL_SLV_CONST)
754 cpu . cu . ORB_ISP = 1;
755 if (subFault.fault_ipr_subtype & FR_ILL_DIG)
756 cpu . cu . ROFF_IPR = 1;
757 }
758 else if (faultNumber == FAULT_CMD)
759 {
760 if (subFault.fault_cmd_subtype == flt_cmd_lprpn_bits)
761 cpu . cu . IA = 0;
762 else if (subFault.fault_cmd_subtype == flt_cmd_not_control)
763 cpu . cu . IA = 010;
764 }
765
766 L68_ (
767 // History registers
768 // IHRRS; AL39 pg 47
769 // History register lock control. If this bit is set ON, set STROBE C|
770 // (bit 30, key k) OFF, locking the history registers for all faults
771 // including the floating faults.
772 CPTUR (cptUseMR);
773 if (cpu.MR.emr && cpu.MR.ihrrs)
774 {
775 cpu.MR.ihr = 0;
776 }
777 )
778 DPS8M_ (
779 // History registers
780 // IHRRS; AL39 pg 49
781 // Additional resetting of bit 30. If bit 31 = 1, the following faults also
782 // reset bit 30:
783 // Lock Up
784 // Parity
785 // Command
786 // Store
787 // Illegal Procedure
788 // Shutdown
789 if (cpu.MR.emr && cpu.MR.ihrrs)
790 {
791 if (faultNumber == FAULT_LUF ||
792 faultNumber == FAULT_PAR ||
793 faultNumber == FAULT_CMD ||
794 faultNumber == FAULT_STR ||
795 faultNumber == FAULT_IPR ||
796 faultNumber == FAULT_SDF)
797 {
798 cpu.MR.ihr = 0;
799 }
800 }
801 // Enable History Registers. This bit will be reset by ... an Op Not
802 // Complete fault. It may be reset by other faults (see bit 31).
803 if (faultNumber == FAULT_ONC)
804 {
805 cpu.MR.ihr = 0;
806 }
807 )
808
809 // If already in a FAULT CYCLE then signal trouble fault
810
811 if (cpu.cycle == FAULT_EXEC_cycle)
812 {
813 sim_debug (DBG_CYCLE, & cpu_dev, "Changing fault number to Trouble fault\r\n");
814
815 cpu.faultNumber = FAULT_TRB;
816 cpu.cu.FI_ADDR = FAULT_TRB;
817 cpu.subFault.bits = 0; // XXX ???
818 if (cpu.bTroubleFaultCycle)
819 {
820 #if !defined(THREADZ) && !defined(LOCKLESS)
821 # if !defined(PANEL68)
822 if ((! sample_interrupts (cpup)) &&
823 (sim_qcount () == 0)) // XXX If clk_svc is implemented it will
824 // break this logic
825 {
826 sim_printf \
827 ("Fault cascade @0%06o with no interrupts pending and no events in queue\r\n",
828 cpu.PPR.IC);
829 sim_printf("\r\nCycles = %"PRId64"\r\n", cpu.cycleCnt);
830 sim_printf("\r\nInstructions = %"PRId64"\r\n", cpu.instrCnt);
831 //stop_reason = STOP_FLT_CASCADE;
832 longjmp (cpu.jmpMain, JMP_STOP);
833 }
834 # endif /* if !defined(PANEL68) */
835 #endif
836 }
837 else
838 {
839 //-- f = &_faults[FAULT_TRB];
840 cpu . bTroubleFaultCycle = true;
841 }
842 }
843 else
844 {
845 cpu . bTroubleFaultCycle = false;
846 }
847
848 // If doInstruction faults, the instruction cycle counter doesn't get
849 // bumped.
850 if (cpu . cycle == EXEC_cycle)
851 cpu.instrCnt ++;
852
853 cpu . cycle = FAULT_cycle;
854 sim_debug (DBG_CYCLE, & cpu_dev, "Setting cycle to FAULT_cycle\r\n");
855 longjmp (cpu.jmpMain, JMP_REENTRY);
856 #if !defined(__SUNPRO_C) && !defined(__SUNPRO_CC)
857 /*NOTREACHED*/ /* unreachable */
858 abort(); /* not reached */
859 #endif
860 }
861
862 void do_FFV_fault (cpu_state_t * cpup, uint fault_number, const char * fault_msg)
/* ![[previous]](../icons/left.png)
![[next]](../icons/right.png)
![[first]](../icons/first.png)
![[last]](../icons/last.png)
![[top]](../icons/top.png)
![[bottom]](../icons/bottom.png)
![[index]](../icons/index.png)
*/
863 {
864 sim_debug (DBG_FAULT, & cpu_dev,
865 "Floating fault %d '%s'\r\n",
866 fault_number, fault_msg);
867 #if !defined(SPEED)
868 if_sim_debug (DBG_FAULT, & cpu_dev)
869 traceInstruction (DBG_FAULT);
870 #endif /* if !defined(SPEED) */
871
872 if (fault_number < 1 || fault_number > 3)
873 {
874 sim_printf ("floating fault(out-of-range): %d '%s'\r\n",
875 fault_number, fault_msg ? fault_msg : "?");
876 sim_warn ("fault out-of-range\r\n");
877 }
878
879 cpu.FFV_fault_number = fault_number;
880 cpu.faultNumber = fault_number;
881
882 // Only the highest priority floating fault is taken (OPCODE trap, then
883 // CU history overflow, then address match): drop the pending ones
884 // below it (PM701 02B: an OPCODE trap with an address match pending)
885 if (fault_number >= 1 && fault_number <= 3)
886 {
887 uint lower = 07u & ~((1u << fault_number) - 1u);
888 cpu.FFV_faults &= ~lower;
889 cpu.FFV_faults_preset &= ~lower;
890 }
891
892 // "The occurrence of a fault or interrupt sets the
893 // cache-to-register mode bit to OFF." a:AL39/cmr1
894 CPTUR (cptUseCMR);
895 cpu.CMR.csh_reg = 0;
896
897 // Increment FCT
898
899 word3 FCT = cpu.cu.APUCycleBits & MASK3;
900 FCT = (FCT + 1) & MASK3;
901 cpu.cu.APUCycleBits = (word12) ((cpu.cu.APUCycleBits & 07770) | FCT);
902
903 // Set fault register bits
904 CPTUR (cptUseFR);
905 cpu.faultRegister [0] = 0;
906
907 // Set cu word1 fault bits
908
909 cpu.cu.IRO_ISN = 0;
910 cpu.cu.OEB_IOC = 0;
911 cpu.cu.EOFF_IAIM = 0;
912 cpu.cu.ORB_ISP = 0;
913 cpu.cu.ROFF_IPR = 0;
914 cpu.cu.OWB_NEA = 0;
915 cpu.cu.WOFF_OOB = 0;
916 cpu.cu.NO_GA = 0;
917 cpu.cu.OCB = 0;
918 cpu.cu.OCALL = 0;
919 cpu.cu.BOC = 0;
920 // FFVs are L68 only, so we don't need this:
921 //# if defined(DPS8M)
922 //cpu.cu.PTWAM_ER = 0;
923 //# endif /* if defined(DPS8M) */
924 cpu.cu.CRT = 0;
925 cpu.cu.RALR = 0;
926 cpu.cu.SDWAM_ER = 0;
927 cpu.cu.OOSB = 0;
928 cpu.cu.PARU = 0;
929 cpu.cu.PARL = 0;
930 cpu.cu.ONC1 = 0;
931 cpu.cu.ONC2 = 0;
932 cpu.cu.IA = 0;
933 cpu.cu.IACHN = 0;
934 cpu.cu.CNCHN = 0;
935
936 // Set control unit 'fault occurred during instruction fetch' flag
937 cpu.cu.FIF = 0;
938 cpu.cu.FI_ADDR = (word5) fault_number & MASK5;
939
940 // XXX Under what conditions should this be set?
941 // Assume no
942 // Reading Multics source, it seems like Multics is setting this bit; I'm going
943 // to assume that the h/w also sets it to 0, and the s/w has to explicitly set it on.
944 cpu.cu.rfi = 0;
945 // T&D: a floating fault at a fetch consumes the refetch request made
946 // for it; left set, the next ordinary fault would report RFI (PS720
947 // 02A: overflow fault after a CU-HR overflow trap)
948 cpu.lufRFI = false;
949
950 // Try to decide if this a MIF fault (fault during EIS instruction)
951 // EIS instructions are not used in fault/interrupt pairs, so the
952 // only time an EIS instruction could be executing is during EXEC_cycle.
953 // I am also assuming that only multi-word EIS instructions are of interest.
954
955 SC_I_MIF (cpu.cycle == EXEC_cycle &&
956 cpu.currentInstruction.info->ndes > 0);
957 sim_debug (DBG_TRACEEXT, & cpu_dev, "MIF %o\r\n", TST_I_MIF);
958
959
960 // History registers
961 // IHRRS; AL39 pg 47
962 // History register lock control. If this bit is set ON, set STROBE C|
963 // (bit 30, key k) OFF, locking the history registers for all faults
964 // including the floating faults.
965 CPTUR (cptUseMR);
966 if (cpu.MR.emr && cpu.MR.ihrrs)
967 {
968 cpu.MR.ihr = 0;
969 }
970
971 if (cpu.cycle == FAULT_EXEC_cycle)
972 {
973 cpu.faultNumber = FAULT_TRB;
974 cpu.cu.FI_ADDR = FAULT_TRB;
975 cpu.subFault.bits = 0; // XXX ???
976 if (cpu.bTroubleFaultCycle)
977 {
978 #if !defined(THREADZ) && !defined(LOCKLESS)
979 # if !defined(PANEL68)
980 if ((! sample_interrupts (cpup)) &&
981 (sim_qcount () == 0)) // XXX If clk_svc is implemented it will
982 // break this logic
983 {
984 sim_printf \
985 ("Fault cascade @0%06o with no interrupts pending and no events in queue\r\n",
986 cpu.PPR.IC);
987 sim_printf("\r\nCycles = %"PRId64"\r\n", cpu.cycleCnt);
988 sim_printf("\r\nInstructions = %"PRId64"\r\n", cpu.instrCnt);
989 longjmp (cpu.jmpMain, JMP_STOP);
990 }
991 # endif /* if !defined(PANEL68) */
992 #endif /* if !defined(THREADZ) && !defined(LOCKLESS) */
993 }
994 else
995 {
996 cpu.bTroubleFaultCycle = true;
997 }
998 cpu.cycle = FAULT_cycle;
999 sim_debug (DBG_CYCLE, & cpu_dev, "Setting cycle to FAULT_cycle\r\n");
1000 longjmp (cpu.jmpMain, JMP_REENTRY);
1001 }
1002 cpu.bTroubleFaultCycle = false;
1003
1004 // If doInstruction faults, the instruction cycle counter doesn't get
1005 // bumped.
1006 if (cpu . cycle == EXEC_cycle)
1007 cpu.instrCnt ++;
1008
1009 cpu.is_FFV = true;
1010 cpu.cycle = FAULT_cycle;
1011 longjmp (cpu.jmpMain, JMP_REENTRY);
1012 }
1013
1014 void dlyDoFault (_fault faultNumber, _fault_subtype subFault,
/* ![[previous]](../icons/left.png)
![[next]](../icons/right.png)
![[first]](../icons/first.png)
![[last]](../icons/last.png)
![[top]](../icons/top.png)
![[bottom]](../icons/bottom.png)
![[index]](../icons/index.png)
*/
1015 const char * faultMsg)
1016 {
1017 cpu_state_t * cpup = _cpup;
1018 cpu.dlyFlt = true;
1019 cpu.dlyFltNum = faultNumber;
1020 cpu.dlySubFltNum = subFault;
1021 cpu.dlyCtx = faultMsg;
1022 }
1023
1024 //
1025 // return true if group 7 faults are pending ...
1026 //
1027
1028 // Note: The DIS code assumes that the only G7 fault is TRO. Adding any
1029 // other G7 faults will potentially require changing the DIS code.
1030
1031 bool bG7Pending (cpu_state_t * cpup)
/* ![[previous]](../icons/left.png)
![[next]](../icons/right.png)
![[first]](../icons/first.png)
![[last]](../icons/last.png)
![[top]](../icons/top.png)
![[bottom]](../icons/bottom.png)
![[index]](../icons/index.png)
*/
1032 {
1033 if (cpu.tweaks.l68_mode)
1034 return cpu.g7Faults != 0 || cpu.FFV_faults != 0; // L68
1035
1036 return cpu.g7Faults != 0; // DPS8M
1037 }
1038
1039 bool bG7PendingNoTRO (cpu_state_t * cpup)
/* ![[previous]](../icons/left.png)
![[next]](../icons/right.png)
![[first]](../icons/first.png)
![[last]](../icons/last.png)
![[top]](../icons/top.png)
![[bottom]](../icons/bottom.png)
![[index]](../icons/index.png)
*/
1040 {
1041 if (cpu.tweaks.l68_mode)
1042 return (cpu.g7Faults & (~ (1u << FAULT_TRO))) != 0 || cpu.FFV_faults != 0; // L68
1043
1044 return (cpu.g7Faults & (~ (1u << FAULT_TRO))) != 0; // DPS8M
1045 }
1046
1047 void setG7fault (uint cpuNo, _fault faultNo)
/* ![[previous]](../icons/left.png)
![[next]](../icons/right.png)
![[first]](../icons/first.png)
![[last]](../icons/last.png)
![[top]](../icons/top.png)
![[bottom]](../icons/bottom.png)
![[index]](../icons/index.png)
*/
1048 {
1049 cpu_state_t * cpup = &cpus[cpuNo];
1050 sim_debug (DBG_FAULT, & cpu_dev, "setG7fault CPU %d fault %d (%o)\r\n",
1051 cpuNo, faultNo, faultNo);
1052 #if defined(THREADZ) || defined(LOCKLESS)
1053 //__atomic_or_fetch (& cpup->g7FaultsPreset, (1u << faultNo), __ATOMIC_ACQUIRE);
1054 (void)atomic_fetch_or_explicit(&cpup->g7FaultsPreset, (1u << faultNo), memory_order_acquire);
1055 #else
1056 cpup->g7FaultsPreset |= (1u << faultNo);
1057 #endif
1058 #if defined(THREADZ) || defined(LOCKLESS)
1059 // An execute fault (the EXECUTE button: SIGUSR1, the XF command)
1060 // comes from outside the CPU, whose thread may be asleep in a DIS;
1061 // current_running_cpu_idx is 0 in those threads, so compare isn't
1062 // enough (T&D: EXECUTE continues the operator halts in GCOS mode)
1063 if (cpuNo != current_running_cpu_idx || faultNo == FAULT_EXF)
1064 wakeCPU(cpuNo);
1065 #endif
1066 }
1067
1068 // The maintenance panel's EXECUTE button with the selector at EXECUTE
1069 // DATA SWITCHES (the XS command): the processor executes the instruction
1070 // in the data switches (XED Y: the pair at Y, as for the Multics "XED
1071 // 10000" bootload; T&D: continuing the bootstrap's operator halts in GCOS
1072 // mode). At EXECUTE FAULT it raises an execute fault (setG7fault
1073 // (FAULT_EXF): the XF command, SIGUSR1).
1074 void press_execute_switches (uint cpuNo)
/* ![[previous]](../icons/left.png)
![[next]](../icons/right.png)
![[first]](../icons/first.png)
![[last]](../icons/last.png)
![[top]](../icons/top.png)
![[bottom]](../icons/bottom.png)
![[index]](../icons/index.png)
*/
1075 {
1076 cpu_state_t * cpup = &cpus[cpuNo];
1077 cpup->execSwitchesReq = true;
1078 setFetchAttention (cpup);
1079 #if defined(THREADZ) || defined(LOCKLESS)
1080 wakeCPU (cpuNo);
1081 #endif
1082 }
1083
1084 void set_FFV_fault (cpu_state_t * cpup, uint f_fault_no)
/* ![[previous]](../icons/left.png)
![[next]](../icons/right.png)
![[first]](../icons/first.png)
![[last]](../icons/last.png)
![[top]](../icons/top.png)
![[bottom]](../icons/bottom.png)
![[index]](../icons/index.png)
*/
1085 {
1086 sim_debug (DBG_FAULT, & cpu_dev, "set_FFV_fault CPU f_fault_no %u\r\n",
1087 f_fault_no);
1088 // Map fault number (2/4/6) to bit mask 01/02/04
1089 cpu.FFV_faults_preset |= 1u << ((f_fault_no / 2) - 1);
1090 }
1091
1092 void clearTROFault (cpu_state_t * cpup)
/* ![[previous]](../icons/left.png)
![[next]](../icons/right.png)
![[first]](../icons/first.png)
![[last]](../icons/last.png)
![[top]](../icons/top.png)
![[bottom]](../icons/bottom.png)
![[index]](../icons/index.png)
*/
1093 {
1094 cpu . g7Faults &= ~(1u << FAULT_TRO);
1095 }
1096
1097 void doG7Fault (cpu_state_t * cpup, bool allowTR)
/* ![[previous]](../icons/left.png)
![[next]](../icons/right.png)
![[first]](../icons/first.png)
![[last]](../icons/last.png)
![[top]](../icons/top.png)
![[bottom]](../icons/bottom.png)
![[index]](../icons/index.png)
*/
1098 {
1099 // sim_printf ("doG7fault %08o [%"PRId64"]\r\n", cpu . g7Faults, cpu.cycleCnt);
1100 // if (cpu . g7Faults)
1101 // {
1102 // sim_debug (DBG_FAULT, & cpu_dev, "doG7Fault %08o\r\n", cpu . g7Faults);
1103 // }
1104 // According AL39, Table 7-1. List of Faults, priority of connect is 25
1105 // and priority of Timer runout is 26, lower number means higher priority
1106 #if defined(THREADZ) || defined(LOCKLESS)
1107 lock_scu ();
1108 #endif
1109 if (cpu.g7Faults & (1u << FAULT_CON))
1110 {
1111 cpu.g7Faults &= ~(1u << FAULT_CON);
1112
1113 #if defined(THREADZ) || defined(LOCKLESS)
1114 unlock_scu ();
1115 #endif
1116 doFault (FAULT_CON, fst_zero, "Connect");
1117 }
1118
1119 if (allowTR && (cpu.g7Faults & (1u << FAULT_TRO)))
1120 {
1121 cpu . g7Faults &= ~(1u << FAULT_TRO);
1122
1123 //sim_printf("timer runout %12o\r\n",cpu.PPR.IC);
1124 #if defined(THREADZ) || defined(LOCKLESS)
1125 unlock_scu ();
1126 #endif
1127 doFault (FAULT_TRO, fst_zero, "Timer runout");
1128 }
1129
1130 // Strictly speaking EXF isn't a G7 fault, but if we treat is as one,
1131 // we are allowing the current instruction to complete, simplifying
1132 // implementation
1133 if (cpu . g7Faults & (1u << FAULT_EXF))
1134 {
1135 cpu . g7Faults &= ~(1u << FAULT_EXF);
1136
1137 #if defined(THREADZ) || defined(LOCKLESS)
1138 unlock_scu ();
1139 #endif
1140 doFault (FAULT_EXF, fst_zero, "Execute fault");
1141 }
1142
1143 if (cpu.tweaks.l68_mode) { // L68
1144 if (cpu.FFV_faults & 1u) // FFV + 2 OC TRAP
1145 {
1146 cpu.FFV_faults &= ~1u;
1147 #if defined(THREADZ) || defined(LOCKLESS)
1148 unlock_scu ();
1149 #endif
1150 do_FFV_fault (cpup, 1, "OC TRAP");
1151 }
1152 if (cpu.FFV_faults & 2u) // FFV + 4 CU HISTORY OVERFLOW TRAP
1153 {
1154 cpu.FFV_faults &= ~2u;
1155 #if defined(THREADZ) || defined(LOCKLESS)
1156 unlock_scu ();
1157 #endif
1158 do_FFV_fault (cpup, 2, "CU HIST OVF TRAP");
1159 }
1160 if (cpu.FFV_faults & 4u) // FFV + 6 ADR TRAP
1161 {
1162 cpu.FFV_faults &= ~4u;
1163 #if defined(THREADZ) || defined(LOCKLESS)
1164 unlock_scu ();
1165 #endif
1166 do_FFV_fault (cpup, 3, "ADR TRAP");
1167 }
1168 }
1169 #if defined(THREADZ) || defined(LOCKLESS)
1170 unlock_scu ();
1171 #endif
1172 doFault (FAULT_TRB, (_fault_subtype) {.bits=cpu.g7Faults}, "Dazed and confused in doG7Fault");
1173 }
1174
1175 // advanceG7Faults (dps8_cpu.h) found preset faults
1176 void advanceG7FaultsPreset (cpu_state_t * cpup)
/* ![[previous]](../icons/left.png)
![[next]](../icons/n_right.png)
![[first]](../icons/first.png)
![[last]](../icons/n_last.png)
![[top]](../icons/top.png)
![[bottom]](../icons/bottom.png)
![[index]](../icons/index.png)
*/
1177 {
1178
1179 #if defined(THREADZ) || defined(LOCKLESS)
1180 lock_scu ();
1181 uint zero = 0;
1182 //__atomic_exchange (& cpu.g7FaultsPreset, & zero, & cpu.g7Faults, __ATOMIC_ACQUIRE);
1183 cpu.g7Faults = atomic_exchange_explicit(&cpu.g7FaultsPreset, zero, memory_order_acquire);
1184 #else
1185 cpu.g7Faults |= cpu.g7FaultsPreset;
1186 cpu.g7FaultsPreset = 0;
1187 #endif
1188 L68_ (
1189 cpu.FFV_faults |= cpu.FFV_faults_preset;
1190 cpu.FFV_faults_preset = 0;
1191 )
1192 #if defined(THREADZ) || defined(LOCKLESS)
1193 unlock_scu ();
1194 #endif
1195 }