commit c2c1dec20d72b9cd15b700054263b0929fe4d94e
parent c64919fd78a5f0d13f8171898f7bed547444b95c
Author: Dimitris Papastamos <dimitris.papastamos@arm.com>
Date: Thu, 13 Dec 2018 14:16:22 +0000
Group all registers in trapframe in an array
Saves space on the stack during panic and makes certain operations
easier as they can easily be expressed with a for loop.
Change-Id: I7c3209bc79320b15b49073e93cff16a301948fc3
Signed-off-by: Dimitris Papastamos <dimitris.papastamos@arm.com>
Diffstat:
8 files changed, 127 insertions(+), 140 deletions(-)
diff --git a/include/rcode/rcode.h b/include/rcode/rcode.h
@@ -24,32 +24,50 @@ enum devflags {
O_TRUNC = 1 << 5,
};
+enum regidx {
+ X0,
+ X1,
+ X2,
+ X3,
+ X4,
+ X5,
+ X6,
+ X7,
+ X8,
+ X9,
+ X10,
+ X11,
+ X12,
+ X13,
+ X14,
+ X15,
+ X16,
+ X17,
+ X18,
+ X19,
+ X20,
+ X21,
+ X22,
+ X23,
+ X24,
+ X25,
+ X26,
+ X27,
+ X28,
+ X29,
+ ELR,
+ X30,
+ SPSR,
+ ESR,
+ SP,
+ FAR,
+ NR_REGS
+};
+
typedef struct rmucmd Rmucmd;
struct trapframe {
- unsigned long long x0, x1;
- unsigned long long x2, x3;
- unsigned long long x4, x5;
- unsigned long long x6, x7;
- unsigned long long x8, x9;
- unsigned long long x10, x11;
- unsigned long long x12, x13;
- unsigned long long x14, x15;
- unsigned long long x16, x17;
- unsigned long long x18, x19;
- unsigned long long x20, x21;
- unsigned long long x22, x23;
- unsigned long long x24, x25;
- unsigned long long x26, x27;
- unsigned long long x28, x29;
-
- void *elr;
- unsigned long long x30;
-
- unsigned long long spsr, esr;
-
- void *sp;
- unsigned long long far;
+ unsigned long long r[NR_REGS];
};
struct rmctab {
@@ -74,6 +92,7 @@ extern void rmc(Rmucmd *cmd);
extern int debug(void);
extern void idev(void);
extern void *reloc(const void *);
+extern char *regstr(enum regidx r);
/* driver functions */
extern int create(const char *name, int flags);
diff --git a/src/libhdl/hdl_RMU_System_InterfaceVersion.c b/src/libhdl/hdl_RMU_System_InterfaceVersion.c
@@ -7,6 +7,6 @@ hdl_RMU_System_InterfaceVersion(Rmucmd *cmd)
unsigned long maj, min;
RMU_System_InterfaceVersion(&maj, &min);
- cmd->fp->x1 = maj;
- cmd->fp->x2 = min;
+ cmd->fp->r[X1] = maj;
+ cmd->fp->r[X2] = min;
}
diff --git a/src/libhdl/hdl_RMU_System_Status.c b/src/libhdl/hdl_RMU_System_Status.c
@@ -7,5 +7,5 @@ hdl_RMU_System_Status(Rmucmd *cmd)
int enabled;
RMU_System_Status(&enabled);
- cmd->fp->x1 = enabled;
+ cmd->fp->r[X1] = enabled;
}
diff --git a/src/romfw/Makefile b/src/romfw/Makefile
@@ -4,6 +4,7 @@ include $(PROJECTDIR)/scripts/rules.mk
OBJS = rmc.o \
ecstr.o \
+ regstr.o \
rmu.o \
dlang.o \
diff --git a/src/romfw/dlang.c b/src/romfw/dlang.c
@@ -30,12 +30,6 @@ struct cmd {
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
@@ -59,25 +53,10 @@ ready(void)
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);
+ int i;
+
+ for (i = X0; i < NR_REGS; i++)
+ kprint("%s=0x%llx\n", regstr(i), fp->r[i]);
}
/* Read a value in a given base between 2 and 16 0 means default base;
@@ -100,19 +79,14 @@ estrtoull(char *str, int base)
/* Get reg struct for named reg */
static unsigned long long *
-get_named_reg(char *name)
+get_named_reg(char *name, struct trapframe *fp)
{
- 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;
+ int i;
+
+ for (i = 0; i < NR_REGS; i++)
+ if (strcmp(name, regstr(i)) == 0)
+ return &fp->r[i];
+ return NULL;
}
/* Get rmudesc struct for named rmu descriptor */
@@ -146,7 +120,7 @@ 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]);
+ reg = get_named_reg(args->argv[1], bss->fp);
if (reg == NULL)
error("set: %s: not found", args->argv[1]);
@@ -160,7 +134,7 @@ do_get(const struct cmd *cmd, struct args *args)
{
unsigned long long *reg = NULL;
- reg = get_named_reg(args->argv[1]);
+ reg = get_named_reg(args->argv[1], bss->fp);
if (reg == NULL)
error("get: %s: not found", args->argv[1]);
@@ -191,9 +165,9 @@ do_rmc(const struct cmd *cmd, struct args *args)
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);
+ bss->fp->r[ESR] = (unsigned long long) RMC << 26;
+ bss->fp->r[ESR] |= class;
+ bss->fp->r[ESR] |= (func << 8);
trap(bss->fp);
return 0;
}
@@ -215,9 +189,9 @@ do_rmu(const struct cmd *cmd, struct args *args)
if (desc == NULL)
error("rmu: %s: not found", args->argv[1]);
- bss->fp->esr = (unsigned long long) RMC << 26;
- bss->fp->esr |= desc->class;
- bss->fp->esr |= (desc->func << 8);
+ bss->fp->r[ESR] = (unsigned long long) RMC << 26;
+ bss->fp->r[ESR] |= desc->class;
+ bss->fp->r[ESR] |= (desc->func << 8);
trap(bss->fp);
return 0;
}
@@ -437,43 +411,3 @@ static const struct cmd cmds[] = {
.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/romfw/regstr.c b/src/romfw/regstr.c
@@ -0,0 +1,47 @@
+#include <rcode/rcode.h>
+
+const char *const regtbl[] = {
+ [X0] = "x0",
+ [X1] = "x1",
+ [X2] = "x2",
+ [X3] = "x3",
+ [X4] = "x4",
+ [X5] = "x5",
+ [X6] = "x6",
+ [X7] = "x7",
+ [X8] = "x8",
+ [X9] = "x9",
+ [X10] = "x10",
+ [X11] = "x11",
+ [X12] = "x12",
+ [X13] = "x13",
+ [X14] = "x14",
+ [X15] = "x15",
+ [X16] = "x16",
+ [X17] = "x17",
+ [X18] = "x18",
+ [X19] = "x19",
+ [X20] = "x20",
+ [X21] = "x21",
+ [X22] = "x22",
+ [X23] = "x23",
+ [X24] = "x24",
+ [X25] = "x25",
+ [X26] = "x26",
+ [X27] = "x27",
+ [X28] = "x28",
+ [X29] = "x29",
+ [ELR] = "elr",
+ [X30] = "x30",
+ [SPSR] = "spsr",
+ [ESR] = "esr",
+ [SP] = "sp",
+ [FAR] = "far",
+ NULL
+};
+
+char *
+regstr(enum regidx r)
+{
+ return reloc(regtbl[r]);
+}
diff --git a/src/romfw/rmc.c b/src/romfw/rmc.c
@@ -11,24 +11,10 @@
static void
dumpregs(struct trapframe *fp)
{
- kprint("x0=%0llx\tx1=%0llx\nx2=%0llx\tx3=%0llx\n"
- "x4=%0llx\tx5=%0llx\nx6=%0llx\tx7=%0llx\n"
- "x8=%0llx\tx9=%0llx\nx10=%0llx\tx11=%0llx\n"
- "x12=%0llx\tx13=%0llx\nx14=%0llx\tx15=%0llx\n"
- "x16=%0llx\tx17=%0llx\nx18=%0llx\tx19=%0llx\n"
- "x20=%0llx\tx21=%0llx\nx22=%0llx\tx23=%0llx\n"
- "x24=%0llx\tx25=%0llx\nx26=%0llx\tx27=%0llx\n"
- "x28=%0llx\tx29=%0llx\nx30=%0llx\telr=%p\n"
- "spsr=%0llx\tesr=%0llx\nfar=%0llx\tsp=%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);
+ int i;
+
+ for (i = X0; i < NR_REGS; i++)
+ kprint("%s=0x%llx\n", regstr(i), fp->r[i]);
}
static void
@@ -39,8 +25,8 @@ backtrace(struct trapframe *fp)
if (!bss->backtrace)
return;
kprint("backtrace:\n");
- kprint("%0llx\n", fp->x30);
- for (bp = (void **) fp->x29; *bp; bp = (void **) *bp)
+ kprint("%0llx\n", fp->r[X30]);
+ for (bp = (void **) fp->r[X29]; *bp; bp = (void **) *bp)
kprint("%p\n", bp[1]);
}
@@ -52,7 +38,7 @@ dumpstack(struct trapframe *fp)
if (!bss->dumpstack)
return;
kprint("stack dump:\n");
- sp = fp->sp;
+ sp = (long long *)fp->r[SP];
for (i = 1; i <= 16; i++)
kprint("%0llx%c", *sp++, (i % 4 == 0) ? '\n' : ' ');
}
@@ -115,7 +101,7 @@ trap(struct trapframe *fp)
}
dbg("exception handler\n");
- ec = (fp->esr >> 26) & 0x3f;
+ ec = (fp->r[ESR] >> 26) & 0x3f;
if (ec != RMC) {
msg = (ec < NR_EC_VALS) ? reloc(ecstr[ec]) : "unknown reason";
@@ -123,8 +109,8 @@ trap(struct trapframe *fp)
halt();
}
- cmd.class = fp->esr & 0xff;
- cmd.func = (fp->esr >> 8) & 0xff;
+ cmd.class = fp->r[ESR] & 0xff;
+ cmd.func = (fp->r[ESR] >> 8) & 0xff;
bss->fp = cmd.fp = fp;
bss->cmd = &cmd;
@@ -138,7 +124,7 @@ badcmd(int error)
Rmucmd *cmd = bss->cmd;
dbg("bad RMC: %d, %d = %d\n", cmd->class, cmd->func, error);
- bss->fp->x0 = error;
+ bss->fp->r[X0] = error;
swtch(bss->fp);
}
@@ -187,7 +173,7 @@ rmc(Rmucmd *cmd)
fn = (void (*) (Rmucmd *)) bp;
(*fn)(cmd);
- cmd->fp->x0 = SUCCESS;
+ cmd->fp->r[X0] = SUCCESS;
}
/*
diff --git a/target/native/rom.c b/target/native/rom.c
@@ -84,9 +84,9 @@ imach(Mach *mp, void *txt, size_t txtsiz, void *ram, size_t ramsiz)
mp->envsiz = ENVSIZ;
mp->bsssiz = BSSSIZ;
- fp->sp = mp->sp;
- fp->elr = (void *) rsysreg(RVBAR_EL3);
- fp->spsr = 0xf << 6 | 0xd;
+ fp->r[SP] = (unsigned long long)mp->sp;
+ fp->r[ELR] = rsysreg(RVBAR_EL3);
+ fp->r[SPSR] = 0xf << 6 | 0xd;
invicache();
invdcache();