Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Memory model

The MB8 VM exposes a single 64 KiB address space. All reads and writes go through the bus (crates/mb8/src/dev/bus.rs), which forwards them to RAM, ROM, or an MMIO device based on the address range.

Layout

RangeSizeDescription
0x00000xBFFF48 KiBRAM
0xC0000xDFFF8 KiBReserved MMIO (not wired yet)
0xE0000xEFFF4 KiBROM
0xF0000xF0FF256 BGPU registers
0xF1000xF1FF256 BKeyboard registers
0xF2000xF3FF512 BDisk registers and buffer
0xF4000xFFFF3072 BReserved MMIO (not wired yet)

The bus rejects the reserved regions with unimplemented!().

Bus

  • CPU memory accesses always call into the bus, which in turn calls the matching device read/write.
  • Devices own their buffers; the bus itself does not store data.

RAM (crates/mb8/src/dev/ram.rs)

  • Plain byte-addressable memory. Writes update the backing array; reads return what was last written.
  • RAM_SIZE = 0xC000. The stack grows downward (STACK_TOP = 0xBFFF, STACK_BOTTOM = 0xBF00).

ROM (crates/mb8/src/dev/rom.rs)

  • Backing store for program code (ROM_SIZE = 0x1000).
  • The device currently accepts writes from the bus, but programs should not rely on mutating ROM; this may be blocked in the future. ROM is meant to hold the kernel/boot image.

GPU (crates/mb8/src/dev/gpu.rs)

  • Registers live at 0xF000 (offsets relative to that base):
    • 0x0000 — mode register. 0x00 = off, 0x01 = TTY.
    • 0x0001 — TTY data register. When mode is TTY, each write pushes a character to the screen and advances the cursor.
  • Reading 0x0000 returns the current mode. Other reads are currently unimplemented.

Keyboard (crates/mb8/src/dev/keyboard.rs)

  • Registers at 0xF100 (offsets relative to that base):
    • 0x00STATUS. Returns 1 when keys are queued, otherwise 0.
    • 0x01DATA. Reading pops the next key code from the queue; returns 0 when empty.
  • Writes are ignored.

Disk (crates/mb8/src/dev/disk.rs)

  • Registers at 0xF200 (offsets relative to that base):
    • 0x0000BLOCK number to operate on.
    • 0x0001CMD (0x00 no-op, 0x01 read, 0x02 write).
    • 0x00020x0102 — 256-byte disk buffer used for reads/writes.
  • CMD operations move data between the internal image and the buffer; buffer reads/writes go directly to the 256-byte window.