diff options
-rw-r--r-- | kernel/fs/tar.c | 1 | ||||
-rw-r--r-- | kernel/lib/kalloc.c | 4 | ||||
-rw-r--r-- | kernel/mboot/module.c | 2 | ||||
-rw-r--r-- | kernel/memory/paging.c | 3 | ||||
-rw-r--r-- | kernel/memory/physalloc.c | 21 | ||||
-rw-r--r-- | kernel/memory/virtalloc.c | 6 |
6 files changed, 26 insertions, 11 deletions
diff --git a/kernel/fs/tar.c b/kernel/fs/tar.c index 86af81f..061dd0c 100644 --- a/kernel/fs/tar.c +++ b/kernel/fs/tar.c @@ -1,3 +1,4 @@ +#include "lib/kio.h" #include <comus/fs.h> #include <lib.h> diff --git a/kernel/lib/kalloc.c b/kernel/lib/kalloc.c index 02e9457..8dca46b 100644 --- a/kernel/lib/kalloc.c +++ b/kernel/lib/kalloc.c @@ -1,3 +1,4 @@ +#include "lib/kio.h" #include <lib.h> #include <comus/memory.h> @@ -34,7 +35,8 @@ static struct page_header *get_header(void *ptr) static void *alloc_new(size_t size) { - size_t pages = ((size + header_len + PAGE_SIZE - 1) / PAGE_SIZE) * PAGE_SIZE; + size_t pages = + ((size + header_len + PAGE_SIZE - 1) / PAGE_SIZE) * PAGE_SIZE; void *addr = kalloc_pages(pages); void *mem = (char *)addr + header_len; diff --git a/kernel/mboot/module.c b/kernel/mboot/module.c index cb05b45..bf15eca 100644 --- a/kernel/mboot/module.c +++ b/kernel/mboot/module.c @@ -33,7 +33,7 @@ void *mboot_get_initrd(size_t *len) return NULL; mod = (struct multiboot_tag_module *)tag; - phys = (void *) (uintptr_t) mod->mod_start; + phys = (void *)(uintptr_t)mod->mod_start; initrd_len = mod->mod_end - mod->mod_start; // map addr diff --git a/kernel/memory/paging.c b/kernel/memory/paging.c index 9dfa236..39f7638 100644 --- a/kernel/memory/paging.c +++ b/kernel/memory/paging.c @@ -1,3 +1,4 @@ +#include "lib/kio.h" #include <lib.h> #include <comus/memory.h> @@ -353,7 +354,7 @@ static volatile struct pt *pt_alloc(volatile struct pd *pPD, void *vADDR, } pPT = alloc_phys_page(); - if (pPD == NULL) + if (pPT == NULL) return NULL; vPT = PT_MAP(pPT); diff --git a/kernel/memory/physalloc.c b/kernel/memory/physalloc.c index 8971bcf..4255339 100644 --- a/kernel/memory/physalloc.c +++ b/kernel/memory/physalloc.c @@ -1,3 +1,4 @@ +#include "lib/kio.h" #include <lib.h> #include <comus/memory.h> #include <comus/asm.h> @@ -62,7 +63,7 @@ static long page_idx(void *page) static inline bool bitmap_get(size_t i) { - return (bitmap[i / 64] >> i % 64) & 1; + return (bitmap[i / 64] >> (i % 64)) & 1; } static inline void bitmap_set(size_t i, bool v) @@ -71,9 +72,9 @@ static inline void bitmap_set(size_t i, bool v) free_memory -= PAGE_SIZE; else free_memory += PAGE_SIZE; - int idx = i / 64; - bitmap[idx] &= ~(1 << i % 64); - bitmap[idx] |= (v << i % 64); + size_t idx = i / 64; + bitmap[idx] &= ~(1 << (i % 64)); + bitmap[idx] |= (v << (i % 64)); } void *alloc_phys_page(void) @@ -105,9 +106,17 @@ void *alloc_phys_pages_exact(size_t pages) free_region_start = i; n_contiguous++; if (n_contiguous == pages) { + void *pADDR; + pADDR = page_at(free_region_start); + + if (pADDR == NULL) { + n_contiguous = 0; + continue; + } + for (size_t j = 0; j < pages; j++) bitmap_set(free_region_start + j, true); - return page_at(free_region_start); + return pADDR; } } else n_contiguous = 0; @@ -118,6 +127,7 @@ void *alloc_phys_pages_exact(size_t pages) struct phys_page_slice alloc_phys_page_withextra(size_t max_pages) { + panic("please dont use this its broken i think?!\n"); if (max_pages == 0) return PHYS_PAGE_SLICE_NULL; @@ -160,6 +170,7 @@ void free_phys_page(void *ptr) void free_phys_pages_slice(struct phys_page_slice slice) { + panic("please dont use this its broken i think?!\n"); free_phys_pages(slice.pagestart, slice.num_pages); } diff --git a/kernel/memory/virtalloc.c b/kernel/memory/virtalloc.c index 4ee75bb..da64f3b 100644 --- a/kernel/memory/virtalloc.c +++ b/kernel/memory/virtalloc.c @@ -100,9 +100,9 @@ void virtaddr_init(struct virt_ctx *ctx) ctx->used_node_count = 0; ctx->is_allocating = false; - virtaddr_take(ctx, (void *)kernel_start, - ((uint64_t)kernel_end - (uint64_t)kernel_start) / PAGE_SIZE + - 1); + virtaddr_take(ctx, (void *)0, + ((uint64_t)kernel_end + PAGE_SIZE - 1) / PAGE_SIZE * + PAGE_SIZE); } int virtaddr_clone(struct virt_ctx *old, struct virt_ctx *new) |