commit b9cf15491605ddf342a7b8d15dddd737f186fa36
parent 5a89ee87069dc273a7159afb314569b0cb6250dc
Author: Dimitris Papastamos <dimitris.papastamos@arm.com>
Date: Tue, 6 Nov 2018 16:46:48 +0000
[debuglang] Change rmu table generation
Change-Id: I9503702dccdfdbb141cd1063bc7543ee437ac69a
Signed-off-by: Dimitris Papastamos <dimitris.papastamos@arm.com>
Diffstat:
5 files changed, 148 insertions(+), 120 deletions(-)
diff --git a/scripts/gendebuglang.sh b/scripts/gendebuglang.sh
@@ -1,71 +1,38 @@
#!/bin/sh
-echo "
-#define BUFFER_SIZE 256
-#define NR_ARGC_MAX 16
-
-struct named_reg {
- char* name;
- size_t offset;
-};
-
-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)}
-};
-
-#define NUM_NAMED_REGS (sizeof(named_regs)/sizeof(struct named_reg))
-
-struct rmc_command {
- unsigned char class;
- unsigned char func;
- char* name;
+set -e
+
+trap 'r=$?; rm -f $$.tmp; exit $r' EXIT HUP INT QUIT TERM
+
+for i
+do
+ case $1 in
+ -o)
+ out=$2
+ shift 2
+ ;;
+ --)
+ break
+ ;;
+ -*)
+ echo usage: gendebuglang.sh -o out [file ...]
+ exit 1
+ ;;
+ esac
+done
+
+out=${out-debuglang.h}
+
+cat $@ |
+tr 'A-Z' 'a-z' |
+sed 's/\./_/' |
+cat <<EOF >$$.tmp && mv $$.tmp $out
+#include <stddef.h>
+
+#include "debuglang.h"
+
+const struct rmudesc rmudescs[] = {
+$(awk 'NF == 4 {printf("\t{%d, %d, \"%s\"},\n", $1, $2, $3)}' "$@")
+ {0, 0, NULL}
};
-
-#define NUM_RMC_COMMANDS (sizeof(rmc_commands)/sizeof(struct rmc_command))
-
-const struct rmc_command rmc_commands[]={
-"
-
-cat $@ |\
-awk '{print tolower($0)}'|\
-sed -e 's/\./\_/'|\
-sed -e 's/\./\_/'|\
-sed -e 's/\(^[0-9]*\)\t\([0-9]*\)\t\([a-z\_\.]*\).*/\t\{\1,\2,"\3"\},/'|\
-sed -e '$ s/.$//'
-
-echo "};"
+EOF
diff --git a/src/debuglang/.gitignore b/src/debuglang/.gitignore
@@ -0,0 +1 @@
+rmu.c
diff --git a/src/debuglang/Makefile b/src/debuglang/Makefile
@@ -1,7 +1,9 @@
PROJECTDIR=../..
include $(PROJECTDIR)/scripts/rules.mk
-OBJS = debuglang.o
+OBJS = debuglang.o \
+ rmu.o \
+
TARGET = builtin.o
all: $(TARGET)
@@ -9,10 +11,8 @@ all: $(TARGET)
builtin.o: $(OBJS)
$(LD) $(RCODE_LDFLAGS) -r -o $@ $(OBJS)
-debuglang.h: $(SCRIPTDIR)/rmu.cmd
- $(SCRIPTDIR)/gendebuglang.sh $(SCRIPTDIR)/rmu.cmd > $@
-
-debuglang.c: debuglang.h
+rmu.c: $(SCRIPTDIR)/rmu.cmd
+ $(SCRIPTDIR)/gendebuglang.sh -o $@ $(SCRIPTDIR)/rmu.cmd
clean:
- rm -f debuglang.h
+ rm -f rmu.c
diff --git a/src/debuglang/debuglang.c b/src/debuglang/debuglang.c
@@ -11,6 +11,8 @@
#include "debuglang.h"
#define PREFIX "> "
+#define NR_ARGC_MAX 16
+#define NUM_NAMED_REGS (sizeof(named_regs) / sizeof(struct named_reg))
extern jmp_buf recover;
@@ -21,13 +23,23 @@ 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 command {
+struct cmd {
char *name;
int (*eval)(char **argv, int argc, struct trapframe *tf);
char *helpmsg;
};
-static const struct command commands[]={
+struct args {
+ char *argv[NR_ARGC_MAX];
+ int argc;
+};
+
+struct named_reg {
+ char *name;
+ size_t offset;
+};
+
+static const struct cmd cmds[]={
{
.name = "set",
.eval = do_set,
@@ -63,6 +75,45 @@ static const struct command commands[]={
}
};
+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 void
error(char *fmt, ...)
{
@@ -139,27 +190,27 @@ get_named_reg(char *name, struct trapframe *tfp)
return (unsigned long long *) regptr;
}
-/* Get rmc_command struct for named rmc command */
-static const struct rmc_command *
-get_rmc_cmd(char *name)
+/* Get rmudesc struct for named rmu descriptor */
+static const struct rmudesc *
+get_rmudesc(char *name)
{
- size_t i;
+ const struct rmudesc *rmudesc;
- for (i = 0; i <NUM_RMC_COMMANDS; i++)
- if (strcmp(name, rmc_commands[i].name) == 0)
- return &rmc_commands[i];
+ for (rmudesc = rmudescs; rmudesc->name; rmudesc++)
+ if (strcmp(rmudesc->name, name) == 0)
+ return rmudesc;
return NULL;
}
-/* Get command struct for named command */
-static const struct command *
-get_command(char *name)
+/* Get cmd struct for named cmd */
+static const struct cmd *
+get_cmd(char *name)
{
- const struct command *com;
+ const struct cmd *cmd;
- for (com = commands; com->name; com++)
- if (strcmp(name, com->name) == 0)
- return com;
+ for (cmd = cmds; cmd->name; cmd++)
+ if (strcmp(name, cmd->name) == 0)
+ return cmd;
return NULL;
}
@@ -244,7 +295,7 @@ do_rmc(char **argv, int argc, struct trapframe *tfp)
unsigned char class;
unsigned char func;
unsigned int base;
- const struct rmc_command *rmc_cmd;
+ const struct rmudesc *rmudesc;
base = 0;
switch (argc) {
@@ -256,11 +307,11 @@ do_rmc(char **argv, int argc, struct trapframe *tfp)
func = base_read(argv[2], base);
break;
case 2:
- rmc_cmd = get_rmc_cmd(argv[1]);
- if (rmc_cmd == NULL)
+ rmudesc = get_rmudesc(argv[1]);
+ if (rmudesc == NULL)
error("rmc '%s' not found\n", argv[1]);
- class = rmc_cmd->class;
- func = rmc_cmd->func;
+ class = rmudesc->class;
+ func = rmudesc->func;
break;
default:
error("Invalid number of parameters for rmc\n");
@@ -276,45 +327,45 @@ do_rmc(char **argv, int argc, struct trapframe *tfp)
static int
do_help(char **argv, int argc, struct trapframe *tfp)
{
- const struct command *com;
+ const struct cmd *cmd;
- for (com = commands; com->name; com++)
- printf(PREFIX "%s\n", com->helpmsg);
+ for (cmd = cmds; cmd->name; cmd++)
+ printf(PREFIX "%s\n", cmd->helpmsg);
return 0;
}
-static void
-parse_cmd(char *cmd, struct trapframe *tfp)
+static const struct cmd *
+parse_cmd(char *buf, struct args *args)
{
- char *argv[NR_ARGC_MAX], *p;
- unsigned argc;
- const struct command *com;
-
- while (isspace(*cmd))
- ++cmd;
-
- argc = 0;
- for (p = strtok(cmd, " \t\r"); p; p = strtok(NULL, " \t\r")) {
- if (argc == NR_ARGC_MAX)
- error("too much parameters");
- argv[argc++] = p;
+ char *p;
+ const struct cmd *cmd;
+
+ while (isspace(*buf))
+ ++buf;
+
+ args->argc = 0;
+ for (p = strtok(buf, " \t\r"); p; p = strtok(NULL, " \t\r")) {
+ if (args->argc == NR_ARGC_MAX)
+ error("too many parameters");
+ args->argv[args->argc++] = p;
}
- if (argc == 0)
- return;
+ if (args->argc == 0)
+ return NULL;
- if ((com = get_command(argv[0])) == NULL)
- error("command '%s' not found", argv[0]);
+ if ((cmd = get_cmd(args->argv[0])) == NULL)
+ error("cmd '%s' not found", args->argv[0]);
- /* Call eval function for specific command */
- com->eval(argv, argc, tfp);
+ return cmd;
}
static int
run(struct trapframe *tf)
{
- char buffer[BUFFER_SIZE];
+ const struct cmd *cmd;
size_t len;
+ struct args args;
+ char buffer[BUFSIZ];
if (fgets(buffer, sizeof(buffer), stdin) == NULL)
return 0;
@@ -323,7 +374,9 @@ run(struct trapframe *tf)
if (buffer[len-1] != '\n')
error("line too long");
buffer[len-1] = '\0';
- parse_cmd(buffer, tf);
+ cmd = parse_cmd(buffer, &args);
+ if (cmd)
+ cmd->eval(args.argv, args.argc, tf);
}
return 1;
}
diff --git a/src/debuglang/debuglang.h b/src/debuglang/debuglang.h
@@ -0,0 +1,7 @@
+struct rmudesc {
+ unsigned char class;
+ unsigned char func;
+ char *name;
+};
+
+extern const struct rmudesc rmudescs[];