diff options
| author | Matteo Gmür <matteo.gmuer1@ost.ch> | 2025-03-10 13:42:38 +0000 |
|---|---|---|
| committer | Matteo Gmür <matteo.gmuer1@ost.ch> | 2025-03-10 13:42:38 +0000 |
| commit | c5151739698620e77622423c109e638f903f01c4 (patch) | |
| tree | 2ac179f1720f5915541c91f0531b4eca7c83a1cd /arch/x86_64/src/context_switching | |
| parent | 1a6d41362447531a2ea5ee344c15b9aaa6c2090a (diff) | |
| download | teachos-c5151739698620e77622423c109e638f903f01c4.tar.xz teachos-c5151739698620e77622423c109e638f903f01c4.zip | |
Adjust register segment descriptors to possible states
Diffstat (limited to 'arch/x86_64/src/context_switching')
3 files changed, 43 insertions, 8 deletions
diff --git a/arch/x86_64/src/context_switching/descriptor_table/access_byte.cpp b/arch/x86_64/src/context_switching/descriptor_table/access_byte.cpp index 15a0947..7a2b0b0 100644 --- a/arch/x86_64/src/context_switching/descriptor_table/access_byte.cpp +++ b/arch/x86_64/src/context_switching/descriptor_table/access_byte.cpp @@ -1,14 +1,15 @@ #include "arch/context_switching/descriptor_table/access_byte.hpp" -#include <bitset> - namespace teachos::arch::context_switching::descriptor_table { - auto access_byte::contains_flags(std::bitset<8U> other) const -> bool { return (flags & other) == other; } - - auto access_byte::get_privilege_level() const -> privilege_level + access_byte::access_byte(uint8_t flags) + : _flags(flags) + , _type(flags) { - constexpr uint8_t PRIVILEGE_MASK = 0b0110'0000; - return static_cast<privilege_level>(flags.to_ulong() & PRIVILEGE_MASK); + // Nothing to do. } + + auto access_byte::contains_flags(std::bitset<4U> other) const -> bool { return (_flags & other) == other; } + + auto access_byte::get_type_field() const -> type_field { return _type; } } // namespace teachos::arch::context_switching::descriptor_table diff --git a/arch/x86_64/src/context_switching/descriptor_table/gdt_flags.cpp b/arch/x86_64/src/context_switching/descriptor_table/gdt_flags.cpp index 8a05956..8e1e939 100644 --- a/arch/x86_64/src/context_switching/descriptor_table/gdt_flags.cpp +++ b/arch/x86_64/src/context_switching/descriptor_table/gdt_flags.cpp @@ -1,6 +1,28 @@ #include "arch/context_switching/descriptor_table/gdt_flags.hpp" +#include "arch/exception_handling/assert.hpp" + namespace teachos::arch::context_switching::descriptor_table { - auto gdt_flags::contains_flags(std::bitset<4U> other) const -> bool { return (flags & other) == other; } + gdt_flags::gdt_flags(uint8_t flags, segment_descriptor_type type) + : _flags(flags << 5U) + { + switch (type) + { + case segment_descriptor_type::SYSTEM_SEGMENT: + _flags.set(2, false); + _flags.set(3, false); + break; + case segment_descriptor_type::DATA_SEGMENT: + _flags.set(3, false); + break; + case segment_descriptor_type::CODE_SEGMENT: + exception_handling::assert((contains_flags(LENGTH) && !contains_flags(DEFAULT_LENGTH)) || + !contains_flags(LENGTH), + "[GDT] Flags of code segment descriptor has both "); + break; + } + } + + auto gdt_flags::contains_flags(std::bitset<4U> other) const -> bool { return (_flags & other) == other; } } // namespace teachos::arch::context_switching::descriptor_table diff --git a/arch/x86_64/src/context_switching/descriptor_table/type_field.cpp b/arch/x86_64/src/context_switching/descriptor_table/type_field.cpp new file mode 100644 index 0000000..d967a97 --- /dev/null +++ b/arch/x86_64/src/context_switching/descriptor_table/type_field.cpp @@ -0,0 +1,12 @@ +#include "arch/context_switching/descriptor_table/type_field.hpp" + +namespace teachos::arch::context_switching::descriptor_table +{ + type_field::type_field(uint8_t flags) + : _flags(flags) + { + // Nothing to do. + } + + auto type_field::contains_flags(std::bitset<4U> other) const -> bool { return (_flags & other) == other; } +} // namespace teachos::arch::context_switching::descriptor_table |
