From 635751fc2a75f66d1541469b3204efb1701bd91c Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Sat, 20 Mar 2021 18:46:33 +0100 Subject: Even more fixes! :^) --- kernel/Makefile | 2 +- kernel/features/load.c | 4 ++-- kernel/features/mm.c | 14 +++++--------- kernel/features/proc.c | 8 +++++--- 4 files changed, 13 insertions(+), 15 deletions(-) (limited to 'kernel') diff --git a/kernel/Makefile b/kernel/Makefile index e9ade73..1d9e87a 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -37,4 +37,4 @@ all: compile compile: $(COBJS) @mkdir -p ../build/ @$(LD) -N -z undefs -ekernel_main -Ttext 0x00050000 -o ../build/kernel.elf -L../build/ $+ -lk - @$(LD) -N -Tlink.ld -o ../build/kernel.bin -L../build/ $+ -lk + @$(LD) -N -z max-page-size=0x1000 -Tlink.ld -o ../build/kernel.bin -L../build/ $+ -lk diff --git a/kernel/features/load.c b/kernel/features/load.c index 079cbbe..d3f3495 100644 --- a/kernel/features/load.c +++ b/kernel/features/load.c @@ -119,8 +119,8 @@ s32 elf_load(const char *path, struct proc *proc) memory_switch_dir(proc->page_dir); u32 stack = (u32)memory_alloc(proc->page_dir, PROC_STACK_SIZE, MEMORY_USER | MEMORY_CLEAR); - proc->regs.ebp = stack + PROC_STACK_SIZE - 1; - proc->regs.useresp = stack + PROC_STACK_SIZE - 1; + proc->regs.ebp = stack + PROC_STACK_SIZE; + proc->regs.useresp = stack + PROC_STACK_SIZE; proc->regs.eip = header.entry; proc->entry = header.entry; diff --git a/kernel/features/mm.c b/kernel/features/mm.c index 01e21e7..b06657f 100644 --- a/kernel/features/mm.c +++ b/kernel/features/mm.c @@ -48,8 +48,8 @@ void page_fault_handler(struct regs *r) struct page_dir *dir = NULL; if (proc && proc->page_dir) { dir = proc->page_dir; - printf("Stack is at %x, entry at %x\n", virtual_to_physical(dir, proc->regs.ebp), - virtual_to_physical(dir, proc->entry)); + /* printf("Stack is at %x, entry at %x\n", virtual_to_physical(dir, proc->regs.ebp), */ + /* virtual_to_physical(dir, proc->entry)); */ } else { dir = &kernel_dir; } @@ -165,7 +165,7 @@ void physical_free(struct memory_range range) * Virtual */ -#define PDI(vaddr) (((vaddr) >> 22) & 0x03ff) +#define PDI(vaddr) ((vaddr) >> 22) #define PTI(vaddr) (((vaddr) >> 12) & 0x03ff) u8 virtual_present(struct page_dir *dir, u32 vaddr) @@ -210,15 +210,11 @@ void virtual_map(struct page_dir *dir, struct memory_range prange, u32 vaddr, u3 struct page_table *table = (struct page_table *)(dir_entry->bits.address * PAGE_SIZE); - if (dir_entry->bits.present) { - // TODO: Is this a security risk? - if (flags & MEMORY_USER) - dir_entry->bits.user = 1; - } else { + if (!dir_entry->bits.present) { table = memory_alloc_identity(dir, MEMORY_CLEAR); dir_entry->bits.present = 1; dir_entry->bits.writable = 1; - dir_entry->bits.user = flags & MEMORY_USER; + dir_entry->bits.user = 1; dir_entry->bits.address = (u32)(table) >> 12; } diff --git a/kernel/features/proc.c b/kernel/features/proc.c index aa595ff..5d3c8aa 100644 --- a/kernel/features/proc.c +++ b/kernel/features/proc.c @@ -81,11 +81,13 @@ void proc_print(void) { struct node *node = proc_list->head; - printf("\nPROCESSES\n"); + printf("--- PROCESSES ---\n"); struct proc *proc = NULL; while (node && (proc = node->data)) { - printf("Process %d: %s [%s]\n", proc->pid, proc->name, - proc->state == PROC_RUNNING ? "RUNNING" : "SLEEPING"); + printf("Process %d: %s [%s] [entry: %x; stack: %x]\n", proc->pid, proc->name, + proc->state == PROC_RUNNING ? "RUNNING" : "SLEEPING", + virtual_to_physical(proc->page_dir, proc->entry), + virtual_to_physical(proc->page_dir, proc->regs.ebp)); node = node->next; } printf("\n"); -- cgit v1.2.3