SLCore.sleela
lib/cpu/SLCore.sleela · 117 line(s) · sleela
<< lib/cpu/SLCore.sleela
SLeeLa Standard Library Definition.
Definition: Defines SLCore — a single execution core: one control unit, its
register file, ALU, program counter, status register, L1 cache, and
interrupt controller, all driven by a clock. A modern CPU is several of
these cores on one die; SLCPU composes them.
assemble() wires the sub-units together so the core is ready to fetch from a
shared RAM. tick() advances one clock cycle (one instruction in this
single-cycle model).
Family: cpu. Composes the Layer-0/1/2 components into a runnable core. >>
#sleela 2.5
material;
class SLCore {
< ---- 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 = 10211;
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; }
int id;
int width;
SLClock clock;
SLRegisterFile regs;
SLALU alu;
SLProgramCounter pc;
SLStatusRegister status;
SLInstructionSet isa;
SLInstructionDecoder decoder;
SLControlUnit control;
SLStack stack;
SLCache l1;
SLInterruptController irq;
void assemble(int coreId, int bits, int clockMHz, SLRAM sharedMemory) {
id = coreId; width = bits;
clock = new SLClock(); clock.configure(clockMHz);
regs = new SLRegisterFile(); regs.configure(16, bits);
alu = new SLALU(); alu.configure(bits);
pc = new SLProgramCounter(); pc.configure(bits, 1);
status = new SLStatusRegister(); status.reset();
isa = new SLInstructionSet(); isa.configure();
decoder = new SLInstructionDecoder(); decoder.configure(isa);
< Per-core hardware stack: a high region of shared memory growing downward. >
< The OS re-points the stack per process; this is the boot default. >
stack = new SLStack();
int top = sharedMemory.capacityWords() - 1 - (coreId * 4096);
stack.configure(sharedMemory, top, top - 2048);
l1 = new SLCache(); l1.configure("L1", 32768, 64, 8); l1.attachBacking(sharedMemory);
irq = new SLInterruptController(); irq.configure(0);
irq.enable(irq.IRQ_TIMER);
control = new SLControlUnit();
control.configure(isa, decoder, regs, alu, pc, status, sharedMemory, stack);
}
void loadEntryPoint(int addr) { pc.branchTo(addr); }
void installSyscallVector(int addr) { control.installSyscallVector(addr); }
< Advance one clock cycle: tick the clock, execute one instruction. >
int tick() { clock.toggle(); return control.step(); }
< Raise the timer interrupt (the OS uses this for preemptive scheduling). >
void timerTick() { irq.raise(irq.IRQ_TIMER); }
boolean halted() { return control.isHalted(); }
int pendingSyscall() { return control.pendingSyscall(); }
void clearSyscall() { control.clearSyscall(); }
int coreId() { return id; }
int cyclesRun() { return clock.cycleCount(); }
int retired() { return control.instructionsRetired(); }
SLControlUnit controlUnit() { return control; }
SLRegisterFile registers() { return regs; }
SLInterruptController interrupts() { return irq; }
SLStack hardwareStack() { return stack; }
SLInstructionSet instructionSet() { return isa; }
}