9os

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

commit 06db3b4bdc78ffcd62b72f4906c6f7a6be4920d7
parent 8322357836dde65eb4779b3b24dd1ffc3ab0cec2
Author: Dimitris Papastamos <dimitris.papastamos@arm.com>
Date:   Wed, 21 Nov 2018 13:54:30 +0000

Merge "[dlang] Move dlang to romfw"
Diffstat:
March/amd64/Makefile | 2--
March/amd64/ram.c | 4+---
March/arm64/Makefile | 2--
March/rmode/Makefile | 2--
Msrc/Makefile | 4++--
Dsrc/dlang/Makefile | 19-------------------
Dsrc/dlang/dlang.c | 452-------------------------------------------------------------------------------
Rsrc/dlang/.gitignore -> src/romfw/.gitignore | 0
Msrc/romfw/Makefile | 7++++++-
Asrc/romfw/dlang.c | 465+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Rsrc/dlang/dlang.h -> src/romfw/dlang.h | 0
Rscripts/gendlang.sh -> src/romfw/mkrmu | 0
12 files changed, 474 insertions(+), 483 deletions(-)

diff --git a/arch/amd64/Makefile b/arch/amd64/Makefile @@ -6,14 +6,12 @@ ROMOBJS = crt-$(SYS).o \ arch.o \ rom.o \ bss.o \ - $(DLANG) \ $(SRCDIR)/romfw/builtin.o \ RAMOBJS = crt-$(SYS).o \ arch.o \ ram.o \ bss.o \ - $(DLANG) \ $(SRCDIR)/ramfw/builtin.o \ TARGET = $(BINDIR)/romfw.elf $(BINDIR)/ramfw.elf diff --git a/arch/amd64/ram.c b/arch/amd64/ram.c @@ -5,7 +5,5 @@ int main(int argc, char *argv[]) { - memset(bss, 0, sizeof(struct bssmap)); - bss->fp = &(struct trapframe) {0}; - return debug(); + return 0; } diff --git a/arch/arm64/Makefile b/arch/arm64/Makefile @@ -6,14 +6,12 @@ ROMOBJS = crt-$(SYS).o \ rom.o \ arch.o \ bss.o \ - $(DLANG) \ $(SRCDIR)/romfw/builtin.o \ RAMOBJS = crt-$(SYS).o \ ram.o \ arch.o \ bss.o \ - $(DLANG) \ $(SRCDIR)/ramfw/builtin.o \ TARGET = $(BINDIR)/romfw.bin $(BINDIR)/ramfw.bin diff --git a/arch/rmode/Makefile b/arch/rmode/Makefile @@ -10,7 +10,6 @@ ROMOBJS = rom-crt.o \ rom.o \ arch.o \ sysreg.o \ - $(DLANG) \ $(DRVDIR)/uart.o \ $(SRCDIR)/romfw/builtin.o \ cache.o \ @@ -19,7 +18,6 @@ RAMOBJS = ram-crt.o \ ram.o \ arch.o \ sysreg.o \ - $(DLANG) \ $(DRVDIR)/uart.o \ $(SRCDIR)/ramfw/builtin.o \ diff --git a/src/Makefile b/src/Makefile @@ -4,7 +4,7 @@ include $(PROJECTDIR)/scripts/rules.mk LIBS = libk libc librmu libtypes libhdl IMGS = ramfw romfw -DIRS = $(LIBS) $(IMGS) dlang +DIRS = $(LIBS) $(IMGS) OBJS = rmc.o ecstr.o all: $(IMGS) @@ -15,7 +15,7 @@ gen: FORCE ecstr.c: $(INCDIR)/rcode.h $(SCRIPTDIR)/genecstr.sh $(INCDIR)/rcode.h -$(IMGS): $(LIBS) $(OBJS) dlang +$(IMGS): $(LIBS) $(OBJS) $(DIRS): FORCE +@cd $@ && $(MAKE) diff --git a/src/dlang/Makefile b/src/dlang/Makefile @@ -1,19 +0,0 @@ -.POSIX: -PROJECTDIR=../.. -include $(PROJECTDIR)/scripts/rules.mk - -OBJS = dlang.o \ - rmu.o \ - -TARGET = builtin.o - -all: $(TARGET) - -builtin.o: $(OBJS) - $(LD) $(RCODE_LDFLAGS) -r -o $@ $(OBJS) - -rmu.c: $(SCRIPTDIR)/rmu.cmd - $(SCRIPTDIR)/gendlang.sh -o $@ $(SCRIPTDIR)/rmu.cmd - -clean: - rm -f rmu.c diff --git a/src/dlang/dlang.c b/src/dlang/dlang.c @@ -1,452 +0,0 @@ -#include <ctype.h> -#include <errno.h> -#include <setjmp.h> -#include <stdarg.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -#include <rcode.h> - -#include "dlang.h" - -#define PREFIX "> " -#define NR_ARGC_MAX 16 -#define toascii(c) ((c) & 0x7f) - -struct args { - char *argv[NR_ARGC_MAX]; - int argc; - int status; -}; - -struct cmd { - char *name; - char *helpmsg; - int (*eval)(const struct cmd *cmd, struct args *args); - unsigned char min; - unsigned char max; -}; - -struct named_reg { - char *name; - size_t offset; -}; - -static const struct named_reg named_regs[]; -static const struct cmd cmds[]; - -static void -error(char *fmt, ...) -{ - va_list va; - - va_start(va, fmt); - fputs(PREFIX "ERR ", stdout); - vprintf(fmt, va); - fputc('\n', stdout); - longjmp(bss->dbgrecover, 1); -} - -static void -ready(void) -{ - puts(PREFIX "READY"); -} - -static void -print_tf(struct trapframe *fp) -{ - printf(PREFIX "x0=0x%llx\tx1=0x%llx\tx2=0x%llx\tx3=0x%llx\n" - PREFIX "x4=0x%llx\tx5=0x%llx\tx6=0x%llx\tx7=0x%llx\n" - PREFIX "x8=0x%llx\tx9=0x%llx\tx10=0x%llx\tx11=0x%llx\n" - PREFIX "x12=0x%llx\tx13=0x%llx\tx14=0x%llx\tx15=0x%llx\n" - PREFIX "x16=0x%llx\tx17=0x%llx\tx18=0x%llx\tx19=0x%llx\n" - PREFIX "x20=0x%llx\tx21=0x%llx\tx22=0x%llx\tx23=0x%llx\n" - PREFIX "x24=0x%llx\tx25=0x%llx\tx26=0x%llx\tx27=0x%llx\n" - PREFIX "x28=0x%llx\tx29=0x%llx\tx30=0x%llx\telr=%p\n" - PREFIX "spsr=0x%llx\tesr=0x%llx\tfar=0x%llx\n" - PREFIX "sp=0x%p\n", - fp->x0, fp->x1, fp->x2, fp->x3, - fp->x4, fp->x5, fp->x6, fp->x7, - fp->x8, fp->x9, fp->x10, fp->x11, - fp->x12, fp->x13, fp->x14, fp->x15, - fp->x16, fp->x17, fp->x18, fp->x19, - fp->x20, fp->x21, fp->x22, fp->x23, - fp->x24, fp->x25, fp->x26, fp->x27, - fp->x28, fp->x29, fp->x30, fp->elr, - fp->spsr, fp->esr, fp->far, fp->sp); -} - -/* Read a value in a given base between 2 and 16 0 means default base; - * 10, unless the string begins with "0x" or "0b" - */ -static unsigned long long -estrtoull(char *str, int base) -{ - unsigned long long val; - char *endptr; - - errno = 0; - val = strtoull(str, &endptr, base); - if (*str == '\0' || *endptr != '\0') - error("estrtoull: %s: not an integer", str); - if (errno) - error("estrtoull: %s: %s", strerror(errno)); - return val; -} - -/* Get reg struct for named reg */ -static unsigned long long * -get_named_reg(char *name) -{ - char *regptr; - const struct named_reg *rp; - - regptr = NULL; - for (rp = named_regs; rp->name; ++rp) { - if (strcmp(name, rp->name) == 0) { - regptr = (char *) bss->fp; - regptr += rp->offset; - } - } - return (unsigned long long *) regptr; -} - -/* Get rmudesc struct for named rmu descriptor */ -static const struct rmudesc * -get_rmudesc(char *name) -{ - const struct rmudesc *rmudesc; - - for (rmudesc = rmudescs; rmudesc->name; rmudesc++) - if (strcmp(rmudesc->name, name) == 0) - return rmudesc; - return NULL; -} - -/* Get cmd struct for named cmd */ -static const struct cmd * -get_cmd(char *name) -{ - const struct cmd *cmd; - - for (cmd = cmds; cmd->name; cmd++) - if (strcmp(name, cmd->name) == 0) - return cmd; - return NULL; -} - -static int -do_set(const struct cmd *cmd, struct args *args) -{ - unsigned long long *reg = NULL; - unsigned long long setval = 0; - - reg = get_named_reg(args->argv[1]); - if (reg == NULL) - error("set: %s: not found", args->argv[1]); - - setval = estrtoull(args->argv[2], 0); - *reg = setval; - return 0; -} - -static int -do_get(const struct cmd *cmd, struct args *args) -{ - unsigned long long *reg = NULL; - - reg = get_named_reg(args->argv[1]); - if (reg == NULL) - error("get: %s: not found", args->argv[1]); - - printf("%llx\n", *reg); - return 0; -} - -static int -do_dump(const struct cmd *cmd, struct args *args) -{ - print_tf(bss->fp); - return 0; -} - -static int -do_trap(const struct cmd *cmd, struct args *args) -{ - trap(bss->fp); - return 0; -} - -static int -do_rmc(const struct cmd *cmd, struct args *args) -{ - unsigned char class; - unsigned char func; - - class = estrtoull(args->argv[1], 0); - func = estrtoull(args->argv[2], 0); - - bss->fp->esr = (unsigned long long) RMC << 26; - bss->fp->esr |= class; - bss->fp->esr |= (func << 8); - trap(bss->fp); - return 0; -} - -static int -do_rmu(const struct cmd *cmd, struct args *args) -{ - const struct rmudesc *rmudesc; - - if (args->argv[1][0] == '?') { - for (rmudesc = rmudescs; rmudesc->name; rmudesc++) - puts(rmudesc->name); - return 0; - } - - rmudesc = get_rmudesc(args->argv[1]); - if (rmudesc == NULL) - error("rmu: %s: not found", args->argv[1]); - - bss->fp->esr = (unsigned long long) RMC << 26; - bss->fp->esr |= rmudesc->class; - bss->fp->esr |= (rmudesc->func << 8); - trap(bss->fp); - return 0; -} - -static int -do_exit(const struct cmd *cmd, struct args *args) -{ - args->status = 0; - if (args->argc == 2) - args->status = estrtoull(args->argv[1], 0); - return -1; -} - -static int -do_help(const struct cmd *cmd, struct args *args) -{ - for (cmd = cmds; cmd->name; cmd++) - printf(PREFIX "%s\n", cmd->helpmsg); - return 0; -} - -static int -do_cat(const struct cmd *cmd, struct args *args) -{ - int fd, n; - char buf[100]; - - if ((fd = open(args->argv[1], FSREAD)) < 0) - return -1; - - while ((n = read(fd, buf, sizeof(buf))) > 0) - kprint(PREFIX "%s\n", buf); - - if (close(fd) < 0 || n < 0) - return -1; - - return 0; -} - -static int -do_chdir(const struct cmd *cmd, struct args *args) -{ - return chdir(args->argv[1]); -} - -static const struct cmd * -parse_cmd(char *buf, struct args *args) -{ - char *p; - const struct cmd *cmd; - - while (isspace(toascii(*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 (args->argc == 0) - return NULL; - - if ((cmd = get_cmd(args->argv[0])) == NULL) - error("%s: not found", args->argv[0]); - - return cmd; -} - -static int -run(struct args *args) -{ - const struct cmd *cmd; - size_t len; - char buffer[BUFSIZ]; - - if (kgetln(buffer, sizeof(buffer)) == NULL) { - args->status = 1; - return -1; - } - - if ((len = strlen(buffer)) != 0) { - if (buffer[len-1] != '\n') - error("line too long"); - buffer[len-1] = '\0'; - cmd = parse_cmd(buffer, args); - if (cmd) { - if (args->argc < cmd->min || args->argc > cmd->max) - error(cmd->helpmsg); - return cmd->eval(cmd, args); - } - } - - return 0; -} - -int -debug(void) -{ - struct args args; - - bss->in_debug = 1; - - setvbuf(stdout, NULL, _IOLBF, 0); - printf("begin debug language interface\n"); - - setjmp(bss->dbgrecover); - for (ready(); !run(&args); ready()) - ; - - if (ferror(stdout)) - puts("error writing in stdout"); - if (ferror(stdin)) - puts("error reading from stdin"); - printf("end debug language interface\n"); - return args.status; -} - -/* - * definition of arrays - */ -static const struct cmd cmds[] = { - { - .name = "set", - .eval = do_set, - .min = 3, - .max = 3, - .helpmsg = "Set a register: set <reg> <value>", - }, - { - .name = "get", - .eval = do_get, - .min = 2, - .max = 2, - .helpmsg = "Get a register: get <reg>", - }, - { - .name = "dump", - .eval = do_dump, - .min = 1, - .max = 1, - .helpmsg = "Dump trapframe: dump", - }, - { - .name = "trap", - .eval = do_trap, - .min = 1, - .max = 1, - .helpmsg = "Call trap handler: trap", - }, - { - .name = "rmc", - .eval = do_rmc, - .min = 3, - .max = 3, - .helpmsg = "Call RMC handler: rmc imm1 imm2", - }, - { - .name = "rmu", - .eval = do_rmu, - .min = 2, - .max = 2, - .helpmsg = "Call RMU handler: rmu rmucmd", - }, - { - .name = "exit", - .eval = do_exit, - .min = 1, - .max = 2, - .helpmsg = "Exit debug environment: exit [status]", - }, - { - .name = "help", - .eval = do_help, - .min = 1, - .max = 1, - .helpmsg = "Print this help menu: help", - }, - { - .name = "cat", - .eval = do_cat, - .min = 2, - .max = 2, - .helpmsg = "Print the content of an entry: cat path", - }, - { - .name = "cd", - .eval = do_chdir, - .min = 2, - .max = 2, - .helpmsg = "change the current directory: cd path", - }, - { - .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}, -}; diff --git a/src/dlang/.gitignore b/src/romfw/.gitignore diff --git a/src/romfw/Makefile b/src/romfw/Makefile @@ -5,6 +5,8 @@ include $(PROJECTDIR)/scripts/rules.mk OBJS = ../rmc.o \ ../ecstr.o \ rmctbl.o \ + rmu.o \ + dlang.o \ fs.o \ drvfs.o \ dirfs.o \ @@ -14,8 +16,11 @@ all: builtin.o builtin.o: $(OBJS) $(LD) $(RCODE_LDFLAGS) -r -o $@ $(OBJS) +rmu.c: $(SCRIPTDIR)/rmu.cmd + ./mkrmu -o $@ $(SCRIPTDIR)/rmu.cmd + rmctbl.c: $(SCRIPTDIR)/rmu.cmd $(SCRIPTDIR)/gentbl.sh -o $@ -b rom -i $(SCRIPTDIR)/rmu.cmd clean: - rm -f rmctbl.c + rm -f rmctbl.c rmu.c diff --git a/src/romfw/dlang.c b/src/romfw/dlang.c @@ -0,0 +1,465 @@ +#include <ctype.h> +#include <errno.h> +#include <setjmp.h> +#include <stdarg.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include <rcode.h> + +#include "dlang.h" + +#define PREFIX "> " +#define NR_ARGC_MAX 16 + +struct args { + char *argv[NR_ARGC_MAX]; + int argc; + int status; +}; + +struct cmd { + char *name; + char *helpmsg; + int (*eval)(const struct cmd *cmd, struct args *args); + unsigned char min; + unsigned char max; +}; + +struct named_reg { + char *name; + size_t offset; +}; + +static const struct named_reg named_regs[]; +static const struct cmd cmds[]; + +static void +error(char *fmt, ...) +{ + va_list va; + + va_start(va, fmt); + kputs(PREFIX "ERR "); + kvprint(fmt, va); + kputc('\n'); + longjmp(bss->dbgrecover, 1); +} + +static void +ready(void) +{ + kputs(PREFIX "READY\n"); +} + +static void +print_tf(struct trapframe *fp) +{ + kprint(PREFIX "x0=0x%llx\tx1=0x%llx\tx2=0x%llx\tx3=0x%llx\n" + PREFIX "x4=0x%llx\tx5=0x%llx\tx6=0x%llx\tx7=0x%llx\n" + PREFIX "x8=0x%llx\tx9=0x%llx\tx10=0x%llx\tx11=0x%llx\n" + PREFIX "x12=0x%llx\tx13=0x%llx\tx14=0x%llx\tx15=0x%llx\n" + PREFIX "x16=0x%llx\tx17=0x%llx\tx18=0x%llx\tx19=0x%llx\n" + PREFIX "x20=0x%llx\tx21=0x%llx\tx22=0x%llx\tx23=0x%llx\n" + PREFIX "x24=0x%llx\tx25=0x%llx\tx26=0x%llx\tx27=0x%llx\n" + PREFIX "x28=0x%llx\tx29=0x%llx\tx30=0x%llx\telr=%p\n" + PREFIX "spsr=0x%llx\tesr=0x%llx\tfar=0x%llx\n" + PREFIX "sp=0x%p\n", + fp->x0, fp->x1, fp->x2, fp->x3, + fp->x4, fp->x5, fp->x6, fp->x7, + fp->x8, fp->x9, fp->x10, fp->x11, + fp->x12, fp->x13, fp->x14, fp->x15, + fp->x16, fp->x17, fp->x18, fp->x19, + fp->x20, fp->x21, fp->x22, fp->x23, + fp->x24, fp->x25, fp->x26, fp->x27, + fp->x28, fp->x29, fp->x30, fp->elr, + fp->spsr, fp->esr, fp->far, fp->sp); +} + +/* Read a value in a given base between 2 and 16 0 means default base; + * 10, unless the string begins with "0x" or "0b" + */ +static unsigned long long +estrtoull(char *str, int base) +{ + unsigned long long val; + char *endptr; + + errno = 0; + val = strtoull(str, &endptr, base); + if (*str == '\0' || *endptr != '\0') + error("estrtoull: %s: not an integer", str); + if (errno) + error("estrtoull: %s: %s", strerror(errno)); + return val; +} + +/* Get reg struct for named reg */ +static unsigned long long * +get_named_reg(char *name) +{ + char *regptr; + const struct named_reg *rp; + + regptr = NULL; + for (rp = named_regs; rp->name; ++rp) { + if (strcmp(name, rp->name) == 0) { + regptr = (char *) bss->fp; + regptr += rp->offset; + } + } + return (unsigned long long *) regptr; +} + +/* Get rmudesc struct for named rmu descriptor */ +static const struct rmudesc * +get_rmudesc(char *name) +{ + const struct rmudesc *rmudesc; + + for (rmudesc = rmudescs; rmudesc->name; rmudesc++) + if (strcmp(rmudesc->name, name) == 0) + return rmudesc; + return NULL; +} + +/* Get cmd struct for named cmd */ +static const struct cmd * +get_cmd(char *name) +{ + const struct cmd *cmd; + + for (cmd = cmds; cmd->name; cmd++) + if (strcmp(name, cmd->name) == 0) + return cmd; + return NULL; +} + +static int +do_set(const struct cmd *cmd, struct args *args) +{ + unsigned long long *reg = NULL; + unsigned long long setval = 0; + + reg = get_named_reg(args->argv[1]); + if (reg == NULL) + error("set: %s: not found", args->argv[1]); + + setval = estrtoull(args->argv[2], 0); + *reg = setval; + return 0; +} + +static int +do_get(const struct cmd *cmd, struct args *args) +{ + unsigned long long *reg = NULL; + + reg = get_named_reg(args->argv[1]); + if (reg == NULL) + error("get: %s: not found", args->argv[1]); + + kprint("%llx\n", *reg); + return 0; +} + +static int +do_dump(const struct cmd *cmd, struct args *args) +{ + print_tf(bss->fp); + return 0; +} + +static int +do_trap(const struct cmd *cmd, struct args *args) +{ + trap(bss->fp); + return 0; +} + +static int +do_rmc(const struct cmd *cmd, struct args *args) +{ + unsigned char class; + unsigned char func; + + class = estrtoull(args->argv[1], 0); + func = estrtoull(args->argv[2], 0); + + bss->fp->esr = (unsigned long long) RMC << 26; + bss->fp->esr |= class; + bss->fp->esr |= (func << 8); + trap(bss->fp); + return 0; +} + +static int +do_rmu(const struct cmd *cmd, struct args *args) +{ + const struct rmudesc *rmudesc; + + if (args->argv[1][0] == '?') { + for (rmudesc = rmudescs; rmudesc->name; rmudesc++) + kprint("%s\n", rmudesc->name); + return 0; + } + + rmudesc = get_rmudesc(args->argv[1]); + if (rmudesc == NULL) + error("rmu: %s: not found", args->argv[1]); + + bss->fp->esr = (unsigned long long) RMC << 26; + bss->fp->esr |= rmudesc->class; + bss->fp->esr |= (rmudesc->func << 8); + trap(bss->fp); + return 0; +} + +static int +do_exit(const struct cmd *cmd, struct args *args) +{ + args->status = 0; + if (args->argc == 2) + args->status = estrtoull(args->argv[1], 0); + return -1; +} + +static int +do_help(const struct cmd *cmd, struct args *args) +{ + for (cmd = cmds; cmd->name; cmd++) + kprint(PREFIX "%s\n", cmd->helpmsg); + return 0; +} + +static int +do_cat(const struct cmd *cmd, struct args *args) +{ + int fd, n; + char buf[100]; + + if ((fd = open(args->argv[1], FSREAD)) < 0) + return -1; + + while ((n = read(fd, buf, sizeof(buf))) > 0) + kprint(PREFIX "%s\n", buf); + + if (close(fd) < 0 || n < 0) + return -1; + + return 0; +} + +static int +do_chdir(const struct cmd *cmd, struct args *args) +{ + return chdir(args->argv[1]); +} + +static char * +tokenize(char **line, const char *delim) +{ + char *s, *t; + + t = *line; + if (!t) + return NULL; + + s = t + strspn(t, delim); + if (*s == '\0') + return *line = NULL; + + t = s + strcspn(s, delim); + if (*t != '\0') + *t++ = '\0'; + else + t = NULL; + *line = t; + + return s; +} + +static const struct cmd * +parse_cmd(char *buf, struct args *args) +{ + char *p; + const struct cmd *cmd; + + args->argc = 0; + while ((p = tokenize(&buf, " \t\r")) != NULL) { + if (args->argc == NR_ARGC_MAX) + error("too many parameters"); + args->argv[args->argc++] = p; + } + + if (args->argc == 0) + return NULL; + + if ((cmd = get_cmd(args->argv[0])) == NULL) + error("%s: not found", args->argv[0]); + + return cmd; +} + +static int +run(struct args *args) +{ + const struct cmd *cmd; + size_t len; + char buffer[BUFSIZ]; + + if (kgetln(buffer, sizeof(buffer)) == NULL) { + args->status = 1; + return -1; + } + + if ((len = strlen(buffer)) != 0) { + if (buffer[len-1] != '\n') + error("line too long"); + buffer[len-1] = '\0'; + cmd = parse_cmd(buffer, args); + if (cmd) { + if (args->argc < cmd->min || args->argc > cmd->max) + error(cmd->helpmsg); + return cmd->eval(cmd, args); + } + } + + return 0; +} + +int +debug(void) +{ + struct args args; + + bss->in_debug = 1; + + kprint("begin debug language interface\n"); + setjmp(bss->dbgrecover); + for (ready(); !run(&args); ready()) + ; + kprint("end debug language interface\n"); + + return args.status; +} + +/* + * definition of arrays + */ +static const struct cmd cmds[] = { + { + .name = "set", + .eval = do_set, + .min = 3, + .max = 3, + .helpmsg = "Set a register: set <reg> <value>", + }, + { + .name = "get", + .eval = do_get, + .min = 2, + .max = 2, + .helpmsg = "Get a register: get <reg>", + }, + { + .name = "dump", + .eval = do_dump, + .min = 1, + .max = 1, + .helpmsg = "Dump trapframe: dump", + }, + { + .name = "trap", + .eval = do_trap, + .min = 1, + .max = 1, + .helpmsg = "Call trap handler: trap", + }, + { + .name = "rmc", + .eval = do_rmc, + .min = 3, + .max = 3, + .helpmsg = "Call RMC handler: rmc imm1 imm2", + }, + { + .name = "rmu", + .eval = do_rmu, + .min = 2, + .max = 2, + .helpmsg = "Call RMU handler: rmu rmucmd", + }, + { + .name = "exit", + .eval = do_exit, + .min = 1, + .max = 2, + .helpmsg = "Exit debug environment: exit [status]", + }, + { + .name = "help", + .eval = do_help, + .min = 1, + .max = 1, + .helpmsg = "Print this help menu: help", + }, + { + .name = "cat", + .eval = do_cat, + .min = 2, + .max = 2, + .helpmsg = "Print the content of an entry: cat path", + }, + { + .name = "cd", + .eval = do_chdir, + .min = 2, + .max = 2, + .helpmsg = "change the current directory: cd path", + }, + { + .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}, +}; diff --git a/src/dlang/dlang.h b/src/romfw/dlang.h diff --git a/scripts/gendlang.sh b/src/romfw/mkrmu