feat: add time syscall & command in shell
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -39,6 +39,16 @@ namespace Zenith {
|
||||
static constexpr uint64_t SYS_GETARGS = 25;
|
||||
static constexpr uint64_t SYS_RESET = 26;
|
||||
static constexpr uint64_t SYS_SHUTDOWN = 27;
|
||||
static constexpr uint64_t SYS_GETTIME = 28;
|
||||
|
||||
struct DateTime {
|
||||
uint16_t Year;
|
||||
uint8_t Month;
|
||||
uint8_t Day;
|
||||
uint8_t Hour;
|
||||
uint8_t Minute;
|
||||
uint8_t Second;
|
||||
};
|
||||
|
||||
struct FbInfo {
|
||||
uint64_t width;
|
||||
|
||||
@@ -176,6 +176,9 @@ namespace zenith {
|
||||
if (rows) *rows = (int)(r >> 32);
|
||||
}
|
||||
|
||||
// Timekeeping (wall-clock)
|
||||
inline void gettime(Zenith::DateTime* out) { syscall1(Zenith::SYS_GETTIME, (uint64_t)out); }
|
||||
|
||||
// Power management
|
||||
[[noreturn]] inline void reset() {
|
||||
syscall0(Zenith::SYS_RESET);
|
||||
|
||||
@@ -47,6 +47,9 @@
|
||||
round-trip times. Timeout is 3 seconds per request.
|
||||
Example: ping 10.0.2.2
|
||||
|
||||
.SS date
|
||||
Display the current date and time in UTC.
|
||||
|
||||
.SS uptime
|
||||
Display the system uptime in minutes, seconds, and milliseconds.
|
||||
|
||||
|
||||
+16
-1
@@ -3,7 +3,7 @@
|
||||
syscalls - overview of ZenithOS system calls
|
||||
|
||||
.SH DESCRIPTION
|
||||
ZenithOS provides 26 system calls (numbers 0-25) for userspace
|
||||
ZenithOS provides 29 system calls (numbers 0-28) for userspace
|
||||
programs. Syscalls use the x86-64 SYSCALL instruction with the
|
||||
following register convention:
|
||||
|
||||
@@ -91,6 +91,12 @@
|
||||
Get milliseconds elapsed since boot.
|
||||
uint64_t zenith::get_milliseconds();
|
||||
|
||||
.B SYS_GETTIME (28)
|
||||
Get the current wall-clock date and time (UTC).
|
||||
Fills a Zenith::DateTime struct with Year, Month, Day,
|
||||
Hour, Minute, and Second fields.
|
||||
void zenith::gettime(Zenith::DateTime* out);
|
||||
|
||||
.SH SYSTEM
|
||||
.B SYS_GETINFO (15)
|
||||
Get OS name, version, and configuration.
|
||||
@@ -133,5 +139,14 @@
|
||||
Get the argument string passed to this process at spawn time.
|
||||
int zenith::getargs(char* buf, uint64_t maxLen);
|
||||
|
||||
.SH POWER MANAGEMENT
|
||||
.B SYS_RESET (26)
|
||||
Reboot the system.
|
||||
[[noreturn]] void zenith::reset();
|
||||
|
||||
.B SYS_SHUTDOWN (27)
|
||||
Shut down the system (currently unimplemented).
|
||||
[[noreturn]] void zenith::shutdown();
|
||||
|
||||
.SH SEE ALSO
|
||||
spawn(2), file(2), framebuffer(2), malloc(3)
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@@ -94,6 +94,7 @@ static void cmd_help() {
|
||||
zenith::print(" cat <file> Display file contents\n");
|
||||
zenith::print(" run <file> Spawn a new process from an ELF file\n");
|
||||
zenith::print(" ping <ip> Send ICMP echo requests\n");
|
||||
zenith::print(" date Show current date and time\n");
|
||||
zenith::print(" uptime Show uptime in milliseconds\n");
|
||||
zenith::print(" clear Clear the screen\n");
|
||||
zenith::print(" reset Reboot the system\n");
|
||||
@@ -390,6 +391,38 @@ static void cmd_man(const char* arg) {
|
||||
}
|
||||
}
|
||||
|
||||
static void print_int_padded(uint64_t n) {
|
||||
if (n < 10) zenith::putchar('0');
|
||||
print_int(n);
|
||||
}
|
||||
|
||||
static const char* month_name(int m) {
|
||||
static const char* months[] = {
|
||||
"", "January", "February", "March", "April", "May", "June",
|
||||
"July", "August", "September", "October", "November", "December"
|
||||
};
|
||||
if (m >= 1 && m <= 12) return months[m];
|
||||
return "?";
|
||||
}
|
||||
|
||||
static void cmd_date() {
|
||||
Zenith::DateTime dt;
|
||||
zenith::gettime(&dt);
|
||||
|
||||
print_int(dt.Day);
|
||||
zenith::putchar(' ');
|
||||
zenith::print(month_name(dt.Month));
|
||||
zenith::putchar(' ');
|
||||
print_int(dt.Year);
|
||||
zenith::print(", ");
|
||||
print_int(dt.Hour);
|
||||
zenith::putchar(':');
|
||||
print_int_padded(dt.Minute);
|
||||
zenith::putchar(':');
|
||||
print_int_padded(dt.Second);
|
||||
zenith::print(" UTC\n");
|
||||
}
|
||||
|
||||
static void cmd_clear() {
|
||||
zenith::print("\033[2J"); // Clear entire screen
|
||||
zenith::print("\033[H"); // Move cursor to top-left
|
||||
@@ -428,6 +461,8 @@ static void process_command(const char* line) {
|
||||
cmd_ping(line + 5);
|
||||
} else if (streq(line, "ping")) {
|
||||
cmd_ping("");
|
||||
} else if (streq(line, "date")) {
|
||||
cmd_date();
|
||||
} else if (streq(line, "uptime")) {
|
||||
cmd_uptime();
|
||||
} else if (streq(line, "clear")) {
|
||||
|
||||
Reference in New Issue
Block a user