aboutsummaryrefslogtreecommitdiff
path: root/arch/x86_64/include
diff options
context:
space:
mode:
authorFabian Imhof <fabian.imhof@ost.ch>2025-02-20 09:38:28 +0000
committerFabian Imhof <fabian.imhof@ost.ch>2025-02-20 09:38:28 +0000
commit9438c9203b7be20147b990ff05e1d99190d18928 (patch)
treea0fbd2948ed3f94c2f1c9ff5e58381888c9b7818 /arch/x86_64/include
parentcd42c21f2460751428b3e1b4ae07ea0b924967bc (diff)
downloadteachos-9438c9203b7be20147b990ff05e1d99190d18928.tar.xz
teachos-9438c9203b7be20147b990ff05e1d99190d18928.zip
added new and delete override
Diffstat (limited to 'arch/x86_64/include')
-rw-r--r--arch/x86_64/include/arch/kernel/interrupt.hpp26
-rw-r--r--arch/x86_64/include/arch/memory/heap/linked_list_allocator.hpp2
-rw-r--r--arch/x86_64/include/arch/memory/heap/new_delete_override.hpp27
3 files changed, 55 insertions, 0 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