<?xml version="1.0" encoding="UTF-8"?>

<rfc xmlns:xi="http://www.w3.org/2001/XInclude"
     category="exp"
     docName="draft-bellis-unheaded-shim-00"
     ipr="trust200902"
     submissionType="independent"
     xml:lang="en"
     tocInclude="true"
     symRefs="true"
     sortRefs="true"
     version="3">

  <front>
    <title>Shim Pipeline Specification for the Unheaded Protocol Computer</title>

    <seriesInfo name="Internet-Draft" value="draft-bellis-unheaded-shim-00"/>
    <author fullname="Stevie Bellis" initials="S." surname="Bellis">
      <organization>Unheaded</organization>
      <address>
        <email>stevie@bellis.tech</email>
      </address>
    </author>

    <date year="2026" month="March" day="19"/>

    <area>Applications</area>
    <workgroup>Unheaded Kingdom</workgroup>

    <abstract>
      <t>This document specifies the Shim pipeline for the Unheaded Protocol Computer (UPC). The Shim translates MBC (Monad Bytecode) programs into eBPF execution contexts, defines the per-hop processing model, and specifies the tick packet protocol that drives distributed computation across IPv6 network hops. The pipeline implements a four-stage architecture: Assembly, Verification, Loading, and Execution, with integrated support for memory-mapped I/O, framebuffer rendering, and CRC validation.</t>
    </abstract>

    <note removeInRFC="false">
      <name>Status of This Memo</name>
      <t>This Internet-Draft is submitted in full conformance with the provisions of BCP 78 and BCP 79.</t>
      <t>Internet-Drafts are working documents of the Internet Engineering Task Force (IETF). Note that other groups may also distribute working documents as Internet-Drafts. The list of current Internet-Drafts is at https://datatracker.ietf.org/drafts/current/.</t>
      <t>Internet-Drafts are draft documents valid for a maximum of six months and may be updated, replaced, or obsoleted by other documents at any time. It is inappropriate to use Internet-Drafts as reference material or to cite them except as reference to a "work in progress."</t>
      <t>This Internet-Draft will expire on September 18, 2026.</t>
    </note>

    <note removeInRFC="false">
      <name>Copyright Notice</name>
      <t>Copyright (c) 2026 IETF Trust and the persons identified as the document authors. All rights reserved.</t>
      <t>This document is subject to BCP 78 and the IETF Trust's Legal Provisions Relating to IETF Documents (https://trustee.ietf.org/license-info/) in effect on the date of publication of this document. Please review these documents carefully, as they describe your rights and restrictions with respect to this document. Code Components extracted from this document must include Simplified BSD License text as described in Section 4.e of the Trust Legal Provisions and are provided without warranty as described in the Simplified BSD License.</t>
    </note>

  </front>

  <middle>

    <section numbered="true" toc="include">
      <name>Introduction</name>
      <t>The Shim is the execution engine of the Unheaded Protocol Computer (UPC), responsible for translating and executing Monad Bytecode (MBC) programs within eBPF runtime contexts. It forms the critical bridge between the declarative instruction set defined by the MBC ISA and the native eBPF verifier and execution model of the Linux kernel.</t>

      <t>The Shim operates within a four-stage pipeline:</t>
      <ol spacing="normal">
        <li>Assembly: Text MBC programs are assembled into binary images</li>
        <li>Verification: Assembled programs are validated against security and conformance rules</li>
        <li>Loading: Verified programs and supporting data structures are loaded into BPF maps</li>
        <li>Execution: The fetch-decode-execute cycle runs within XDP context, processing tick packets</li>
      </ol>

      <t>This specification defines:</t>
      <ul spacing="normal">
        <li>The binary encoding of MBC programs and instruction formats</li>
        <li>Verification rules enforced before loading and execution</li>
        <li>BPF map structures supporting program state, memory, and I/O</li>
        <li>The tick packet protocol that drives distributed computation</li>
        <li>Memory-mapped I/O semantics for framebuffer and keyboard access</li>
        <li>The Dream Ladder stratification model for conformance levels</li>
      </ul>

      <section numbered="true" toc="include">
        <name>Relationship to Other Specifications</name>
        <t>The Shim pipeline operates in conjunction with several related specifications in accordance with <xref target="RFC8126"/>:</t>
        <ul spacing="normal">
          <li>The Protocol Foundation specification defines the Monad wire format (20-byte fixed header carried in IPv6 Hop-by-Hop options per <xref target="RFC8200"/>), which encodes register state and control flags at each hop</li>
          <li>The MBC ISA specification specifies the MBC instruction set architecture (48 opcodes, 16-register architecture, 32-bit words)</li>
          <li>The Sophia Dictionary specification defines dictionary lookup semantics used during MBC execution</li>
          <li>The Wotan Memory Model specification specifies the BPF map memory model backing the Shim's RAM_MAP and ROM_MAP structures</li>
        </ul>
      </section>
    </section>

    <section numbered="true" toc="include">
      <name>Requirements Language</name>
      <t>The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in BCP 14 <xref target="RFC2119"/> <xref target="RFC8174"/> when, and only when, they appear in all capitals, as shown here.</t>
    </section>

    <section numbered="true" toc="include">
      <name>Pipeline Overview</name>
      <t>The Shim pipeline transforms MBC source code into executable packet processing logic through four sequential stages:</t>

      <artwork type="ascii-art"><![CDATA[
  ┌─────────────────────────────────────────────────────┐
  │ MBC Source Code (Text)                              │
  └──────────────────┬──────────────────────────────────┘
                     │
                     ▼
        ╔════════════════════════════╗
        ║  Stage 1: Assembly         ║
        ║  • Label resolution        ║
        ║  • Instruction encoding    ║
        ║  • Binary image output     ║
        ╚════════════┬═══════════════╝
                     │
                     ▼
  ┌─────────────────────────────────────────────────────┐
  │ Binary Program Image (32-bit words, little-endian)  │
  └──────────────────┬──────────────────────────────────┘
                     │
                     ▼
        ╔════════════════════════════╗
        ║  Stage 2: Verification     ║
        ║  • Opcode whitelist        ║
        ║  • Register range check    ║
        ║  • Immediate range check   ║
        ║  • Branch target check     ║
        ╚════════════┬═══════════════╝
                     │
                     ▼
  ┌─────────────────────────────────────────────────────┐
  │ Verified Program Image                              │
  └──────────────────┬──────────────────────────────────┘
                     │
                     ▼
        ╔════════════════════════════╗
        ║  Stage 3: Loading          ║
        ║  • Create BPF maps         ║
        ║  • Populate ROM_MAP        ║
        ║  • Initialize CPU state    ║
        ║  • Attach XDP program      ║
        ╚════════════┬═══════════════╝
                     │
                     ▼
  ┌─────────────────────────────────────────────────────┐
  │ Loaded Program in BPF Runtime                       │
  └──────────────────┬──────────────────────────────────┘
                     │
                     ▼
        ╔════════════════════════════╗
        ║  Stage 4: Execution        ║
        ║  • Fetch-decode-execute    ║
        ║  • XDP invocation loop     ║
        ║  • Tick packet processing  ║
        ║  • State persistence       ║
        ╚════════════┬═══════════════╝
                     │
                     ▼
  ┌─────────────────────────────────────────────────────┐
  │ Output: Monad state via XDP_TX                      │
  └─────────────────────────────────────────────────────┘
      ]]></artwork>

      <t>Each stage is atomic and idempotent. Programs rejected at Verification are never loaded. Programs that fail CRC validation during Execution emit an Anomaly event but do not execute MBC.</t>
    </section>

    <section numbered="true" toc="include">
      <name>Stage 1: Assembly</name>
      <t>Assembly translates MBC instruction mnemonics into a binary program image.</t>

      <section numbered="true" toc="include">
        <name>Input Format</name>
        <t>MBC assembly is plain text, one instruction per line. Comments begin with '#' and extend to end of line. Blank lines are ignored. Labels are declared with a trailing colon and must appear alone on a line.</t>
        <sourcecode type="asm"><![CDATA[
  # FizzBuzz example
  MOVI r0, 1        # Initialize r0 = 1

  loop:
  ADDI r0, r0, 1    # Increment r0
  JNE r0, 100, loop # Jump if not equal

  MOV r1, r0        # Move result to r1
  HALT              # Stop execution
        ]]></sourcecode>
      </section>

      <section numbered="true" toc="include">
        <name>Binary Encoding</name>
        <t>The output is a sequence of 32-bit words in little-endian byte order. Each instruction encodes to one word with format:</t>
        <artwork type="ascii-art"><![CDATA[
  Bits  31-26  25-20  19-14  13-8   7-2   1-0
  ┌──────────┬──────┬──────┬──────┬────┬──┐
  │ Opcode   │ Dest │ Src1 │ Src2 │Imm │Rsvd│
  │ (6 bits) │(6b)  │(6b)  │(6b)  │(4b)│(2b)│
  └──────────┴──────┴──────┴──────┴────┴──┘
        ]]></artwork>

        <t>Example encoding of MOVI r0, 42:</t>
        <sourcecode><![CDATA[
  Instruction: MOVI r0, 42
  Opcode: 0x0F (MOVI)
  Destination: r0 (0)
  Immediate: 42 (0x2A)

  Binary: 0x0F00002A (little-endian)
  Bytes: 2A 00 00 0F
        ]]></sourcecode>
      </section>

      <section numbered="true" toc="include">
        <name>Label Resolution</name>
        <t>The assembler performs two passes:</t>
        <ol spacing="normal">
          <li>First pass: Record label offsets (word addresses in the program image)</li>
          <li>Second pass: Replace label references in branch instructions with computed offsets</li>
        </ol>
        <t>Label references are resolved as relative word offsets from the branch instruction's position. A label at word address N referenced from instruction at word address M becomes offset (N - M).</t>
      </section>
    </section>

    <section numbered="true" toc="include">
      <name>Stage 2: Verification</name>
      <t>Verification enforces security and correctness constraints before a program is loaded. Programs MUST pass verification or be rejected entirely.</t>

      <section numbered="true" toc="include">
        <name>Opcode Whitelist</name>
        <t>Only 48 opcodes are valid. The verifier MUST reject any program containing an opcode not in the following list:</t>
        <sourcecode><![CDATA[
  Valid opcodes:
  0x00 HALT      0x01 NOP       0x02 MOV       0x03 MOVI
  0x04 ADD       0x05 ADDI      0x06 SUB       0x07 SUBI
  0x08 MUL       0x09 MULI      0x0A DIV       0x0B DIVI
  0x0C MOD       0x0D MODI      0x0E AND       0x0F OR
  0x10 XOR       0x11 NOT       0x12 SHL       0x13 SHR
  0x14 LD        0x15 LDI       0x16 ST        0x17 STI
  0x18 JMP       0x19 JEQ       0x1A JNE       0x1B JLT
  0x1C JGT       0x1D CALL      0x1E RET       0x1F PUSH
  0x20 POP       0x21 PUSHI     0x22 SYSCALL   0x23 LDMAP
  0x24 STMAP     0x25 DICTLOOKUP 0x26 CRC16   0x27 FLAG
  0x28 RFLAG     0x29 RESERVED  0x2A RESERVED  0x2B RESERVED
  0x2C RESERVED  0x2D RESERVED  ...
        ]]></sourcecode>
      </section>

      <section numbered="true" toc="include">
        <name>Register Range Validation</name>
        <t>All register references MUST be in range [0, 15]. The verifier MUST reject programs with register fields containing values greater than 15.</t>
      </section>

      <section numbered="true" toc="include">
        <name>Immediate Value Range Validation</name>
        <t>Immediate values occupy 4 bits in the instruction encoding. MOVI and ADDI instructions with immediate values larger than 15 MUST be rejected at verification time. Programs requiring larger immediates MUST use multi-instruction sequences or load from ROM_MAP.</t>
      </section>

      <section numbered="true" toc="include">
        <name>Branch Target Validation</name>
        <t>Branch instructions (JMP, JEQ, JNE, JLT, JGT) MUST have target offsets that:</t>
        <ul spacing="normal">
          <li>Point to valid instruction boundaries (word-aligned addresses within the program image)</li>
          <li>Do not exceed the program image bounds</li>
          <li>Do not form backward branches with unbounded depth (prevent infinite loops without instruction limit enforcement)</li>
        </ul>
      </section>
    </section>

    <section numbered="true" toc="include">
      <name>Stage 3: Loading</name>
      <t>Loading creates the runtime BPF map structures and initializes program state. All maps MUST be created before the program begins execution.</t>

      <section numbered="true" toc="include">
        <name>BPF Map Structures</name>

        <section numbered="true" toc="include">
          <name>ROM_MAP</name>
          <t>ROM_MAP stores the immutable program image and constant data.</t>
          <ul spacing="normal">
            <li>Type: BPF_MAP_TYPE_ARRAY</li>
            <li>Entries: 262,144 (2^18)</li>
            <li>Value size: 4 bytes per entry</li>
            <li>Total size: 1 MiB</li>
            <li>Access: Read-only during execution</li>
          </ul>
          <t>Verified program image is populated into ROM_MAP starting at index 0. Unused entries are zero-filled.</t>
        </section>

        <section numbered="true" toc="include">
          <name>RAM_MAP</name>
          <t>RAM_MAP provides the flat address space for data memory and dynamic state.</t>
          <ul spacing="normal">
            <li>Type: BPF_MAP_TYPE_ARRAY</li>
            <li>Entries: 16,777,216 (2^24)</li>
            <li>Value size: 4 bytes per entry</li>
            <li>Total size: 64 MiB</li>
            <li>Access: Read-write during execution</li>
          </ul>
          <t>RAM_MAP is initialized to zero. Memory layout is defined in Section 7 (Memory-Mapped I/O).</t>
        </section>

        <section numbered="true" toc="include">
          <name>CPU_MAP</name>
          <t>CPU_MAP maintains per-flow CPU state across distributed hops.</t>
          <ul spacing="normal">
            <li>Type: BPF_MAP_TYPE_HASH</li>
            <li>Max entries: 256</li>
            <li>Value size: 128 bytes (MbcCpuState structure)</li>
            <li>Key: Flow tuple (source, destination, flow label)</li>
          </ul>
          <t>MbcCpuState structure contains:</t>
          <ul spacing="normal">
            <li>r0-r15: 16 x 32-bit general-purpose registers</li>
            <li>pc: 32-bit program counter (word address)</li>
            <li>sp: 32-bit stack pointer (byte address)</li>
            <li>flags: 16-bit condition code flags</li>
            <li>ticks: 32-bit execution tick counter</li>
            <li>reserved: 8 bytes for future extension</li>
          </ul>
        </section>

        <section numbered="true" toc="include">
          <name>SCREEN_MAP</name>
          <t>SCREEN_MAP provides memory-mapped framebuffer access.</t>
          <ul spacing="normal">
            <li>Type: BPF_MAP_TYPE_ARRAY</li>
            <li>Entries: 64,000</li>
            <li>Value size: 1 byte per entry</li>
            <li>Total size: 64 KiB</li>
            <li>Layout: 320x200 pixels, 8-bit palette indices</li>
          </ul>
        </section>

        <section numbered="true" toc="include">
          <name>KBD_MAP</name>
          <t>KBD_MAP provides memory-mapped keyboard input.</t>
          <ul spacing="normal">
            <li>Type: BPF_MAP_TYPE_ARRAY</li>
            <li>Entries: 8</li>
            <li>Value size: 4 bytes per entry</li>
            <li>Total size: 32 bytes</li>
            <li>Layout: Bitmask of 256 key states (1 bit per key)</li>
          </ul>
        </section>

        <section numbered="true" toc="include">
          <name>Additional Maps</name>
          <t>The following maps support extended functionality:</t>
          <ul spacing="normal">
            <li>TTY_MAP: Terminal I/O ring buffer</li>
            <li>PROC_TABLE: Process/thread state management</li>
            <li>SCHED_STATE: Scheduler state (Level 3+ feature)</li>
            <li>TLB_MAP: Virtual memory translation cache (Level 3+ feature)</li>
            <li>COMPUTE_EVENTS: Event log for anomalies and diagnostics</li>
          </ul>
        </section>
      </section>

      <section numbered="true" toc="include">
        <name>Loading Sequence</name>
        <ol spacing="normal">
          <li>Create all BPF maps in kernel</li>
          <li>Populate ROM_MAP with verified program image</li>
          <li>Initialize CPU_MAP with default CPU state (all registers zero, pc=0, sp=0, flags=0)</li>
          <li>Zero-fill RAM_MAP</li>
          <li>Attach XDP program to network interface</li>
          <li>Enable the program for packet processing</li>
        </ol>
      </section>
    </section>

    <section numbered="true" toc="include">
      <name>Stage 4: Execution</name>
      <t>Execution implements the fetch-decode-execute cycle within XDP context, processing one instruction per invocation up to a 256-instruction limit.</t>

      <section numbered="true" toc="include">
        <name>Fetch-Decode-Execute Cycle</name>
        <artwork type="ascii-art"><![CDATA[
  Loop:
  1. Fetch: Read instruction from ROM[pc]
  2. Decode: Parse opcode and operand fields
  3. Execute: Perform operation, update registers/memory
  4. Increment: pc += 1
  5. Check limit: if ticks >= 256 or HALT, exit loop
  6. Else: goto Loop
        ]]></artwork>
      </section>

      <section numbered="true" toc="include">
        <name>Instruction Limit and BPF Verifier Compliance</name>
        <t>Each XDP invocation MUST execute at most 256 instructions. This limit:</t>
        <ul spacing="normal">
          <li>Prevents CPU exhaustion attacks</li>
          <li>Ensures bounded execution time</li>
          <li>Complies with BPF verifier's loop detection requirements</li>
          <li>Enables predictable per-hop processing latency</li>
        </ul>
        <t>If an instruction limit is reached without HALT, the program suspends and resumes at the next tick packet. PC and register state persist via CPU_MAP across ticks.</t>
      </section>

      <section numbered="true" toc="include">
        <name>State Persistence</name>
        <t>Program state persists across tick packets via BPF maps:</t>
        <ul spacing="normal">
          <li>CPU_MAP: PC, registers, flags persist across ticks</li>
          <li>RAM_MAP: Memory contents persist across ticks</li>
          <li>SCREEN_MAP: Framebuffer contents persist across ticks</li>
        </ul>
        <t>State is keyed by flow tuple (source IP, destination IP, flow label). Different flows maintain independent execution contexts.</t>
      </section>
    </section>

    <section numbered="true" toc="include">
      <name>Tick Packet Protocol</name>
      <t>Tick packets are IPv6 packets <xref target="RFC8200"/> carrying Monad state and driving distributed computation across hops, with Shim programs verified against the BPF instruction set defined in <xref target="RFC9669"/>.</t>

      <section numbered="true" toc="include">
        <name>Packet Structure</name>
        <t>A tick packet consists of:</t>
        <ol spacing="normal">
          <li>IPv6 Fixed Header (40 bytes)</li>
          <li>Hop-by-Hop Options Header (24 bytes, containing Monad register file)</li>
          <li>Payload (variable, application-specific data)</li>
        </ol>

        <artwork type="ascii-art"><![CDATA[
  ┌─────────────────────────────────┐
  │ IPv6 Fixed Header (40 B)        │
  │ • Version (4b)                  │
  │ • Traffic Class (8b)            │
  │ • Flow Label (20b)              │
  │ • Payload Length (16b)          │
  │ • Next Header (8b) = 0 (HbH)    │
  │ • Hop Limit (8b)                │
  │ • Source Address (128b)         │
  │ • Destination Address (128b)    │
  └─────────────────────────────────┘
           │
           ▼
  ┌─────────────────────────────────┐
  │ Hop-by-Hop Options (24 B)       │
  │ • Next Header (8b)              │
  │ • Hdr Ext Len (8b) = 2          │
  │ • Padding (16b)                 │
  │ • Option Type: 0x3E (Monad)     │
  │ • Option Data Len (8b) = 20     │
  │ • Monad Register File (20 B)    │
  │   (per draft-bellis-foundation) │
  └─────────────────────────────────┘
           │
           ▼
  ┌─────────────────────────────────┐
  │ Payload (variable)              │
  │ Application-specific data       │
  └─────────────────────────────────┘
        ]]></artwork>
      </section>

      <section numbered="true" toc="include">
        <name>Processing Pipeline</name>
        <ol spacing="normal">
          <li>Packet arrives at ingress interface</li>
          <li>XDP program extracts Monad state from HbH option</li>
          <li>Load/initialize CPU_MAP entry from Monad state</li>
          <li>Validate Monad CRC-16/CCITT (MUST reject if invalid)</li>
          <li>Execute MBC program (up to 256 instructions)</li>
          <li>Recompute Monad CRC-16/CCITT</li>
          <li>Write updated Monad state to packet HbH option</li>
          <li>Return XDP_TX (bounce packet to next hop or originating interface)</li>
        </ol>
      </section>

      <section numbered="true" toc="include">
        <name>Tick Rates</name>
        <t>Tick packet generation rates vary by operational mode:</t>
        <ul spacing="normal">
          <li>LOCAL mode (single-hop loopback): 35 Hz (28 ms between ticks)</li>
          <li>DISTRIBUTED mode (multi-hop propagation): ~1 kHz (1 ms between ticks, governed by network propagation)</li>
        </ul>
        <t>Tick rate is controlled by application logic, not the Shim itself. The Shim simply processes each arriving tick packet up to its 256-instruction limit.</t>
      </section>
    </section>

    <section numbered="true" toc="include">
      <name>Memory-Mapped I/O</name>
      <t>The Shim provides a unified 32-bit flat address space with reserved regions for memory-mapped I/O.</t>

      <section numbered="true" toc="include">
        <name>Physical Address Map</name>
        <artwork type="ascii-art"><![CDATA[
  Address Range          Size    Device                  Access
  ─────────────────────────────────────────────────────────────
  0x0000_0000-0x0003_FFFF  256 KB  ROM                     R
  0x0004_0000-0x0006_7FFF  160 KB  Reserved                -
  0x0006_8000-0x0006_8FFF  4 KB    Keyboard (KBD_MAP)      R
  0x0006_9000-0x0006_FFFF  28 KB   Reserved                -
  0x0007_0000-0x0007_FFFF  64 KB   Framebuffer             R/W
  0x0008_0000-0xFFFF_FFFF  4GB -   RAM (RAM_MAP)           R/W
        ]]></artwork>
      </section>

      <section numbered="true" toc="include">
        <name>Keyboard Access (0x0006_8000)</name>
        <t>Keyboard state is exposed as an 8-entry array of 32-bit values, where each bit represents one key state (1 = pressed, 0 = released). Total of 256 keys supported.</t>
        <sourcecode type="asm"><![CDATA[
  LD r0, 0x68000    # Load keyboard state word 0
  LDI r1, 1         # Shift amount for key 1 (ESC)
  SHR r0, r0, r1    # Shift right by 1
  AND r0, r0, 1     # Mask for single bit
  # r0 now contains ESC key state (1 if pressed, 0 if not)
        ]]></sourcecode>
      </section>

      <section numbered="true" toc="include">
        <name>Framebuffer Access (0x0007_0000)</name>
        <t>The framebuffer is a 320x200 pixel display with 8-bit palette indices. Pixel (x, y) is stored at byte address 0x70000 + (y * 320) + x.</t>
        <sourcecode type="asm"><![CDATA[
  # Write color 42 to pixel (x=100, y=50)
  MOVI r0, 100      # x coordinate
  MOVI r1, 50       # y coordinate

  # Calculate offset: y * 320 + x
  MULI r2, r1, 320  # r2 = y * 320
  ADD r2, r2, r0    # r2 += x

  # Add base address
  ADDI r2, r2, 0x70000

  # Write color value
  MOVI r3, 42       # Color index
  ST r2, r3         # Store at calculated address
        ]]></sourcecode>
      </section>

      <section numbered="true" toc="include">
        <name>TTY/Console I/O (0x0007_F000 – 0x0007_FFFF)</name>
        <t>Ring buffer for terminal output. Write operations enqueue characters; read operations drain the queue.</t>
      </section>
    </section>

    <section numbered="true" toc="include">
      <name>Framebuffer Specification</name>
      <t>The framebuffer is a 320x200 pixel display with scanline-major layout.</t>

      <section numbered="true" toc="include">
        <name>Dimensions and Layout</name>
        <ul spacing="normal">
          <li>Width: 320 pixels</li>
          <li>Height: 200 scanlines</li>
          <li>Color depth: 8-bit palette index (256 colors)</li>
          <li>Scanline stride: 320 bytes</li>
          <li>Total size: 64 KiB</li>
        </ul>
      </section>

      <section numbered="true" toc="include">
        <name>Pixel Address Calculation</name>
        <t>To write a pixel at coordinate (x, y):</t>
        <sourcecode><![CDATA[
  address = 0x70000 + (y * 320) + x
        ]]></sourcecode>
        <t>Constraints:</t>
        <ul spacing="normal">
          <li>0 ≤ x ≤ 319</li>
          <li>0 ≤ y ≤ 199</li>
          <li>Out-of-bounds writes are silently dropped by the BPF verifier</li>
        </ul>
      </section>

      <section numbered="true" toc="include">
        <name>Access Methods</name>
        <ul spacing="normal">
          <li>STB (single-byte write): ST instruction writes one pixel at a time (slowest, most precise)</li>
          <li>SYS_DRAW_FRAME (bulk copy): Syscall that copies entire 64 KiB buffer to framebuffer in one operation (fastest, for scene rendering)</li>
        </ul>
      </section>
    </section>

    <section numbered="true" toc="include">
      <name>Dream Ladder Feature Stratification</name>
      <t>The Shim defines conformance levels that implementations must support, organized as a stratified ladder.</t>

      <section numbered="true" toc="include">
        <name>Conformance Levels</name>

        <section numbered="true" toc="include">
          <name>Level 0: Microcode (Required)</name>
          <t>Foundation layer providing:</t>
          <ul spacing="normal">
            <li>Monad wire format (20-byte HbH option) with CRC-16/CCITT validation</li>
            <li>Sophia dictionary lookups during instruction execution</li>
            <li>XDP packet processing model</li>
          </ul>
          <t>Conformance: All implementations MUST support Level 0.</t>
        </section>

        <section numbered="true" toc="include">
          <name>Level 1: Digital (Required)</name>
          <t>Instruction execution layer providing:</t>
          <ul spacing="normal">
            <li>Full MBC instruction set (48 opcodes)</li>
            <li>16-register architecture (r0-r15)</li>
            <li>32-bit word operations</li>
            <li>Arithmetic, logic, and control flow instructions (no memory operations)</li>
            <li>256-instruction limit per tick</li>
          </ul>
          <t>Conformance: All implementations MUST support Level 1.</t>
        </section>

        <section numbered="true" toc="include">
          <name>Level 2: Mechanical (Required)</name>
          <t>Memory operations layer providing:</t>
          <ul spacing="normal">
            <li>RAM_MAP and ROM_MAP (64 MiB + 1 MiB flat address space)</li>
            <li>LD/ST instructions for memory access</li>
            <li>CPU_MAP for state persistence across ticks</li>
            <li>Level 0 and 1 features</li>
          </ul>
          <t>Conformance: All implementations MUST support Level 2.</t>
        </section>

        <section numbered="true" toc="include">
          <name>Level 2a: Memory I/O (Recommended)</name>
          <t>Memory-mapped I/O layer providing:</t>
          <ul spacing="normal">
            <li>Framebuffer (320x200, 8-bit palette) at 0x70000</li>
            <li>Keyboard input at 0x68000</li>
            <li>TTY console at 0x7F000</li>
            <li>All Level 0-2 features</li>
          </ul>
          <t>Conformance: Implementations SHOULD support Level 2a. Level 2a enables interactive applications (games, demos, interactive programs).</t>
        </section>

        <section numbered="true" toc="include">
          <name>Level 3: Interrupts and Exceptions (Optional)</name>
          <t>Advanced features for future extension:</t>
          <ul spacing="normal">
            <li>Hardware interrupt handling</li>
            <li>Exception handling and recovery</li>
            <li>Trap vector dispatch</li>
          </ul>
          <t>Conformance: Level 3 is OPTIONAL. Implementations may define their own Level 3 features.</t>
        </section>

        <section numbered="true" toc="include">
          <name>Level 4: Scheduling and Multitasking (Optional)</name>
          <t>Process and thread management:</t>
          <ul spacing="normal">
            <li>PROC_TABLE for process state</li>
            <li>SCHED_STATE for scheduler decisions</li>
            <li>Preemptive multitasking</li>
          </ul>
          <t>Conformance: Level 4 is OPTIONAL.</t>
        </section>

        <section numbered="true" toc="include">
          <name>Level 5+: Virtual Memory, Syscalls, Filesystem (Future)</name>
          <t>Reserved for future extension. Currently not defined.</t>
        </section>
      </section>

      <section numbered="true" toc="include">
        <name>Conformance Declaration</name>
        <t>Implementations MUST declare which levels they support. A conforming implementation MUST support a contiguous range of levels starting from Level 0. For example:</t>
        <ul spacing="normal">
          <li>"Level 0-2": Supports Microcode, Digital, and Mechanical layers</li>
          <li>"Level 0-2a": Supports Mechanical plus Memory I/O</li>
          <li>"Level 0-4": Supports full multitasking stack</li>
        </ul>
        <t>An implementation claiming Level N support MUST also support all levels 0 through N-1.</t>
      </section>
    </section>

    <section numbered="true" toc="include">
      <name>CRC Validation Ordering</name>
      <t>CRC-16/CCITT validation ensures that register state has not been corrupted during network transmission.</t>

      <section numbered="true" toc="include">
        <name>Pre-Execution Validation</name>
        <t>When a tick packet arrives, the Shim MUST:</t>
        <ol spacing="normal">
          <li>Extract Monad state from IPv6 HbH option</li>
          <li>Validate CRC-16/CCITT of Monad state</li>
          <li>If CRC is invalid: emit an Anomaly event to COMPUTE_EVENTS map and DO NOT execute MBC</li>
          <li>If CRC is valid: proceed to stage 4 execution</li>
        </ol>
        <t>This ensures corrupted state never affects program execution.</t>
      </section>

      <section numbered="true" toc="include">
        <name>Post-Execution Recomputation</name>
        <t>After MBC execution completes (whether via HALT or 256-instruction limit), the Shim MUST:</t>
        <ol spacing="normal">
          <li>Recompute CRC-16/CCITT of the updated register state</li>
          <li>Write the updated Monad state with new CRC into the outgoing packet's HbH option</li>
          <li>Return XDP_TX to transmit the packet</li>
        </ol>
        <t>This ensures correct state propagates to the next hop.</t>
      </section>

      <section numbered="true" toc="include">
        <name>Anomaly Event Format</name>
        <t>When CRC validation fails, an Anomaly event is written to COMPUTE_EVENTS with structure:</t>
        <ul spacing="normal">
          <li>timestamp: 64-bit Unix nanoseconds</li>
          <li>event_type: 8-bit code (0x01 = CRC_FAILED)</li>
          <li>flow_tuple: Source IP, Dest IP, Flow Label (for correlation)</li>
          <li>monad_state: Copy of corrupted Monad state</li>
          <li>expected_crc: Expected CRC value</li>
          <li>computed_crc: Computed CRC value</li>
        </ul>
      </section>
    </section>

    <section numbered="true" toc="include">
      <name>IANA Considerations</name>
      <t>This specification requests creation of three IANA registries to support interoperability and future standardization.</t>

      <section numbered="true" toc="include">
        <name>Shim Pipeline Stage Registry</name>
        <t>Registry Name: Unheaded Shim Pipeline Stages</t>
        <t>Range: 0-255</t>
        <t>Initial assignments:</t>
        <ul spacing="normal">
          <li>1: Assembly</li>
          <li>2: Verification</li>
          <li>3: Loading</li>
          <li>4: Execution</li>
        </ul>
      </section>

      <section numbered="true" toc="include">
        <name>BPF Map Type Registry for UPC</name>
        <t>Registry Name: Unheaded BPF Map Types</t>
        <t>Range: 0-255</t>
        <t>Initial assignments:</t>
        <ul spacing="normal">
          <li>1: ROM_MAP (read-only program image)</li>
          <li>2: RAM_MAP (read-write memory)</li>
          <li>3: CPU_MAP (register state)</li>
          <li>4: SCREEN_MAP (framebuffer)</li>
          <li>5: KBD_MAP (keyboard input)</li>
          <li>6: TTY_MAP (terminal output)</li>
          <li>7: PROC_TABLE (process state)</li>
          <li>8: SCHED_STATE (scheduler state)</li>
          <li>9: TLB_MAP (virtual memory)</li>
          <li>10: COMPUTE_EVENTS (event log)</li>
        </ul>
      </section>

      <section numbered="true" toc="include">
        <name>Dream Ladder Level Registry</name>
        <t>Registry Name: Unheaded Dream Ladder Levels</t>
        <t>Range: 0-7</t>
        <t>Initial assignments:</t>
        <ul spacing="normal">
          <li>0: Microcode (required)</li>
          <li>1: Digital (required)</li>
          <li>2: Mechanical (required)</li>
          <li>2a: Memory I/O (recommended)</li>
          <li>3: Interrupts and Exceptions (optional)</li>
          <li>4: Scheduling and Multitasking (optional)</li>
          <li>5-7: Reserved for future use</li>
        </ul>
      </section>
    </section>

    <section numbered="true" toc="include">
      <name>Security Considerations</name>

      <section numbered="true" toc="include">
        <name>Primary Security Boundary: eBPF Verifier</name>
        <t>The eBPF verifier is the primary security boundary. All MBC execution occurs within eBPF context, subject to kernel verification rules following principles established in <xref target="RFC9000"/> for transport reliability:</t>
        <ul spacing="normal">
          <li>Memory access must be in-bounds (BPF map bounds enforce this)</li>
          <li>Loops must be bounded (256-instruction limit enforces this)</li>
          <li>Privilege escalation is not possible (XDP context isolation enforces this)</li>
        </ul>
      </section>

      <section numbered="true" toc="include">
        <name>CPU Exhaustion Prevention</name>
        <t>The 256-instruction limit per tick prevents malicious programs from consuming excessive CPU resources. Programs exceeding this limit are suspended and resume at the next tick. Over a period of N ticks, the maximum total instructions executed is 256 * N, providing predictable resource consumption.</t>
      </section>

      <section numbered="true" toc="include">
        <name>Memory Access Control</name>
        <t>BPF maps provide bounds checking:</t>
        <ul spacing="normal">
          <li>ROM_MAP: Out-of-bounds reads return zero</li>
          <li>RAM_MAP: Out-of-bounds writes are silently dropped</li>
          <li>SCREEN_MAP: Out-of-bounds pixel writes are silently dropped</li>
        </ul>
        <t>The kernel enforces all bounds checks; the Shim does not need to replicate this.</t>
      </section>

      <section numbered="true" toc="include">
        <name>Packet Leakage Prevention</name>
        <t>All Shim processing returns XDP_TX (bounce packet to sender or next hop). Return codes XDP_DROP and XDP_PASS are never used, preventing accidental packet leakage into the host stack or transmission to unintended recipients.</t>
      </section>

      <section numbered="true" toc="include">
        <name>Tick Packet Injection Trust Model</name>
        <t>Any node on the network path can inject tick packets. The Shim does not authenticate the origin of tick packets. This is an architectural assumption: use network ACLs and IPSec if authentication is required. The Shim's responsibility is to:</t>
        <ul spacing="normal">
          <li>Validate CRC to detect corruption (but not forgery)</li>
          <li>Process only valid, well-formed MBC instructions</li>
          <li>Prevent execution of out-of-spec opcodes</li>
        </ul>
      </section>

      <section numbered="true" toc="include">
        <name>Register State Confidentiality</name>
        <t>Monad register contents are visible in plaintext at each hop (in the IPv6 HbH option). There is no confidentiality for register state. If confidentiality is required, apply TLS or IPSec encryption at a layer above the Shim.</t>
      </section>

      <section numbered="true" toc="include">
        <name>Verification as a Security Gate</name>
        <t>The Verification stage MUST reject programs with:</t>
        <ul spacing="normal">
          <li>Invalid opcodes (prevents execution of undefined instructions)</li>
          <li>Out-of-range registers (prevents register field corruption)</li>
          <li>Out-of-range immediates (prevents encoding errors)</li>
          <li>Invalid branch targets (prevents control flow attacks)</li>
        </ul>
        <t>Programs that fail verification MUST NEVER be loaded. No exceptions.</t>
      </section>
    </section>

  </middle>

  <back>

    <references>
      <name>Normative References</name>
      <reference anchor="RFC2119" target="https://www.rfc-editor.org/info/rfc2119">
        <front>
          <title>Key words for use in RFCs to Indicate Requirement Levels</title>
          <author initials="S." surname="Bradner"/>
          <date year="1997" month="March"/>
        </front>
        <seriesInfo name="BCP" value="14"/>
        <seriesInfo name="RFC" value="2119"/>
      </reference>
      <reference anchor="RFC8174" target="https://www.rfc-editor.org/info/rfc8174">
        <front>
          <title>Ambiguity of Uppercase vs Lowercase in RFC 2119 Key Words</title>
          <author initials="B." surname="Leiba"/>
          <date year="2017" month="May"/>
        </front>
        <seriesInfo name="BCP" value="14"/>
        <seriesInfo name="RFC" value="8174"/>
      </reference>
      <reference anchor="RFC8200" target="https://www.rfc-editor.org/info/rfc8200">
        <front>
          <title>Internet Protocol, Version 6 (IPv6) Specification</title>
          <author initials="S." surname="Deering"/>
          <author initials="R." surname="Hinden"/>
          <date year="2017" month="July"/>
        </front>
        <seriesInfo name="RFC" value="8200"/>
      </reference>
      <reference anchor="RFC8126" target="https://www.rfc-editor.org/info/rfc8126">
        <front>
          <title>Guidelines for Writing an IANA Considerations Section in RFCs</title>
          <author initials="M." surname="Cotton"/>
          <author initials="B." surname="Leiba"/>
          <author initials="T." surname="Narten"/>
          <date year="2017" month="June"/>
        </front>
        <seriesInfo name="BCP" value="26"/>
        <seriesInfo name="RFC" value="8126"/>
      </reference>
      <reference anchor="RFC9669" target="https://www.rfc-editor.org/info/rfc9669">
        <front>
          <title>BPF Instruction Set Architecture (ISA)</title>
          <author fullname="D. Thaler" initials="D." role="editor" surname="Thaler"/>
          <date year="2024" month="October"/>
        </front>
        <seriesInfo name="RFC" value="9669"/>
        <seriesInfo name="DOI" value="10.17487/RFC9669"/>
      </reference>
    </references>

    <references>
      <name>Informative References</name>
      <reference anchor="RFC9000" target="https://www.rfc-editor.org/info/rfc9000">
        <front>
          <title>QUIC: A UDP-Based Multiplexed and Secure Transport</title>
          <author initials="J." surname="Iyengar"/>
          <author initials="M." surname="Thomson"/>
          <date year="2021" month="May"/>
        </front>
        <seriesInfo name="RFC" value="9000"/>
      </reference>
    </references>

  </back>

</rfc>
