9os

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 4f5eca627a2749db773bccc7a76bcd535958fc47
parent d54afdf905e4bb6fa7002a279077801dca0a23d7
Author: Dimitris Papastamos <dimitris.papastamos@arm.com>
Date:   Thu,  8 Nov 2018 11:33:24 +0000

[debuglang] Pass cmd to the handlers so we can reuse the usage message

Change-Id: I28c5c602bd06ff50ecd47c4e5d8c48004b502a67
Signed-off-by: Dimitris Papastamos <dimitris.papastamos@arm.com>

Diffstat:
Msrc/debuglang/debuglang.c | 29++++++++++++++---------------
1 file changed, 14 insertions(+), 15 deletions(-)

diff --git a/src/debuglang/debuglang.c b/src/debuglang/debuglang.c @@ -22,7 +22,7 @@ struct args { struct cmd { char *name; - int (*eval)(struct args *args); + int (*eval)(const struct cmd *cmd, struct args *args); char *helpmsg; }; @@ -135,13 +135,13 @@ get_cmd(char *name) } static int -do_set(struct args *args) +do_set(const struct cmd *cmd, struct args *args) { unsigned long long *reg = NULL; unsigned long long setval = 0; if (args->argc != 3) - error("usage: set <reg> <value>"); + error(cmd->helpmsg); reg = get_named_reg(args->argv[1]); if (reg == NULL) @@ -153,12 +153,12 @@ do_set(struct args *args) } static int -do_get(struct args *args) +do_get(const struct cmd *cmd, struct args *args) { unsigned long long *reg = NULL; if (args->argc != 2) - error("usage: get <reg>"); + error(cmd->helpmsg); reg = get_named_reg(args->argv[1]); if (reg == NULL) @@ -169,21 +169,21 @@ do_get(struct args *args) } static int -do_dump(struct args *args) +do_dump(const struct cmd *cmd, struct args *args) { print_tf(bss->fp); return 0; } static int -do_trap(struct args *args) +do_trap(const struct cmd *cmd, struct args *args) { trap(bss->fp); return 0; } static int -do_rmc(struct args *args) +do_rmc(const struct cmd *cmd, struct args *args) { unsigned char class; unsigned char func; @@ -207,8 +207,9 @@ do_rmc(struct args *args) func = rmudesc->func; break; default: - error("Invalid number of parameters for rmc"); + error(cmd->helpmsg); } + dbg("class: %d,func:%d\n", class, func); bss->fp->esr = (unsigned long long) RMC << 26; bss->fp->esr |= class; @@ -218,7 +219,7 @@ do_rmc(struct args *args) } static int -do_exit(struct args *args) +do_exit(const struct cmd *cmd, struct args *args) { switch (args->argc) { case 2: @@ -228,16 +229,14 @@ do_exit(struct args *args) args->status = 0; break; default: - error("usage: exit [status]"); + error(cmd->helpmsg); } return -1; } static int -do_help(struct args *args) +do_help(const struct cmd *cmd, struct args *args) { - const struct cmd *cmd; - for (cmd = cmds; cmd->name; cmd++) printf(PREFIX "%s\n", cmd->helpmsg); return 0; @@ -286,7 +285,7 @@ run(struct args *args) buffer[len-1] = '\0'; cmd = parse_cmd(buffer, args); if (cmd) - return cmd->eval(args); + return cmd->eval(cmd, args); } args->status = 1;