From 92d3a34a9b8d70e08b52164a5ca24dfd93a76af1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Marques?= Date: Wed, 23 Oct 2019 19:04:57 +0100 Subject: Add --help (#179) --- pk/pk.c | 49 +++++++++++++++++++++++++++++++++++-------------- 1 file changed, 35 insertions(+), 14 deletions(-) (limited to 'pk') diff --git a/pk/pk.c b/pk/pk.c index 8ba9dc3..a2be365 100644 --- a/pk/pk.c +++ b/pk/pk.c @@ -11,22 +11,43 @@ elf_info current; long disabled_hart_mask; -static void handle_option(const char* s) +static void help() { - switch (s[1]) - { - case 's': // print cycle count upon termination - current.cycle0 = 1; - break; - - case 'p': // disable demand paging - demand_paging = 0; - break; - - default: - panic("unrecognized option: `%c'", s[1]); - break; + printk("Proxy kernel\n\n"); + printk("usage: pk [pk options] [program options]\n"); + printk("Options:\n"); + printk(" -h, --help Print this help message\n"); + printk(" -p Disable on-demand program paging\n"); + printk(" -s Print cycles upon termination\n"); + + shutdown(0); +} + +static void suggest_help() +{ + printk("Try 'pk --help' for more information.\n"); + shutdown(1); +} + +static void handle_option(const char* arg) +{ + if (strcmp(arg, "-h") == 0 || strcmp(arg, "--help") == 0) { + help(); + return; } + + if (strcmp(arg, "-s") == 0) { // print cycle count upon termination + current.cycle0 = 1; + return; + } + + if (strcmp(arg, "-p") == 0) { // disable demand paging + demand_paging = 0; + return; + } + + panic("unrecognized option: `%s'", arg); + suggest_help(); } #define MAX_ARGS 256 -- cgit v1.1