Add subprocesses and convert terminal to an app

This commit is contained in:
2026-06-17 21:20:14 +03:00
parent 1c935cf154
commit 03b3ddac73
28 changed files with 490 additions and 247 deletions
+27 -16
View File
@@ -7,8 +7,10 @@
#include "src/kernel/pic.h"
#include "src/kernel/process.h"
#include "src/kernel/syscall.h"
#include "src/kernel/tss.h"
#include "src/kernel/util.h"
#include "src/kernel/vga.h"
#include "src/lib/layout.h"
#include "src/lib/memory.h"
__attribute__((interrupt)) void isr_divide_by_zero(__attribute__((unused)) struct interrupt_frame *frame) {
@@ -47,30 +49,39 @@ void kernel_main() {
gdt_init();
syscall_init();
process_t *kp = memory_allocate(sizeof(process_t));
kp->root = fs_mount();
kp->cwd = memory_allocate(sizeof(path_t));
kp->stdin = keyboard_init();
kp->stdout = vga_init();
process_t *kernel = memory_allocate(sizeof(process_t));
kernel->pml4 = (void *)KERNEL_VIRTUAL_PML4;
kernel->root = fs_mount();
kernel->cwd = memory_allocate(sizeof(path_t));
kernel->stdin = keyboard_init();
kernel->stdout = vga_init();
fs_node_t *hello = fs_open_by(kp->root, "HELLO.BIN");
fs_node_t *bin = fs_open_by(kernel->root, "terminal");
ASSERT(hello, "kernel: hello.bin not found");
ASSERT(bin, "kernel: terminal not found");
uint8_t *hello_code = memory_allocate(hello->size);
fs_read(hello, 0, hello->size, hello_code);
uint8_t *code = memory_allocate(bin->size);
fs_read(bin, 0, bin->size, code);
process_t *proc = process_create(kp, hello_code, hello->size);
process_t *terminal = process_create(kernel, code, bin->size);
memory_free(hello_code);
fs_close(hello);
memory_free(code);
fs_close(bin);
process_run(proc);
__asm__ volatile("mov %0, %%cr3" : : "r"((uint64_t)VIRT_TO_PHYS((void *)KERNEL_VIRTUAL_PML4)) : "memory");
while (1)
;
uint8_t *stack = (uint8_t *)terminal->user_stack;
fs_unmount(kp->root);
stack -= sizeof(uint64_t);
*(uint64_t *)stack = 0;
terminal->user_rsp = (void *)(USER_VIRTUAL_STACK_TOP - ((uint64_t)terminal->user_stack - (uint64_t)stack));
current_process = terminal;
tss.rsp0 = (uint64_t)current_process->kernel_stack;
process_switch_to(&kernel->kernel_rsp, terminal->kernel_rsp, VIRT_TO_PHYS(terminal->pml4));
fs_unmount((fs_node_t *)kernel->root);
outw(0x604, 0x2000); // TODO: parse ACPI tables for real hardware
__asm__ volatile("cli; hlt");