diff options
author | Alex Auvolat <alex.auvolat@ens.fr> | 2014-12-04 10:43:58 +0100 |
---|---|---|
committer | Alex Auvolat <alex.auvolat@ens.fr> | 2014-12-04 10:43:58 +0100 |
commit | 292e4141078d18993b1395820631503ac852eb3d (patch) | |
tree | 3b3e5cb75d9bf3abb2639deedc247eba2cdeabe6 /kernel/l0/region.c | |
parent | d78a3d8be9c194554580cb3c73c1c5ebd0d82a9b (diff) | |
download | kogata-292e4141078d18993b1395820631503ac852eb3d.tar.gz kogata-292e4141078d18993b1395820631503ac852eb3d.zip |
Make paging work ! \o/
Diffstat (limited to 'kernel/l0/region.c')
-rw-r--r-- | kernel/l0/region.c | 25 |
1 files changed, 4 insertions, 21 deletions
diff --git a/kernel/l0/region.c b/kernel/l0/region.c index 63e464d..6001346 100644 --- a/kernel/l0/region.c +++ b/kernel/l0/region.c @@ -17,7 +17,7 @@ typedef union region_descriptor { } used; } descriptor_t; -#define N_RESERVE_DESCRIPTORS 3 // always keep at least 3 unused descriptors +#define N_RESERVE_DESCRIPTORS 2 // always keep at least 3 unused descriptors #define N_BASE_DESCRIPTORS 12 // pre-allocate memory for 12 descriptors static descriptor_t base_descriptors[N_BASE_DESCRIPTORS]; @@ -210,7 +210,7 @@ void region_allocator_init(void* kernel_data_end) { descriptor_t *f0 = &base_descriptors[1]; f0->free.addr = PAGE_ALIGN_UP(kernel_data_end); - f0->free.size = (0xFFFFF000-f0->free.addr); // last page cannot be used... + f0->free.size = (LAST_KERNEL_ADDR-f0->free.addr); f0->free.next_by_size = 0; f0->free.first_bigger = 0; first_free_region_by_size = first_free_region_by_addr = f0; @@ -234,8 +234,7 @@ static size_t region_alloc_inner(size_t size, uint32_t type, page_fault_handler_ return 0; } - // this assert is a bit tricky to prove, - // but basically it means that the allocation function + // this assert basically means that the allocation function // is called less than N_RESERVE_DESCRIPTORS times with // the use_reserve flag before more descriptors // are allocated. @@ -267,20 +266,6 @@ static size_t region_alloc_inner(size_t size, uint32_t type, page_fault_handler_ return 0; //No big enough block found } -bool region_alloc_for_pt_use_reserve = false; -size_t region_alloc_for_pt() { - if (region_alloc_for_pt_use_reserve) { - return region_alloc_inner( - N_PAGES_IN_PT_REGION * PAGE_SIZE, - REGION_T_PAGETABLE, - 0, true); - } else { - return region_alloc( - N_PAGES_IN_PT_REGION * PAGE_SIZE, - REGION_T_PAGETABLE, 0); - } -} - size_t region_alloc(size_t size, uint32_t type, page_fault_handler_t pf) { if (n_unused_descriptors <= N_RESERVE_DESCRIPTORS) { uint32_t frame = frame_alloc(1); @@ -289,9 +274,7 @@ size_t region_alloc(size_t size, uint32_t type, page_fault_handler_t pf) { size_t descriptor_region = region_alloc_inner(PAGE_SIZE, REGION_T_DESCRIPTORS, 0, true); ASSERT(descriptor_region != 0); - region_alloc_for_pt_use_reserve = true; - int error = pd_map_page(0, descriptor_region, frame, 1); - region_alloc_for_pt_use_reserve = false; + int error = pd_map_page(descriptor_region, frame, 1); if (error) { // this can happen if we weren't able to allocate a frame for // a new pagetable |