db352f7ef4
We have added POSIX signals to KirkOS It is very much experimental Alongside, we have PCI support fully, and we have imported sbase coreutils, I'm not too sure if all of them work, likely not, but a good few should be okay. Signed-off-by: kaguya <kaguya3311@national.shitposting.agency>
136 lines
4.3 KiB
C
136 lines
4.3 KiB
C
#include "libk/debug.h"
|
|
#include "fs/vfs.h"
|
|
#include "sched/sched_types.h"
|
|
#include "sched/sched.h"
|
|
#include "sched/signal.h"
|
|
#include "fs/tmpfs.h"
|
|
#include "fs/devtmpfs.h"
|
|
#include "libk/random.h"
|
|
#include "fs/streams.h"
|
|
#include "fs/partition.h"
|
|
#include "drivers/fb/fb.h"
|
|
#include "drivers/tty/console.h"
|
|
#include "drivers/input/input.h"
|
|
#include "drivers/ps2/ps2.h"
|
|
#include "arch/x86_64/sys/timer.h"
|
|
#include "libk/kargs.h"
|
|
#include "fs/ramdisk.h"
|
|
#include "sched/syscall.h"
|
|
#include "mm/mmap.h"
|
|
#include "drivers/tty/pty.h"
|
|
#include "ipc/pipe.h"
|
|
|
|
|
|
const char *module_list[] = {};
|
|
|
|
#define MODULE_LIST_SIZE (sizeof(module_list) / sizeof(module_list[0]))
|
|
#define ONE_SECOND (uint64_t)(1000 * 1000 * 1000)
|
|
|
|
static void hcf(void) {
|
|
for (;;) {
|
|
asm volatile ("pause");
|
|
}
|
|
}
|
|
|
|
void kernel_main(void *args) {
|
|
vfs_init();
|
|
tmpfs_init();
|
|
devtmpfs_init();
|
|
vfs_mount(vfs_root, NULL, "/", "tmpfs");
|
|
vfs_create(vfs_root, "/tmp", 0755 | S_IFDIR);
|
|
vfs_mount(vfs_root, NULL, "/tmp", "tmpfs");
|
|
vfs_create(vfs_root, "/dev", 0755 | S_IFDIR);
|
|
vfs_mount(vfs_root, NULL, "/dev", "devtmpfs");
|
|
streams_init();
|
|
randdev_init();
|
|
|
|
kprintf("Hello I am %s\n", sched_get_running_thread()->mother_proc->name);
|
|
|
|
if (args != NULL) {
|
|
uint64_t *module_info = (uint64_t *)args;
|
|
kprintf("Ramdisk located at %p\n", module_info[0]);
|
|
ramdisk_install(module_info[0], module_info[1]);
|
|
}
|
|
|
|
partition_enumerate(NULL, NULL);
|
|
|
|
fbdev_init();
|
|
|
|
|
|
|
|
syscall_register_handler(0x0, syscall_read);
|
|
syscall_register_handler(0x1, syscall_write);
|
|
syscall_register_handler(0x2, syscall_open);
|
|
syscall_register_handler(0x3, syscall_close);
|
|
syscall_register_handler(0x8, syscall_seek);
|
|
syscall_register_handler(0x9, syscall_mmap);
|
|
syscall_register_handler(0xa, syscall_mprotect);
|
|
syscall_register_handler(0xb, syscall_munmap);
|
|
syscall_register_handler(0x10, syscall_ioctl);
|
|
syscall_register_handler(0x48, syscall_fcntl);
|
|
syscall_register_handler(0x4f, syscall_getcwd);
|
|
syscall_register_handler(0x50, syscall_chdir);
|
|
syscall_register_handler(0x59, syscall_readdir);
|
|
syscall_register_handler(0x101, syscall_openat);
|
|
syscall_register_handler(0x102, syscall_mkdirat);
|
|
syscall_register_handler(0x103, syscall_mknodat);
|
|
syscall_register_handler(0x106, syscall_fstatat);
|
|
syscall_register_handler(0x107, syscall_unlinkat);
|
|
syscall_register_handler(0x109, syscall_linkat);
|
|
syscall_register_handler(0x10b, syscall_readlinkat);
|
|
syscall_register_handler(0x10c, syscall_fchmodat);
|
|
syscall_register_handler(0x124, syscall_dup3);
|
|
syscall_register_handler(0x125, syscall_pipe);
|
|
syscall_register_handler(0xff, syscall_openpty);
|
|
syscall_register_handler(0x10f, syscall_ppoll);
|
|
syscall_register_handler(0x54, syscall_rmdir);
|
|
|
|
|
|
/* ── POSIX signal syscalls ──────────────────────────────────────── */
|
|
syscall_register_handler(13, syscall_sigaction); /* rt_sigaction */
|
|
syscall_register_handler(14, syscall_sigprocmask); /* rt_sigprocmask */
|
|
syscall_register_handler(15, syscall_sigreturn); /* rt_sigreturn */
|
|
syscall_register_handler(34, syscall_pause);
|
|
syscall_register_handler(127, syscall_sigpending);
|
|
syscall_register_handler(130, syscall_sigsuspend);
|
|
|
|
/* ── POSIX session / process-group syscalls ─────────────────────── */
|
|
syscall_register_handler(109, syscall_setpgid);
|
|
syscall_register_handler(111, syscall_getpgrp);
|
|
syscall_register_handler(112, syscall_setsid);
|
|
syscall_register_handler(121, syscall_getpgid);
|
|
syscall_register_handler(124, syscall_getsid);
|
|
|
|
/* ── Shared input ring buffer + PS/2 keyboard ───────────────────── */
|
|
input_init();
|
|
ps2_init();
|
|
|
|
kprintf("Halting for 5 seconds...");
|
|
timer_sleep(5000);
|
|
|
|
console_init();
|
|
|
|
std_console_device = (vfs_get_node(vfs_root, "/dev/console", true))->resource;
|
|
|
|
char *argv[] = {"init", NULL};
|
|
char* envp[] = {
|
|
"HOME=/",
|
|
"TERM=linux",
|
|
NULL,
|
|
};
|
|
|
|
char *init_path = "/bin/sh";
|
|
if (kernel_arguments.kernel_args & KERNEL_ARGS_INIT_PATH_GIVEN) {
|
|
init_path = kernel_arguments.init_binary_path;
|
|
}
|
|
|
|
kprintf("Running init binary %s\n", init_path);
|
|
|
|
if (!process_run_init(init_path, argv, envp, sched_get_running_thread()->mother_proc)) {
|
|
panic("Failed to run the init binary o algo\n");
|
|
}
|
|
|
|
for (;;) {
|
|
sched_yield(true);
|
|
}
|
|
} |