diff options
Diffstat (limited to 'common')
| -rw-r--r-- | common/mem.c | 12 | ||||
| -rw-r--r-- | common/vmem.c | 24 |
2 files changed, 22 insertions, 14 deletions
diff --git a/common/mem.c b/common/mem.c index 48bd776..cff11b7 100644 --- a/common/mem.c +++ b/common/mem.c @@ -9,19 +9,19 @@ size_t __mm_sizes[10]; size_t __mm_page_shift; size_t __mm_max_order; -void init_mem(size_t max_order, size_t widths[10], size_t page_shift) +void init_mem(size_t max_order, size_t bits[10], size_t page_shift) { __mm_max_order = max_order; __mm_page_shift = page_shift; __mm_shifts[0] = 0; - __mm_widths[0] = 1 << widths[0]; + __mm_widths[0] = 1 << bits[0]; __mm_sizes[0] = 1 << __mm_page_shift; - for(size_t i = 0; i <= __mm_max_order; ++i){ - __mm_widths[i] = 1 << widths[i]; - __mm_shifts[i] = __mm_shifts[i - 1] + __mm_widths[i - 1]; - __mm_sizes[i] = 1 << __mm_shifts[i] << __mm_page_shift; + for(size_t i = 1; i <= __mm_max_order; ++i){ + __mm_widths[i] = 1 << bits[i]; + __mm_shifts[i] = __mm_shifts[i - 1] + bits[i - 1]; + __mm_sizes[i] = 1UL << __mm_shifts[i] << __mm_page_shift; } } diff --git a/common/vmem.c b/common/vmem.c index c30f99b..c874e3d 100644 --- a/common/vmem.c +++ b/common/vmem.c @@ -33,22 +33,22 @@ struct mm_block_region_t { struct mm_block_t *first; }; -static struct mm_block_region_t *root_region = 0; -/* a block represents free regions */ +static struct mm_block_region_t *root_region = (struct mm_block_region_t *)ROOT_REGION; static struct mm_block_t *root_block = 0; #define NODE_REGION(x) ((struct mm_block_region_t *)(((vm_t)x) & (__mm_page_shift - 1))) +#define NEXT_BLOCK() ((struct mm_block_region_t *)\ +((region_counter * __o_size(MM_O0)) + ROOT_PTE)) +/* TODO: mark all used regions, also blocks */ static struct mm_block_t *get_free_block(struct vm_branch_t *branch) { struct mm_block_region_t *region = root_region; size_t region_counter = 1; - for(;region; region = region->next){ + for(; region; region = region->next){ if(region->next == 0){ pm_t next_pa = alloc_page(MM_O0, 0); - struct mm_block_region_t *next_va = - (struct mm_block_region_t *) - (region_counter * __o_size(MM_O0)); + struct mm_block_region_t *next_va = NEXT_BLOCK(); map_vmem(branch, next_pa, (vm_t)next_va, VM_W | VM_R | VM_V, MM_O0); @@ -71,15 +71,23 @@ static struct mm_block_t *get_free_block(struct vm_branch_t *branch) return &block[i]; } } + + region_counter++; } return 0; } -void init_vmem(struct vm_branch_t *branch) +void init_vmem(struct vm_branch_t *branch, vm_t tmp_pte) { +#if defined(KERNEL) + arch_init_vmem(branch, tmp_pte); +#else + (void)tmp_pte; +#endif + pm_t first_block = alloc_page(MM_O0, 0); - map_vmem(branch, first_block, 0, VM_W | VM_R | VM_V, MM_O0); + map_vmem(branch, first_block, (vm_t)root_region, VM_W | VM_R | VM_V, MM_O0); memset(root_region, 0, __o_size(MM_O0)); root_region->max_blocks = (__o_size(MM_O0) - sizeof(struct mm_block_region_t)) |
