Symbolics Ivory Function Calling, Message Passing & Stack Groups
This document provides a comprehensive technical specification of function calling conventions, stack architecture, dynamic variable binding, Flavors message dispatch, and stack group switching on the Symbolics Ivory processor (I-Machine).
It is derived from Chapter 4 of the I-Machine Architecture Specification, I_Machine/Function_Calling_Message_Passing_Stack_Group_Switching.pdf, and cross-referenced with canonical Genera 8.3 sources (local-only when present):
genera-original/sys.sct/i-sys/sysdef.lisp(stack frame descriptors, control register fields, catch blocks, stack groups)genera-original/sys.sct/sys/istack.lisp(stack frame manipulation, unwind-protect, multiple-value handling)genera-original/sys.sct/i-compiler/i-back-end.lisp(compiler calling sequences, frame layout, and entry protocols)
1. The Multi-Stack Architecture
Ivory manages runtime execution using four distinct stack regions:
+-------------------+---------------------------------------------------------------+
| Stack Name | Primary Purpose / Resident Contents |
+-------------------+---------------------------------------------------------------+
| Control Stack | Function frames, arguments, locals, temporaries, return info. |
| Binding Stack | Dynamic variable bindings (shallow-binding restoration undo). |
| Data Stack | Dynamic allocations for lists, structures, and byte arrays. |
| Extra Stack | Guaranteed wired stack for emergency trap/page-fault handling.|
+-------------------+---------------------------------------------------------------+
All stacks grow upward (towards increasing virtual memory addresses). Each stack is bounded by:
- A Base Pointer: Virtual address of the lowest word in the stack.
- A Stack Pointer: Points to the highest valid active word (
SP). - A Stack Limit: Maximum permissible virtual address before triggering overflow traps.
2. Control Stack Frames & Registers
2.1 Frame Layout
Unlike the Symbolics 3600 (which copied arguments between caller and callee frames), Ivory uses an in-place argument passing architecture: arguments pushed by the caller become the argument slots of the callee's frame without copying.
Increasing Memory Addresses --->
+-------------------------------------------------------------------------------+
| Offset | Word Contents |
+-------------------------------------------------------------------------------+
| FP + 0 | Frame Header 0: Saved Caller's Continuation Register (Return PC) |
| FP + 1 | Frame Header 1: Saved Caller's Control Register |
+-------------------------------------------------------------------------------+
| FP + 2 | Argument 0 (First supplied parameter) |
| FP + 3 | Argument 1 |
| ... | ... |
| FP + k | Argument k-1 |
+-------------------------------------------------------------------------------+
| LP + 0 | Local Variable 0 (Initialized by locate-locals) |
| LP + 1 | Local Variable 1 |
| ... | Temporaries & Evaluation Stack Elements |
| SP + 0 | Top of Stack (TOS) |
+-------------------------------------------------------------------------------+
2.2 Base Registers
The active frame is bounded by three hardware registers:
Frame Pointer (FP)(0o0001): Points to Header Word 0 (FP + 0). All arguments are accessed viaFP[offset].Local Pointer (LP)(0o0002): Points to the base of local variables immediately following the spread arguments. Local variables are accessed viaLP[offset].Stack Pointer (SP)(0o0003): Points to the topmost word currently pushed on the evaluation stack.
2.3 Maximum Frame Size
Because the on-chip stack cache holds a finite number of words (128 words in Revision 0 silicon), a single stack frame cannot exceed the cache's maximum frame size:
If a function requires more than 119 arguments and locals, the compiler partitions the frame or spills variables to heap arrays.
3. Function Calling & Argument Matchup
3.1 Function Invocation Lifecycle
StartCall(0o0010):- Opens a new frame header on the stack.
- Saves current
Continuation(return PC) andControl Registerinto Header Words 0 and 1. - Sets the function to be invoked.
- Pushing Arguments:
- Caller pushes argument expressions sequentially onto the stack.
FinishCallN/FinishCallTos(0o0134,0o0136):- Transfers control to callee entry point.
- Updates
Continuationwith return PC. - Dispatches to callee entry instruction.
3.2 Callee Entry Instructions
Every compiled function begins with an Entry Instruction:
EntryRestNotAccepted(0o0177): Function accepts only fixed positional (required + optional) arguments.EntryRestAccepted(0o0176): Function accepts an arbitrary number of trailing arguments via&rest.
The entry instruction specifies:
MinArgs(bits<7:0>): Number of required arguments (biased by +2).MaxArgs(bits<25:18>): Maximum required + optional arguments (biased by +2).
Arguments Passed vs. Required Matchup:
1. Supplied < MinArgs: Triggers TooFewArguments exception.
2. MinArgs <= Supplied <= MaxArgs: Unsupplied optional arguments are bound to NIL.
3. Supplied > MaxArgs:
- If &rest accepted: Trailing arguments are consed into a list (or stack-allocated list).
- If &rest not accepted: Triggers TooManyArguments exception.
3.3 Push-Apply-Args and Pull-Apply-Args
- When a function call uses
apply, the final argument is a list. push-apply-args: Unpacks list elements directly onto the control stack as individual positional arguments.pull-apply-args: The inverse operation: when a callee accepts&rest, trailing stack arguments are bundled back into a Lisp list structure.
4. Dynamic Variable Binding (Binding Stack)
Ivory implements shallow binding for dynamic (special) variables. When a variable is dynamically rebound using let or progv, its global value cell is overwritten, and its previous value is saved on the Binding Stack.
4.1 Binding Stack Entry Layout
Every dynamic binding creates a 2-word entry on the binding stack (sys:binding-stack-pointer 0o1002):
Word 0: Locative Address of Bound Value Cell
39 38 37 32 31 0
+--+--+-----+------------------------------------------------------------------+
| 0| C| Tag | 32-Bit Memory Address of Value Cell |
+--+--+-----+------------------------------------------------------------------+
^
+-- Bit <38> (Chain Bit): 1 if another binding belongs to the same stack frame.
Word 1: Saved Previous Cell Contents
39 38 37 32 31 0
+-----+-----+------------------------------------------------------------------+
| CDR | Tag | Original Data Payload / Object Reference |
+-----+-----+------------------------------------------------------------------+
4.2 Binding Operations
BindLocative(0o0005): Pushes locative address and current value onto the binding stack, then writes new value into cell.BindLocativeToValue(0o0236): Takes locative and new value from stack, saving previous value.UnbindN(0o0107): Unwinds \(N\) entries from the binding stack, restoring previous contents into each value cell.%RestoreBindingStack(0o0006): Unwinds all bindings back to a specified binding stack pointer checkpoint.
5. Function Return & Value Matchup
Ivory supports Common Lisp multiple-value return semantics natively in hardware:
| Mnemonic | Opcode | Semantics |
|---|---|---|
ReturnSingle | 0o0115 | Fast path: returns 1 value on TOS, unwinds frame, restores Continuation and Control Register. |
ReturnMultiple | 0o0104 | Returns \(N\) values pushed on TOS. Matchup hardware adjusts values according to caller's expectation. |
ReturnKludge | 0o0105 | Low-level primitive: returns arbitrary value blocks (used by trap handlers and FEP). |
TakeValues | 0o0106 | Caller side: consumes and adjusts multiple values into destination stack locations. |
Frame Cleanup:
When a function returns:
- If the frame header indicates active dynamic bindings, hardware or microcode automatically unbinds all associated binding stack entries.
- The caller's
ContinuationandControl Registerare restored fromFP + 0andFP + 1. - Stack pointer
SPis reset to caller's frame top, discarding callee frame.
6. Flavors Generic Functions & Message Passing
Object-oriented programming in Symbolics Genera is built on Flavors. Ivory provides specialized hardware instructions to accelerate message sending:
6.1 Dispatch Instructions
GenericDispatch(0o0052): Dispatches a call to a generic function based on the argument data types.MessageDispatch(0o0053): Sends a message to an instance object.
6.2 Method Lookup Mechanism
- Instance Header: The first word of an instance points to its Flavor descriptor.
- Handler Hash Table:
- Each Flavor maintains a method hash table.
- The message selector symbol is hashed using the Flavor's hash mask.
- If found, the entry points directly to the compiled method function.
- If not found or if the target is not an instance, the CPU traps to
GenericDispatchTrap(0o5114) orMessageDispatchTrap(0o5116).
- Instance Variable Mapping:
- Instance variables are accessed via
PushInstanceVar(0o0110),PopInstanceVar(0o0320), andMovemInstanceVar(0o0321), indexing directly into the instance's storage vector.
- Instance variables are accessed via
7. Stack Groups (Coroutines & Processes)
A Stack Group represents an independent thread of computation (a complete execution context comprising a Control Stack, Binding Stack, and Data Stack). The Genera process scheduler multiplexes active processes by switching stack groups.
7.1 Stack Group State Machine
A stack group exists in one of several lifecycle states:
Active: Currently running on the physical Ivory processor.Resumable: Suspended, waiting to be resumed viastack-group-resume.AwaitingReturn: Suspended in a call to another stack group, awaiting return values.Exhausted: Top-level function has completed.
7.2 Context Switch Sequence
When switching from stack group \(A\) to stack group \(B\):
- Current hardware registers for \(A\) are saved into \(A\)'s stack group descriptor:
SP,FP,LPContinuation(Resume PC)Control RegisterBinding Stack Pointer(0o1002)Catch Block Pointer(0o1003)
- Stack cache contents are flushed/scrolled to memory.
- Hardware registers are reloaded from \(B\)'s stack group descriptor.
- Stack cache is primed with \(B\)'s top frame.
- Execution resumes at \(B\)'s saved
Continuationaddress.