<< lib/operating-system/os-creator/SLDriverLoaderEmitter.sleela SLeeLa Standard Library Definition. Definition: Defines SLDriverLoaderEmitter — the OS Creator(TM) emitter for the driver-loader piece. Given an SLOSModel it walks the model's driver manifest (SLDriverSet) and produces the C and C++ source for the stage the kernel runs to bring up devices: it probes the bus, loads every built-in driver first (storage must be present before the rootfs mounts), then loads module drivers on demand. It emits a drivers.conf listing each driver and its binding (builtin|module). This is piece #5 of the chain. The emitted C contains one load_driver() call per driver, ordered built-ins first, generated from the model's manifest. Family: operating-system. OS Creator(TM) piece emitter; consumes SLOSModel, fills SLOSPiece. >> #sleela 2.5 material; class SLDriverLoaderEmitter { < ---- 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 = 10889; String metaAuthor = "Kiro Agent"; String metaDate = "2026-10-16"; String metaCopyright = "SLeeLa project"; String metaTrademark = "none"; String metaCorporation = "none"; < metaOrigin: National | | 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("Driver Loader", "kernel/driver-loader", "driver_loader"); String manifest = m.driverSet().driverManifest(); String c = "/* driver_loader.c - device bring-up, OS Creator(TM) for " + m.name() + " */\n"; c = c + "#include \n\n"; c = c + "extern int probe_buses(void);\n"; c = c + "extern int load_driver(const char *name);\n\n"; c = c + "int driver_loader_main(void) {\n"; c = c + " if (probe_buses() != 0) return 1;\n"; c = c + " /* Built-in drivers first (storage must precede the rootfs mount). */\n"; c = c + emitLoadCalls(manifest, "builtin", 2); c = c + " /* Module drivers on demand. */\n"; c = c + emitLoadCalls(manifest, "module", 3); c = c + " return 0;\n"; c = c + "}\n"; p.setC(c); String cpp = "// driver_loader.cpp - device bring-up (C++ surface) for " + m.name() + "\n"; cpp = cpp + "#include \n#include \nnamespace oscreator {\n"; cpp = cpp + "class DriverLoader {\npublic:\n"; cpp = cpp + " std::vector builtins = {" + driverList(manifest, "builtin") + "};\n"; cpp = cpp + " std::vector modules = {" + driverList(manifest, "module") + "};\n"; cpp = cpp + " int load() {\n"; cpp = cpp + " if (!probeBuses()) return 1;\n"; cpp = cpp + " for (auto &d : builtins) if (!loadDriver(d)) return 2;\n"; cpp = cpp + " for (auto &d : modules) loadDriver(d);\n"; cpp = cpp + " return 0;\n }\n"; cpp = cpp + "private:\n bool probeBuses();\n bool loadDriver(const std::string&);\n"; cpp = cpp + "};\n} // namespace oscreator\n"; p.setCpp(cpp); String conf = "# drivers.conf - generated by OS Creator(TM)\n"; conf = conf + "# format: \n"; conf = conf + manifest + "\n"; p.setConfig("drivers.conf", conf); p.setReadme("# Driver Loader piece\n\nProbes buses and loads drivers (`driver_loader.c`/" + "`driver_loader.cpp`): built-ins first (storage before the rootfs mount), then modules. " + "Driven by `drivers.conf`.\n"); return p; } < One load_driver() call per manifest line whose binding matches, with the > < given error code on failure. > String emitLoadCalls(String manifest, String binding, int errCode) { String out = ""; String line = ""; int i = 0; int n = strLen(manifest); while (i <= n) { String ch = charAt(manifest, i); if (ch == "\n" || i == n) { if (lineBinding(line) == binding) { out = out + " if (load_driver(\"" + lineName(line) + "\") != 0) return " + intToStr(errCode) + ";\n"; } line = ""; } else { line = line + ch; } i = i + 1; } return out; } < A comma-separated C++ initializer list of driver names with the binding. > String driverList(String manifest, String binding) { String out = ""; String line = ""; int i = 0; int n = strLen(manifest); int first = 1; while (i <= n) { String ch = charAt(manifest, i); if (ch == "\n" || i == n) { if (lineBinding(line) == binding) { if (first == 1) { out = out + "\"" + lineName(line) + "\""; first = 0; } else { out = out + ", \"" + lineName(line) + "\""; } } line = ""; } else { line = line + ch; } i = i + 1; } return out; } < "name binding" -> name (token before the space). > String lineName(String line) { int i = 0; int n = strLen(line); while (i < n) { if (charAt(line, i) == " ") { return substr(line, 0, i); } i = i + 1; } return line; } < "name binding" -> binding (token after the space). > String lineBinding(String line) { int i = 0; int n = strLen(line); while (i < n) { if (charAt(line, i) == " ") { return substr(line, i + 1, n); } i = i + 1; } return ""; } int strLen(String s) { return native sleela_str_length(s); } String substr(String s, int a, int b) { return native sleela_str_substring(s, a, b); } String charAt(String s, int i) { return substr(s, i, i + 1); } String intToStr(int v) { return "" + v; } }