diff options
author | Alex AUVOLAT <alexis211@gmail.com> | 2012-05-01 12:20:45 +0200 |
---|---|---|
committer | Alex AUVOLAT <alexis211@gmail.com> | 2012-05-01 12:20:45 +0200 |
commit | 5cac9acd3aedc8043d4272d93c56805c46ff6214 (patch) | |
tree | ba9eb5ef86f7cf7afd4f7ab02de1d6bb86715632 /src/kernel/mem | |
parent | 66b32658d2e5aa99493dcb3abcb73cdb2cc6f0b5 (diff) | |
download | TCE-5cac9acd3aedc8043d4272d93c56805c46ff6214.tar.gz TCE-5cac9acd3aedc8043d4272d93c56805c46ff6214.zip |
Some cleanup ; relocated the kernel at 0xC0000000
Diffstat (limited to 'src/kernel/mem')
-rw-r--r-- | src/kernel/mem/heap.basic.h | 2 | ||||
-rw-r--r-- | src/kernel/mem/heap.std.c | 6 | ||||
-rw-r--r-- | src/kernel/mem/heap.std.h | 2 | ||||
-rw-r--r-- | src/kernel/mem/mem.c | 4 | ||||
-rw-r--r-- | src/kernel/mem/mem.h | 4 | ||||
-rw-r--r-- | src/kernel/mem/paging.c | 24 |
6 files changed, 26 insertions, 16 deletions
diff --git a/src/kernel/mem/heap.basic.h b/src/kernel/mem/heap.basic.h index c752750..b52be4e 100644 --- a/src/kernel/mem/heap.basic.h +++ b/src/kernel/mem/heap.basic.h @@ -3,7 +3,7 @@ /* This heap implementation is extra-simple and extra-slow. */ -#include "types.h" +#include <types.h> #define HH_FREE_MAGIC 0xFEE0FEE0 #define HH_ALLOC_MAGIC 0xA110A110 diff --git a/src/kernel/mem/heap.std.c b/src/kernel/mem/heap.std.c index 5b2d025..84c11e2 100644 --- a/src/kernel/mem/heap.std.c +++ b/src/kernel/mem/heap.std.c @@ -2,7 +2,9 @@ #include "paging.h" #include <core/sys.h> -#include <lib/stdlib.h> +#include <mem/mem.h> + +#include <stdlib.h> #define HEAP_MAGIC 0xBAD0BEEF #define HEAP_MIN_SIZE 0x4000 @@ -156,7 +158,7 @@ static void heap_contract(struct heap *heap) { /* Alocate some bytes on the heap. */ void* heap_alloc(struct heap *heap, size_t sz) { - ASSERT(heap > 0xE0000000); + ASSERT(heap > K_HIGHHALF_ADDR); size_t newsize = sz + sizeof(struct heap_header) + sizeof(struct heap_footer); uint32_t iterator = 0; diff --git a/src/kernel/mem/heap.std.h b/src/kernel/mem/heap.std.h index fa146ae..2018508 100644 --- a/src/kernel/mem/heap.std.h +++ b/src/kernel/mem/heap.std.h @@ -6,7 +6,7 @@ The heap algorithm used is based on the one described here : http://www.jamesmolloy.co.uk/tutorial_html/7.-The%20Heap.html */ -#include "types.h" +#include <types.h> struct heap_header { uint32_t magic; diff --git a/src/kernel/mem/mem.c b/src/kernel/mem/mem.c index c6494b7..8d814e4 100644 --- a/src/kernel/mem/mem.c +++ b/src/kernel/mem/mem.c @@ -11,6 +11,8 @@ #include "heap.std.h" #endif +#include "mem.h" + #define FREEPAGESTOKEEP 5 #define KHEAP_IDXSIZE 0x4000 // only used with heap.std.h @@ -50,7 +52,7 @@ static void get_free_pages() { mem_placementAddr += 0x1000; } freepages[freepagecount].virt = (size_t)kmalloc(0x1000); - freepages[freepagecount].phys = freepages[freepagecount].virt - 0xE0000000; + freepages[freepagecount].phys = freepages[freepagecount].virt - K_HIGHHALF_ADDR; freepagecount++; } } diff --git a/src/kernel/mem/mem.h b/src/kernel/mem/mem.h index b372fae..093545e 100644 --- a/src/kernel/mem/mem.h +++ b/src/kernel/mem/mem.h @@ -16,5 +16,9 @@ void kheap_init(); extern size_t mem_placementAddr; extern void end; //Symbol defined by linker : end of kernel code +extern void k_highhalf_addr; // Symbol defined by linker : high half position of the kerne + // Should be at 0xC0000000 +#define K_HIGHHALF_ADDR ((size_t)(&k_highhalf_addr)) + #endif diff --git a/src/kernel/mem/paging.c b/src/kernel/mem/paging.c index 4e5f33a..3e2bffa 100644 --- a/src/kernel/mem/paging.c +++ b/src/kernel/mem/paging.c @@ -7,6 +7,8 @@ #include <core/sys.h> #include <task/task.h> +#define FIRST_KERNEL_PAGETABLE (K_HIGHHALF_ADDR >> 22) + static struct bitset frames; struct page_directory *kernel_pagedir, *current_pagedir; @@ -27,7 +29,7 @@ void frame_free(uint32_t id) { /************************* PAGING INITIALIZATION *****************************/ /* This function creates the kernel page directory. It must be called before the GDT is loaded. - It maps 0xE0000000+ to the corresponding physical kernel code, but it also maps + It maps 0xC0000000+ (k_highhalf_addr) to the corresponding physical kernel code, but it also maps 0x00000000+ to that code because with the false GDT we set up in loader_.asm, the code will be looked for at the beginning of the memory. Only when the real GDT is loaded we can de-allocate pages at 0x00000000 ; this is done by paging_cleanup. */ @@ -45,12 +47,12 @@ void paging_init(size_t totalRam) { kernel_pagedir->tablesPhysical[i] = 0; } - for (i = 0xE0000000; i < mem_placementAddr; i += 0x1000) { + for (i = K_HIGHHALF_ADDR; i < mem_placementAddr; i += 0x1000) { page_map(pagedir_getPage(kernel_pagedir, i, 1), frame_alloc(), 0, 0); } - for (i = 0; i < (mem_placementAddr - 0xE0000000) / 0x100000; i++) { - kernel_pagedir->tablesPhysical[i] = kernel_pagedir->tablesPhysical[i + 896]; - kernel_pagedir->tables[i] = kernel_pagedir->tables[i + 896]; + for (i = 0; i < (mem_placementAddr - K_HIGHHALF_ADDR) / 0x100000; i++) { + kernel_pagedir->tablesPhysical[i] = kernel_pagedir->tablesPhysical[i + FIRST_KERNEL_PAGETABLE]; + kernel_pagedir->tables[i] = kernel_pagedir->tables[i + FIRST_KERNEL_PAGETABLE]; } monitor_write("{PD: "); @@ -61,8 +63,8 @@ void paging_init(size_t totalRam) { /* De-allocates pages at 0x00000000 where kernel code was read from with the GDT from loader_.asm. */ void paging_cleanup() { - uint32_t i; - for (i = 0; i < (mem_placementAddr - 0xE0000000) / 0x100000; i++) { + size_t i; + for (i = 0; i < (mem_placementAddr - K_HIGHHALF_ADDR) / 0x100000; i++) { kernel_pagedir->tablesPhysical[i] = 0; kernel_pagedir->tables[i] = 0; } @@ -94,7 +96,7 @@ struct page_directory *pagedir_new() { pd->tables[i] = 0; pd->tablesPhysical[i] = 0; } - for (i = 896; i < 1024; i++) { + for (i = FIRST_KERNEL_PAGETABLE; i < 1024; i++) { pd->tables[i] = kernel_pagedir->tables[i]; pd->tablesPhysical[i] = kernel_pagedir->tablesPhysical[i]; } @@ -108,7 +110,7 @@ void pagedir_delete(struct page_directory *pd) { //Unmap segments while (pd->mappedSegs != 0) seg_unmap(pd->mappedSegs); //Cleanup page tables - for (i = 0; i < 896; i++) { + for (i = 0; i < FIRST_KERNEL_PAGETABLE; i++) { kfree_page(pd->tables[i]); } kfree_page(pd->tablesPhysical); @@ -130,7 +132,7 @@ uint32_t paging_fault(struct registers *regs) { } if (seg != 0) { - if (seg->seg->handle_fault(seg, addr, (regs->err_code & 0x2) && (regs->eip < 0xE0000000)) != 0) seg = 0; + if (seg->seg->handle_fault(seg, addr, (regs->err_code & 0x2) && (regs->eip < K_HIGHHALF_ADDR)) != 0) seg = 0; } if (seg == 0) { @@ -158,7 +160,7 @@ struct page *pagedir_getPage(struct page_directory *pd, uint32_t address, int ma return &pd->tables[table_idx]->pages[address % 1024]; } else if (make) { pd->tables[table_idx] = kmalloc_page(pd->tablesPhysical + table_idx); - if (table_idx >= 896) + if (table_idx >= FIRST_KERNEL_PAGETABLE) tasking_updateKernelPagetable(table_idx, pd->tables[table_idx], pd->tablesPhysical[table_idx]); memset((uint8_t*)pd->tables[table_idx], 0, 0x1000); pd->tablesPhysical[table_idx] |= 0x07; |