From bfcc6d7bdfc830cecf2cae034eb382200cf83de7 Mon Sep 17 00:00:00 2001 From: Mark Date: Sat, 12 Oct 2019 13:57:32 +0300 Subject: [PATCH] Add phys init --- include/sys/thread.h | 9 +++++++++ sys/amd64/kernel.c | 12 +++++++++++- sys/amd64/mm/mm.c | 24 +++++++++++++----------- 3 files changed, 33 insertions(+), 12 deletions(-) diff --git a/include/sys/thread.h b/include/sys/thread.h index 5413ea3..b272986 100644 --- a/include/sys/thread.h +++ b/include/sys/thread.h @@ -19,3 +19,12 @@ struct thread { // TODO: maybe __sched_thread struct thread *next; }; + +int thread_init(struct thread *t, + mm_space_t *space, + uintptr_t entry, + uintptr_t stack0_base, + size_t stack0_size, + uintptr_t stack3_base, + size_t stack3_size, + uint32_t flags); diff --git a/sys/amd64/kernel.c b/sys/amd64/kernel.c index 8813993..58cc229 100644 --- a/sys/amd64/kernel.c +++ b/sys/amd64/kernel.c @@ -1,13 +1,23 @@ #include "sys/debug.h" +#include "sys/amd64/loader/multiboot.h" #include "sys/amd64/hw/gdt.h" #include "sys/amd64/hw/idt.h" #include "sys/amd64/mm/mm.h" +#include "sys/amd64/mm/phys.h" #include "sys/amd64/hw/acpi.h" +static multiboot_info_t *multiboot_info; + void kernel_main(struct amd64_loader_data *data) { + data = (struct amd64_loader_data *) MM_VIRTUALIZE(data); + multiboot_info = (multiboot_info_t *) MM_VIRTUALIZE(data->multiboot_info_ptr); + + amd64_phys_memory_map((multiboot_memory_map_t *) MM_VIRTUALIZE(multiboot_info->mmap_addr), + multiboot_info->mmap_length); + amd64_gdt_init(); amd64_idt_init(); - amd64_mm_init(NULL); + amd64_mm_init(data); extern void sched_init(void); sched_init(); diff --git a/sys/amd64/mm/mm.c b/sys/amd64/mm/mm.c index 9688277..278a440 100644 --- a/sys/amd64/mm/mm.c +++ b/sys/amd64/mm/mm.c @@ -1,12 +1,14 @@ -// #include "sys/vmalloc.h" -// #include "sys/assert.h" +#include "sys/vmalloc.h" +#include "sys/assert.h" #include "sys/debug.h" #include "sys/string.h" #include "sys/amd64/mm/mm.h" -// #include "sys/panic.h" -// #include "sys/heap.h" +#include "sys/panic.h" +#include "sys/heap.h" +#include "sys/amd64/mm/pool.h" +#include "sys/amd64/mm/phys.h" // #include "sys/mem.h" -// #include "sys/mm.h" +#include "sys/mm.h" mm_space_t mm_kernel; @@ -40,15 +42,15 @@ void amd64_mm_init(struct amd64_loader_data *data) { asm volatile ("mov %0, %%cr3"::"a"(pml4):"memory"); // Create a pool located right after kernel image - // amd64_mm_pool_init((uintptr_t) &_kernel_end, MM_POOL_SIZE); + amd64_mm_pool_init((uintptr_t) &_kernel_end, MM_POOL_SIZE); mm_kernel = (mm_space_t) (MM_VIRTUALIZE(pml4)); // // Allocate some pages for kernel heap (base size: 16MiB) - // uintptr_t heap_base_phys = amd64_phys_alloc_contiguous(KERNEL_HEAP >> 12); - // assert(heap_base_phys != MM_NADDR, "Could not allocate %S of memory for kernel heap\n", KERNEL_HEAP); - // kdebug("Setting up kernel heap of %S @ %p\n", KERNEL_HEAP, heap_base_phys); - // amd64_heap_init(heap_global, heap_base_phys, KERNEL_HEAP); + uintptr_t heap_base_phys = amd64_phys_alloc_contiguous(KERNEL_HEAP >> 12); + assert(heap_base_phys != MM_NADDR, "Could not allocate %S of memory for kernel heap\n", KERNEL_HEAP); + kdebug("Setting up kernel heap of %S @ %p\n", KERNEL_HEAP, heap_base_phys); + amd64_heap_init(heap_global, heap_base_phys, KERNEL_HEAP); - // amd64_heap_dump(heap_global); + amd64_heap_dump(heap_global); }