From f8b30fee6285e82ca8e7c0efc9b0bc5a865aee05 Mon Sep 17 00:00:00 2001 From: Mark Date: Tue, 31 Dec 2019 13:13:38 +0200 Subject: [PATCH] Add help --- sys/amd64/hw/timer.c | 2 +- usr/init.c | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/sys/amd64/hw/timer.c b/sys/amd64/hw/timer.c index e6785cf..03b4fd2 100644 --- a/sys/amd64/hw/timer.c +++ b/sys/amd64/hw/timer.c @@ -53,7 +53,7 @@ void amd64_timer_init(void) { // LAPIC Timer is only used to trigger task switches LAPIC(LAPIC_REG_TMRDIV) = 0x3; LAPIC(LAPIC_REG_LVTT) = 32 | (1 << 17); - LAPIC(LAPIC_REG_TMRINITCNT) = 1000; + LAPIC(LAPIC_REG_TMRINITCNT) = 10000; LAPIC(LAPIC_REG_TMRCURRCNT) = 0; get_cpu()->ticks = 0; diff --git a/usr/init.c b/usr/init.c index d48d74a..8e2020e 100644 --- a/usr/init.c +++ b/usr/init.c @@ -37,6 +37,7 @@ static int b_pwd(const char *_); static int b_cat(const char *path); static int b_curs(const char *arg); static int b_sleep(const char *arg); +static int b_help(const char *arg); static struct builtin builtins[] = { { @@ -69,6 +70,11 @@ static struct builtin builtins[] = { "Sleep N seconds", b_sleep }, + { + "help", + "Please help me", + b_help + }, { NULL, NULL, NULL } }; @@ -208,6 +214,27 @@ static int b_sleep(const char *arg) { return 0; } +static int b_help(const char *arg) { + if (arg) { + // Describe a specific command + for (size_t i = 0; builtins[i].run; ++i) { + if (!strcmp(arg, builtins[i].name)) { + printf("%s: %s\n", builtins[i].name, builtins[i].desc); + return 0; + } + } + + printf("%s: Unknown command\n", arg); + return -1; + } else { + for (size_t i = 0; builtins[i].run; ++i) { + printf("%s: %s\n", builtins[i].name, builtins[i].desc); + } + + return 0; + } +} + static void prompt(void) { printf("\033[36mygg\033[0m > "); }