Skip to content

Commit d9a3ac9

Browse files
authored
Implement a dynamic virtual memory manager (#7)
* Implement vaddr_t_to_ptr * vaddr_t should have uint16_t indices * Add a simple alloc_vpage * Fix some mistypes * Revamp to a smarter alloc system + add alloc_vpages * Format + add free_all_vpages_in_range * Bugfix + quell some warnings * Minor readability improvement * Add free for vpages * Move the check for pml4 index to free_vpages * Switch to novel vmm for malloc * Deprecate try_assign_pt * Remove now unused 'allocated' flag * Remove most of init_memmgt * Don't delete the pdpt even if it is empty * Format * Add a message to signify that execution has completed * Expose the alloc functions just in case * Make static some file-only functions * init_memmgt -> __init_memmgt__ to match convention
1 parent f9944f5 commit d9a3ac9

3 files changed

Lines changed: 333 additions & 100 deletions

File tree

include/kernel/memmgt.h

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,7 @@ typedef struct {
6262
uint64_t dirty : 1;
6363
uint64_t pat : 1;
6464
uint64_t global : 1;
65-
uint64_t allocated : 1;
66-
uint64_t available1 : 2;
65+
uint64_t available1 : 3;
6766
uint64_t frame_base_address : 40;
6867
uint64_t available2 : 11;
6968
uint64_t nex : 1;
@@ -77,24 +76,28 @@ typedef struct {
7776
} memmap_bitmap;
7877

7978
typedef struct {
80-
uint8_t pml4_index;
81-
uint8_t pdpt_index;
82-
uint8_t pd_index;
83-
uint8_t pt_index;
79+
uint16_t pml4_index;
80+
uint16_t pdpt_index;
81+
uint16_t pd_index;
82+
uint16_t pt_index;
8483
uint16_t offset;
8584
} vaddr_t;
8685

8786
typedef uint64_t* paddr_t;
8887

8988
vaddr_t get_vaddr_t_from_ptr (void* ptr);
9089
void* get_vaddr_hhdm (uint64_t phys_address);
90+
void* vaddr_t_to_ptr (vaddr_t* virtual_addr);
91+
92+
void* alloc_vpages (size_t req_count);
93+
void* alloc_vpage (void);
94+
void free_vpages (void* ptr, size_t count);
95+
void free_vpage (void* ptr);
9196

92-
void init_memmgt (uint64_t, struct limine_memmap_response*);
97+
void __init_memmgt__ (uint64_t, struct limine_memmap_response*);
9398
void walk_pagetable (void);
9499
void* get_paddr (void* vaddr);
95100

96-
uint64_t allocate_physical_pageframes (size_t);
97-
98101
// LIBALLOC FUNCTION IMPLEMENTATIONS
99102

100103
void* try_assign_pt (pt_entry_t*, size_t);

src/kernel/entry.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ void _start (void) {
7272
hcf ();
7373
}
7474

75-
init_memmgt (hhdm_base, memmap_req.response);
75+
__init_memmgt__ (hhdm_base, memmap_req.response);
7676

7777
set_color (0x44eeaa);
7878

@@ -104,5 +104,6 @@ void _start (void) {
104104
printf ("CR3: %lx", cr3);
105105

106106
// We're done, just hang...
107+
printf ("\n\nAll execution completed.");
107108
hcf ();
108109
}

0 commit comments

Comments
 (0)