#bytecode Region

Planned — design subject to change

This feature is designed but not yet implemented. The syntax and behavior described here represent the target specification.

Purpose

The #bytecode region provides inline assembly for performance-critical or hardware-specific code. Only available in t0 (freestanding/kernel) profile.

tape
#bytecode
fn fast_memcpy(dst: i64, src: i64, len: i64) {
    mov(rsi, src);
    mov(rdi, dst);
    mov(rcx, len);
    rep_movsb();
}

fn outb(port: u16, value: u8) {
    mov(dx, port);
    mov(al, value);
    out(dx, al);
}

Syntax

Inside #bytecode, register names are builtins and instructions are function calls:

tape
fn cli() { cli(); }
fn sti() { sti(); }
fn hlt() { hlt(); }

fn read_cr3() -> u64 {
    mov(rax, cr3);
    ret();
}

Available registers

General purpose: rax, rbx, rcx, rdx, rsi, rdi, rbp, rsp, r8r15

Segment: cs, ds, es, fs, gs, ss

Control: cr0, cr2, cr3, cr4

Sub-registers: al, ah, ax, eax (and equivalents for other registers)

Calling from #code

Functions declared in #bytecode are callable from #code like any other function:

tape
#code
fn init_hardware() {
    cli();
    setup_gdt();
    setup_idt();
    sti();
}

Restrictions

  • Only available with @profile(t0)
  • No automatic register allocation — you manage registers manually
  • No stack frame setup — you’re responsible for the calling convention
  • The compiler does NOT validate instruction operands

Last modified: