SOPHIA OS — kernel, drivers, bootloader and persistent store
Owner: Skye S Mcdade of Lichfield.  Everything here is local: no network, no telemetry.

WHAT IS IN THE BUNDLE
  boot.asm / boot.bin      512-byte MBR boot sector. Loads 64 sectors of kernel to 0x8000.
                           Uses BIOS LBA read, with a per-sector CHS fallback so it also
                           boots from CD/USB floppy emulation.
  kernel.asm / kernel.bin  32 KiB kernel: real mode -> GDT -> 32-bit protected mode.
                           Drivers: VGA text console (scrolling, hardware cursor),
                           8259 PIC remap, 8254 timer at 100 Hz, PS/2 keyboard (IRQ1,
                           shift handling), ATA PIO disk driver (primary master).
  sophia-os.img            16 MiB raw disk image, ready for QEMU or for writing to USB.
  sophia-os.iso            Bootable El Torito CD/USB image.
  sophia-os-live.png       Screenshot: chat, memory and connections being saved.
  sophia-os-after-reboot.png  Screenshot: the same data read back after a full reboot.
  sophia-os-iso-boot.png   Screenshot: booting from the ISO.
  SHA256SUMS.txt           Checksums for everything above.

SHELL COMMANDS
  help ver clear mem uptime who halt
  say <text>        append a line to the chat log (written to disk immediately)
  chat              read the chat log back
  remember <text>   store a memory
  memory            read memories back
  connect <name>    store a device/connection
  links             read connections back
  save              force a flush of all three regions
  wipe              clear the store

PERSISTENT STORE
  Three 512-byte sectors at LBA 64, 65, 66 (chat, memory, connections).
  Each region: bytes 0-3 magic "SOPH", 4-7 length (uint32 LE), 8+ newline-separated text.
  Writes go through the ATA PIO driver with a cache flush, so data survives power loss.
  A CD is read-only: booted from ISO the store reads fine but cannot be written —
  use the raw image or a USB stick for persistence.

RUN IT IN QEMU
  qemu-system-i386 -drive file=sophia-os.img,format=raw,if=ide -m 64
  qemu-system-i386 -cdrom sophia-os.iso -boot d -m 64

WRITE IT TO A REAL USB STICK (this erases the whole stick — check the name twice)
  Linux:   lsblk                                  # find the stick, e.g. /dev/sdb
           sudo umount /dev/sdb*                  # unmount any partitions
           sudo dd if=sophia-os.img of=/dev/sdb bs=4M conv=fsync status=progress
           sync
  macOS:   diskutil list                          # find /dev/diskN
           diskutil unmountDisk /dev/diskN
           sudo dd if=sophia-os.img of=/dev/rdiskN bs=4m
  Windows: use Rufus or balenaEtcher in "DD / raw image" mode with sophia-os.img.

BOOT IT ON A PC
  The kernel is legacy BIOS / MBR. In firmware settings enable Legacy Boot or CSM
  (and disable Secure Boot), then choose the USB stick in the boot menu.
  On UEFI-only machines it will not boot — use QEMU there.

CARRY HER MEMORY BETWEEN THE APP AND THE KERNEL
  In the Sophia app open Kernel Bridge (/kernel-bridge):
    1. Download sophia-store.bin — her newest chat, memory and connections.
    2. sudo dd if=sophia-store.bin of=/dev/sdX bs=512 seek=64 conv=fsync
    3. Boot the stick. 'chat', 'memory' and 'links' show what she brought with her.
    4. After using her on bare metal:
       sudo dd if=/dev/sdX of=sophia-store.bin bs=512 skip=64 count=3
       then load that file back on the Kernel Bridge page.

REBUILD FROM SOURCE
  nasm -f bin boot.asm -o boot.bin
  nasm -f bin kernel.asm -o kernel.bin
  dd if=/dev/zero of=sophia-os.img bs=1M count=16
  dd if=boot.bin of=sophia-os.img conv=notrunc
  dd if=kernel.bin of=sophia-os.img bs=512 seek=1 conv=notrunc
  mkdir -p isoroot && cat boot.bin kernel.bin > isoroot/boot.img
  truncate -s 1474560 isoroot/boot.img
  xorriso -as mkisofs -o sophia-os.iso -b boot.img -V SOPHIA_OS isoroot
