add system time, clean up pci into pci.sys, clean up syscall names, fix USERAPC1 typo

This commit is contained in:
maksw committed 2026-06-11 18:11:59 +02:00
1 parent c1a291c4c9
commit e41bf6e2c0
64 files changed
+4514 -2220

No files matched your search

+58 -3
View File
@@ -77,12 +77,35 @@ static void printUIntWidth(uint32_t n, size_t width) {
printUInt(n);
}
static void printUIntZeroWidth(uint32_t n, size_t width) {
uint32_t digits = u64Digits(n);
while (width > digits) { print("0"); width--; }
printUInt(n);
}
static void printUInt64Width(uint64_t n, size_t width) {
uint32_t digits = u64Digits(n);
if (width > digits) printSpaces(width - digits);
printUInt64(n);
}
static void printDirTime(const SYS_SYSTEM_TIME* t) {
if (!t || !(t->Flags & SYS_TIME_FLAG_VALID)) {
print("---- -- -- --:-- ");
return;
}
printUIntZeroWidth(t->Year, 4);
print("-");
printUIntZeroWidth(t->Month, 2);
print("-");
printUIntZeroWidth(t->Day, 2);
print(" ");
printUIntZeroWidth(t->Hour, 2);
print(":");
printUIntZeroWidth(t->Minute, 2);
print(" ");
}
static void printStringWidth(const char* s, size_t width) {
size_t len = s ? strlen(s) : 0;
if (s) print(s);
@@ -95,7 +118,7 @@ static void printStringWidth(const char* s, size_t width) {
static void readLine(char* buf, int len) {
int pos = 0;
while (true) {
char c = SysKbReadChar();
char c = SysReadKeyboardChar();
if (!c) { SysYield(); continue; }
if (c == '\r' || c == '\n') { print("\n"); break; }
if ((c == '\b' || c == 127) && pos > 0) { pos--; print("\b \b"); continue; }
@@ -120,6 +143,7 @@ static void cmd_help() {
print("Available commands:\n"
" help - Show this list\n"
" mem - Show memory usage\n"
" time - Show system wall-clock time\n"
" stats - Show scheduler/CPU/PMM telemetry\n"
" ps - List processes\n"
" dir [path] - List directory contents\n"
@@ -226,6 +250,34 @@ static void cmd_stats(void) {
print(" 1024+: "); printUInt64(pmm.FreeRunHistogram[7]); print("\n");
}
static void cmd_time(void) {
SYS_SYSTEM_TIME t;
uint32_t status = SysGetSystemTime(&t);
if (status != 0) {
print("time: failed: ");
printUInt(status);
print("\n");
return;
}
printUIntZeroWidth(t.Year, 4); print("-");
printUIntZeroWidth(t.Month, 2); print("-");
printUIntZeroWidth(t.Day, 2); print(" ");
printUIntZeroWidth(t.Hour, 2); print(":");
printUIntZeroWidth(t.Minute, 2); print(":");
printUIntZeroWidth(t.Second, 2); print(".");
printUIntZeroWidth(t.Millisecond, 3);
print(" epoch="); printUInt64(t.EpochSeconds);
print(" flags=0x"); printUInt(t.Flags);
if (t.Flags & SYS_TIME_FLAG_TZ_KNOWN) {
print(" tz="); printInt(t.TimeZoneMinutes);
} else {
print(" tz=unspecified");
}
print("\n");
}
static void cmd_mem(void) {
SYS_MEMORY_STATUS st;
if (SysGetMemoryStatus(&st) != 0) {
@@ -338,6 +390,8 @@ static void cmd_dir(const char* path) {
SYS_DIR_ENTRY ke;
while (SysReadDir(hDir, &ke) == 0) {
printDirTime(&ke.LastWriteTime);
// Corrected Attribute Check: 0x10 is the Directory bit in FAT
if (ke.Attr & 0x10) {
print("<DIR> ");
@@ -397,7 +451,7 @@ static int runCommand(const char* cmd) {
if (!cmd || *cmd == '\0') return 0;
if (strcmp(cmd, "exit") == 0) return 1;
if (strcmp(cmd, "help") == 0) { cmd_help(); return 0; }
if (strcmp(cmd, "clear") == 0) { SysScreenClear(0x012456); return 0; }
if (strcmp(cmd, "clear") == 0) { SysClearScreen(0x012456); return 0; }
if (strncmp(cmd, "crash", 5) == 0) {
// Check the sub-option trailing "crash " (offset 6)
if (strcmp(cmd + 6, "void") == 0) {
@@ -437,6 +491,7 @@ static int runCommand(const char* cmd) {
}
}
if (strcmp(cmd, "mem") == 0) { cmd_mem(); return 0; }
if (strcmp(cmd, "time") == 0 || strcmp(cmd, "date") == 0) { cmd_time(); return 0; }
if (strcmp(cmd, "stats") == 0 || strcmp(cmd, "telemetry") == 0) { cmd_stats(); return 0; }
if (strcmp(cmd, "ps") == 0) { cmd_ps(); return 0; }
if (strcmp(cmd, "dir") == 0) { cmd_dir("."); return 0; }
@@ -453,7 +508,7 @@ static int runCommand(const char* cmd) {
if (create_process(program, &hProc, cmd) == 0) {
SysWaitForProcess(hProc);
SysCloseHandle(hProc);
while (SysKbPoll()) (void)SysKbReadChar();
while (SysPollKeyboard()) (void)SysReadKeyboardChar();
} else { print("shell: launch failed\n"); }
return 0;
}