Kernel: We can create basic userspace processes

These are still allocated on the kernel memory
This commit is contained in:
Bananymous
2023-04-12 17:51:36 +03:00
parent 34358b8471
commit 8ee63f8264
10 changed files with 121 additions and 82 deletions

View File

@@ -1,28 +1,12 @@
#include <BAN/Formatter.h>
#include <kernel/Syscall.h>
#include <unistd.h>
#define USERSPACE __attribute__((section(".userspace")))
USERSPACE int syscall(int syscall, void* arg1 = nullptr, void* arg2 = nullptr, void* arg3 = nullptr)
{
int ret;
asm volatile("int $0x80" : "=a"(ret) : "a"(syscall), "b"(arg1), "c"(arg2), "d"(arg3) : "memory");
return ret;
}
USERSPACE void user_putc(char ch)
{
syscall(SYS_PUTC, (void*)(uintptr_t)ch);
}
USERSPACE void print(const char* str)
{
while (*str)
user_putc(*str++);
}
USERSPACE void userspace_entry()
{
BAN::Formatter::println(user_putc, "Hello {}!", "World");
for (;;);
Kernel::syscall(SYS_WRITE, STDOUT_FILENO, "Hello World!", 12);
Kernel::syscall(SYS_EXIT);
}