SLBIOSEmitter.sleela
lib/operating-system/os-creator/SLBIOSEmitter.sleela · 109 line(s) · sleela
<< lib/operating-system/os-creator/SLBIOSEmitter.sleela
SLeeLa Standard Library Definition.
Definition: Defines SLBIOSEmitter — the OS Creator(TM) emitter for the legacy
BIOS / Compatibility Support Module piece. Given an SLOSModel it produces
the C and C++ source for a legacy boot path: a C entry that reads the Master
Boot Record, loads the first-stage boot sector, and jumps to it, plus a
bios.cfg recording whether the CSM is enabled for this build. On UEFI-only
builds the piece is still emitted as a documented, inert fallback so the
project can target legacy hardware when CSM is turned on.
This is piece #2 of the chain (the legacy sibling of UEFI). Output is String
concatenation on OP_ADD; no new VM opcode is used.
Family: operating-system. OS Creator(TM) piece emitter; consumes SLOSModel, fills SLOSPiece. >>
#sleela 2.5
material;
class SLBIOSEmitter {
< ---- 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 = 10868;
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-10";
< 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; }
SLOSPiece emit(SLOSModel m) {
SLOSPiece p = new SLOSPiece();
p.configure("BIOS", "firmware/bios", "bios");
String c = "/* bios.c - legacy BIOS/CSM boot path, generated by OS Creator(TM) for " + m.name() + " */\n";
c = c + "#include <stdint.h>\n\n";
c = c + "/* Legacy BIOS INT 13h disk-read surface (modeled). */\n";
c = c + "extern int bios_read_sector(int drive, int lba, void *dst);\n";
c = c + "extern void bios_jump(void *entry);\n\n";
c = c + "/* Read the MBR, load the first-stage boot sector, and jump to it. */\n";
c = c + "int bios_boot(int drive) {\n";
c = c + " static unsigned char mbr[512];\n";
c = c + " if (bios_read_sector(drive, 0, mbr) != 0) return 1;\n";
c = c + " if (mbr[510] != 0x55 || mbr[511] != 0xAA) return 2; /* no boot signature */\n";
c = c + " static unsigned char stage1[512];\n";
c = c + " if (bios_read_sector(drive, 1, stage1) != 0) return 3;\n";
c = c + " bios_jump(stage1);\n";
c = c + " return 0;\n";
c = c + "}\n";
p.setC(c);
String cpp = "// bios.cpp - legacy BIOS/CSM boot path (C++ surface) for " + m.name() + "\n";
cpp = cpp + "#include <cstdint>\nnamespace oscreator {\n";
cpp = cpp + "class LegacyBios {\npublic:\n";
cpp = cpp + " bool csmEnabled = " + boolLit(m.bootloader().firmwareName() != "UEFI") + ";\n";
cpp = cpp + " int boot(int drive) {\n";
cpp = cpp + " if (!readMbr(drive)) return 1;\n";
cpp = cpp + " if (!loadStage1(drive)) return 3;\n";
cpp = cpp + " jumpToStage1();\n return 0;\n";
cpp = cpp + " }\n";
cpp = cpp + "private:\n bool readMbr(int);\n bool loadStage1(int);\n void jumpToStage1();\n";
cpp = cpp + "};\n} // namespace oscreator\n";
p.setCpp(cpp);
String csm = "false";
if (m.bootloader().firmwareName() != "UEFI") { csm = "true"; }
String cfg = "# bios.cfg - generated by OS Creator(TM)\n";
cfg = cfg + "mode = legacy\n";
cfg = cfg + "csm_enabled = " + csm + "\n";
cfg = cfg + "note = Emitted as a CSM/legacy fallback; UEFI is the primary firmware.\n";
p.setConfig("bios.cfg", cfg);
p.setReadme("# BIOS / CSM piece\n\nLegacy BIOS boot path (`bios.c`/`bios.cpp`): read the MBR, "
+ "load the first-stage boot sector, and jump. Active only when the Compatibility Support "
+ "Module is enabled; UEFI (`../uefi`) is the primary firmware.\n");
return p;
}
String boolLit(boolean b) { if (b) { return "true"; } return "false"; }
}