aboutsummaryrefslogtreecommitdiff
path: root/src/userspace
diff options
context:
space:
mode:
authorMarvin Borner2020-05-09 17:39:31 +0200
committerMarvin Borner2020-05-09 17:39:31 +0200
commit09a66e91ec9e8a677aa48f27798753084f213713 (patch)
tree9685a13b459e60d830179c565417ed72ae855ebe /src/userspace
parent3a97fef4bb4780e4bc2423699063d40cbf5da923 (diff)
Replaced fork() with spawn()!
Who needs forks anyway
Diffstat (limited to 'src/userspace')
-rw-r--r--src/userspace/libc/syscall.c4
-rw-r--r--src/userspace/libc/syscall.h2
-rw-r--r--src/userspace/libc/unistd.h4
-rw-r--r--src/userspace/libc/unistd/fork.c7
-rw-r--r--src/userspace/libc/unistd/spawn.c7
-rw-r--r--src/userspace/programs/init.c26
-rw-r--r--src/userspace/programs/root.c15
-rw-r--r--src/userspace/programs/sh.c6
8 files changed, 25 insertions, 46 deletions
diff --git a/src/userspace/libc/syscall.c b/src/userspace/libc/syscall.c
index 5a9fda8..fb00a12 100644
--- a/src/userspace/libc/syscall.c
+++ b/src/userspace/libc/syscall.c
@@ -9,14 +9,14 @@ DEFN_SYSCALL0(halt, SYS_HALT);
DEFN_SYSCALL1(exit, SYS_EXIT, u32);
-DEFN_SYSCALL0(fork, SYS_FORK);
-
DEFN_SYSCALL4(read, SYS_READ, char *, u32, u32, u8 *);
DEFN_SYSCALL4(write, SYS_WRITE, char *, u32, u32, u8 *);
DEFN_SYSCALL1(exec, SYS_EXEC, char *);
+DEFN_SYSCALL1(spawn, SYS_SPAWN, char *);
+
DEFN_SYSCALL3(wait, SYS_WAIT, u32, u32 *, u32);
DEFN_SYSCALL0(get_pid, SYS_GET_PID);
diff --git a/src/userspace/libc/syscall.h b/src/userspace/libc/syscall.h
index bd9d38d..cb1551a 100644
--- a/src/userspace/libc/syscall.h
+++ b/src/userspace/libc/syscall.h
@@ -80,6 +80,8 @@ DECL_SYSCALL4(write, char *, u32, u32, u8 *);
DECL_SYSCALL1(exec, char *);
+DECL_SYSCALL1(spawn, char *);
+
DECL_SYSCALL3(wait, u32, u32 *, u32);
DECL_SYSCALL0(get_pid);
diff --git a/src/userspace/libc/unistd.h b/src/userspace/libc/unistd.h
index 876f35c..7610eb5 100644
--- a/src/userspace/libc/unistd.h
+++ b/src/userspace/libc/unistd.h
@@ -5,9 +5,9 @@
u32 exec(char *path);
-void exit(u32 code);
+u32 spawn(char *path);
-u32 fork();
+void exit(u32 code);
u32 get_pid();
diff --git a/src/userspace/libc/unistd/fork.c b/src/userspace/libc/unistd/fork.c
deleted file mode 100644
index 6ca054a..0000000
--- a/src/userspace/libc/unistd/fork.c
+++ /dev/null
@@ -1,7 +0,0 @@
-#include <stdint.h>
-#include <syscall.h>
-
-u32 fork()
-{
- return syscall_fork();
-} \ No newline at end of file
diff --git a/src/userspace/libc/unistd/spawn.c b/src/userspace/libc/unistd/spawn.c
new file mode 100644
index 0000000..91ed340
--- /dev/null
+++ b/src/userspace/libc/unistd/spawn.c
@@ -0,0 +1,7 @@
+#include <stdint.h>
+#include <syscall.h>
+
+u32 spawn(char *path)
+{
+ return syscall_spawn(path);
+} \ No newline at end of file
diff --git a/src/userspace/programs/init.c b/src/userspace/programs/init.c
index 6cb80ce..1f6d0a3 100644
--- a/src/userspace/programs/init.c
+++ b/src/userspace/programs/init.c
@@ -5,14 +5,9 @@
#include <syscall.h>
#include <unistd.h>
-void test(u8 *data)
-{
- printf(".");
-}
-
void main()
{
- if (get_pid() != 2) {
+ if (get_pid() != 1) {
printf("Wrong PID!\n");
exit(1);
}
@@ -20,22 +15,13 @@ void main()
// TODO: Fix page fault when mallocing
printf("Initializing userspace...\n");
- // TODO: Find out, why init gets PID 1 and stops
- syscall_map(MAP_KEYBOARD, (u32)&test);
-
+ // TODO: Find out, why processes change pid randomly
// TODO: Fix occasional race conditions with cli/sti
- // TODO: Fix scheduler turning off randomly..
- /* u32 x; */
- /* u32 f = fork(); */
- /* if (f == 0) { */
- /* printf("Waiting...\n"); */
- /* wait(&x); */
- /* } else { */
- /* printf("Executing...\n"); */
- /* exec("/bin/sh"); */
- /* } */
+ // TODO: Fix scheduler turning off at some point
+ spawn("/bin/sh");
+ printf("ok");
while (1) {
//printf("B");
};
-}
+} \ No newline at end of file
diff --git a/src/userspace/programs/root.c b/src/userspace/programs/root.c
deleted file mode 100644
index 86b8bf7..0000000
--- a/src/userspace/programs/root.c
+++ /dev/null
@@ -1,15 +0,0 @@
-#include <stdio.h>
-#include <syscall.h>
-#include <unistd.h>
-
-// This process only exists because it can't crash
-void main()
-{
- if (get_pid() != 1) {
- printf("Wrong PID!\n");
- exit(1);
- }
-
- exec("/bin/init");
- printf("The init process crashed!");
-} \ No newline at end of file
diff --git a/src/userspace/programs/sh.c b/src/userspace/programs/sh.c
index f8f93f3..ba6ba8f 100644
--- a/src/userspace/programs/sh.c
+++ b/src/userspace/programs/sh.c
@@ -6,6 +6,11 @@
#include <syscall.h>
#include <unistd.h>
+void test(u8 *data)
+{
+ printf(".");
+}
+
void main()
{
printf("[~] ");
@@ -13,6 +18,7 @@ void main()
/* while (1) { */
/* putch(getch()); */
/* } */
+ //syscall_map(MAP_KEYBOARD, (u32)&test);
/* syscall_halt(); */
while (1) {