summaryrefslogtreecommitdiffstats
path: root/usr
diff options
context:
space:
mode:
authorJon Santmyer <jon@jonsantmyer.com>2024-05-22 13:00:41 -0400
committerJon Santmyer <jon@jonsantmyer.com>2024-05-22 13:00:41 -0400
commitace65b453151845bc361f21f3e5b651c35f9f126 (patch)
tree262ebd29b0ca1d8584f0b6f1efa7a00d9f4f3e43 /usr
parentf004c1ade8d617a82cea2fe249434cccb47a2358 (diff)
downloadjove-kernel-ace65b453151845bc361f21f3e5b651c35f9f126.tar.gz
jove-kernel-ace65b453151845bc361f21f3e5b651c35f9f126.tar.bz2
jove-kernel-ace65b453151845bc361f21f3e5b651c35f9f126.zip
massive refactor for mp and organizationHEADmaster
Diffstat (limited to 'usr')
-rw-r--r--usr/elf.h12
-rw-r--r--usr/syscall.c104
-rw-r--r--usr/syscall.h11
-rw-r--r--usr/tasking.c7
-rw-r--r--usr/tasking.h28
-rw-r--r--usr/umode.c39
-rw-r--r--usr/umode.h8
7 files changed, 0 insertions, 209 deletions
diff --git a/usr/elf.h b/usr/elf.h
deleted file mode 100644
index d805e55..0000000
--- a/usr/elf.h
+++ /dev/null
@@ -1,12 +0,0 @@
-#ifndef JOVE_USER_ELF_H
-#define JOVE_USER_ELF_H 1
-
-#include <stddef.h>
-
-/**Load an ELF file into usermode memory.
- * @param data pointer to ELF file data buffer
- * @param len length of ELF file data buffer
- * @return entry point for loaded ELF exec*/
-void *elf_load(const void *data, size_t len);
-
-#endif
diff --git a/usr/syscall.c b/usr/syscall.c
deleted file mode 100644
index fbc5fe7..0000000
--- a/usr/syscall.c
+++ /dev/null
@@ -1,104 +0,0 @@
-#include "syscall.h"
-#include "sys/errno.h"
-#include "sys/permission.h"
-#include "usr/tasking.h"
-#include "mem/memory.h"
-#include "io/log.h"
-
-#define ENSURE_ADDR(ptr) \
- if(!mem_check_ptr(ptr)) { klogf("User passed bad address %#016X\n", ptr); return -EFAULT; }
-
-#define ENSURE_PERM(p) \
- if(!(task_current->perm & p)) return -ENOPERM
-
-#define PD_FOR_LINEAR_ADDRESS(addr) current_page_directory; \
- if(addr.tid == -1) addr.tid = task_current->id; \
- if(addr.tid != task_current->id) { \
- ENSURE_PERM(PERM_MEM_VIRT_PD); \
- struct Task *task = task_get(addr.tid); \
- if(task == NULL) return -EFAULT; \
- pd = task->pd; \
- }
-
-int _syscall_handler_log(struct syscall_log *req)
-{
- ENSURE_ADDR(req->message);
- klogf("%s", req->message);
- return 0;
-}
-
-intmax_t _syscall_handler_tid(syscall_t *req)
-{
- return task_current->id;
-}
-
-int _syscall_handler_mem_phys_resv(struct syscall_mem_phys_range_op *req)
-{
- ENSURE_PERM(PERM_MEM_PHYS_RESV);
- mem_phys_reserve(req->base, req->limit);
- return 0;
-}
-
-int _syscall_handler_mem_phys_free(struct syscall_mem_phys_range_op *req)
-{
- ENSURE_PERM(PERM_MEM_PHYS_FREE);
- mem_phys_release(req->base, req->limit);
- return 0;
-}
-
-int _syscall_handler_mem_phys_alloc(struct syscall_mem_phys_alloc *req)
-{
- ENSURE_ADDR(req->result);
- ENSURE_PERM(PERM_MEM_PHYS_ALLOC);
- *req->result = mem_phys_alloc(req->npages);
- return 0;
-}
-
-int _syscall_handler_mem_virt_mapping(struct syscall_mem_virt_mapping *req)
-{
- ENSURE_ADDR(req->result);
- ENSURE_PERM(PERM_MEM_VIRT_MAP);
- page_directory_t *pd = PD_FOR_LINEAR_ADDRESS(req->addr);
- *req->result = mem_get_mapping_as(pd, req->addr.addr);
- return 0;
-}
-
-int _syscall_handler_mem_virt_map(struct syscall_mem_virt_map *req)
-{
- ENSURE_PERM(PERM_MEM_VIRT_MAP);
- page_directory_t *pd = PD_FOR_LINEAR_ADDRESS(req->addr);
- mem_set_mapping_as(pd, req->map, req->addr.addr);
- return 0;
-}
-
-int _syscall_handler_mem_virt_alloc(struct syscall_mem_virt_alloc *req)
-{
- ENSURE_PERM(PERM_MEM_VIRT_MAP);
- ENSURE_PERM(PERM_MEM_PHYS_ALLOC);
- page_directory_t *pd = PD_FOR_LINEAR_ADDRESS(req->from);
- mem_ensure_range_as(pd, req->from.addr, req->to, req->flg);
- return 0;
-}
-
-void *_syscall_handlers[SYSCALL_COUNT] = {
- _syscall_handler_log,
- _syscall_handler_tid,
-
- _syscall_handler_mem_phys_resv,
- _syscall_handler_mem_phys_free,
- _syscall_handler_mem_phys_alloc,
-
- _syscall_handler_mem_virt_mapping,
- _syscall_handler_mem_virt_map,
- _syscall_handler_mem_virt_alloc,
-};
-
-int
-syscall_handler(syscall_t *req)
-{
- ENSURE_ADDR(req);
- if(req->id >= SYSCALL_COUNT) return -ENOSYS;
-
- ENSURE_ADDR(_syscall_handlers[req->id]);
- return ((syscall_handler_t)(_syscall_handlers[req->id]))(req);
-}
diff --git a/usr/syscall.h b/usr/syscall.h
deleted file mode 100644
index 5cc82b8..0000000
--- a/usr/syscall.h
+++ /dev/null
@@ -1,11 +0,0 @@
-#ifndef JOVE_USER_SYSCALL_H
-#define JOVE_USER_SYSCALL_H 1
-
-#include "sys/syscall.h"
-
-typedef int (*syscall_handler_t)(syscall_t*);
-
-int _syscall_handler_log(struct syscall_log *req);
-intmax_t _syscall_handler_tid(syscall_t *req);
-
-#endif
diff --git a/usr/tasking.c b/usr/tasking.c
deleted file mode 100644
index cb4df25..0000000
--- a/usr/tasking.c
+++ /dev/null
@@ -1,7 +0,0 @@
-#include "tasking.h"
-
-void
-task_perm_release(struct Task *task, size_t mask)
-{
- task->perm &= ~mask;
-}
diff --git a/usr/tasking.h b/usr/tasking.h
deleted file mode 100644
index 4b11999..0000000
--- a/usr/tasking.h
+++ /dev/null
@@ -1,28 +0,0 @@
-#ifndef JOVE_TASKING_H
-#define JOVE_TASKING_H 1
-
-#include <stddef.h>
-#include <stdint.h>
-#include "sys/types.h"
-#include "mem/memory.h"
-
-struct Task
-{
- struct Task *next;
- tid_t id;
- uintptr_t kbp;
- size_t perm;
-
- page_directory_t *pd;
-};
-
-extern struct Task *task_current;
-
-void tasking_setup(void);
-
-struct Task *task_new(struct Task *parent);
-struct Task *task_get(tid_t id);
-
-void task_perm_release(struct Task *task, size_t mask);
-
-#endif
diff --git a/usr/umode.c b/usr/umode.c
deleted file mode 100644
index 1105d9e..0000000
--- a/usr/umode.c
+++ /dev/null
@@ -1,39 +0,0 @@
-#include "umode.h"
-#include "elf.h"
-#include "boot/cmdline.h"
-#include "lib/jove.h"
-#include "ird/initrd.h"
-#include "mem/memory.h"
-
-void
-umode_setup(void)
-{
- extern void syscall_setup_syscall(void);
- syscall_setup_syscall();
-
- const char *init_path = cmdline_get("init");
- if(init_path == NULL)
- kpanic("Missing path to init ELF file / binary\n");
-
- struct InitrdFile *init_file = ird_getfile(init_path);
- if(init_file == NULL)
- kpanic("Missing init file %s in initrd\n", init_path);
-
- void (*entry_point)(void) = elf_load(init_file->data, init_file->size);
- if(entry_point == NULL)
- kpanic("Init file %s is incorrectly formatted (want ELF64)\n", init_path);
-
- void *user_stack = (void*)(0x00007FFFFFFFFFFF);
- mem_ensure_range(
- (uintptr_t)user_stack & ~0xFFF,
- (uintptr_t)user_stack,
- (page_flags_t) {
- .present = true,
- .writeable = true,
- .useraccess = true,
- .executable = false
- });
-
- klogf("User entry point %#016X\n", entry_point);
- umode_enter(entry_point, user_stack);
-}
diff --git a/usr/umode.h b/usr/umode.h
deleted file mode 100644
index 2755abe..0000000
--- a/usr/umode.h
+++ /dev/null
@@ -1,8 +0,0 @@
-#ifndef JOVE_UMODE_H
-#define JOVE_UMODE_H 1
-
-void umode_setup(void);
-
-void umode_enter(void (*entry)(void), void *stack);
-
-#endif