slab: add umalloc

This commit is contained in:
Michael Shaw 2025-02-12 17:20:20 -05:00
commit b496366469
8 changed files with 238 additions and 12 deletions

View file

@ -66,6 +66,13 @@
movq 0(%rax), %rax
.endm
.macro save_sysretq_frame
movq %rsp, 144(%rax)
pushfq
popq %rdi
movq %rdi, 136(%rax)
.endm
.macro save_iretq_frame
/* save IRETQ frame */
popq %rdi
@ -149,6 +156,7 @@
_exception_\nr:
cli
save_context
save_iretq_frame
popq %rsi
pushq %rsi
movq $\nr, %rdi
@ -234,15 +242,56 @@ irq 0x0F
.global gate_syscall
gate_syscall:
pushq %r11
pushq %rcx
cli
save_context
save_sysretq_frame
/* switch to a kernel process */
movq %rax, %rdi
movq $_gate_syscall_entry_ret, %rsi
call proc_enter_kernel
_gate_syscall_entry_ret:
movq %rdi, %rax
/* restore argument registers */
movq 40(%rax), %rdi
movq 32(%rax), %rsi
movq 24(%rax), %rdx
movq 72(%rax), %r10
movq 56(%rax), %r8
movq 0(%rax), %rax
movq %r10, %rcx
movq %rax, %r9
call syscall
popq %rcx
popq %r11
/* switch back to user process */
movq %rax, %rdi
movq $1, %rsi
cli
call proc_leave_kernel
pushq %rax
call proc_current_regs
/* restore sysretq frame */
movq 120(%rax), %rcx /* RIP */
movq 136(%rax), %r11 /* RFLAGS */
/* switch to user stack */
popq %rbp
movq 144(%rax), %rsp
restore_context
pushq %rbp
movq 48(%rax), %rbp
/* syscall return code */
popq %rax
sysretq
.global gate_syscall_int80
@ -391,3 +440,8 @@ _save_context:
yield:
hlt
ret
.global reboot
reboot:
movq $0, %rax
movq %rax, %cr3

View file

@ -1,10 +1,11 @@
/* SPDX-License-Identifier: GPL-2.0-only */
#include "kernel/mem.h"
#include <kernel/common.h>
#include <kernel/proc.h>
#include <kernel/rbtree.h>
#include <kernel/mem.h>
#include <kernel/slab.h>
#include <kernel/gdt.h>
#include <kernel/pio.h>
#include <lib/sem.h>
@ -121,6 +122,11 @@ void proc_set_exec_addr(struct proc *proc, uintptr_t addr)
void proc_term(pid_t pid)
{
if(pid == 1) {
/* reboot */
reboot();
}
struct rbnode *proc_node = rbt_search(proc_tree, pid);
if (proc_node) {
@ -389,3 +395,4 @@ void proc_init(unsigned num_cpus)
proc_set_current(0);
(void)rbt_insert(proc_tree, 0);
}