commit 6e2d2bb546697770a84c56da2c52aceecd3ac571
parent 06260c1e28a5d6fd74b0df83105c0cace809f9ad
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date: Sun, 27 Sep 2020 14:19:07 +0200
os9/hosted: Movee panic() to arch code
Panic() cannot be generic as it depends heavily of the architecture
and having a generic panic() is not possible.
Change-Id: Iaa7b5e4b3171262ce3a0021709abbe6fa01649e4
Diffstat:
10 files changed, 162 insertions(+), 169 deletions(-)
diff --git a/include/os9/os9.h b/include/os9/os9.h
@@ -28,46 +28,6 @@ typedef struct proc Proc;
typedef struct task Task;
typedef struct win Win;
-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
-};
-
enum pstates {
PSYSTEM = 1 << 0,
};
@@ -97,10 +57,6 @@ enum start_reason {
SNORMAL,
};
-struct context {
- unsigned long long r[NR_REGS];
-};
-
struct task {
int tid;
@@ -123,7 +79,7 @@ struct task {
int flags;
- Context ctx;
+ /* Context ctx; */
};
struct proc {
@@ -164,7 +120,7 @@ extern void idev(void);
extern void dumpregs(Context *ctx, int fd);
/* architectural functions */
-extern Context *getcontext(Context *ctx);
+extern Context *getctx(Context *ctx);
extern void *alloc(size_t size);
extern void interrupt(int);
extern uint8_t inm8(void *addr);
diff --git a/src/os9/Makefile b/src/os9/Makefile
@@ -4,7 +4,6 @@ include $(PROJECTDIR)/scripts/rules.mk
OBJS =\
dlang.o\
- panic.o\
sched.o\
dev/builtin.o\
diff --git a/src/os9/arch/arm64/Makefile b/src/os9/arch/arm64/Makefile
@@ -3,15 +3,16 @@ PROJECTDIR = ../../../..
include $(PROJECTDIR)/scripts/rules.mk
OBJS =\
- svc.o \
- ecstr.o \
- crt.o \
- main.o \
- arch.o \
- debug_lock.o \
- sysreg.o \
- cache.o \
+ svc.o\
+ ecstr.o\
+ main.o\
+ arch.o\
+ debug_lock.o\
+ sysreg.o\
+ cache.o\
+ panic.o\
fvp.o\
+ crt.o\
$(SRCDIR)/os9/builtin.o \
TARGET = $(BINDIR)/os9.bin
diff --git a/src/os9/arch/arm64/arch.h b/src/os9/arch/arm64/arch.h
@@ -82,12 +82,56 @@ enum barrier_type {
typedef struct mach Mach;
typedef unsigned long long pte_t, phyaddr_t;
+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
+};
+
struct mach {
phyaddr_t phystack;
phyaddr_t ktzero;
phyaddr_t ptable;
};
+struct context {
+ unsigned long long r[NR_REGS];
+};
+
extern void main(Mach *);
extern void syswr(int, unsigned long long);
extern unsigned long long sysrd(int);
diff --git a/src/os9/arch/arm64/panic.c b/src/os9/arch/arm64/panic.c
@@ -0,0 +1,96 @@
+#include <libk.h>
+#include <os9/os9.h>
+
+#include "arch.h"
+
+const char *const regnames[] = {
+ [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
+};
+
+void
+dumpregs(Context *ctx, int fd)
+{
+ int i;
+
+ for (i = 0; i < NR_REGS; i++)
+ kprint(fd, "%s=0x%llx%c", regnames[i], ctx->r[i],
+ (i > 0 && i % 3 == 0) ? '\n' : ' ');
+ if (i % 4 != 3)
+ kputc(fd, '\n');
+}
+
+static void
+backtrace(Context *ctx)
+{
+ void **bp;
+
+ kprint(kerr, "backtrace:\n");
+ kprint(kerr, "%0llx\n", ctx->r[X30]);
+ for (bp = (void **) ctx->r[X29]; *bp; bp = (void **) *bp)
+ kprint(kerr, "%p\n", bp[1]);
+}
+
+static void
+dumpstack(Context *ctx)
+{
+ long long *sp, i;
+
+ kprint(kerr, "stack dump:\n");
+ sp = (long long *) ctx->r[SP];
+ for (i = 1; i <= 16; i++)
+ kprint(kerr, "%0llx%c", *sp++, (i % 4 == 0) ? '\n' : ' ');
+}
+
+void
+panic(const char *msg)
+{
+ static int first = 1;
+ Context ctx;
+
+ if (first) {
+ first = 0;
+ getctx(&ctx);
+ kprint(kerr, "panic: %s\n", msg);
+ dumpregs(&ctx, kerr);
+ backtrace(&ctx);
+ dumpstack(&ctx);
+ }
+
+ halt();
+}
diff --git a/src/os9/arch/arm64/svc.c b/src/os9/arch/arm64/svc.c
@@ -5,6 +5,7 @@
#include <os9/os9.h>
#include "ec.h"
+#include "arch.h"
void
trap(Context *ctx)
diff --git a/src/os9/hosted/Makefile b/src/os9/hosted/Makefile
@@ -3,11 +3,11 @@ PROJECTDIR = ../../..
include $(PROJECTDIR)/scripts/rules.mk
OBJS =\
- arch.o \
- lock.o \
- main.o \
- $(LIBDIR)/crt.o \
- $(SRCDIR)/os9/builtin.o \
+ arch.o\
+ lock.o\
+ main.o\
+ $(LIBDIR)/crt.o\
+ $(SRCDIR)/os9/builtin.o\
TARGET = $(BINDIR)/os9.elf
diff --git a/src/os9/hosted/arch.c b/src/os9/hosted/arch.c
@@ -11,13 +11,6 @@ jmp_buf recover;
noreturn void abort(void);
noreturn void longjmp(jmp_buf env, int val);
-Context *(*getframe)(void);
-
-Context *
-getcontext(Context *ctx)
-{
- return memcpy(ctx, (*getframe)(), sizeof(*ctx));
-}
void
halt(void)
diff --git a/src/os9/hosted/main.c b/src/os9/hosted/main.c
@@ -7,15 +7,13 @@
#include "hosted.h"
-static Context *frame(void);
+noreturn void longjmp(jmp_buf env, int val);
-Context trapframe, *framep;
-Context *(*getframe)(void) = frame;
-
-static Context *
-frame(void)
+void
+panic(const char *msg)
{
- return framep;
+ kprint(kerr, "panic %s\n", msg);
+ longjmp(recover, 1);
}
void *
@@ -42,7 +40,6 @@ imach(void)
{
if (setjmp(recover))
exit(EXIT_FAILURE);
- framep = &trapframe;
}
static void
diff --git a/src/os9/panic.c b/src/os9/panic.c
@@ -1,94 +0,0 @@
-#include <libk.h>
-#include <os9/os9.h>
-
-const char *const regnames[] = {
- [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
-};
-
-void
-dumpregs(Context *ctx, int fd)
-{
- int i;
-
- for (i = 0; i < NR_REGS; i++)
- kprint(fd, "%s=0x%llx%c", regnames[i], ctx->r[i],
- (i > 0 && i % 3 == 0) ? '\n' : ' ');
- if (i % 4 != 3)
- kputc(fd, '\n');
-}
-
-static void
-backtrace(Context *ctx)
-{
- void **bp;
-
- kprint(kerr, "backtrace:\n");
- kprint(kerr, "%0llx\n", ctx->r[X30]);
- for (bp = (void **) ctx->r[X29]; *bp; bp = (void **) *bp)
- kprint(kerr, "%p\n", bp[1]);
-}
-
-static void
-dumpstack(Context *ctx)
-{
- long long *sp, i;
-
- kprint(kerr, "stack dump:\n");
- sp = (long long *) ctx->r[SP];
- for (i = 1; i <= 16; i++)
- kprint(kerr, "%0llx%c", *sp++, (i % 4 == 0) ? '\n' : ' ');
-}
-
-void
-panic(const char *msg)
-{
- static int first = 1;
- Context ctx;
-
- if (first) {
- first = 0;
- getctx(&ctx);
- kprint(kerr, "panic: %s\n", msg);
- dumpregs(&ctx, kerr);
- backtrace(&ctx);
- dumpstack(&ctx);
- }
-
- halt();
-}