aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xarch/riscv64/conf/initbin1096 -> 1232 bytes
-rw-r--r--arch/riscv64/conf/initrdbin1536 -> 1536 bytes
-rw-r--r--arch/riscv64/conf/s.S44
-rw-r--r--arch/riscv64/kernel/entry.S2
-rw-r--r--common/uapi/dispatch.c26
-rw-r--r--include/apos/syscalls.h17
-rw-r--r--include/apos/uapi.h16
7 files changed, 100 insertions, 5 deletions
diff --git a/arch/riscv64/conf/init b/arch/riscv64/conf/init
index 0a67c41..23c3097 100755
--- a/arch/riscv64/conf/init
+++ b/arch/riscv64/conf/init
Binary files differ
diff --git a/arch/riscv64/conf/initrd b/arch/riscv64/conf/initrd
index 6021c8f..efba349 100644
--- a/arch/riscv64/conf/initrd
+++ b/arch/riscv64/conf/initrd
Binary files differ
diff --git a/arch/riscv64/conf/s.S b/arch/riscv64/conf/s.S
index 516dc39..7dbaf4f 100644
--- a/arch/riscv64/conf/s.S
+++ b/arch/riscv64/conf/s.S
@@ -10,3 +10,47 @@ li a2, 2
li a3, 3
li a4, 4
ecall
+
+/* "print" hello world */
+li a0, 1
+li a1, 'H'
+ecall
+li a0, 1
+li a1, 'e'
+ecall
+li a0, 1
+li a1, 'l'
+ecall
+li a0, 1
+li a1, 'l'
+ecall
+li a0, 1
+li a1, 'o'
+ecall
+li a0, 1
+li a1, ','
+ecall
+li a0, 1
+li a1, ' '
+ecall
+li a0, 1
+li a1, 'w'
+ecall
+li a0, 1
+li a1, 'o'
+ecall
+li a0, 1
+li a1, 'r'
+ecall
+li a0, 1
+li a1, 'l'
+ecall
+li a0, 1
+li a1, 'd'
+ecall
+li a0, 1
+li a1, '!'
+ecall
+li a0, 1
+li a1, '\n'
+ecall
diff --git a/arch/riscv64/kernel/entry.S b/arch/riscv64/kernel/entry.S
index 7301d4e..1bd6046 100644
--- a/arch/riscv64/kernel/entry.S
+++ b/arch/riscv64/kernel/entry.S
@@ -128,7 +128,7 @@ restore_noreturn:
lr s2, offsetof_s2(sp)
lr s3, offsetof_s3(sp)
lr s4, offsetof_s4(sp)
- lr s5, offsetof_s4(sp)
+ lr s5, offsetof_s5(sp)
lr s6, offsetof_s6(sp)
lr s7, offsetof_s7(sp)
lr s8, offsetof_s8(sp)
diff --git a/common/uapi/dispatch.c b/common/uapi/dispatch.c
index 73e037a..b16b255 100644
--- a/common/uapi/dispatch.c
+++ b/common/uapi/dispatch.c
@@ -14,6 +14,10 @@
static const sys_t syscall_table[] = {
/* noop */
[SYS_NOOP] = sys_noop,
+
+ /* debugging */
+ [SYS_PUTCH] = sys_putch,
+
/* mem */
[SYS_REQ_MEM] = sys_req_mem,
[SYS_REQ_PMEM] = sys_req_pmem,
@@ -55,6 +59,18 @@ SYSCALL_DEFINE0(noop)(){
return (struct sys_ret){ OK, 0 };
}
+/**
+ * Putch syscall handler.
+ *
+ * @param a Character to put.
+ * @return \ref OK and 0.
+ */
+SYSCALL_DEFINE1(putch)(sys_arg_t a){
+ const char c[2] = {a, 0};
+ dbg((const char *)&c);
+ return (struct sys_ret){ OK, 0 };
+}
+
struct sys_ret syscall_dispatch(sys_arg_t syscall, sys_arg_t a, sys_arg_t b,
sys_arg_t c, sys_arg_t d)
{
@@ -67,9 +83,13 @@ struct sys_ret syscall_dispatch(sys_arg_t syscall, sys_arg_t a, sys_arg_t b,
return (struct sys_ret){ ERR_INVAL, 0 };
}
- /* the syscall must be a valid number, as they're numbered in a linear
- * fashion */
- struct sys_ret r = syscall_table[syscall](a, b, c, d);
+ sys_t call = syscall_table[sc];
+ if (!call) {
+ error("Syscall %zu not legitimate value\n", sc);
+ return (struct sys_ret){ ERR_INVAL, 0 };
+ }
+
+ struct sys_ret r = call(a, b, c, d);
if (check_canary(t)) {
bug("Syscall %zu overwrote stack canary\n", syscall);
diff --git a/include/apos/syscalls.h b/include/apos/syscalls.h
index baa1139..84d9e07 100644
--- a/include/apos/syscalls.h
+++ b/include/apos/syscalls.h
@@ -12,10 +12,25 @@
/** enum for now, possibly macros in the future once I get an approximate idea of
* which syscalls are necessary etc. */
enum {
- /** @name Misc. */
+ /**
+ * @name Misc.
+ * Implementation in \ref dispatch.c instead of a separate file, as I
+ * consider them 'internal' and not intended for users.
+ */
/** @{ */
/** Noop, mainly for testing syscall subsystem and sanity checking. */
SYS_NOOP,
+
+ /**
+ * Put a single character to the serial lines.
+ * Do not rely on this actually working, as the serial drivers are only
+ * included on debugging kernels.
+ *
+ * \todo Should serial drivers be always included and debugging mode
+ * turned into whether \ref info is turned on or off or something?
+ */
+ SYS_PUTCH,
+
/** @} */
/* @name Memory management. */
diff --git a/include/apos/uapi.h b/include/apos/uapi.h
index 6832f79..1ebdc21 100644
--- a/include/apos/uapi.h
+++ b/include/apos/uapi.h
@@ -181,6 +181,9 @@ struct sys_ret {
} \
static inline struct sys_ret __##name
+/** @name Misc syscalls. */
+/** @{ */
+
/**
* Noop syscall.
*
@@ -192,6 +195,19 @@ struct sys_ret {
*/
SYSCALL_DECLARE0(noop);
+/**
+ * Putch syscall.
+ *
+ * @param ch Character to put.
+ * @param b Unused.
+ * @param c Unused.
+ * @param d Unused.
+ * @return \ref OK and 0.
+ */
+SYSCALL_DECLARE1(putch, ch);
+
+/** @} */
+
/* @name Memory handling syscalls. */
/** @{ */
/**