diff options
author | dzwdz | 2022-04-14 07:51:32 +0200 |
---|---|---|
committer | dzwdz | 2022-04-14 07:51:32 +0200 |
commit | cd096cf7aa7b96e04a68d059efe3239d77d25d78 (patch) | |
tree | 5c76b652c584c0cda2d770cbb87f25196fdf9d85 /src/kernel/arch | |
parent | f1ef26f435d2eef53a718cf1c2b06387e29b2a3b (diff) |
kernel: basic page allocator, `process_free`
Diffstat (limited to 'src/kernel/arch')
-rw-r--r-- | src/kernel/arch/generic.h | 2 | ||||
-rw-r--r-- | src/kernel/arch/i386/boot.c | 2 | ||||
-rw-r--r-- | src/kernel/arch/i386/multiboot.s | 1 | ||||
-rw-r--r-- | src/kernel/arch/i386/pagedir.c | 23 |
4 files changed, 28 insertions, 0 deletions
diff --git a/src/kernel/arch/generic.h b/src/kernel/arch/generic.h index 01a3826..84be937 100644 --- a/src/kernel/arch/generic.h +++ b/src/kernel/arch/generic.h @@ -27,6 +27,8 @@ _Noreturn void sysexit(struct registers); // all of those can allocate memory struct pagedir *pagedir_new(void); struct pagedir *pagedir_copy(const struct pagedir *orig); + +void pagedir_free(struct pagedir *); void pagedir_map(struct pagedir *dir, void __user *virt, void *phys, bool user, bool writeable); diff --git a/src/kernel/arch/i386/boot.c b/src/kernel/arch/i386/boot.c index c25a848..a2b4f01 100644 --- a/src/kernel/arch/i386/boot.c +++ b/src/kernel/arch/i386/boot.c @@ -32,5 +32,7 @@ void kmain_early(struct multiboot_info *multiboot) { info.init.size = module->end - module->start; } + info.memtop = (void*) (multiboot->mem_upper * 1024); + kmain(info); } diff --git a/src/kernel/arch/i386/multiboot.s b/src/kernel/arch/i386/multiboot.s index 10702c6..62bc9fd 100644 --- a/src/kernel/arch/i386/multiboot.s +++ b/src/kernel/arch/i386/multiboot.s @@ -1,6 +1,7 @@ .set MAGIC, 0x1BADB002 /* 1<<0 - align modules on page boundaries. + 1<<1 - fill the mem_ fields in multiboot_info 1<<16 - enable manual addressing */ .set FLAGS, 1<<0 | 1<<16 .set CHECKSUM, -(MAGIC + FLAGS) diff --git a/src/kernel/arch/i386/pagedir.c b/src/kernel/arch/i386/pagedir.c index 88f6ebb..e3c2fa5 100644 --- a/src/kernel/arch/i386/pagedir.c +++ b/src/kernel/arch/i386/pagedir.c @@ -46,6 +46,29 @@ struct pagedir *pagedir_new(void) { return dir; } +void pagedir_free(struct pagedir *dir) { + // assumes all user pages are unique and can be freed + struct pagetable_entry *pt; + void *page; + + for (int i = 0; i < 1024; i++) { + if (!dir->e[i].present) continue; + if (!dir->e[i].user) continue; + + pt = (void*)(dir->e[i].address << 11); + + for (int j = 0; j < 1024; j++) { + if (!pt[j].present) continue; + if (!pt[j].user) continue; + + page = (void*)(pt[j].address << 11); + page_free(page, 1); + } + page_free(pt, 1); + } + page_free(dir, 1); +} + void pagedir_map(struct pagedir *dir, void __user *virt, void *phys, bool user, bool writeable) { |