XL1200-EMU Symbolics XL1200 Emulator
Architecture & Guides docs/traps-and-exceptions.md

Ivory Processor Traps, Interrupts & Exception Handling

This document specifies the hardware trap mechanism, trap mode escalation, vector dispatch table, Ivory Rev 4 / Rev 4A error microstate codes, and pre/post-trap stack frame semantics implemented by the from-scratch C11 emulator (emu/src/cpu.c, emu/src/isa_stack.c, emu/src/isa_arith.c, emu/include/ivory_hw.h).

For complete ISA instruction semantics see Volume 2: ISA & Execution Semantics; for the emulator's hot-path and slow-path trap dispatch architecture see Emulator Core & Acceleration.

Primary Reference Sources (local-only when present):

  • genera-original/sys.sct/i-sys/sysdf1.lisp — Trap vector table offsets (#o0000..#o5127).
  • genera-original/sys.sct/i-sys/sysdef.lisp — Control Register (CR) trap-mode and cleanup fields.
  • genera-original/sys.sct/debugger/{itrap-dispatch.lisp,itrap-defs.lisp,error-table-compiler.lisp} — Rev 4 / Rev 4A 2,048-entry *TRAP-DISPATCH-TABLE* microstate definitions.
  • genera-original/sys.sct/sys/iarithdefs.lisp — -NO-POP binary arithmetic predicate trap handler contracts.
  • I_Machine/I-Machine_Architecture_Specification.pdf — Chapter 8 (Traps & Exceptions).

1. Trap Modes & Control Register Priority Hierarchy

The 2-bit trap_mode field in %REGISTER-CONTROL-REGISTER (#o14, bits <31:30>) defines a four-level privilege and fault-handling hierarchy (IvoryTrapMode in ivory_hw.h):

trap_modeEnum ConstantEnvironmentTrap Vector Base
0IVORY_TRAP_MODE_EMULATORNormal Genera Lisp execution0xF8040000 (IVORY_TRAP_VECTOR_BASE_VMA)
1IVORY_TRAP_MODE_EXTRA_STACKStack overflow recovery / extra stack segment0xF8040000
2IVORY_TRAP_MODE_IOLow-level I/O / interrupt handlers0xF8040000
3IVORY_TRAP_MODE_FEPFront-End Processor / Cold Boot / Debugger%REGISTER-FEP-MODE-TRAP-VECTOR-ADDRESS (#o1024)

Trap Mode Escalation & Double-Fault Rules

When a trap vector entry word entry is fetched from vector_base + trap_offset:

  1. Vector Base Selection:
    • In IVORY_TRAP_MODE_FEP (trap_mode == 3), the base address is taken from scratchpad register #o1024 (IVORY_REG_FEP_MODE_TRAP_VECTOR_ADDRESS).
    • In modes 0, 1, and 2, the base address is fixed at 0xF8040000 (#o37001000000, PMA 0x00040000).
  2. Mode Escalation:
    • The 2-bit CDR code (entry.q.cdr_code) of the fetched trap vector entry specifies the minimum trap mode required by the handler.
    • Hardware sets the new trap mode to max(current_trap_mode, entry.q.cdr_code).
    • If the trap vector entry itself has an invalid tag (not DTP_EVEN_PC or DTP_ODD_PC) or reading the vector faults while already in FEP mode, the CPU signals a double fault (IVORY_ERR_DOUBLE_FAULT) and halts rather than recursing infinitely.
  3. Cold Boot & *BOOT-SPY-PC* Halt Vector (0xFFFE0000):
    • At cold reset (ivory_cpu_reset), CR.trap_mode = 3 (IVORY_TRAP_MODE_FEP).
    • The 64-word wired Boot Communication Area at VMA 0xFFFE0000 (PMA 0x07FE0000) stores *BOOT-SPY-PC* at word offset +0x04 (0xFFFE0004), pointing to a 3-word Stage-0 halt vector at 0xFFFE0010..0xFFFE0012 (IVORY_BOOT_SPY_HALT_VMA):
      • +0 (0xFFFE0010): Clean Shutdown / Remote Debugger entry (%halt).
      • +2 (0xFFFE0012): Fatal unhandled trap halt (%halt).

2. Hardware Trap Vector Table (IvoryTrapVector)

All offsets are in octal relative to vector_base (0xF8040000 in modes 0..2, or #o1024 in mode 3):

Octal OffsetEnum ConstantTrap ClassDescription
#o0000..#o3777IVORY_TRAP_ARITH_EXCEPTION_BASEPost-TrapArithmetic dispatch table: ((opcode & #o37) << 6) | ((dtp1 & 7) << 3) | (dtp2 & 7)
#o4000..#o4377IVORY_TRAP_INSTR_EXCEPTION_BASE + opPost-TrapUnimplemented / software-emulated opcode (#o000..#o377)
#o4400..#o4477IVORY_TRAP_INTERPRETER_FN_BASE + dtpPost-TrapNon-compiled call target dispatch indexed by 6-bit DTP
#o5000IVORY_TRAP_GENERIC_DISPATCH_TBLPost-TrapGeneric function dispatch table base
#o5100IVORY_TRAP_ERRORPre-TrapGeneral hardware error trap (carries Rev 4 microstate + optional fault VMA)
#o5101IVORY_TRAP_RESETPre-TrapHardware reset vector
#o5102IVORY_TRAP_PULL_APPLY_ARGSPre-TrapPull remaining &rest/apply arguments across stack cache
#o5103IVORY_TRAP_STACK_OVERFLOWPre-TrapControl stack overflow (SP crossed CONTROL-STACK-LIMIT)
#o5104IVORY_TRAP_TRACEPre-TrapInstruction / call trace trap (CR.trace_pending)
#o5105IVORY_TRAP_PREEMPT_REQUESTPre-TrapPreempt request / scheduler quantum check
#o5106IVORY_TRAP_TRANSPORTPre-TrapEphemeral/Dynamic GC read barrier (oldspace pointer loaded)
#o5107IVORY_TRAP_FEP_MODEPre-TrapExplicit software entry into FEP mode (trap_mode -> 3)
#o5110IVORY_TRAP_LOW_PRIO_SEQ_BREAKPre-TrapLow-priority Merlin-II sequence break (serial/SCSI/Ethernet/VME LP)
#o5111IVORY_TRAP_HIGH_PRIO_SEQ_BREAKPre-TrapHigh-priority Merlin-II sequence break (82C54 Timer0/Timer1&2, VME HP)
#o5112IVORY_TRAP_MONITORPre-TrapMemory write/read monitor trap (DTP_MONITOR_FORWARD)
#o5114IVORY_TRAP_GENERIC_DISPATCHPost-TrapGeneric function cache miss / dispatch trap
#o5116IVORY_TRAP_MESSAGE_DISPATCHPost-TrapFlavors message dispatch cache miss
#o5120IVORY_TRAP_PAGE_NOT_RESIDENTPre-TrapPHT lookup missed (VPN not mapped in PHT)
#o5121IVORY_TRAP_PAGE_FAULT_REQUESTPre-TrapPHT0 fault_request bit (<7>) set on resident page
#o5122IVORY_TRAP_PAGE_WRITE_FAULTPre-TrapWrite attempted to page with PHT1 write_protect (<6>) set
#o5123IVORY_TRAP_UNCORRECTABLE_MEMPre-TrapUncorrectable ECC memory error
#o5124IVORY_TRAP_MEMORY_BUS_ERRORPre-TrapPhysical bus fault / unpopulated I/O board (0x50000000, etc.)
#o5125IVORY_TRAP_DB_CACHE_MISSPre-TrapDynamic binding cache miss
#o5126IVORY_TRAP_DB_UNWIND_FRAMEPre-TrapUnwind dynamic bindings on frame exit (CR.cleanup_bindings)
#o5127IVORY_TRAP_DB_UNWIND_CATCHPre-TrapUnwind catch block on frame exit (CR.cleanup_catch)

3. Pre-Trap vs. Post-Trap Stack Frame Semantics

Ivory distinguishes two fundamental trap classes (ivory_cpu_take_trap / ivory_cpu_take_trap_args in emu/src/cpu.c):

Pre-Traps (Restartable Faults)

Used for memory faults (#o5120..#o5124), GC transport (#o5106), hardware interrupts (#o5110..#o5111), stack overflow (#o5103), and hardware errors (#o5100).

  • Saved PC: Points to the faulting instruction itself so returning from the handler re-executes the instruction cleanly.
  • Stack Frame Layout:
    1. Push saved CONTINUATION word (FP + 0).
    2. Push saved CONTROL_REGISTER word (FP + 1, tagged DTP_FIXNUM).
    3. Push trap-specific arguments starting at FP + 2 (LP):
      • Trap microstate (fixnum; for IVORY_TRAP_ERROR, carries the Rev 4 microstate code #o0000..#o3777).
      • fault_pc (DTP_EVEN_PC / DTP_ODD_PC of the faulting instruction).
      • fault_vma (DTP_LOCATIVE or DTP_FIXNUM, when applicable such as page faults, bus errors, or vma_valid=1 error microstates).
    4. Update FP to the new frame header, LP = SP + 1, set CR.caller_frame_size, CR.argument_size, CR.value_disposition = IVORY_DISP_EFFECT, CR.call_started = 0, CR.trap_mode = max(old, entry.cdr), and branch PC to entry.

Post-Traps (Software Instruction / Arithmetic Emulation)

Used for arithmetic exceptions (#o0000..#o3777), instruction exceptions (#o4000..#o4377), interpreter function calls (#o4400..#o4477), and generic/message dispatch (#o5114, #o5116).

  • Saved PC: Points to the next sequential instruction (after the trapping instruction), because the software handler computes the result and returns directly to the caller's continuation.
  • Stack Frame Layout:
    • The instruction's operand(s) are popped and passed as normal arguments (arg1, arg2, ...) in the trap handler's frame, with CR.value_disposition = IVORY_DISP_VALUE (or IVORY_DISP_MULTIPLE for multi-value post-traps) so the handler's RETURN-SINGLE / RETURN-MULTIPLE leaves the computed result directly on the caller's TOS.

-NO-POP Binary Predicate Trap Rule (iarithdefs.lisp:221-252)

The five -NO-POP binary numeric/bitwise predicates (EQUAL-NUMBER-NO-POP #o264, LESSP-NO-POP #o265, GREATERP-NO-POP #o266, EQL-NO-POP #o267, LOGTEST-NO-POP #o277, plus UNSIGNED-LESSP-NO-POP #o335) normally leave arg1 on the stack and push the boolean result above it. When one of these instructions takes an arithmetic post-trap (e.g., mixed bignum/ratio/complex comparison), Genera's software trap handlers execute (VALUES arg1 result) (returning 2 values). Therefore, hardware (take_pred_arith_trap2 in emu/src/isa_stack.c) pops arg1 before pushing the trap frame so the trap frame starts at arg1's stack slot; returning 2 values overwrites arg1 and pushes result at the exact expected stack depth without leaking an extra word.


4. Ivory Rev 4 / Rev 4A Error-Trap Microstate Table (IVORY_TRAP_ERROR)

Both Ivory Rev 4 and Rev 4A report %REGISTER-CHIP-REVISION = 4 and share the identical 2,048-entry Genera 8.3 *TRAP-DISPATCH-TABLE* (#o0000..#o3777). When IVORY_TRAP_ERROR (#o5100) fires, the debugger indexes *TRAP-DISPATCH-TABLE* by the hardware microstate code to classify the exact Lisp error (including CLOS:SLOT-UNBOUND on DTP_NULL memory reads).

Key microstate constants defined in ivory_hw.h:

HexOctalConstantvma_validCondition / Debugger Action
0x0000#o0000IVORY_REV4_USTATE_ILLEGAL_FULLWORD_INSTR0Illegal fullword tag executed in instruction stream
0x0034#o0064IVORY_REV4_USTATE_TOO_FEW_ARGUMENTS0Callee ENTRY received fewer than min_args
0x0044#o0104IVORY_REV4_USTATE_FIXNUM_ARRAY_ASET_TYPE_ERROR0Non-fixnum stored into fixnum/byte array
0x0045#o0105IVORY_REV4_USTATE_CHAR_ARRAY_ASET_TYPE_ERROR0Non-character stored into string/fat-string array
0x0047#o0107IVORY_REV4_USTATE_MEMORY_DATA_ERROR1DTP_NULL read via DATA_READ (unbound variable or CLOS:SLOT-UNBOUND)
0x0048#o0110IVORY_REV4_USTATE_BYTE_ARRAY_WORD_TYPE_CHECK1Non-fixnum word encountered inside byte array storage
0x0056#o0126IVORY_REV4_USTATE_LIST_OP_TAIL_NOT_LIST1Dotted tail in list search (MEMBER/ASSOC/RGETF)
0x0057#o0127IVORY_REV4_USTATE_BAD_CDR_CODE_IN_MEMORY1Illegal CDR-JUMP (3) encountered in cons/list cell
0x007A#o0172IVORY_REV4_USTATE_SHALLOW_BIND_IN_DEEP_MODE1Shallow binding attempted while in deep-binding mode
0x008F#o0217IVORY_REV4_USTATE_SUBSCRIPT_BOUNDS_ERROR0Array index < 0 or >= array_length
0x0098#o0230IVORY_REV4_USTATE_ALOC_NON_OBJECT_ARRAY0ALOC-1 on non-ART-Q packed array
0x00A0#o0240IVORY_REV4_USTATE_ARRAY_REG_FORMAT_ERROR0Malformed fast array register descriptor
0x00B5#o0265IVORY_REV4_USTATE_FRAME_OVERFLOW0Frame exceeds STACK-FRAME-MAXIMUM-SIZE
0x011E#o0436IVORY_REV4_USTATE_I_STAGE_ERROR0Sequencing fence (CDR=1), odd fullword, or illegal address mode (SP-pop/immediate as address operand)
0x04C9#o2311IVORY_REV4_TRAP_ON_EXIT_MICROSTATE0CR.trap_on_exit fired on function return
0x0559#o2531IVORY_REV4_USTATE_DIVIDE_BY_ZERO0Fixnum / bignum division by zero
0x058F#o2617IVORY_REV4_USTATE_BRANCH_DOT_ERROR0Malformed branch target
0x0613#o3023IVORY_REV4_USTATE_TOO_MANY_ARGUMENTS0Callee ENTRY-REST-NOT-ACCEPTED exceeded max_args
0x07CD#o3715IVORY_REV4_USTATE_BINDING_STACK_UNDERFLOW0Binding stack popped below base
0x07D7#o3727IVORY_REV4_USTATE_BINDING_STACK_OVERFLOW0Binding stack exceeded BINDING-STACK-LIMIT
0x07FB#o3773IVORY_REV4_USTATE_DIVIDE_OVERFLOW0Signed division overflow (INT32_MIN / -1)
0x0408..0x07E4#o2010..#o3744IVORY_REV4_USTATE_WTA_*0Wrong-Type-Argument unary, binary, and ternary type checks (LIST_OR_NIL, ARRAY, LOCATIVE, FIXNUM, CHARACTER, BIN_NUMBERS, BIN_ARRAY_FIXNUM, ARRAY_ACCESS_BIN, etc.)

5. Hardware Interrupt Delivery (Merlin-II Sequence Breaks)

Merlin-II aggregates motherboard and I/O Board 0 interrupt sources in MERLIN_IRQ_REG_PMA (0x0A00000C, accessed via DTP_PHYSICAL_ADDRESS) into two Ivory hardware interrupt lines:

  1. High-Priority Sequence Break (IVORY_TRAP_HIGH_PRIO_SEQ_BREAK, #o5111):
    • Triggered by the Intel 82C54 PIT (Timer0 2.5 ms scheduler clock / Timer1&2) and Merlin-II VME high-priority interrupts.
    • Checked at instruction boundaries when CR.trap_mode == 0 (and reflected in %REGISTER-PREEMPT-REGISTER #o23).
  2. Low-Priority Sequence Break (IVORY_TRAP_LOW_PRIO_SEQ_BREAK, #o5110):
    • Triggered by I/O Board 0 peripherals: WD33C93A SCSI (<8..11>), ESDI (<12..15>), SCN68562 DUSCC serial & 8237A DMAC (<16..17>), Intel 82586 Ethernet (<18>), and VME low-priority (<2>).
  3. Explicit Preempt Polling (CHECK-PREEMPT-REQUEST, #o054):
    • Allows tight loops to poll pending preempt requests and enter #o5105 (IVORY_TRAP_PREEMPT_REQUEST) cleanly.

In the emulator (emu/src/cpu.c), deterministic pacing runs at IVORY_INSTRS_PER_US = 4 macroinstructions per microsecond (~4 MIPS XL1200 clock) with a capped 256-µs event-horizon timer batching window (merlin_us_until_next_timer_irq), ensuring bit-exact interrupt delivery at identical instruction counts across all three execution tiers (portable, avx512_c, avx512).

Related Chip Datasheets (7)All Component Datasheets →