summaryrefslogtreecommitdiff
path: root/src/user
diff options
context:
space:
mode:
Diffstat (limited to 'src/user')
-rw-r--r--src/user/init.cc34
-rw-r--r--src/user/user.ld27
-rw-r--r--src/user/usys.S31
3 files changed, 92 insertions, 0 deletions
diff --git a/src/user/init.cc b/src/user/init.cc
new file mode 100644
index 0000000..3c42adf
--- /dev/null
+++ b/src/user/init.cc
@@ -0,0 +1,34 @@
+#include "user/user.h"
+
+int main();
+
+extern "C" void _start()
+{
+ exit(main());
+}
+
+int main()
+{
+ int pid = fork();
+
+ if (pid < 0)
+ {
+ write(1, "Fork failed\n", 12);
+ exit(1);
+ }
+
+ if (pid == 0)
+ {
+ write(1, "Hello from Child!\n", 18);
+ exit(0);
+ }
+ else
+ {
+ write(1, "Parent waiting...\n", 18);
+ wait(0);
+ write(1, "Parent: Child exited.\n", 22);
+ }
+
+ while (1);
+ return 0;
+} \ No newline at end of file
diff --git a/src/user/user.ld b/src/user/user.ld
new file mode 100644
index 0000000..2111b14
--- /dev/null
+++ b/src/user/user.ld
@@ -0,0 +1,27 @@
+OUTPUT_ARCH(riscv)
+ENTRY(_start)
+
+SECTIONS
+{
+ . = 0x0;
+
+ .text : {
+ *(.text.entry)
+ *(.text .text.*)
+ }
+
+ .rodata : {
+ . = ALIGN(16);
+ *(.rodata .rodata.*)
+ }
+
+ .data : {
+ . = ALIGN(16);
+ *(.data .data.*)
+ }
+
+ .bss : {
+ . = ALIGN(16);
+ *(.bss .bss.*)
+ }
+} \ No newline at end of file
diff --git a/src/user/usys.S b/src/user/usys.S
new file mode 100644
index 0000000..e805d82
--- /dev/null
+++ b/src/user/usys.S
@@ -0,0 +1,31 @@
+#include "kernel/syscall.h"
+
+#define SYSCALL(name) \
+ .global name; \
+ name: \
+ li a7, SYS_ ## name; \
+ ecall; \
+ ret
+
+SYSCALL(fork)
+SYSCALL(exit)
+SYSCALL(wait)
+SYSCALL(pipe)
+SYSCALL(read)
+SYSCALL(write)
+SYSCALL(close)
+SYSCALL(kill)
+SYSCALL(exec)
+SYSCALL(open)
+SYSCALL(mknod)
+SYSCALL(unlink)
+SYSCALL(fstat)
+SYSCALL(link)
+SYSCALL(mkdir)
+SYSCALL(chdir)
+SYSCALL(dup)
+SYSCALL(getpid)
+SYSCALL(sbrk)
+SYSCALL(sleep)
+SYSCALL(uptime)
+SYSCALL(putc) \ No newline at end of file