diff options
-rw-r--r-- | boot/entry.asm | 2 | ||||
-rw-r--r-- | kernel/features/memory.c | 26 | ||||
-rw-r--r-- | kernel/features/proc.asm | 6 | ||||
-rw-r--r-- | libc/alloc.c | 1 | ||||
-rw-r--r-- | libc/inc/mem.h | 3 |
5 files changed, 26 insertions, 12 deletions
diff --git a/boot/entry.asm b/boot/entry.asm index 7285fb8..f77c4e7 100644 --- a/boot/entry.asm +++ b/boot/entry.asm @@ -94,7 +94,7 @@ %define GDT_DATA_OFFSET 0x10 ; Offset to GDT data segment ; Kernel constants -%define STACK_POINTER 0x00900000 ; The initial stack pointer in kernel mode +%define STACK_POINTER 0x00500000 ; The initial stack pointer in kernel mode %define KERNEL_POSITION 0x00040000 ; Loaded kernel position in protected mode (* 0x10) ; ENOUGH, let's go! diff --git a/kernel/features/memory.c b/kernel/features/memory.c index f8e183a..4dfebff 100644 --- a/kernel/features/memory.c +++ b/kernel/features/memory.c @@ -28,10 +28,7 @@ void paging_switch_dir(u32 dir) cr3_set(dir); } -void paging_invalidate_tlb(void) -{ - /* __asm__ volatile("invlpg"); */ -} +extern void paging_invalidate_tlb(void); /** * Physical @@ -390,8 +387,9 @@ void memory_initialize(struct mem_info *mem_info) u32 size = p->lsize; if (p->hsize) - size = U32_MAX; + size = U32_MAX - p->lbase; + /* printf("Memory region: %x-%x\n", p->lbase, p->lbase + size); */ if (p->type == MEMORY_AVAILABLE) { physical_set_free(p->lbase, size / PAGE_SIZE); memory_total += size; @@ -403,22 +401,30 @@ void memory_initialize(struct mem_info *mem_info) memory_used = 0; printf("Detected memory: %dKiB (%dMiB)\n", memory_total >> 10, memory_total >> 20); + // Map kernel memory_map_identity(&kernel_dir, kernel_memory_range(), MEMORY_NONE); + // Map kernel stack + memory_map_identity(&kernel_dir, memory_range_around_address(STACK_START, 0x1000), + MEMORY_NONE); + + // Map kernel heap + memory_map_identity(&kernel_dir, memory_range_around_address(HEAP_START, HEAP_INIT_SIZE), + MEMORY_NONE); + + // Map stack guard? + /* memory_map_identity(&kernel_dir, memory_range_around_address(0xdeadbeef, 0x1), MEMORY_NONE); */ + // Unmap NULL byte/page virtual_free(&kernel_dir, memory_range(0, PAGE_SIZE)); physical_set_used(0, 1); memory_dir_switch(&kernel_dir); - printf("Enabling...\n"); paging_enable(); - printf("Enabled!\n"); } -#define HEAP_START 0x00f00000 void paging_install(struct mem_info *mem_info) { - heap_init(HEAP_START); memory_initialize(mem_info); - printf("OK!\n"); + heap_init(HEAP_START); } diff --git a/kernel/features/proc.asm b/kernel/features/proc.asm index 1a2ba65..dfc3448 100644 --- a/kernel/features/proc.asm +++ b/kernel/features/proc.asm @@ -28,3 +28,9 @@ proc_jump_userspace: push dword [_eip] iret + +global paging_invalidate_tlb +paging_invalidate_tlb: + mov eax, cr3 + mov cr3, eax + ret diff --git a/libc/alloc.c b/libc/alloc.c index 16154ef..11639a6 100644 --- a/libc/alloc.c +++ b/libc/alloc.c @@ -16,7 +16,6 @@ #ifdef kernel #define HEAP_MAGIC 0x424242 -#define HEAP_INIT_SIZE 0xf000000 #define HEAP_MIN_SIZE HEAP_INIT_SIZE #define MIN_ALLOC_SZ 4 #define BIN_COUNT 9 diff --git a/libc/inc/mem.h b/libc/inc/mem.h index 6c37844..737f772 100644 --- a/libc/inc/mem.h +++ b/libc/inc/mem.h @@ -13,6 +13,9 @@ void *realloc(void *ptr, u32 size); void *zalloc(u32 size); #ifdef kernel +#define STACK_START (0x00500000 - 1) // Defined it bootloader +#define HEAP_START 0x00f00000 +#define HEAP_INIT_SIZE 0x0f00000 void heap_init(u32 start); #elif defined(userspace) #else |