SLKernelLoaderEmitter.sleela
lib/operating-system/os-creator/SLKernelLoaderEmitter.sleela · 117 line(s) · sleela
<< lib/operating-system/os-creator/SLKernelLoaderEmitter.sleela
SLeeLa Standard Library Definition.
Definition: Defines SLKernelLoaderEmitter — the OS Creator(TM) emitter for the
kernel-loader piece. Given an SLOSModel it produces the C and C++ source for
the stage that the boot loader hands control to: it loads the kernel image
(the family the SLKernelSpec names: Linux / NT / XNU), optionally unpacks an
initramfs, applies the kernel command line, and jumps to the kernel entry
point. It emits a kernel-loader.conf recording the kernel name/version,
command line, and whether an initramfs is staged.
This is piece #4 of the chain. Output is String concatenation on OP_ADD.
Family: operating-system. OS Creator(TM) piece emitter; consumes SLOSModel, fills SLOSPiece. >>
#sleela 2.5
material;
class SLKernelLoaderEmitter {
< ---- 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 = 10901;
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("Kernel Loader", "boot/kernel-loader", "kernel_loader");
String kname = m.kernelSpec().name();
String kver = m.kernelSpec().kernelVersion();
String cmdline = m.kernelSpec().commandLine();
int initramfs = 0;
if (m.bootloader().stagesInitramfs()) { initramfs = 1; }
String c = "/* kernel_loader.c - loads the " + kname + " kernel, OS Creator(TM) for " + m.name() + " */\n";
c = c + "#include <stdint.h>\n\n";
c = c + "extern void *load_kernel_image(const char *path);\n";
c = c + "extern int unpack_initramfs(const char *path);\n";
c = c + "extern void enter_kernel(void *entry, const char *cmdline);\n\n";
c = c + "int kernel_loader_main(void) {\n";
c = c + " void *k = load_kernel_image(\"/boot/kernel\");\n";
c = c + " if (!k) return 1;\n";
if (initramfs == 1) {
c = c + " if (unpack_initramfs(\"/boot/initrd.img\") != 0) return 2;\n";
}
c = c + " enter_kernel(k, \"" + cmdline + "\"); /* " + kname + " " + kver + " */\n";
c = c + " return 0; /* unreached: control passes to the kernel */\n";
c = c + "}\n";
p.setC(c);
String cpp = "// kernel_loader.cpp - kernel loader (C++ surface) for " + m.name() + "\n";
cpp = cpp + "#include <string>\nnamespace oscreator {\n";
cpp = cpp + "class KernelLoader {\npublic:\n";
cpp = cpp + " std::string kernel = \"" + kname + "\";\n";
cpp = cpp + " std::string version = \"" + kver + "\";\n";
cpp = cpp + " std::string cmdline = \"" + cmdline + "\";\n";
cpp = cpp + " bool initramfs = " + boolLit(initramfs == 1) + ";\n";
cpp = cpp + " int load() {\n";
cpp = cpp + " void *k = loadImage(\"/boot/kernel\");\n";
cpp = cpp + " if (!k) return 1;\n";
if (initramfs == 1) { cpp = cpp + " if (!unpackInitramfs()) return 2;\n"; }
cpp = cpp + " enterKernel(k, cmdline);\n return 0;\n";
cpp = cpp + " }\n";
cpp = cpp + "private:\n void *loadImage(const std::string&);\n bool unpackInitramfs();\n";
cpp = cpp + " void enterKernel(void *, const std::string&);\n";
cpp = cpp + "};\n} // namespace oscreator\n";
p.setCpp(cpp);
String conf = "# kernel-loader.conf - generated by OS Creator(TM)\n";
conf = conf + "kernel = " + kname + "\n";
conf = conf + "version = " + kver + "\n";
conf = conf + "cmdline = " + cmdline + "\n";
conf = conf + "initramfs = " + boolLit(initramfs == 1) + "\n";
p.setConfig("kernel-loader.conf", conf);
p.setReadme("# Kernel Loader piece\n\nLoads the `" + kname + "` kernel image, "
+ "applies the command line, and enters the kernel. Hands off from the boot loader "
+ "(`../loader`) to the kernel; drivers come up next (`../../kernel/driver-loader`).\n");
return p;
}
String boolLit(boolean b) { if (b) { return "true"; } return "false"; }
}