Mezzano Operating System Documentation

repository·master·Indexed 26 days ago

https://github.com/froggey/mezzano

Mezzano is an operating system written in Common Lisp featuring multicore/SMP support, a GUI environment, and various file system implementations including EXT2/3/4 and FAT32. The documentation covers running pre-built images in VirtualBox or QEMU, building from source via MBuild, and advanced system features such as atomic operations (CAS/DCAS), extended defstruct options for memory allocation and slot optimization, and dual-boot configuration using kboot or GRUB2.

Tokens
15.3K
Snippets
18
Records
79
Agent score
82%

What's inside Mezzano

  1. Understand the Compiler Backend Design

    master

    The Mezzano compiler backend processes optimized ASTs into Intermediate Representation (IR) instructions, which are then converted to assembly.

    Key design concepts:

    • Instruction Structure: Instructions are linked via an intrusive doubly-linked list. Basic blocks are implicit, started by a label instruction and ended by a terminator-instruction.
    • Function Entry: The first instruction in any function must be an argument-setup-instruction.
    • Data Flow: Uses virtual-register (vreg) objects. In SSA form, a vreg is defined exactly once. Physical registers (preg) can be used directly, but they cannot be live over basic block boundaries until after register allocation.
    • Lexical Variables: Represented by the lexical-variable class. They are explicitly bound and unbound and are not converted to SSA form to preserve debug lifetime information.
    • Multiple Values: Handled outside the vreg/preg system using target-specific multiple value registers. They can only be live over a small set of instructions.
  2. Understand Mezzano Instances

    master

    Instances are the underlying representation for STRUCTURE-OBJECT, STANDARD-OBJECT, and FUNCALLABLE-STANDARD-OBJECT. An instance is a pointer with the value tag +TAG-OBJECT+ and consists of a header word followed by instance slots.

    Key characteristics:

    • Header Word: Contains GC/spare bits, object tag bits (+OBJECT-TAG-INSTANCE+ or +OBJECT-TAG-FUNCALLABLE-INSTANCE+), and a pointer to the LAYOUT object.
    • Slots: Follow the header and are defined by the instance's specific layout.
    • Funcallable Instances: Differ from normal instances by having two additional hidden slots after the header used for function calling.
  3. Deploy Mezzano image to a partition

    master

    Use the dd command to write the Mezzano image to a specific partition. The command parameters depend on whether you are using a cdrom.iso or a image.raw file, as you must skip the initial partition headers.

    If using cdrom.iso (skips first two partitions):

    sudo dd if=cdrom.iso of=<partition> bs=2048 skip=1635

    If using image.raw:

    sudo dd if=image.raw of=<partition> bs=8192 skip=512
  4. Use Line Editing Commands

    master

    The line editor supports standard navigation and editing commands:

    • C-F or Right-Arrow: Move forward one character.
    • C-B or Left-Arrow: Move backward one character.
    • C-A or Home: Move to the beginning of the line.
    • C-E or End: Move to the end of the line.
    • M-F: Move forward one word.
    • M-B: Move backward one word.
    • M-P or Up-Arrow: Find previous matching history item.
    • M-N or Down-Arrow: Find next matching history item.

    Editing

    • C-D or Delete: Delete the next character.
    • Backspace: Delete the previous character.
    • M-D: Delete the next word.
    • M-Backspace: Delete the previous word.
    • C-K: Delete from the cursor to the end of the line.
    • Tab: Cycle through completions for the current symbol.

    Debugging

    • C-C: Enter the debugger using BREAK.
    • C-G: Invoke the most recent ABORT restart (clears input and returns to prompt).
  5. Run Ansi-Tests

    master

    To run ANSI regression tests, load the test initialization, configure the runtime to handle specific test cases (like disabling certain notes), and execute the tests using regression-test:do-tests.

    To skip a specific test during execution, use: (throw 'rt::*in-test* nil)

    (in-package :cl-user)
    (load (merge-pathnames "ansi-test/init.lsp" (user-homedir-pathname)) :verbose t :print t)
    (rt:disable-note :nil-vectors-are-strings)
    (mapc #'rt:rem-test
          '(cl-test::make-array.23 ; Exhausts memory
            cl-test::make-array.28 ; Stack overflows
            cl-test::print.cons.7 ; Missing circularity detection
            cl-test::print.vector.circle.1 ; Stack overflows
            ;; These all take ages.
            cl-test::find-all-symbols.1
            cl-test::do-all-symbols.1
            cl-test::do-all-symbols.2
            cl-test::do-all-symbols.3
            cl-test::do-all-symbols.4
            cl-test::bignum.float.compare.7
            cl-test::bignum.float.compare.8
            cl-test::rational.double-float.random.compare.1
            cl-test::rational.long-float.random.compare.1
            cl-test::print.vector.random.1
            ))
    ;; Since we're evaluating lots, better to avoid the compiler
    (setf mezzano.internals::*eval-hook* 'mezzano.full-eval:eval-in-lexenv)
    (time (regression-test:do-tests))
  6. Configure GRUB2 to boot Mezzano

    master

    To add Mezzano to the GRUB2 boot menu, add a custom menu entry to /etc/grub.d/40_custom and then regenerate the main GRUB configuration.

    Note: It is recommended to back up /boot/grub/grub2/grub.cfg before modifying it.

    # 1. Add to /etc/grub.d/40_custom
    menuentry 'Mezzano' {
    	multiboot /kboot.bin
    	module /kboot.cfg kboot.cfg
    }
    
    # 2. Update grub configuration
    sudo grub2-mkconfig -o /boot/grub/grub2/grub.cfg
  7. Common Calling Convention (x86-64 and Arm64)

    master

    x86-64 Calling Convention

    • Argument Count: Passed in RCX as a fixnum.
    • First 5 Arguments: Passed in R8, R9, R10, R11, R12.
    • Remaining Arguments: Passed on the stack immediately above the return address.
    • Stack Alignment: The stack pointer must have bit 3 set and bits 2-0 clear on function entry (offset 8 bytes from a 16-byte boundary).

    Arm64 Calling Convention

    • Return Address: Uses a link register; the callee is responsible for pushing it to the stack.
    • Stack Alignment: The stack must always be 16-byte aligned.
    • Arguments: On entry, the stack pointer points at the first stack argument. The first 5 arguments are at sp+0 through sp+32 (increments of 8).
  8. Create a Mezzano disk image

    master

    To create a Mezzano image for use in a dual-boot system, follow these steps:

    1. Boot Mezzano in a virtual machine.
    2. Configure the environment as desired.
    3. In a Lisp listener, run (mezzano.supervisor:snapshot) to save the current state to the virtual disk.
    4. Convert the VMDK to a raw image or build a compressed CD-ROM image.

    To convert a VMDK to a raw image:

    qemu-img convert -O raw mezzano.vmdk Mezzano/tools/kboot/image.raw

    To create a compressed, smaller cdrom.iso (requires kboot toolset installed):

    ./build-native-image
  9. Take a System Snapshot for Persistence

    master

    Mezzano supports whole-system transparent persistence. You can save the current machine state to disk to be restored upon reboot.

    To perform a snapshot:

    1. Run (mezzano.supervisor:snapshot) in a REPL.
    2. Wait for the yellow status light (Blinkenlights) to turn off.
    3. Reboot the system.
    (mezzano.supervisor:snapshot)
  10. Configure kboot for Mezzano dual boot

    master

    To use kboot as a secondary bootloader within a dual-boot system, copy kboot.bin into your /boot directory and create a kboot.cfg file in /boot.

    kboot.cfg allows you to define different boot entries. Common options include:

    • video_mode: Sets the resolution (e.g., lfb:1440x900).
    • mezzano <partition> <options>: Specifies the partition (e.g., hd0,2) and boot modes.
    • video-console: Displays console messages directly on the background window.
    • freestanding: Runs Mezzano in memory without paging or snapshots (useful for read-only media).
    • no-detect: Disables most hardware detection (useful for troubleshooting).
    set "timeout" 5
    
    entry "Mezzano - hardware detection with video console" {
          set "video_mode" "lfb:1440x900"
          mezzano "hd0,2" "video-console"
    }
    
    entry "Mezzano - hardware detection" {
          set "video_mode" "lfb:1440x900"
          mezzano "hd0,2"
    }
    
    entry "Mezzano - freestanding with video console" {
          set "video_mode" "lfb:1440x900"
          mezzano "hd0,2" "freestanding" "no-detect" "video-console"
    }
    
    entry "Mezzano - freestanding" {
          set "video_mode" "lfb:1440x900"
          mezzano "hd0,2" "freestanding"  "no-detect"
    }
  11. Connect to Swank Server

    master

    Mezzano includes Swank 2.24. The Swank server listens on port 4005.

    If running in a virtual machine (e.g., VirtualBox), you must enable port forwarding for port 4005 in your VM settings: Settings -> Network -> Advanced -> Port Forwarding.