diff options
| -rw-r--r-- | arch/x86_64/include/arch/kernel/interrupt.hpp | 26 | ||||
| -rw-r--r-- | arch/x86_64/include/arch/memory/heap/linked_list_allocator.hpp | 2 | ||||
| -rw-r--r-- | arch/x86_64/include/arch/memory/heap/new_delete_override.hpp | 27 | ||||
| -rw-r--r-- | arch/x86_64/src/kernel/main.cpp | 37 |
4 files changed, 71 insertions, 21 deletions
diff --git a/arch/x86_64/include/arch/kernel/interrupt.hpp b/arch/x86_64/include/arch/kernel/interrupt.hpp new file mode 100644 index 0000000..521318d --- /dev/null +++ b/arch/x86_64/include/arch/kernel/interrupt.hpp @@ -0,0 +1,26 @@ +#ifndef TEACHOS_ARCH_X86_64_KERNEL_INTERRUPT_HPP +#define TEACHOS_ARCH_X86_64_KERNEL_INTERRUPT_HPP + +#include <cstdint> + +namespace teachos::arch::kernel +{ + struct stack_frame + { + std::uint16_t instruction_pointer; + std::uint16_t cs; + std::uint16_t flags; + std::uint16_t sp; + std::uint16_t ss; + }; + + /** + * @brief Handles an interrupt + * + * https://clang.llvm.org/docs/AttributeReference.html#interrupt-x86 + */ + __attribute__((interrupt)) extern "C" auto interrupt_handler(struct stack_frame * frame) -> void; + +} // namespace teachos::arch::kernel + +#endif // TEACHOS_ARCH_X86_64_KERNEL_INTERRUPT_HPP diff --git a/arch/x86_64/include/arch/memory/heap/linked_list_allocator.hpp b/arch/x86_64/include/arch/memory/heap/linked_list_allocator.hpp index 06b21bb..99c9218 100644 --- a/arch/x86_64/include/arch/memory/heap/linked_list_allocator.hpp +++ b/arch/x86_64/include/arch/memory/heap/linked_list_allocator.hpp @@ -127,6 +127,8 @@ namespace teachos::arch::memory::heap shared::mutex mutex; ///< Mutex to ensure only one thread calls allocate or deallocate at once. }; + extern linked_list_allocator kernel_heap; + } // namespace teachos::arch::memory::heap #endif // TEACHOS_ARCH_X86_64_MEMORY_HEAP_LINKED_LIST_ALLOCATOR_HPP diff --git a/arch/x86_64/include/arch/memory/heap/new_delete_override.hpp b/arch/x86_64/include/arch/memory/heap/new_delete_override.hpp new file mode 100644 index 0000000..c51c737 --- /dev/null +++ b/arch/x86_64/include/arch/memory/heap/new_delete_override.hpp @@ -0,0 +1,27 @@ +#ifndef TEACHOS_ARCH_X86_64_MEMORY_NEW_DELETE_OVERRIDE_CONCEPT_HPP +#define TEACHOS_ARCH_X86_64_MEMORY_NEW_DELETE_OVERRIDE_CONCEPT_HPP + +#include "linked_list_allocator.hpp" +#include <cstdint> + +void * operator new(std::size_t size) { teachos::arch::memory::heap::kernel_heap.allocate(size); } + +void operator delete(void * pointer) noexcept { teachos::arch::memory::heap::kernel_heap.deallocate(pointer, 64); } + +void operator delete(void * pointer, std::size_t size) noexcept +{ + teachos::arch::memory::heap::kernel_heap.deallocate(pointer, size); +} + +void * operator new[](std::size_t size) { teachos::arch::memory::heap::kernel_heap.allocate(size); } + +void operator delete[](void * pointer) noexcept +{ + // NOPE +} + +void operator delete[](void * pointer, std::size_t size) noexcept +{ + teachos::arch::memory::heap::kernel_heap.deallocate(pointer, size); +} +#endif // TEACHOS_ARCH_X86_64_KERNEL_NEW_DELETE_OVERRIDE_HPP
\ No newline at end of file diff --git a/arch/x86_64/src/kernel/main.cpp b/arch/x86_64/src/kernel/main.cpp index 681f960..a41132d 100644 --- a/arch/x86_64/src/kernel/main.cpp +++ b/arch/x86_64/src/kernel/main.cpp @@ -22,38 +22,33 @@ namespace teachos::arch::kernel auto heap_test() -> void { - memory::heap::linked_list_allocator heap_allocator{memory::heap::HEAP_START, - memory::heap::HEAP_START + memory::heap::HEAP_SIZE}; - auto test = heap_allocator.allocate(1024); - auto test2 = new (test) memory::multiboot::memory_information{}; - auto test3 = new (static_cast<void *>(static_cast<memory::multiboot::memory_information *>(test) + 1)) - memory::multiboot::memory_information{}; + memory::heap::linked_list_allocator kernel_heap(memory::heap::HEAP_START, + memory::heap::HEAP_START + memory::heap::HEAP_SIZE); + + auto test2 = new memory::multiboot::memory_information{}; auto test4 = *test2; - auto test5 = *test3; test4.kernel_end = 5000; - test5.kernel_end = 3000; auto test6 = test4.kernel_end; - auto test7 = test5.kernel_end; auto test8 = memory::multiboot::read_multiboot2(); - if (test6 && test7 && test8.kernel_end) + if (test6 && test8.kernel_end) { video::vga::text::write("Heap test successful", video::vga::text::common_attributes::green_on_black); } test2->kernel_end = 2000; test2->kernel_start = 1000; test2->multiboot_start = 2000; - heap_allocator.deallocate(test, 1024); + delete test2; - auto test9 = heap_allocator.allocate(1024); - auto test10 = heap_allocator.allocate(1024); - auto test11 = heap_allocator.allocate(1024); - heap_allocator.deallocate(test9, 1024); - auto test12 = heap_allocator.allocate(1024); - auto test13 = heap_allocator.allocate(1024); - heap_allocator.deallocate(test11, 1024); - heap_allocator.deallocate(test10, 1024); - heap_allocator.deallocate(test13, 1024); - heap_allocator.deallocate(test12, 1024); + // auto test9 = heap_allocator.allocate(1024); + // auto test10 = heap_allocator.allocate(1024); + // auto test11 = heap_allocator.allocate(1024); + // heap_allocator.deallocate(test9, 1024); + // auto test12 = heap_allocator.allocate(1024); + // auto test13 = heap_allocator.allocate(1024); + // heap_allocator.deallocate(test11, 1024); + // heap_allocator.deallocate(test10, 1024); + // heap_allocator.deallocate(test13, 1024); + // heap_allocator.deallocate(test12, 1024); } auto main() -> void |
