9os

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

commit f29e5bde03827ebd9b8217206b91609820e26a36
parent 4ee5f2129aa0bcfc0421c0543ef53bd016ed5d8e
Author: Roberto Vargas <roberto.vargas@arm.com>
Date:   Wed,  7 Nov 2018 08:45:55 +0000

[debuglang] Move the array definition at the botton

Having the array at the botton allows us to avoid the prototype
of the functions.

Change-Id: Ie4cc195e296d310372ae51326d86d48d6a4a0ce6

Diffstat:
Msrc/debuglang/debuglang.c | 175+++++++++++++++++++++++++++++++++++++++----------------------------------------
1 file changed, 87 insertions(+), 88 deletions(-)

diff --git a/src/debuglang/debuglang.c b/src/debuglang/debuglang.c @@ -12,16 +12,6 @@ #define PREFIX "> " #define NR_ARGC_MAX 16 -#define NUM_NAMED_REGS (sizeof(named_regs) / sizeof(struct named_reg)) - -extern jmp_buf recover; - -static int do_set(char **argv, int argc, struct trapframe *tf); -static int do_get(char **argv, int argc, struct trapframe *tf); -static int do_dump(char **argv, int argc, struct trapframe *tf); -static int do_trap(char **argv, int argc, struct trapframe *tf); -static int do_rmc(char **argv, int argc, struct trapframe *tf); -static int do_help(char **argv, int argc, struct trapframe *tf); struct cmd { char *name; @@ -39,80 +29,10 @@ struct named_reg { size_t offset; }; -static const struct cmd cmds[]={ - { - .name = "set", - .eval = do_set, - .helpmsg = "Set a register: set <reg> <value>", - }, - { - .name = "get", - .eval = do_get, - .helpmsg = "Get register value: get <reg>", - }, - { - .name = "dump", - .eval = do_dump, - .helpmsg = "Dump trapframe: dump", - }, - { - .name = "trap", - .eval = do_trap, - .helpmsg = "Call trap handler: trap", - }, - { - .name = "rmc", - .eval = do_rmc, - .helpmsg = "Call RMC handler: rmc", - }, - { - .name = "help", - .eval = do_help, - .helpmsg = "Print this help menu: help", - }, - { - .name = NULL - } -}; +extern jmp_buf recover; -static const struct named_reg named_regs[]={ - {"x0", offsetof(struct trapframe, x0)}, - {"x1", offsetof(struct trapframe, x1)}, - {"x2", offsetof(struct trapframe, x2)}, - {"x3", offsetof(struct trapframe, x3)}, - {"x4", offsetof(struct trapframe, x4)}, - {"x5", offsetof(struct trapframe, x5)}, - {"x6", offsetof(struct trapframe, x6)}, - {"x7", offsetof(struct trapframe, x7)}, - {"x8", offsetof(struct trapframe, x8)}, - {"x9", offsetof(struct trapframe, x9)}, - {"x10", offsetof(struct trapframe, x10)}, - {"x11", offsetof(struct trapframe, x11)}, - {"x12", offsetof(struct trapframe, x12)}, - {"x13", offsetof(struct trapframe, x13)}, - {"x14", offsetof(struct trapframe, x14)}, - {"x15", offsetof(struct trapframe, x15)}, - {"x16", offsetof(struct trapframe, x16)}, - {"x17", offsetof(struct trapframe, x17)}, - {"x18", offsetof(struct trapframe, x18)}, - {"x19", offsetof(struct trapframe, x19)}, - {"x20", offsetof(struct trapframe, x20)}, - {"x21", offsetof(struct trapframe, x21)}, - {"x22", offsetof(struct trapframe, x22)}, - {"x23", offsetof(struct trapframe, x23)}, - {"x24", offsetof(struct trapframe, x24)}, - {"x25", offsetof(struct trapframe, x25)}, - {"x26", offsetof(struct trapframe, x26)}, - {"x27", offsetof(struct trapframe, x27)}, - {"x28", offsetof(struct trapframe, x28)}, - {"x29", offsetof(struct trapframe, x29)}, - {"x30", offsetof(struct trapframe, x30)}, - {"sp", offsetof(struct trapframe, sp)}, - {"far", offsetof(struct trapframe, far)}, - {"esr", offsetof(struct trapframe, esr)}, - {"spsr", offsetof(struct trapframe, spsr)}, - {"elr", offsetof(struct trapframe, elr)} -}; +static const struct named_reg named_regs[]; +static const struct cmd cmds[]; static void error(char *fmt, ...) @@ -122,7 +42,7 @@ error(char *fmt, ...) va_start(va, fmt); fputs(PREFIX "ERR ", stdout); vprintf(fmt, va); - va_end(va); + fputc('\n', stdout); longjmp(recover, 1); } @@ -177,14 +97,14 @@ base_read(char *str, int base) static unsigned long long * get_named_reg(char *name, struct trapframe *tfp) { - size_t i; char *regptr; + const struct named_reg *rp; regptr = NULL; - for (i = 0; i < NUM_NAMED_REGS; i++) { - if (strcmp(name, named_regs[i].name) == 0) { + for (rp = named_regs; rp->name; ++rp) { + if (strcmp(name, rp->name) == 0) { regptr = (char *) tfp; - regptr += named_regs[i].offset; + regptr += rp->offset; } } return (unsigned long long *) regptr; @@ -402,3 +322,82 @@ debug(void) puts("debug language interface: error reading from stdin"); printf("end debug language interface\n"); } + +/* + * definintion of arrays + */ +static const struct cmd cmds[] = { + { + .name = "set", + .eval = do_set, + .helpmsg = "Set a register: set <reg> <value>", + }, + { + .name = "get", + .eval = do_get, + .helpmsg = "Get register value: get <reg>", + }, + { + .name = "dump", + .eval = do_dump, + .helpmsg = "Dump trapframe: dump", + }, + { + .name = "trap", + .eval = do_trap, + .helpmsg = "Call trap handler: trap", + }, + { + .name = "rmc", + .eval = do_rmc, + .helpmsg = "Call RMC handler: rmc", + }, + { + .name = "help", + .eval = do_help, + .helpmsg = "Print this help menu: help", + }, + { + .name = NULL + } +}; + +static const struct named_reg named_regs[]={ + {"x0", offsetof(struct trapframe, x0)}, + {"x1", offsetof(struct trapframe, x1)}, + {"x2", offsetof(struct trapframe, x2)}, + {"x3", offsetof(struct trapframe, x3)}, + {"x4", offsetof(struct trapframe, x4)}, + {"x5", offsetof(struct trapframe, x5)}, + {"x6", offsetof(struct trapframe, x6)}, + {"x7", offsetof(struct trapframe, x7)}, + {"x8", offsetof(struct trapframe, x8)}, + {"x9", offsetof(struct trapframe, x9)}, + {"x10", offsetof(struct trapframe, x10)}, + {"x11", offsetof(struct trapframe, x11)}, + {"x12", offsetof(struct trapframe, x12)}, + {"x13", offsetof(struct trapframe, x13)}, + {"x14", offsetof(struct trapframe, x14)}, + {"x15", offsetof(struct trapframe, x15)}, + {"x16", offsetof(struct trapframe, x16)}, + {"x17", offsetof(struct trapframe, x17)}, + {"x18", offsetof(struct trapframe, x18)}, + {"x19", offsetof(struct trapframe, x19)}, + {"x20", offsetof(struct trapframe, x20)}, + {"x21", offsetof(struct trapframe, x21)}, + {"x22", offsetof(struct trapframe, x22)}, + {"x23", offsetof(struct trapframe, x23)}, + {"x24", offsetof(struct trapframe, x24)}, + {"x25", offsetof(struct trapframe, x25)}, + {"x26", offsetof(struct trapframe, x26)}, + {"x27", offsetof(struct trapframe, x27)}, + {"x28", offsetof(struct trapframe, x28)}, + {"x29", offsetof(struct trapframe, x29)}, + {"x30", offsetof(struct trapframe, x30)}, + {"sp", offsetof(struct trapframe, sp)}, + {"far", offsetof(struct trapframe, far)}, + {"esr", offsetof(struct trapframe, esr)}, + {"spsr", offsetof(struct trapframe, spsr)}, + {"elr", offsetof(struct trapframe, elr)}, + {NULL}, +};