From 12cafeca2d8125322edd506d563bc8d9356e01e5 Mon Sep 17 00:00:00 2001 From: Joshua Phillips Date: Thu, 5 Feb 2009 20:38:53 +0000 Subject: [PATCH] Moved PAGE_SIZE to kernel/archinf.h --- kernel/archinf.h | 33 +++++++++++++++++++++++++++++++++ kernel/kmain.c | 7 +++++++ kernel/loadelf.c | 1 + kernel/mm/allocation.c | 2 +- kernel/mm/allocation.h | 1 - kernel/mm/kvmalloc.c | 1 + kernel/mm/malloc.c | 11 ++++++----- kernel/mm/paging.c | 1 + 8 files changed, 50 insertions(+), 7 deletions(-) create mode 100644 kernel/archinf.h diff --git a/kernel/archinf.h b/kernel/archinf.h new file mode 100644 index 0000000..1f3c356 --- /dev/null +++ b/kernel/archinf.h @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2009 Joshua Phillips. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER + * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef ARCHINF_H +#define ARCHINF_H + +#define PAGE_SIZE 4096 + +#endif diff --git a/kernel/kmain.c b/kernel/kmain.c index 25c6ef0..cc9d35a 100644 --- a/kernel/kmain.c +++ b/kernel/kmain.c @@ -138,9 +138,16 @@ void kmain(uint32_t freemem_base, struct mb_info *mbi, unsigned int magic) console_printf(&tty1, "Free memory: %d MiB\n", uldivru(pmem_get_size(), 1024 * 1024)); mm_allocation_init(); create_init_pagedir(&init_pagedir); + map_mem(&init_pagedir, 0xF0000000, 0x00000000, 4096, PTE_PRESENT | PTE_WRITABLE); TRACE("map_mem returned! Check the mapping!"); + static struct pagedir second_pagedir; + pagedir_create(&second_pagedir); + map_mem(&second_pagedir, 0x00000000, 0x40000000, 4096, PTE_PRESENT | PTE_WRITABLE); + pagedir_switch(&second_pagedir); + TRACE("Well I seem to be still alive!"); + asm volatile ("cli ; hlt"); // allocate a page for the IDT, GDT and TSS diff --git a/kernel/loadelf.c b/kernel/loadelf.c index 8b18471..4e716c4 100644 --- a/kernel/loadelf.c +++ b/kernel/loadelf.c @@ -27,6 +27,7 @@ #include "loadelf.h" #include "elf.h" +#include "archinf.h" #include "mm/region.h" #include "thread.h" #include "console.h" diff --git a/kernel/mm/allocation.c b/kernel/mm/allocation.c index 5851544..b1f8b02 100644 --- a/kernel/mm/allocation.c +++ b/kernel/mm/allocation.c @@ -27,10 +27,10 @@ #include "mm/allocation.h" #include "mm/buddy.h" -#include "mm/paging.h" // for PAGE_TAB #include "stdlib.h" // for malloc! #include "trace.h" #include "extlib.h" +#include "archinf.h" // Boundaries of contiguous free memory. // This is far from ideal. diff --git a/kernel/mm/allocation.h b/kernel/mm/allocation.h index 32d9846..30f321a 100644 --- a/kernel/mm/allocation.h +++ b/kernel/mm/allocation.h @@ -44,7 +44,6 @@ extern int _phys_base[]; // defined in linker script extern int _virt_base[]; // defined in linker script -#define PAGE_SIZE 4096 #define KERNEL_PHYS_BASE ((uintptr_t) _phys_base) #define KERNEL_VIRT_BASE ((uintptr_t) _virt_base) diff --git a/kernel/mm/kvmalloc.c b/kernel/mm/kvmalloc.c index e067bf2..a8af2b6 100644 --- a/kernel/mm/kvmalloc.c +++ b/kernel/mm/kvmalloc.c @@ -33,6 +33,7 @@ #include "mm/kvmalloc.h" #include "mm/allocation.h" #include "mm/paging.h" +#include "archinf.h" size_t kvmalloc(size_t min_pages, size_t max_pages, void **ptr_out, uintptr_t *phys_array) diff --git a/kernel/mm/malloc.c b/kernel/mm/malloc.c index 0a7cff8..c559fb6 100644 --- a/kernel/mm/malloc.c +++ b/kernel/mm/malloc.c @@ -1,6 +1,7 @@ #include "stdlib.h" #include "trace.h" -#include "mm/allocation.h" +#include "mm/kvmalloc.h" +#include "archinf.h" #include "assert.h" #include "string.h" @@ -55,11 +56,11 @@ static void *fake_mmap(void *start, size_t length, int prot, int flags, assert(start == NULL); assert(flags == (MAP_ANONYMOUS | MAP_PRIVATE)); assert((length % PAGE_SIZE) == 0); - n = alloc_kvmem(length / PAGE_SIZE, length / PAGE_SIZE, &ptr, NULL); + n = kvmalloc(length / PAGE_SIZE, length / PAGE_SIZE, &ptr, NULL); if (n != (length / PAGE_SIZE)){ - TRACE("fake_mmap: alloc_kvmem failed"); + TRACE("kvmalloc failed"); if (n != 0){ - free_kvmem(ptr, n); + kvfree(ptr, n); } return NULL; } else { @@ -73,7 +74,7 @@ static int fake_munmap(void *start, size_t length) // with the same parameters as mmap, then we have // to assume the buddy allocator doesn't mind. // Currently, this is so, but it may not be, in the future. - free_kvmem(start, length); + kvfree(start, length); return 0; } diff --git a/kernel/mm/paging.c b/kernel/mm/paging.c index 52864ba..3560e2b 100644 --- a/kernel/mm/paging.c +++ b/kernel/mm/paging.c @@ -28,6 +28,7 @@ #include "mm/paging.h" #include "mm/allocation.h" #include "mm/kvmalloc.h" +#include "archinf.h" #include "trace.h" #include "assert.h" #include "stdbool.h" -- 2.11.4.GIT