Home /Modules/cpu/SLBootloader.sleela

SLBootloader.sleela

lib/cpu/SLBootloader.sleela · 84 line(s) · sleela

<< lib/cpu/SLBootloader.sleela
   SLeeLa Standard Library Definition.
   Definition: Defines SLBootloader — the firmware/boot sequence that runs on
     the CPU's boot core after power-on. It reads the kernel image from the boot
     disk into main memory, sets the boot core's entry point to the kernel, and
     hands off control. This is the bridge from bare hardware (SLCPU) to the OS
     (SLKernel).
   
   Family: cpu. Composes SLCPU, SLDiskDriver, SLRAM. >>
#sleela 2.5
material;
class SLBootloader {
  < ---- Descriptive metadata (version 1.11 nested-friendly accessors) ---- >
  << Eleven catalogued attributes with getter/setter pairs, so a GUI, loader,
     or catalog can read and (where appropriate) override this record.
     Values are faithful to the subject's real origin where publicly known. >>
  String metaVersion = "1.0.0";
  int metaId = 10202;
  String metaAuthor = "Kiro Agent";
  String metaDate = "2026-10-16";
  String metaCopyright = "SLeeLa project";
  String metaTrademark = "none";
  String metaCorporation = "none";
  < metaOrigin: National | <nation> | International | Galactic >
  String metaOrigin = "International";
  String metaBirthDate = "2026-10-06";
  < metaScienceRating: maturity/robustness on a 1..10 scale >
  int metaScienceRating = 9;
  < metaNationalSchedule: a real, citable instrument or "none" >
  String metaNationalSchedule = "none";

  String getMetaVersion() { return metaVersion; }
  void setMetaVersion(String v) { metaVersion = v; }
  int getMetaId() { return metaId; }
  void setMetaId(int v) { metaId = v; }
  String getAuthor() { return metaAuthor; }
  void setAuthor(String v) { metaAuthor = v; }
  String getDate() { return metaDate; }
  void setDate(String v) { metaDate = v; }
  String getCopyright() { return metaCopyright; }
  void setCopyright(String v) { metaCopyright = v; }
  String getTrademark() { return metaTrademark; }
  void setTrademark(String v) { metaTrademark = v; }
  String getCorporation() { return metaCorporation; }
  void setCorporation(String v) { metaCorporation = v; }
  String getOrigin() { return metaOrigin; }
  void setOrigin(String v) { metaOrigin = v; }
  String getBirthDate() { return metaBirthDate; }
  void setBirthDate(String v) { metaBirthDate = v; }
  int getScienceRating() { return metaScienceRating; }
  void setScienceRating(int v) { metaScienceRating = v; }
  String getNationalSchedule() { return metaNationalSchedule; }
  void setNationalSchedule(String v) { metaNationalSchedule = v; }
  SLCPU cpu;
  SLDiskDriver boot;
  SLRAM memory;
  int kernelLoadAddr;
  int kernelBlocks;
  int booted;

  void configure(SLCPU processor, SLDiskDriver bootDisk, SLRAM ram) {
    cpu = processor; boot = bootDisk; memory = ram;
    kernelLoadAddr = 0; kernelBlocks = 0; booted = 0;
  }

  < POST: minimal power-on self test — confirm core 0 and memory are present. >
  boolean post() { return cpu != null && cpu.bootCore() != null && memory != null; }

  < Load `blocks` of the kernel image starting at disk block `fromBlock` into >
  < memory at `loadAddr`, then point the boot core at it. >
  int loadKernel(int fromBlock, int blocks, int loadAddr) {
    if (!post()) { return -1; }
    kernelLoadAddr = loadAddr; kernelBlocks = blocks;
    int i = 0;
    while (i < blocks) { boot.readBlock(fromBlock + i); i = i + 1; }
    cpu.bootCore().loadEntryPoint(loadAddr);
    booted = 1;
    return loadAddr;
  }

  boolean handedOff() { return booted == 1; }
  int entryPoint() { return kernelLoadAddr; }
}