diff options
author | Aqua-sama <aqua@iserlohn-fortress.net> | 2021-03-28 12:41:57 +0300 |
---|---|---|
committer | Aqua-sama <aqua@iserlohn-fortress.net> | 2021-03-28 12:41:57 +0300 |
commit | b3b1385e7af85ba2cb1f92bc31706099f1b9d562 (patch) | |
tree | 2086f7333e33970f17898049d7392e7dece705ff | |
parent | clang-tidy fixes (diff) | |
download | kernel.cpp-b3b1385e7af85ba2cb1f92bc31706099f1b9d562.tar.xz |
Move MemoryAllocator to libk
-rw-r--r-- | libk/makefile | 1 | ||||
-rw-r--r-- | libk/memory.h (renamed from src/allocator.h) | 4 | ||||
-rw-r--r-- | libk/memory/allocator.cc (renamed from src/allocator.cc) | 14 | ||||
-rw-r--r-- | makefile | 9 | ||||
-rw-r--r-- | src/kernel.cc | 3 | ||||
-rw-r--r-- | src/makefile | 1 |
6 files changed, 15 insertions, 17 deletions
diff --git a/libk/makefile b/libk/makefile index f3b9aeb..eafa98c 100644 --- a/libk/makefile +++ b/libk/makefile @@ -1,4 +1,5 @@ CXX_OBJ = string/integerview.o string/memory.o \ + memory/allocator.o \ stdlib/abort.o stdlib/console.o stdlib/virtual.o CXX_OBJ := $(addprefix $(OBJ_DIR)/, $(CXX_OBJ)) CXX_DEP = $(CXX_OBJ:%.o=%.d) diff --git a/src/allocator.h b/libk/memory.h index 8a12be8..a01252c 100644 --- a/src/allocator.h +++ b/libk/memory.h @@ -6,8 +6,8 @@ class MemoryAllocator { public: MemoryAllocator(uint32_t start, size_t size); - void* malloc(size_t size); - void free(void* ptr); + void* allocate(size_t size); + void deallocate(void* ptr); size_t free_space() const; size_t used_space() const; diff --git a/src/allocator.cc b/libk/memory/allocator.cc index 77736cc..351646f 100644 --- a/src/allocator.cc +++ b/libk/memory/allocator.cc @@ -1,4 +1,4 @@ -#include "allocator.h" +#include <memory.h> static MemoryAllocator* mem_alloc = nullptr; @@ -11,7 +11,7 @@ MemoryAllocator::MemoryAllocator(uint32_t start, size_t size) { if (mem_alloc == nullptr) mem_alloc = this; } -void* MemoryAllocator::malloc(size_t size) { +void* MemoryAllocator::allocate(size_t size) { // TODO spinlock // TODO memset 0 over allocated memory MemoryChunk* result = nullptr; @@ -34,7 +34,7 @@ void* MemoryAllocator::malloc(size_t size) { return result + sizeof(MemoryChunk); } -void MemoryAllocator::free(void* ptr) { +void MemoryAllocator::deallocate(void* ptr) { auto* chunk = reinterpret_cast<MemoryChunk*>(reinterpret_cast<uint32_t>(ptr) - sizeof(MemoryChunk)); chunk->allocated = false; @@ -68,18 +68,18 @@ size_t MemoryAllocator::used_space() const { void* operator new(unsigned sz, const std::nothrow_t&) noexcept { if (mem_alloc == nullptr) return nullptr; - return mem_alloc->malloc(sz); + return mem_alloc->allocate(sz); } void* operator new[](unsigned sz, const std::nothrow_t&) noexcept { if (mem_alloc == nullptr) return nullptr; - return mem_alloc->malloc(sz); + return mem_alloc->allocate(sz); } void operator delete(void* ptr) { - if (mem_alloc != nullptr) mem_alloc->free(ptr); + if (mem_alloc != nullptr) mem_alloc->deallocate(ptr); } void operator delete[](void* ptr) { - if (mem_alloc != nullptr) mem_alloc->free(ptr); + if (mem_alloc != nullptr) mem_alloc->deallocate(ptr); } void* operator new(unsigned /* size_bytes */, void* ptr) { @@ -2,9 +2,8 @@ include .config OBJ_DIR != echo $(CONFIG_OBJ_DIR) include toolchain.makefile -.PHONY: all libk clean test tidy todo run menuconfig +.PHONY: all libk libd clean test tidy todo run menuconfig all: $(OBJ_DIR)/src/glitch.elf -libk: $(OBJ_DIR)/libk.a LIBS := $(OBJ_DIR)/libk.a $(OBJ_DIR)/libd.a LD_FLAGS := $(LD_FLAGS) --library-path $(CURDIR)/$(OBJ_DIR) @@ -14,13 +13,13 @@ export AR AR_FLAGS AS AS_FLAGS NM SED \ TEST_CXX TEST_CXX_FLAGS \ LD LD_FLAGS -$(OBJ_DIR)/src/glitch.elf: $(LIBS) +$(OBJ_DIR)/src/glitch.elf: libk libd @make -C src OBJ_DIR=$(CURDIR)/$(OBJ_DIR)/src $(CURDIR)/$(OBJ_DIR)/src/glitch.elf -$(OBJ_DIR)/libk.a: +libk: @make -C libk OBJ_DIR=$(CURDIR)/$(OBJ_DIR)/libk $(CURDIR)/$(OBJ_DIR)/libk.a -$(OBJ_DIR)/libd.a: +libd: @make -C drivers OBJ_DIR=$(CURDIR)/$(OBJ_DIR)/drivers $(CURDIR)/$(OBJ_DIR)/libd.a compile_commands: diff --git a/src/kernel.cc b/src/kernel.cc index 578344c..fc02f5b 100644 --- a/src/kernel.cc +++ b/src/kernel.cc @@ -8,9 +8,8 @@ #error "This tutorial needs to be compiled with a ix86-elf compiler" #endif +#include <memory.h> #include <stdlib.h> -#include <types.h> -#include "allocator.h" #include "cga.h" #include "cpu/cpu.h" #include "gdt.h" diff --git a/src/makefile b/src/makefile index 1d85f4b..d1e2147 100644 --- a/src/makefile +++ b/src/makefile @@ -9,7 +9,6 @@ CXX_OBJ = kernel.o \ idt.o \ idt/exception.o idt/interruptgate.o idt/interrupthandler.o \ vmm.o \ - allocator.o \ scheduler.o scheduler/task.o CXX_OBJ := $(addprefix $(OBJ_DIR)/, $(CXX_OBJ)) CXX_DEP = $(CXX_OBJ:%.o=%.d) |