aboutsummaryrefslogtreecommitdiff
path: root/common/vmem.c
diff options
context:
space:
mode:
authorKimplul <kimi.h.kuparinen@gmail.com>2021-10-25 19:40:53 +0300
committerKimplul <kimi.h.kuparinen@gmail.com>2021-10-25 19:44:11 +0300
commit7f7b3d61baf46fe358d3f1bd1cb584e0daed3a81 (patch)
tree51ded3e49cb467915a6e2b0e570b5d9973515553 /common/vmem.c
parent59a374b0eed4313d1a67e2cdb673a295e79a6494 (diff)
downloadkmi-7f7b3d61baf46fe358d3f1bd1cb584e0daed3a81.tar.gz
kmi-7f7b3d61baf46fe358d3f1bd1cb584e0daed3a81.zip
Some minor changes to virtual memory handling
+ Should start to think about how virtual memory should be handled efficiently, I'm sort of flailing around and not actually doing anything beneficial. The mapping system I've so far implemented _works_, but it's not good and I'm not happy with it. I might come back and fix/improve it, but I think I'll go ahead and do other things for a while, might give me a better overhead view of what the virtual memory system should do. + TODO: should probably document the memory layout I'm going with at the moment.
Diffstat (limited to 'common/vmem.c')
-rw-r--r--common/vmem.c24
1 files changed, 16 insertions, 8 deletions
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))