SLGuestBlockDevice.sleela
lib/cpu/SLGuestBlockDevice.sleela · 99 line(s) · sleela
<< lib/cpu/SLGuestBlockDevice.sleela
SLeeLa Standard Library Definition.
Definition: Defines SLGuestBlockDevice — a virtual block storage device
(virtio-blk-style) backed by a host SLHardDrive. The guest kernel programs
a block number and buffer address, issues a read or write, and the device
performs the transfer and raises its IRQ on completion. This is how a guest
OS loads its root filesystem and pages to/from disk.
MMIO registers: 0 = block number, 1 = guest buffer address, 2 = command
(1 read, 2 write), 3 = status (RO). Completion raises the device IRQ.
Family: cpu. Extends SLGuestDevice; composes SLHardDrive. >>
#sleela 2.5
material;
class SLGuestBlockDevice extends SLGuestDevice {
< ---- 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 = 10225;
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; }
SLHardDrive backing;
int blockNo;
int bufAddr;
< 0 idle, 1 busy, 2 done >
int status;
int reads;
int writes;
void init(int base, int irq, SLHardDrive drive) {
configure("blk", base, 4, irq);
backing = drive; blockNo = 0; bufAddr = 0; status = 0; reads = 0; writes = 0;
}
int read(int addr) {
int r = registerOf(addr);
if (r == 0) { return blockNo; }
if (r == 1) { return bufAddr; }
if (r == 3) { return status; }
return 0;
}
void write(int addr, int value) {
int r = registerOf(addr);
if (r == 0) { blockNo = value; }
if (r == 1) { bufAddr = value; }
if (r == 2) { command(value); }
}
< Execute a block command and signal completion. >
void command(int cmd) {
< busy >
status = 1;
if (cmd == 1 && backing != null) { backing.readBlock(blockNo); reads = reads + 1; }
if (cmd == 2 && backing != null) { backing.writeBlock(blockNo, bufAddr); writes = writes + 1; }
< done >
status = 2;
raiseIRQ();
}
int readCount() { return reads; }
int writeCount() { return writes; }
}