proc: enter into userspace

Signed-off-by: Michael Shaw <m@michaelsshaw.com>
This commit is contained in:
Michael Shaw 2026-07-19 19:25:38 -04:00
commit cd916f624b
12 changed files with 138 additions and 29 deletions

View file

@ -4,6 +4,7 @@
*
* Copyright 2023-2026 Michael Shaw
*/
#include <arch/proc.h>
#include <kernel/common.h>
#include <kernel/buddy.h>
@ -90,9 +91,31 @@ static void kmain()
do_initcalls();
arch_ap_startup();
/* do nothing, for now :) */
dirent_t *init;
res = vfs_open("/bin/utest", &init);
if (res < 0)
panic("failed to open /bin/utest: %s\n", strerror(-res));
char *init_buf = kalloc(init->inode->file_size, ALLOC_KERN);
if (!init_buf)
panic("failed to allocate buffer for /bin/utest: %s\n", strerror(ENOMEM));
res = vfs_read(init->inode, init_buf, init->inode->file_size, 0);
if (res < 0)
panic("failed to read /bin/utest: %s\n", strerror(-res));
struct proc *init_proc = proc_create(NULL);
uaddr_t entry = proc_load_file(init_buf, init_proc);
if ((ssize_t)entry < 0)
panic("failed to load /bin/utest: %s\n", strerror(-(ssize_t)entry));
kernel_init_ready = true;
yield();
init_proc->main_thread->state = PROC_STATE_RUNNING;
enter_userspace_init(init_proc->main_thread, entry);
__builtin_unreachable();
}
void _before_stack()