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-POPbinary 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_mode | Enum Constant | Environment | Trap Vector Base |
|---|---|---|---|
0 | IVORY_TRAP_MODE_EMULATOR | Normal Genera Lisp execution | 0xF8040000 (IVORY_TRAP_VECTOR_BASE_VMA) |
1 | IVORY_TRAP_MODE_EXTRA_STACK | Stack overflow recovery / extra stack segment | 0xF8040000 |
2 | IVORY_TRAP_MODE_IO | Low-level I/O / interrupt handlers | 0xF8040000 |
3 | IVORY_TRAP_MODE_FEP | Front-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:
- 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, and2, the base address is fixed at0xF8040000(#o37001000000, PMA0x00040000).
- In
- 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_PCorDTP_ODD_PC) or reading the vector faults while already inFEPmode, the CPU signals a double fault (IVORY_ERR_DOUBLE_FAULT) and halts rather than recursing infinitely.
- The 2-bit CDR code (
- 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(PMA0x07FE0000) stores*BOOT-SPY-PC*at word offset+0x04(0xFFFE0004), pointing to a 3-word Stage-0 halt vector at0xFFFE0010..0xFFFE0012(IVORY_BOOT_SPY_HALT_VMA):+0(0xFFFE0010): CleanShutdown/ Remote Debugger entry (%halt).+2(0xFFFE0012): Fatal unhandled trap halt (%halt).
- At cold reset (
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 Offset | Enum Constant | Trap Class | Description |
|---|---|---|---|
#o0000..#o3777 | IVORY_TRAP_ARITH_EXCEPTION_BASE | Post-Trap | Arithmetic dispatch table: ((opcode & #o37) << 6) | ((dtp1 & 7) << 3) | (dtp2 & 7) |
#o4000..#o4377 | IVORY_TRAP_INSTR_EXCEPTION_BASE + op | Post-Trap | Unimplemented / software-emulated opcode (#o000..#o377) |
#o4400..#o4477 | IVORY_TRAP_INTERPRETER_FN_BASE + dtp | Post-Trap | Non-compiled call target dispatch indexed by 6-bit DTP |
#o5000 | IVORY_TRAP_GENERIC_DISPATCH_TBL | Post-Trap | Generic function dispatch table base |
#o5100 | IVORY_TRAP_ERROR | Pre-Trap | General hardware error trap (carries Rev 4 microstate + optional fault VMA) |
#o5101 | IVORY_TRAP_RESET | Pre-Trap | Hardware reset vector |
#o5102 | IVORY_TRAP_PULL_APPLY_ARGS | Pre-Trap | Pull remaining &rest/apply arguments across stack cache |
#o5103 | IVORY_TRAP_STACK_OVERFLOW | Pre-Trap | Control stack overflow (SP crossed CONTROL-STACK-LIMIT) |
#o5104 | IVORY_TRAP_TRACE | Pre-Trap | Instruction / call trace trap (CR.trace_pending) |
#o5105 | IVORY_TRAP_PREEMPT_REQUEST | Pre-Trap | Preempt request / scheduler quantum check |
#o5106 | IVORY_TRAP_TRANSPORT | Pre-Trap | Ephemeral/Dynamic GC read barrier (oldspace pointer loaded) |
#o5107 | IVORY_TRAP_FEP_MODE | Pre-Trap | Explicit software entry into FEP mode (trap_mode -> 3) |
#o5110 | IVORY_TRAP_LOW_PRIO_SEQ_BREAK | Pre-Trap | Low-priority Merlin-II sequence break (serial/SCSI/Ethernet/VME LP) |
#o5111 | IVORY_TRAP_HIGH_PRIO_SEQ_BREAK | Pre-Trap | High-priority Merlin-II sequence break (82C54 Timer0/Timer1&2, VME HP) |
#o5112 | IVORY_TRAP_MONITOR | Pre-Trap | Memory write/read monitor trap (DTP_MONITOR_FORWARD) |
#o5114 | IVORY_TRAP_GENERIC_DISPATCH | Post-Trap | Generic function cache miss / dispatch trap |
#o5116 | IVORY_TRAP_MESSAGE_DISPATCH | Post-Trap | Flavors message dispatch cache miss |
#o5120 | IVORY_TRAP_PAGE_NOT_RESIDENT | Pre-Trap | PHT lookup missed (VPN not mapped in PHT) |
#o5121 | IVORY_TRAP_PAGE_FAULT_REQUEST | Pre-Trap | PHT0 fault_request bit (<7>) set on resident page |
#o5122 | IVORY_TRAP_PAGE_WRITE_FAULT | Pre-Trap | Write attempted to page with PHT1 write_protect (<6>) set |
#o5123 | IVORY_TRAP_UNCORRECTABLE_MEM | Pre-Trap | Uncorrectable ECC memory error |
#o5124 | IVORY_TRAP_MEMORY_BUS_ERROR | Pre-Trap | Physical bus fault / unpopulated I/O board (0x50000000, etc.) |
#o5125 | IVORY_TRAP_DB_CACHE_MISS | Pre-Trap | Dynamic binding cache miss |
#o5126 | IVORY_TRAP_DB_UNWIND_FRAME | Pre-Trap | Unwind dynamic bindings on frame exit (CR.cleanup_bindings) |
#o5127 | IVORY_TRAP_DB_UNWIND_CATCH | Pre-Trap | Unwind 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:
- Push saved
CONTINUATIONword (FP + 0). - Push saved
CONTROL_REGISTERword (FP + 1, taggedDTP_FIXNUM). - Push trap-specific arguments starting at
FP + 2(LP):- Trap
microstate(fixnum; forIVORY_TRAP_ERROR, carries the Rev 4 microstate code#o0000..#o3777). fault_pc(DTP_EVEN_PC/DTP_ODD_PCof the faulting instruction).fault_vma(DTP_LOCATIVEorDTP_FIXNUM, when applicable such as page faults, bus errors, orvma_valid=1error microstates).
- Trap
- Update
FPto the new frame header,LP = SP + 1, setCR.caller_frame_size,CR.argument_size,CR.value_disposition = IVORY_DISP_EFFECT,CR.call_started = 0,CR.trap_mode = max(old, entry.cdr), and branchPCtoentry.
- Push saved
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, withCR.value_disposition = IVORY_DISP_VALUE(orIVORY_DISP_MULTIPLEfor multi-value post-traps) so the handler'sRETURN-SINGLE/RETURN-MULTIPLEleaves the computed result directly on the caller's TOS.
- The instruction's operand(s) are popped and passed as normal arguments (
-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:
| Hex | Octal | Constant | vma_valid | Condition / Debugger Action |
|---|---|---|---|---|
0x0000 | #o0000 | IVORY_REV4_USTATE_ILLEGAL_FULLWORD_INSTR | 0 | Illegal fullword tag executed in instruction stream |
0x0034 | #o0064 | IVORY_REV4_USTATE_TOO_FEW_ARGUMENTS | 0 | Callee ENTRY received fewer than min_args |
0x0044 | #o0104 | IVORY_REV4_USTATE_FIXNUM_ARRAY_ASET_TYPE_ERROR | 0 | Non-fixnum stored into fixnum/byte array |
0x0045 | #o0105 | IVORY_REV4_USTATE_CHAR_ARRAY_ASET_TYPE_ERROR | 0 | Non-character stored into string/fat-string array |
0x0047 | #o0107 | IVORY_REV4_USTATE_MEMORY_DATA_ERROR | 1 | DTP_NULL read via DATA_READ (unbound variable or CLOS:SLOT-UNBOUND) |
0x0048 | #o0110 | IVORY_REV4_USTATE_BYTE_ARRAY_WORD_TYPE_CHECK | 1 | Non-fixnum word encountered inside byte array storage |
0x0056 | #o0126 | IVORY_REV4_USTATE_LIST_OP_TAIL_NOT_LIST | 1 | Dotted tail in list search (MEMBER/ASSOC/RGETF) |
0x0057 | #o0127 | IVORY_REV4_USTATE_BAD_CDR_CODE_IN_MEMORY | 1 | Illegal CDR-JUMP (3) encountered in cons/list cell |
0x007A | #o0172 | IVORY_REV4_USTATE_SHALLOW_BIND_IN_DEEP_MODE | 1 | Shallow binding attempted while in deep-binding mode |
0x008F | #o0217 | IVORY_REV4_USTATE_SUBSCRIPT_BOUNDS_ERROR | 0 | Array index < 0 or >= array_length |
0x0098 | #o0230 | IVORY_REV4_USTATE_ALOC_NON_OBJECT_ARRAY | 0 | ALOC-1 on non-ART-Q packed array |
0x00A0 | #o0240 | IVORY_REV4_USTATE_ARRAY_REG_FORMAT_ERROR | 0 | Malformed fast array register descriptor |
0x00B5 | #o0265 | IVORY_REV4_USTATE_FRAME_OVERFLOW | 0 | Frame exceeds STACK-FRAME-MAXIMUM-SIZE |
0x011E | #o0436 | IVORY_REV4_USTATE_I_STAGE_ERROR | 0 | Sequencing fence (CDR=1), odd fullword, or illegal address mode (SP-pop/immediate as address operand) |
0x04C9 | #o2311 | IVORY_REV4_TRAP_ON_EXIT_MICROSTATE | 0 | CR.trap_on_exit fired on function return |
0x0559 | #o2531 | IVORY_REV4_USTATE_DIVIDE_BY_ZERO | 0 | Fixnum / bignum division by zero |
0x058F | #o2617 | IVORY_REV4_USTATE_BRANCH_DOT_ERROR | 0 | Malformed branch target |
0x0613 | #o3023 | IVORY_REV4_USTATE_TOO_MANY_ARGUMENTS | 0 | Callee ENTRY-REST-NOT-ACCEPTED exceeded max_args |
0x07CD | #o3715 | IVORY_REV4_USTATE_BINDING_STACK_UNDERFLOW | 0 | Binding stack popped below base |
0x07D7 | #o3727 | IVORY_REV4_USTATE_BINDING_STACK_OVERFLOW | 0 | Binding stack exceeded BINDING-STACK-LIMIT |
0x07FB | #o3773 | IVORY_REV4_USTATE_DIVIDE_OVERFLOW | 0 | Signed division overflow (INT32_MIN / -1) |
0x0408..0x07E4 | #o2010..#o3744 | IVORY_REV4_USTATE_WTA_* | 0 | Wrong-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:
- High-Priority Sequence Break (
IVORY_TRAP_HIGH_PRIO_SEQ_BREAK,#o5111):- Triggered by the Intel 82C54 PIT (
Timer02.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).
- Triggered by the Intel 82C54 PIT (
- 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>).
- Triggered by I/O Board 0 peripherals: WD33C93A SCSI (
- Explicit Preempt Polling (
CHECK-PREEMPT-REQUEST,#o054):- Allows tight loops to poll pending preempt requests and enter
#o5105(IVORY_TRAP_PREEMPT_REQUEST) cleanly.
- Allows tight loops to poll pending preempt requests and enter
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).
- Intel 8237A —
intel_8237A_dmac.pdf - Intel 82586 —
intel_82586_lan_coprocessor.pdf(mirror) - Intel 82586 —
intel_82586_reference_manual_1983.pdf(mirror) - Intel 82C54 —
intel_82C54_pit.pdf - Signetics SCN68562 / SCN26562 —
signetics_1991_IC019_data_comm_SCN68562.pdf(mirror) - Western Digital WD33C93A —
wd_WD33C93A_datasheet_and_appnotes_1990.pdf(mirror) - Western Digital WD33C93A —
wd_WD33C93A_scsi_datasheet.pdf(mirror)