aboutsummaryrefslogtreecommitdiff
path: root/arch/x86_64
diff options
context:
space:
mode:
Diffstat (limited to 'arch/x86_64')
-rw-r--r--arch/x86_64/CMakeLists.txt58
-rw-r--r--arch/x86_64/include/arch/context_switching/interrupt_descriptor_table/gate_descriptor.hpp69
-rw-r--r--arch/x86_64/include/arch/context_switching/interrupt_descriptor_table/idt_flags.hpp81
-rw-r--r--arch/x86_64/include/arch/context_switching/interrupt_descriptor_table/interrupt_descriptor_table.hpp24
-rw-r--r--arch/x86_64/include/arch/context_switching/interrupt_descriptor_table/interrupt_descriptor_table_pointer.hpp40
-rw-r--r--arch/x86_64/include/arch/context_switching/interrupt_descriptor_table/ist_offset.hpp45
-rw-r--r--arch/x86_64/include/arch/context_switching/interrupt_descriptor_table/segment_selector.hpp105
-rw-r--r--arch/x86_64/include/arch/context_switching/main.hpp51
-rw-r--r--arch/x86_64/include/arch/context_switching/segment_descriptor_table/access_byte.hpp104
-rw-r--r--arch/x86_64/include/arch/context_switching/segment_descriptor_table/gdt_flags.hpp93
-rw-r--r--arch/x86_64/include/arch/context_switching/segment_descriptor_table/global_descriptor_table.hpp37
-rw-r--r--arch/x86_64/include/arch/context_switching/segment_descriptor_table/global_descriptor_table_pointer.hpp41
-rw-r--r--arch/x86_64/include/arch/context_switching/segment_descriptor_table/segment_descriptor_base.hpp73
-rw-r--r--arch/x86_64/include/arch/context_switching/segment_descriptor_table/segment_descriptor_extension.hpp74
-rw-r--r--arch/x86_64/include/arch/context_switching/segment_descriptor_table/segment_descriptor_type.hpp27
-rw-r--r--arch/x86_64/include/arch/context_switching/segment_descriptor_table/task_state_segment.hpp32
-rw-r--r--arch/x86_64/include/arch/context_switching/syscall/main.hpp88
-rw-r--r--arch/x86_64/include/arch/context_switching/syscall/syscall_enable.hpp18
-rw-r--r--arch/x86_64/include/arch/context_switching/syscall/syscall_handler.hpp18
-rw-r--r--arch/x86_64/include/arch/interrupt_handling/generic_interrupt_handler.hpp34
-rw-r--r--arch/x86_64/include/arch/kernel/cpu/call.hpp30
-rw-r--r--arch/x86_64/include/arch/kernel/cpu/control_register.hpp (renamed from arch/x86_64/include/arch/memory/cpu/control_register.hpp)10
-rw-r--r--arch/x86_64/include/arch/kernel/cpu/gdtr.hpp27
-rw-r--r--arch/x86_64/include/arch/kernel/cpu/idtr.hpp27
-rw-r--r--arch/x86_64/include/arch/kernel/cpu/if.hpp21
-rw-r--r--arch/x86_64/include/arch/kernel/cpu/msr.hpp (renamed from arch/x86_64/include/arch/memory/cpu/msr.hpp)10
-rw-r--r--arch/x86_64/include/arch/kernel/cpu/segment_register.hpp97
-rw-r--r--arch/x86_64/include/arch/kernel/cpu/tlb.hpp (renamed from arch/x86_64/include/arch/memory/cpu/tlb.hpp)12
-rw-r--r--arch/x86_64/include/arch/kernel/cpu/tr.hpp24
-rw-r--r--arch/x86_64/include/arch/memory/allocator/area_frame_allocator.hpp6
-rw-r--r--arch/x86_64/include/arch/memory/allocator/physical_frame.hpp8
-rw-r--r--arch/x86_64/include/arch/memory/heap/global_heap_allocator.hpp50
-rw-r--r--arch/x86_64/include/arch/memory/heap/heap_allocator.hpp6
-rw-r--r--arch/x86_64/include/arch/memory/heap/linked_list_allocator.hpp11
-rw-r--r--arch/x86_64/include/arch/memory/heap/memory_block.hpp2
-rw-r--r--arch/x86_64/include/arch/memory/heap/user_heap_allocator.hpp148
-rw-r--r--arch/x86_64/include/arch/memory/main.hpp14
-rw-r--r--arch/x86_64/include/arch/memory/multiboot/elf_symbols_section.hpp8
-rw-r--r--arch/x86_64/include/arch/memory/multiboot/memory_map.hpp6
-rw-r--r--arch/x86_64/include/arch/memory/paging/active_page_table.hpp10
-rw-r--r--arch/x86_64/include/arch/memory/paging/kernel_mapper.hpp45
-rw-r--r--arch/x86_64/include/arch/memory/paging/page_entry.hpp8
-rw-r--r--arch/x86_64/include/arch/memory/paging/page_table.hpp11
-rw-r--r--arch/x86_64/include/arch/memory/paging/virtual_page.hpp4
-rw-r--r--arch/x86_64/include/arch/stl/container.hpp (renamed from arch/x86_64/include/arch/shared/container.hpp)34
-rw-r--r--arch/x86_64/include/arch/stl/contiguous_pointer_iterator.hpp (renamed from arch/x86_64/include/arch/shared/contiguous_pointer_iterator.hpp)44
-rw-r--r--arch/x86_64/include/arch/stl/forward_value_iterator.hpp (renamed from arch/x86_64/include/arch/shared/forward_value_iterator.hpp)25
-rw-r--r--arch/x86_64/include/arch/stl/mutex.hpp (renamed from arch/x86_64/include/arch/shared/mutex.hpp)13
-rw-r--r--arch/x86_64/include/arch/stl/shared_pointer.hpp191
-rw-r--r--arch/x86_64/include/arch/stl/stack.hpp212
-rw-r--r--arch/x86_64/include/arch/stl/unique_pointer.hpp158
-rw-r--r--arch/x86_64/include/arch/stl/vector.hpp604
-rw-r--r--arch/x86_64/include/arch/user/main.hpp16
-rw-r--r--arch/x86_64/scripts/kernel.ld18
-rw-r--r--arch/x86_64/src/boot/boot.s4
-rw-r--r--arch/x86_64/src/context_switching/interrupt_descriptor_table/gate_descriptor.cpp24
-rw-r--r--arch/x86_64/src/context_switching/interrupt_descriptor_table/idt_flags.cpp17
-rw-r--r--arch/x86_64/src/context_switching/interrupt_descriptor_table/interrupt_descriptor_table.cpp53
-rw-r--r--arch/x86_64/src/context_switching/interrupt_descriptor_table/interrupt_descriptor_table_pointer.cpp13
-rw-r--r--arch/x86_64/src/context_switching/interrupt_descriptor_table/ist_offset.cpp10
-rw-r--r--arch/x86_64/src/context_switching/interrupt_descriptor_table/segment_selector.cpp15
-rw-r--r--arch/x86_64/src/context_switching/main.cpp63
-rw-r--r--arch/x86_64/src/context_switching/segment_descriptor_table/access_byte.cpp17
-rw-r--r--arch/x86_64/src/context_switching/segment_descriptor_table/gdt_flags.cpp20
-rw-r--r--arch/x86_64/src/context_switching/segment_descriptor_table/global_descriptor_table.cpp109
-rw-r--r--arch/x86_64/src/context_switching/segment_descriptor_table/global_descriptor_table_pointer.cpp11
-rw-r--r--arch/x86_64/src/context_switching/segment_descriptor_table/segment_descriptor_base.cpp38
-rw-r--r--arch/x86_64/src/context_switching/segment_descriptor_table/segment_descriptor_extension.cpp24
-rw-r--r--arch/x86_64/src/context_switching/syscall/main.cpp35
-rw-r--r--arch/x86_64/src/context_switching/syscall/syscall_enable.cpp32
-rw-r--r--arch/x86_64/src/context_switching/syscall/syscall_handler.cpp118
-rw-r--r--arch/x86_64/src/interrupt_handling/generic_interrupt_handler.cpp13
-rw-r--r--arch/x86_64/src/kernel/cpu/call.cpp9
-rw-r--r--arch/x86_64/src/kernel/cpu/control_register.cpp (renamed from arch/x86_64/src/memory/cpu/control_register.cpp)12
-rw-r--r--arch/x86_64/src/kernel/cpu/gdtr.cpp19
-rw-r--r--arch/x86_64/src/kernel/cpu/idtr.cpp18
-rw-r--r--arch/x86_64/src/kernel/cpu/if.cpp7
-rw-r--r--arch/x86_64/src/kernel/cpu/msr.cpp (renamed from arch/x86_64/src/memory/cpu/msr.cpp)8
-rw-r--r--arch/x86_64/src/kernel/cpu/segment_register.cpp98
-rw-r--r--arch/x86_64/src/kernel/cpu/tlb.cpp (renamed from arch/x86_64/src/memory/cpu/tlb.cpp)10
-rw-r--r--arch/x86_64/src/kernel/cpu/tr.cpp16
-rw-r--r--arch/x86_64/src/kernel/main.cpp12
-rw-r--r--arch/x86_64/src/memory/allocator/area_frame_allocator.cpp2
-rw-r--r--arch/x86_64/src/memory/heap/bump_allocator.cpp4
-rw-r--r--arch/x86_64/src/memory/heap/global_heap_allocator.cpp95
-rw-r--r--arch/x86_64/src/memory/heap/linked_list_allocator.cpp6
-rw-r--r--arch/x86_64/src/memory/heap/memory_block.cpp4
-rw-r--r--arch/x86_64/src/memory/heap/user_heap_allocator.cpp200
-rw-r--r--arch/x86_64/src/memory/main.cpp64
-rw-r--r--arch/x86_64/src/memory/paging/page_entry.cpp5
-rw-r--r--arch/x86_64/src/memory/paging/temporary_page.cpp8
-rw-r--r--arch/x86_64/src/stl/mutex.cpp (renamed from arch/x86_64/src/shared/mutex.cpp)6
-rw-r--r--arch/x86_64/src/user/main.cpp35
93 files changed, 3965 insertions, 311 deletions
diff --git a/arch/x86_64/CMakeLists.txt b/arch/x86_64/CMakeLists.txt
index e9f8d5f..57b3a60 100644
--- a/arch/x86_64/CMakeLists.txt
+++ b/arch/x86_64/CMakeLists.txt
@@ -7,6 +7,15 @@ mark_as_advanced(TEACHOS_KERNEL_LINKER_SCRIPT)
target_sources("_kernel" PRIVATE
"src/kernel/main.cpp"
+ "src/kernel/cpu/control_register.cpp"
+ "src/kernel/cpu/gdtr.cpp"
+ "src/kernel/cpu/idtr.cpp"
+ "src/kernel/cpu/if.cpp"
+ "src/kernel/cpu/call.cpp"
+ "src/kernel/cpu/msr.cpp"
+ "src/kernel/cpu/segment_register.cpp"
+ "src/kernel/cpu/tlb.cpp"
+ "src/kernel/cpu/tr.cpp"
)
target_link_options("_kernel" PRIVATE
@@ -53,21 +62,19 @@ target_sources("_memory" PRIVATE
"src/memory/paging/virtual_page.cpp"
"src/memory/paging/active_page_table.cpp"
"src/memory/paging/inactive_page_table.cpp"
- "src/memory/cpu/tlb.cpp"
- "src/memory/cpu/control_register.cpp"
- "src/memory/cpu/msr.cpp"
"src/memory/heap/bump_allocator.cpp"
+ "src/memory/heap/user_heap_allocator.cpp"
"src/memory/heap/memory_block.cpp"
"src/memory/heap/linked_list_allocator.cpp"
"src/memory/heap/global_heap_allocator.cpp"
)
#[============================================================================[
-# The Shared Library
+# The STL Library
#]============================================================================]
-target_sources("_shared" PRIVATE
- "src/shared/mutex.cpp"
+target_sources("_stl" PRIVATE
+ "src/stl/mutex.cpp"
)
#[============================================================================[
@@ -82,6 +89,45 @@ target_sources("_exception" PRIVATE
)
#[============================================================================[
+# The Context switching Library
+#]============================================================================]
+
+target_sources("_context" PRIVATE
+ "src/context_switching/segment_descriptor_table/access_byte.cpp"
+ "src/context_switching/segment_descriptor_table/gdt_flags.cpp"
+ "src/context_switching/segment_descriptor_table/global_descriptor_table_pointer.cpp"
+ "src/context_switching/segment_descriptor_table/global_descriptor_table.cpp"
+ "src/context_switching/segment_descriptor_table/segment_descriptor_base.cpp"
+ "src/context_switching/segment_descriptor_table/segment_descriptor_extension.cpp"
+ "src/context_switching/main.cpp"
+ "src/context_switching/syscall/main.cpp"
+ "src/context_switching/syscall/syscall_enable.cpp"
+ "src/context_switching/syscall/syscall_handler.cpp"
+ "src/context_switching/interrupt_descriptor_table/gate_descriptor.cpp"
+ "src/context_switching/interrupt_descriptor_table/idt_flags.cpp"
+ "src/context_switching/interrupt_descriptor_table/interrupt_descriptor_table_pointer.cpp"
+ "src/context_switching/interrupt_descriptor_table/interrupt_descriptor_table.cpp"
+ "src/context_switching/interrupt_descriptor_table/ist_offset.cpp"
+ "src/context_switching/interrupt_descriptor_table/segment_selector.cpp"
+)
+
+#[============================================================================[
+# The Interrupt Handlers
+#]============================================================================]
+
+target_sources("_interrupt_handling" PRIVATE
+ "src/interrupt_handling/generic_interrupt_handler.cpp"
+)
+
+#[============================================================================[
+# The User code
+#]============================================================================]
+
+target_sources("_context" PRIVATE
+ "src/user/main.cpp"
+)
+
+#[============================================================================[
# The Bootable ISO Image
#]============================================================================]
diff --git a/arch/x86_64/include/arch/context_switching/interrupt_descriptor_table/gate_descriptor.hpp b/arch/x86_64/include/arch/context_switching/interrupt_descriptor_table/gate_descriptor.hpp
new file mode 100644
index 0000000..07110c8
--- /dev/null
+++ b/arch/x86_64/include/arch/context_switching/interrupt_descriptor_table/gate_descriptor.hpp
@@ -0,0 +1,69 @@
+#ifndef TEACHOS_ARCH_X86_64_CONTEXT_SWITCHING_INTERRUPT_DESCRIPTOR_TABLE_GATE_DESCRIPTOR_HPP
+#define TEACHOS_ARCH_X86_64_CONTEXT_SWITCHING_INTERRUPT_DESCRIPTOR_TABLE_GATE_DESCRIPTOR_HPP
+
+#include "arch/context_switching/interrupt_descriptor_table/idt_flags.hpp"
+#include "arch/context_switching/interrupt_descriptor_table/ist_offset.hpp"
+#include "arch/context_switching/interrupt_descriptor_table/segment_selector.hpp"
+
+#include <bitset>
+#include <cstdint>
+
+namespace teachos::arch::context_switching::interrupt_descriptor_table
+{
+ __extension__ typedef __int128 int128_t;
+ __extension__ typedef unsigned __int128 uint128_t;
+
+ /**
+ * @brief Defines helper function for all states and the actual data the gate descriptor can have.
+ */
+ struct [[gnu::packed]] gate_descriptor
+ {
+ /**
+ * @brief Default Constructor.
+ */
+ gate_descriptor() = default;
+
+ /**
+ * @brief Constructor.
+ *
+ * @note Created gate descriptor copies the given bytes into these components ending with a 32 bit reserved
+ * field that has to be used, because the 64-bit gate descriptor needs to be big enough for two 32-bit gate
+ * descriptor.
+ * - 16 bit Segment Selector
+ * - 3 bit Interrupt Stack Table Offset
+ * - 8 bit Type and Flags
+ * - 64 bit Offset
+ *
+ * @param flags Copies the bits set from the given data into the individual components of a gate
+ * descriptor.
+ */
+ explicit gate_descriptor(uint128_t flags);
+
+ /**
+ * @brief Constructor.
+ *
+ * @param selector, ist, flags, offset Copies the bits set from the given data into the individual components of
+ * a gate descriptor.
+ */
+ gate_descriptor(segment_selector selector, ist_offset ist, idt_flags flags, uint64_t offset);
+
+ /**
+ * @brief Allows to compare the underlying bits of two instances.
+ *
+ * @param other Other instance that we want to compare with.
+ * @return Whether the underlying set bits of both types are the same.
+ */
+ auto operator==(gate_descriptor const & other) const -> bool = default;
+
+ private:
+ // The order in private variables starts for the first variable being the rightmost bit.
+ uint16_t _offset_1 = {}; ///< Lower 16 bits of handler function address (0 - 15)
+ segment_selector _selector = {}; ///< Segment selector (16 - 31)
+ ist_offset _ist = {}; ///< Interrupt Stack Table offset (32 - 39)
+ idt_flags _flags = {}; ///< Gate Type and Flags (40 - 47)
+ uint64_t _offset_2 : 48 = {}; ///< Upper 48 bits of handler function address (48 - 95)
+ uint32_t : 32; ///< Reserved field used to ensure this struct is 128 bits big (96 - 127)
+ };
+} // namespace teachos::arch::context_switching::interrupt_descriptor_table
+
+#endif // TEACHOS_ARCH_X86_64_CONTEXT_SWITCHING_INTERRUPT_DESCRIPTOR_TABLE_GATE_DESCRIPTOR_HPP
diff --git a/arch/x86_64/include/arch/context_switching/interrupt_descriptor_table/idt_flags.hpp b/arch/x86_64/include/arch/context_switching/interrupt_descriptor_table/idt_flags.hpp
new file mode 100644
index 0000000..5104c36
--- /dev/null
+++ b/arch/x86_64/include/arch/context_switching/interrupt_descriptor_table/idt_flags.hpp
@@ -0,0 +1,81 @@
+
+#ifndef TEACHOS_ARCH_X86_64_CONTEXT_SWITCHING_INTERRUPT_DESCRIPTOR_TABLE_IDT_FLAGS_HPP
+#define TEACHOS_ARCH_X86_64_CONTEXT_SWITCHING_INTERRUPT_DESCRIPTOR_TABLE_IDT_FLAGS_HPP
+
+#include <bitset>
+#include <cstdint>
+
+namespace teachos::arch::context_switching::interrupt_descriptor_table
+{
+ /**
+ * @brief Defines helper function for all states that the access byte field of a segment descriptor can
+ * have.
+ */
+ struct [[gnu::packed]] idt_flags
+ {
+ /**
+ * @brief Possible set bits in our underlying bits and the meaning when they are set.
+ */
+ enum bitset : uint8_t
+ {
+ INTERRUPT_GATE = 0b01110, ///< The actual type of gate segment is a interrupt gate.
+ TRAP_GATE = 0b01111, ///< The actual type of gate segment is a trap gate.
+ DESCRIPTOR_LEVEL_KERNEL =
+ 0U << 5U, ///< Highest privileged level used by the kernel to allow for full access of resources.
+ DESCRIPTOR_LEVEL_ADMIN =
+ 1U << 5U, ///< Restricts access to own application and thoose of lower privilege. Should only be used if more
+ ///< than two privilege levels are required, otherwise using Level 3 and Level 0 is recommended.
+ DESCRIPTOR_LEVEL_PRIVILEGED_USER =
+ 2U << 5U, ///< Restricts access to own application and thoose of lower privilege. Should only be used if more
+ ///< than two privilege levels are required, otherwise using Level 3 and Level 0 is recommended.
+ DESCRIPTOR_LEVEL_USER = 3U << 5U, ///< Restricts