commit b1e20f0c2a7dc2bca495afad4524e5e630d7e661
parent 044d1b41b1758fda7edead14273628e64fb8f1dd
Author: Dimitris Papastamos <dimitris.papastamos@arm.com>
Date: Thu, 8 Nov 2018 12:51:21 +0000
Rework bss access and split halt into C/asm parts
Change-Id: I23be63bd0c7c416c6416b7f606f553c8e1312a37
Signed-off-by: Dimitris Papastamos <dimitris.papastamos@arm.com>
Diffstat:
14 files changed, 77 insertions(+), 50 deletions(-)
diff --git a/arch/amd64/Makefile b/arch/amd64/Makefile
@@ -7,8 +7,11 @@ RAMOBJS = crt-$(SYS).o arch.o rom.o $(DEBUGLANG) $(SRCDIR)/ramfw/builtin.o
TARGET = $(BINDIR)/romfw.elf $(BINDIR)/ramfw.elf
LIBS = -lhdl -lrmu -lk -lc
-LIBDEP = $(LIBDIR)/libhdl.a $(LIBDIR)/librmu.a $(LIBDIR)/libc.a
+LIBDEP = $(LIBDIR)/libhdl.a \
+ $(LIBDIR)/librmu.a \
+ $(LIBDIR)/libk.a \
+ $(LIBDIR)/libc.a \
all: $(TARGET)
diff --git a/arch/amd64/arch.c b/arch/amd64/arch.c
@@ -10,7 +10,7 @@ _Noreturn void abort(void);
_Noreturn void longjmp(jmp_buf env, int val);
void
-halt(void)
+dohalt(void)
{
abort();
}
@@ -24,6 +24,5 @@ doswtch(struct trapframe *fp)
void
dopanic(void)
{
- printf("%s\n", bss->errstr);
- halt();
+ trap(NULL);
}
diff --git a/arch/arm64/Makefile b/arch/arm64/Makefile
@@ -22,7 +22,11 @@ RAMOBJS = ram-crt-$(SYS).o \
TARGET = $(BINDIR)/romfw.bin $(BINDIR)/ramfw.bin
LIBS = -lhdl -lrmu -lk -lc
-LIBDEP = $(LIBDIR)/libhdl.a $(LIBDIR)/librmu.a $(LIBDIR)/libc.a
+
+LIBDEP = $(LIBDIR)/libhdl.a \
+ $(LIBDIR)/librmu.a \
+ $(LIBDIR)/libk.a \
+ $(LIBDIR)/libc.a \
all: $(TARGET)
diff --git a/arch/arm64/arch.s b/arch/arm64/arch.s
@@ -1,7 +1,7 @@
.file "arch.s"
.text
- .globl panic,halt,enaint,dopanic
+ .globl panic,dohalt,enaint,dopanic
.globl rd_actlr_r,wr_actlr_r
.globl rd_id_aa64rmfr0_r,wr_id_aa64rmfr0_r
.globl rd_rcr_r,wr_rcr_r,rd_rdscr_r,wr_rdscr_r
@@ -85,10 +85,10 @@ outm32:
str w0, [x1]
ret
-halt:
+dohalt:
msr daifset,#15
wfe
- b halt
+ b dohalt
dopanic:
exception:
diff --git a/include/rcode.h b/include/rcode.h
@@ -128,42 +128,20 @@ struct rmucmd {
unsigned class, func;
};
-static inline struct bssmap * volatile
-bss(void)
-{
- uintptr_t addr;
-
- addr = ((uintptr_t)&addr & ~(PAGESIZE-1));
- return (struct bssmap *)addr;
-}
-#define bss bss()
-
-/*
- * Reloc() is used to relocate address
- * because we are linked at address 0 but we can be
- * loaded at any address
- */
-static inline void *
-reloc(const void *addr)
-{
- uintptr_t a = (uintptr_t) addr;
- uintptr_t off = (uintptr_t) bss->text;
-
- return (void *) (a + off);
-}
-
+extern _Noreturn void halt(void);
+extern _Noreturn void panic(const char *msg);
+extern _Noreturn void swtch(struct trapframe *fp);
extern void trap(struct trapframe *fp);
extern void badcmd(int error);
-extern _Noreturn void dopanic(void);
-extern _Noreturn void panic(const char *msg);
extern void printk(const char * restrict fmt, ...) PRINTKFMT;
extern void rmc(Rmucmd *cmd);
-extern _Noreturn void doswtch(struct trapframe *fp);
-extern _Noreturn void swtch(struct trapframe *fp);
extern int debug(void);
+extern struct bssmap *bss(void);
/* architectural functions */
-extern _Noreturn void halt(void);
+extern _Noreturn void dohalt(void);
+extern _Noreturn void dopanic(void);
+extern _Noreturn void doswtch(struct trapframe *fp);
extern void enaint(void);
extern unsigned long long rd_actlr_r(void);
extern void wr_actlr_r(unsigned long long v);
@@ -188,3 +166,19 @@ extern uint32_t outm32(uint32_t, void *addr);
extern const struct rowidx rowidx[];
extern const void *const handler[];
extern const char *const ecstr[];
+
+#define bss bss()
+
+/*
+ * Reloc() is used to relocate address
+ * because we are linked at address 0 but we can be
+ * loaded at any address
+ */
+static inline void *
+reloc(const void *addr)
+{
+ uintptr_t a = (uintptr_t) addr;
+ uintptr_t off = (uintptr_t) bss->text;
+
+ return (void *) (a + off);
+}
diff --git a/src/libk/Makefile b/src/libk/Makefile
@@ -3,6 +3,7 @@ PROJECTDIR=../..
include $(PROJECTDIR)/scripts/rules.mk
OBJS = printk.o \
+ bss.o \
TARGET = $(LIBDIR)/libk.a
diff --git a/src/libk/bss.c b/src/libk/bss.c
@@ -0,0 +1,12 @@
+#include <rcode.h>
+
+#undef bss
+
+struct bssmap *
+bss(void)
+{
+ uintptr_t addr;
+
+ addr = ((uintptr_t)&addr & ~(PAGESIZE-1));
+ return (struct bssmap *)addr;
+}
diff --git a/src/rmc.c b/src/rmc.c
@@ -68,6 +68,14 @@ panicfmt(const char *msg, struct trapframe *fp)
}
void
+halt(void)
+{
+ if (bss->in_debug)
+ longjmp(bss->dbgrecover, 1);
+ dohalt();
+}
+
+void
panic(const char *msg)
{
bss->errstr = msg;
diff --git a/test/unit/test1/Makefile b/test/unit/test1/Makefile
@@ -73,8 +73,8 @@ LIBOBJ = hdl_RMU_System_InterfaceVersion.o \
ROMOBJS = $(ARCHDIR)/crt-$(SYS).o $(SRCDIR)/romfw/builtin.o test.o
RAMOBJS = $(ARCHDIR)/crt-$(SYS).o $(SRCDIR)/ramfw/builtin.o test.o
-LIBS = -lhdl -lc
-LIBDEP = libhdl.a $(LIBDIR)/libc.a
+LIBS = -lhdl -lk -lc
+LIBDEP = libhdl.a $(LIBDIR)/libk.a $(LIBDIR)/libc.a
TARGET = romfw ramfw
diff --git a/test/unit/test1/test.c b/test/unit/test1/test.c
@@ -29,7 +29,7 @@ main(int argc, char *argv[])
}
void
-halt(void)
+dohalt(void)
{
abort();
}
@@ -37,8 +37,7 @@ halt(void)
void
dopanic(void)
{
- printf("%s\n", bss->errstr);
- halt();
+ trap(NULL);
}
void
diff --git a/test/unit/test3/Makefile b/test/unit/test3/Makefile
@@ -3,8 +3,12 @@ PROJECTDIR = ../../..
include $(PROJECTDIR)/scripts/rules.mk
OBJS = $(ARCHDIR)/crt-$(SYS).o $(SRCDIR)/romfw/builtin.o test.o
-LIBS = -lhdl -lrmu -lc
-LIBDEP = $(LIBDIR)/libhdl.a $(LIBDIR)/librmu.a $(LIBDIR)/libc.a
+LIBS = -lhdl -lrmu -lk -lc
+
+LIBDEP = $(LIBDIR)/libhdl.a \
+ $(LIBDIR)/librmu.a \
+ $(LIBDIR)/libk.a \
+ $(LIBDIR)/libc.a \
TARGET = run
diff --git a/test/unit/test3/test.c b/test/unit/test3/test.c
@@ -21,7 +21,7 @@ main(void)
}
void
-halt(void)
+dohalt(void)
{
abort();
}
@@ -29,8 +29,7 @@ halt(void)
void
dopanic(void)
{
- printf("%s\n", bss->errstr);
- halt();
+ trap(NULL);
}
void
diff --git a/test/unit/test4/Makefile b/test/unit/test4/Makefile
@@ -3,8 +3,12 @@ PROJECTDIR = ../../..
include $(PROJECTDIR)/scripts/rules.mk
OBJS = $(ARCHDIR)/crt-$(SYS).o $(SRCDIR)/romfw/builtin.o test.o
-LIBS = -lhdl -lrmu -lc
-LIBDEP = $(LIBDIR)/libhdl.a $(LIBDIR)/librmu.a $(LIBDIR)/libc.a
+LIBS = -lhdl -lrmu -lk -lc
+
+LIBDEP = $(LIBDIR)/libhdl.a \
+ $(LIBDIR)/librmu.a \
+ $(LIBDIR)/libk.a \
+ $(LIBDIR)/libc.a \
TARGET = run
diff --git a/test/unit/test4/test.c b/test/unit/test4/test.c
@@ -9,7 +9,7 @@ main(void)
}
void
-halt(void)
+dohalt(void)
{
exit(0);
}