Volume 2: Ivory Instruction Set Architecture & Execution Semantics
This volume specifies Ivory's instruction stream encoding, packed halfword and fullword formats, the complete 8-bit opcode table (#o000..#o377), function call/entry/return conventions, arithmetic and Weitek W3x64 FPA execution rules, and hardware trap dispatch semantics.
All encodings and microstate constants match ivory_hw.h and the from-scratch C11 execution units in emu/src/{cpu.c,cpu_decode.c,isa_call.c,isa_stack.c,isa_arith.c,isa_lisp.c,isa_sys.c,fpa_w3x64.c}.
Primary Reference Sources (local-only when present):
genera-original/sys.sct/i-sys/opdef.lisp— Canonical 8-bit opcode assignments (DEFOPCODE).genera-original/sys.sct/i-compiler/{i-instruction-set.lisp,i-back-end.lisp,disassemble.lisp}— Halfword formats, entry words, andFINISH-CALL-Nencoding.genera-original/sys.sct/sys/iarithdefs.lisp—-NO-POPbinary arithmetic predicate trap contract.genera-original/sys.sct/debugger/{itrap-dispatch.lisp,itrap-defs.lisp}— Rev 4 / Rev 4A*TRAP-DISPATCH-TABLE*.I_Machine/I-Machine_Architecture_Specification.pdf— Chapters 6–9 (Instructions, Calling Convention, Traps).
1. Instruction Stream & Sequencing Rules
Every 40-bit word fetched from the instruction stream is classified by its 2-bit sequence code (<39:38>, IvoryInstructionSequenceCode) and 6-bit Data Type (<37:32>):
- Sequencing Fence (
seq_code == 1,IVORY_SEQ_FENCE):- Marks non-executable function trailers / debug info. Attempting to execute at either Even or Odd phase raises
IVORY_TRAP_ERRORwithIVORY_REV4_USTATE_I_STAGE_ERROR(0x011E).
- Marks non-executable function trailers / debug info. Attempting to execute at either Even or Odd phase raises
- Packed Halfword Pair (
DTPin#o60..#o77,(dtp & #o60) == #o60):- Packs two 18-bit instructions into bits
<35:0>:- Even halfword (
DTP_EVEN_PC): bits<17:0>. - Odd halfword (
DTP_ODD_PC): bits<35:18>(its top 4 bits<35:32>occupy the low 4 bits of the 6-bit DTP!).
- Even halfword (
- Sequential PC advancement depends on
seq_code(expressed as halfword slot stride):0(IVORY_SEQ_PC_PLUS_1): Even+1(-> Odd same word), Odd+1(-> Even next word).2(IVORY_SEQ_PC_MINUS_1): Even-1, Odd-1(steps backwards by 1 halfword).3(IVORY_SEQ_PC_EVEN_2_ODD_3,CDR-JUMP): Even+2(-> Even next word, skipping Odd), Odd+3(-> Even word+2).
- Packs two 18-bit instructions into bits
- Fullword Instructions (
DTP < #o60, Even phase only):- Executing any non-packed word at
DTP_ODD_PCraisesIVORY_TRAP_ERRORwithIVORY_REV4_USTATE_I_STAGE_ERROR(0x011E). - Sequential stride is
+2halfwords (next word, Even phase), or-1ifseq_code == 2. - Subclasses:
- Fullword Call Starters (
#o50..#o57):StartCallinstructions (DTP_CALL_COMPILED_EVEN,ODD,INDIRECT,GENERIC, and their+4prefetch variants). They open a call frame, loadCONTINUATION, setCR.call_started = 1, and advance sequentially so caller code can push arguments beforeFinishCall. DTP_EXTERNAL_VALUE_CELL_POINTER(#o04): Reads the cell atword.pointerviaIVORY_MEM_DATA_READ(following invisible forwarding pointers and GC read barriers) and pushes the result onto TOS.- Inline Fullword Constants (
ivory_is_fullword_constant): Valid Lisp values (FIXNUM,SINGLE_FLOAT,NIL,LIST,SYMBOL,ARRAY,STRING,CHARACTER,COMPILED_FUNCTION, etc.) are pushed directly onto TOS withCDR_NEXT. - Illegal Fullword Tags (
ivory_is_fullword_illegal:NULL,MONITOR_FORWARD,HEADER_P,HEADER_I,ONE_Q_FORWARD,HEADER_FORWARD,ELEMENT_FORWARD,BOUND_LOCATION,LOGIC_VARIABLE,GC_FORWARD): RaiseIVORY_TRAP_ERRORwithIVORY_REV4_USTATE_ILLEGAL_FULLWORD_INSTR(0x0000).
- Fullword Call Starters (
- Executing any non-packed word at
2. 18-Bit Halfword Formats & Function Entry Words
Format 1: Stack / Address Operand (IvoryHalfwordInstr.stack_op)
17 10 9 8 7 0
+------------+------+-----------------+
| Opcode | Mode | 8-Bit Offset |
| (8 bits) |(2 b) | (8 bits) |
+------------+------+-----------------+
Mode | Constant | Value Operand (ivory_cpu_resolve_operand) | Address Operand (ivory_cpu_resolve_address) |
|---|---|---|---|
00 | IVORY_ADDR_FP | Read stack word at FP + offset | Locative FP + offset |
01 | IVORY_ADDR_LP | Read stack word at LP + offset | Locative LP + offset |
10 | IVORY_ADDR_SP | offset == 0: SP-pop (pop TOS); else read SP + offset - 255 | offset == 0: illegal (I_STAGE_ERROR); else SP + offset - 255 |
11 | IVORY_ADDR_IMMEDIATE | 8-bit immediate fixnum (signed or unsigned per opcode) | Illegal (I_STAGE_ERROR) |
Format 2: 10-Bit Immediate / Signed Branch Offset (IvoryHalfwordInstr.immed10_op)
17 10 9 0
+------------+------------------------+
| Opcode | 10-Bit Immediate |
| (8 bits) | (or Signed Branch Δ) |
+------------+------------------------+
Used by branches (#o060..#o077, #o174, #o175, #o375 — signed 10-bit halfword delta relative to current PC), TYPE-MEMBER (#o040..#o047 — 12-bit mask across opcode low 2 bits + 10-bit imm), FINISH-CALL-* (#o134..#o137), MEMORY-READ (#o116..#o117), READ/WRITE-INTERNAL-REGISTER (#o154..#o155), COPROCESSOR-READ/WRITE (#o156..#o157), and LDB/DPB (#o170..#o173, #o370..#o373).
Format 3: Full 36-Bit Function Entry Instruction (#o176 / #o177)
Function entry points always reside at an Even halfword and consume the entire 36-bit packed word (IvoryWord.entry_instr, sysdef.lisp:763-774):
39 38 37 36 35 32 31 28 27 26 25 18 17 10 9 8 7 0
+-----+-----+------+------+---+---+-----------+----------+-----+----------+
| Seq | 11 | Odd | SW |Int|Inh| max_args | Opcode | 11 | min_args |
|(2b) |(2b) | Top |Flags |Fn |Lnk| (+2, 8b) | #o176/177|(2b) | (+2, 8b) |
+-----+-----+------+------+---+---+-----------+----------+-----+----------+
#o176(OP_ENTRY_REST_ACCEPTED): Accepts excess arguments beyondmax_argsas a&restlist.#o177(OP_ENTRY_REST_NOT_ACCEPTED): Rejectsnargs > max_argswithIVORY_REV4_USTATE_TOO_MANY_ARGUMENTS(0x0613).- Both
min_args(<7:0>) andmax_args(<25:18>) are biased by+2(accounting for the 2-word frame header). Receiving fewer thanmin_argstraps withIVORY_REV4_USTATE_TOO_FEW_ARGUMENTS(0x0034). - Entry words normally carry
CDR-JUMP(seq_code = 3) so execution advances directly toPC + 1Even, skipping the upper halfword'smax_args/flag metadata.
3. Complete Verified 8-Bit Opcode Table (#o000..#o377)
Matches IvoryOpcode in ivory_hw.h and k_implemented_opcode[256] in emu/src/cpu_decode.c (219 implemented opcodes; unlisted slots decode to HANDLER_TRAP_UNIMP_OPCODE, post-trapping to IVORY_TRAP_INSTR_EXCEPTION_BASE + opcode):
| Octal Range | Mnemonics |
|---|---|
#o000..#o007 | CAR, CDR, ENDP, SETUP-1D-ARRAY, SETUP-FORCE-1D-ARRAY, BIND-LOCATIVE, RESTORE-BINDING-STACK, EPHEMERALP |
#o010..#o015 | START-CALL, JUMP, TAG, DEREFERENCE, LOGIC-TAIL-TEST, %PROC-BREAKPOINT |
#o020..#o027 | PUSH-LEXICAL-VAR-0..7 |
#o030..#o036 | BLOCK-0..3-WRITE, ZEROP, MINUSP, PLUSP |
#o040..#o047 | TYPE-MEMBER-0..3, TYPE-MEMBER-NO-POP-0..3 |
#o050..#o057 | LOCATE-LOCALS, CATCH-CLOSE, GENERIC-DISPATCH, MESSAGE-DISPATCH, CHECK-PREEMPT-REQUEST, PUSH-GLOBAL-LOGIC-VARIABLE, NO-OP, HALT |
#o060..#o067 | BRANCH-TRUE family (8 pop/no-pop/extra-pop variants) |
#o070..#o077 | BRANCH-FALSE family (8 pop/no-pop/extra-pop variants) |
#o100..#o107 | PUSH, PUSH-N-NILS, PUSH-ADDRESS-SP-RELATIVE, PUSH-LOCAL-LOGIC-VARIABLES, RETURN-MULTIPLE, RETURN-KLUDGE, TAKE-VALUES, UNBIND-N |
#o110..#o117 | PUSH-{,ADDRESS-}INSTANCE-VARIABLE{,-ORDERED}, UNARY-MINUS, RETURN-SINGLE, MEMORY-READ, MEMORY-READ-ADDRESS |
#o120..#o133 | BLOCK-0..3-READ, BLOCK-0..3-READ-SHIFT, BLOCK-0..3-READ-TEST |
#o134..#o137 | FINISH-CALL-N, FINISH-CALL-N-APPLY, FINISH-CALL-TOS, FINISH-CALL-TOS-APPLY |
#o140..#o147 | SET-TO-CAR, SET-TO-CDR, SET-TO-CDR-PUSH-CAR, INCREMENT, DECREMENT, POINTER-INCREMENT, SET-CDR-CODE-1, SET-CDR-CODE-2 |
#o150..#o157 | PUSH-ADDRESS, SET-SP-TO-ADDRESS, SET-SP-TO-ADDRESS-SAVE-TOS, READ-INTERNAL-REGISTER, WRITE-INTERNAL-REGISTER, COPROCESSOR-READ, COPROCESSOR-WRITE |
#o160..#o163 | BLOCK-0..3-READ-ALU |
#o170..#o177 | LDB, CHAR-LDB, P-LDB, P-TAG-LDB, BRANCH, LOOP-DECREMENT-TOS, ENTRY-REST-ACCEPTED, ENTRY-REST-NOT-ACCEPTED |
#o200..#o217 | RPLACA, RPLACD, MULTIPLY, QUOTIENT, CEILING, FLOOR, TRUNCATE, ROUND, REMAINDER, RATIONAL-QUOTIENT, MIN, MAX, ALU, LOGAND, LOGXOR, LOGIOR |
#o220..#o237 | ROT, LSH, MULTIPLY-DOUBLE, LSHC-BIGNUM-STEP, STACK-BLT, RGETF, MEMBER, ASSOC, POINTER-PLUS, POINTER-DIFFERENCE, ASH, STORE-CONDITIONAL, MEMORY-WRITE, P-STORE-CONTENTS, BIND-LOCATIVE-TO-VALUE, UNIFY |
#o240..#o257 | POP-LEXICAL-VAR-0..7, MOVEM-LEXICAL-VAR-0..7 |
#o260..#o267 | EQUAL-NUMBER, LESSP, GREATERP, EQL, EQUAL-NUMBER-NO-POP, LESSP-NO-POP, GREATERP-NO-POP, EQL-NO-POP |
#o270..#o277 | EQ (#o270), LOGTEST (#o273), EQ-NO-POP (#o274), LOGTEST-NO-POP (#o277) |
#o300..#o307 | ADD, SUB, 32-BIT-PLUS, 32-BIT-DIFFERENCE, ADD-BIGNUM-STEP, SUB-BIGNUM-STEP, MULTIPLY-BIGNUM-STEP, DIVIDE-BIGNUM-STEP |
#o310..#o317 | ASET-1, ALLOCATE-LIST-BLOCK, AREF-1, ALOC-1, STORE-ARRAY-LEADER, ALLOCATE-STRUCTURE-BLOCK, ARRAY-LEADER, ALOC-LEADER |
#o320..#o327 | POP/MOVEM-INSTANCE-VARIABLE{,-ORDERED}, INSTANCE-REF, INSTANCE-SET, INSTANCE-LOC, SET-TAG |
#o331, #o335 | UNSIGNED-LESSP, UNSIGNED-LESSP-NO-POP |
#o340..#o342 | POP, MOVEM, MERGE-CDR-NO-POP |
#o350..#o352 | FAST-AREF-1, FAST-ASET-1, STACK-BLT-ADDRESS |
#o370..#o373 | DPB, CHAR-DPB, P-DPB, P-TAG-DPB |
#o375..#o377 | LOOP-INCREMENT-TOS-LESS-THAN, CATCH-OPEN, %HACK (%halt) |
4. Calling Convention, Closures & Frame Lifecycle (isa_call.c)
StartCall(Fullword#o50..#o57or Packed#o010):- Pushes the 2-word frame header onto the stack:
[saved CONTINUATION, saved CR](settingsaved CR.call_started = old,saved CR.value_dispositionfrom the call). - Resolves the callee target:
DTP_COMPILED_FUNCTION/DTP_EVEN_PC/DTP_ODD_PC: loads entry PC intoCONTINUATION.DTP_LEXICAL_CLOSURE(#o32): reads[env, fn], pushesenvas an extra argument right after the frame header, setsCR.extra_argument = 1, and resolvesfnintoCONTINUATION.DTP_SYMBOL(#o30): dereferences the symbol's function cell (symbol + 2) viaDATA_READ.DTP_GENERIC_FUNCTION(#o35) or non-compiled objects: dispatches viaIVORY_TRAP_INTERPRETER_FN_BASE + dtp(#o4400 + dtp) or generic dispatch.
- Sets
CR.call_started = 1and advances PC sequentially so arguments can be pushed.
- Pushes the 2-word frame header onto the stack:
FinishCall(#o134..#o137):- Critical encoding invariant: For
FINISH-CALL-N(#o134) andFINISH-CALL-N-APPLY(#o135), bits<7:0>encoden_args + 1(0 arguments ->1, 2 arguments ->3), and bits<9:8>encodevalue_disposition(EFFECT,VALUE,RETURN,MULTIPLE). - Computes
new_fp = SP - n_args - (extra_argument ? 1 : 0) - 1, setsLP = SP + 1, recordscaller_frame_size = new_fp - old_fpandargument_size = LP - new_fp, transfersCONTINUATION->PC, and saves the return PC intoCONTINUATION.
- Critical encoding invariant: For
Entry(#o176/#o177):- Validates
argument_sizeagainstmin_argsandmax_args(both+2), handlesCR.applyviaPULL-APPLY-ARGS, builds a&restlist if#o176with excess args, and initializesLP.
- Validates
Return(RETURN-SINGLE#o115,RETURN-MULTIPLE#o104,RETURN-KLUDGE#o105):- Checks
CR.trap_on_exit(0x04C9),CR.cleanup_catch(#o5127), andCR.cleanup_bindings(#o5126) before unwinding. - Delivers return values according to
CR.value_disposition(EFFECTdiscards,VALUEpushes 1 value,MULTIPLEpushes N values + fixnum count,RETURNpropagates directly to grandparent frame) and restoresFP,LP,CR, andPC.
- Checks
5. Arithmetic, -NO-POP Predicates & Weitek W3x64 FPA Execution
- Fixnum & Single-Float Fast Paths (
isa_arith.c):- Same-tag
DTP_FIXNUMarithmetic executes natively in 32-bit signed arithmetic; 32-bit signed overflow or mixed/non-fixnum operands post-trap toIVORY_TRAP_ARITH_EXCEPTION_BASE + ((op & #o37) << 6) | ((dtp1 & 7) << 3) | (dtp2 & 7). DTP_SINGLE_FLOATfast paths inisa_arith.croute throughivory_fpa_exec_single_op()(emu/src/fpa_w3x64.c) so rounding modes (SR0<2:1>) and exception traps (SR2) match the W3x64 hardware coprocessor exactly.
- Same-tag
-NO-POPBinary Predicate Trap Contract (iarithdefs.lisp:221-252,isa_stack.c):EQUAL-NUMBER-NO-POP(#o264),LESSP-NO-POP(#o265),GREATERP-NO-POP(#o266),EQL-NO-POP(#o267),LOGTEST-NO-POP(#o277), andUNSIGNED-LESSP-NO-POP(#o335) normally keeparg1on the stack and push the boolean result above it.- When an operand type forces an arithmetic post-trap, Genera's software handler returns
(VALUES arg1 result)(2 values). Hardware therefore popsarg1before pushing the trap frame (take_pred_arith_trap2) so returning 2 values overwritesarg1and pushesresultwithout shiftingSPby+1.
- Weitek W3x64 Coprocessor Execution Sequence (
fpa_w3x64.c):- Software stages
R0_HI(#o0000) /R0_LO(#o0002) andR1_LO(#o0003) viaCOPROCESSOR-WRITE(#o157). - Writing
R1_HIto an operation trigger port (opcode + 1) executes the IEEE-754 single/double operation (add, sub, mul, div, sqrt, neg, abs, compare, fix/float conversions) under the activeSR0rounding mode, latchesSR3/SR6/SR11, and setslast_fpexif any unmaskedSR2exception fires. - Software reads results from
#o0002(RES_HI: taggedDTP_SINGLE_FLOATif!last_fpex, elseDTP_FIXNUMsignaling software trap recovery),#o0003(RES_LO), or#o0400; for comparisons, readingopcode + 2returnsT,NIL, orDTP_FIXNUM 0onlast_fpex.
- Software stages
6. Hardware Traps & Rev 4 / Rev 4A Error Microstates
Trap dispatch routes through vector_base + trap_offset, where vector_base is 0xF8040000 in modes 0..2 and %REGISTER-FEP-MODE-TRAP-VECTOR-ADDRESS (#o1024) in mode 3 (FEP):
| Vector Range (Octal) | Class | Meaning |
|---|---|---|
#o0000..#o3777 | Post-Trap | Arithmetic exception dispatch (op, dtp1, dtp2) |
#o4000..#o4377 | Post-Trap | Unimplemented / software-emulated opcode (#o4000 + op) |
#o4400..#o4477 | Post-Trap | Interpreter / non-compiled function call (#o4400 + dtp) |
#o5000 | Post-Trap | Generic dispatch table |
#o5100..#o5127 | Pre/Post | Hardware traps: ERROR (#o5100), RESET (#o5101), STACK_OVERFLOW (#o5103), PREEMPT (#o5105), TRANSPORT (#o5106), FEP_MODE (#o5107), LOW/HIGH_PRIO_SEQ_BREAK (#o5110..#o5111), MONITOR (#o5112), PAGE_NOT_RESIDENT (#o5120), PAGE_FAULT_REQUEST (#o5121), PAGE_WRITE_FAULT (#o5122), MEMORY_BUS_ERROR (#o5124), DB_UNWIND_FRAME/CATCH (#o5126..#o5127) |
When IVORY_TRAP_ERROR (#o5100) fires, the trap frame passes an Ivory Rev 4 / Rev 4A microstate code (0x0000..0x07FF, identical across Rev 4 and Rev 4A) that indexes Genera 8.3's 2,048-entry *TRAP-DISPATCH-TABLE* (e.g., 0x0000 ILLEGAL_FULLWORD_INSTR, 0x0034 TOO_FEW_ARGUMENTS, 0x0047 MEMORY_DATA_ERROR -> CLOS:SLOT-UNBOUND with vma_valid=1, 0x0057 BAD_CDR_CODE_IN_MEMORY, 0x008F SUBSCRIPT_BOUNDS_ERROR, 0x011E I_STAGE_ERROR, 0x04C9 TRAP_ON_EXIT, 0x0559 DIVIDE_BY_ZERO, 0x0613 TOO_MANY_ARGUMENTS, plus Wrong-Type-Argument microstates 0x0408..0x07E4).
For the full trap vector listing, microstate table, and *BOOT-SPY-PC* halt vector, see Traps, Interrupts & Exception Handling.
- Weitek WTL1164/1165 (W3x64 family) —
weitek_WTL1164_1165_64bit_ieee_1986.pdf(mirror) - Weitek WTL3132/3332 (W3x64 family) —
weitek_WTL3132_3332_fpdp_1988.pdf(mirror) - Weitek WTL3167 (W3x64 core) —
weitek_WTL3167_coprocessor_1988.pdf(mirror)