From bf9e5005b66c3e1219340837d3c29443dd0fb4e1 Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Thu, 4 Jul 2024 23:44:14 -0400 Subject: kernel: init_main: Startup PID 1 Signed-off-by: Ian Moffett --- sys/kern/init_main.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/sys/kern/init_main.c b/sys/kern/init_main.c index a5bdf1c..02e8705 100644 --- a/sys/kern/init_main.c +++ b/sys/kern/init_main.c @@ -32,13 +32,31 @@ #include #include #include +#include +#include #include #include #include #include +#include static struct proc proc0; +static void +start_init(void) +{ + struct proc *td = this_td(); + struct execve_args execve_args; + char *argv[] = { "/usr/sbin/init", NULL }; + char *envp[] = { NULL }; + + execve_args.pathname = argv[0]; + execve_args.argv = argv; + execve_args.envp = envp; + if (execve(td, &execve_args) != 0) + panic("Failed to load init\n"); +} + int main(void) { @@ -63,6 +81,10 @@ main(void) sched_init(); mp_bootstrap_aps(&g_bsp_ci); + /* Startup init */ + memset(&proc0, 0, sizeof(proc0.tf)); + fork1(&proc0, 0, start_init, NULL); + /* Nothing left to do... halt */ cpu_reboot(REBOOT_HALT); __builtin_unreachable(); -- cgit v1.2.3