aboutsummaryrefslogtreecommitdiff
path: root/arch
diff options
context:
space:
mode:
Diffstat (limited to 'arch')
-rwxr-xr-xarch/riscv64/conf/initbin1232 -> 2136 bytes
-rw-r--r--arch/riscv64/conf/init.c106
-rw-r--r--arch/riscv64/conf/initrdbin1536 -> 2560 bytes
3 files changed, 106 insertions, 0 deletions
diff --git a/arch/riscv64/conf/init b/arch/riscv64/conf/init
index 23c3097..d9a585d 100755
--- a/arch/riscv64/conf/init
+++ b/arch/riscv64/conf/init
Binary files differ
diff --git a/arch/riscv64/conf/init.c b/arch/riscv64/conf/init.c
new file mode 100644
index 0000000..4bd6a4e
--- /dev/null
+++ b/arch/riscv64/conf/init.c
@@ -0,0 +1,106 @@
+/* This file is allowed to be undocumented as it is only temporarily in this
+ * tree. At some point in the (hopefully) near future, I intend to move the
+ * kernel code and initrd generation stuff into separate repositories, to make
+ * things easier for myself. For now though, this is good enough.
+ */
+
+/* compile with riscv64-unknown-elf-gcc -ffreestanding -nostdlib */
+/* create initrd with echo init | cpio -H newc -o > initrd */
+#include <stdint.h>
+#include "../../../include/apos/syscalls.h"
+
+static void sys_noop()
+{
+ long register a0 asm ("a0") = SYS_NOOP;
+ asm ("ecall" : : : "a0", "a1");
+}
+
+static void sys_putch(char c)
+{
+ long register a0 asm ("a0") = SYS_PUTCH;
+ long register a1 asm ("a1") = c;
+ asm ("ecall" : : : "a0", "a1");
+}
+
+static uint64_t sys_timebase()
+{
+ long register a0 asm ("a0") = SYS_TIMEBASE;
+ long register a1 asm ("a1") = 0;
+ asm ("ecall" : : : "a0", "a1");
+#if defined(_LP64)
+ return a1;
+#else
+ uint64_t t = a0;
+ t <<= 32;
+ return t + a1;
+#endif
+}
+
+static uint64_t sys_ticks()
+{
+ long register a0 asm ("a0") = SYS_TICKS;
+ long register a1 asm ("a1") = 0;
+ asm ("ecall" : : : "a0", "a1");
+#if defined(_LP64)
+ return a1;
+#else
+ uint64_t t = a0;
+ t <<= 32;
+ return t + a1;
+#endif
+}
+
+static void puts(const char *s)
+{
+ while (*s)
+ sys_putch(*s++);
+}
+
+static void _print_number(uint64_t v)
+{
+ if (v == 0)
+ return;
+
+ _print_number(v / 10);
+ sys_putch((v % 10) + '0');
+}
+
+static void print_number(uint64_t v)
+{
+ if (v == 0) {
+ sys_putch('0');
+ return;
+ }
+
+ _print_number(v);
+}
+
+static void print_value(const char *s, uint64_t v)
+{
+ puts(s);
+ puts(": ");
+
+ print_number(v);
+ sys_putch('\n');
+}
+
+void _start()
+{
+ sys_noop();
+ puts("Hello, world!\n");
+
+ uint64_t second = sys_timebase();
+ print_value("Timebase", second);
+
+ uint64_t n = 0, i, start;
+ start = i = sys_ticks();
+ print_value("Start ticks", start);
+
+ while (i < start + second) {
+ i = sys_ticks();
+ n++;
+ }
+
+ print_value("End ticks", i);
+ print_value("Syscalls per second", n);
+}
diff --git a/arch/riscv64/conf/initrd b/arch/riscv64/conf/initrd
index efba349..f05e035 100644
--- a/arch/riscv64/conf/initrd
+++ b/arch/riscv64/conf/initrd
Binary files differ