aboutsummaryrefslogtreecommitdiff
path: root/arch/x86_64/src
diff options
context:
space:
mode:
authorMatteo Gmür <matteo.gmuer1@ost.ch>2025-03-10 16:35:01 +0000
committerMatteo Gmür <matteo.gmuer1@ost.ch>2025-03-10 16:35:01 +0000
commit569cf73d1fa14ec11afbb37464d2c356d55d64b4 (patch)
tree655f1c9ecaf5f78bed08c527e63616ba21bc0e72 /arch/x86_64/src
parent52fffdf2c76def4a875e0328eb45d74c6e97e805 (diff)
downloadteachos-569cf73d1fa14ec11afbb37464d2c356d55d64b4.tar.xz
teachos-569cf73d1fa14ec11afbb37464d2c356d55d64b4.zip
Implement segment descriptor
Diffstat (limited to 'arch/x86_64/src')
-rw-r--r--arch/x86_64/src/context_switching/descriptor_table/gdt_flags.cpp18
-rw-r--r--arch/x86_64/src/context_switching/descriptor_table/segment_descriptor.cpp21
2 files changed, 18 insertions, 21 deletions
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 8e1e939..8fbf869 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
@@ -4,24 +4,10 @@
namespace teachos::arch::context_switching::descriptor_table
{
- gdt_flags::gdt_flags(uint8_t flags, segment_descriptor_type type)
+ gdt_flags::gdt_flags(uint8_t flags)
: _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;
- }
+ // Nothing to do.
}
auto gdt_flags::contains_flags(std::bitset<4U> other) const -> bool { return (_flags & other) == other; }
diff --git a/arch/x86_64/src/context_switching/descriptor_table/segment_descriptor.cpp b/arch/x86_64/src/context_switching/descriptor_table/segment_descriptor.cpp
index fb9c034..57564f2 100644
--- a/arch/x86_64/src/context_switching/descriptor_table/segment_descriptor.cpp
+++ b/arch/x86_64/src/context_switching/descriptor_table/segment_descriptor.cpp
@@ -3,11 +3,22 @@
namespace teachos::arch::context_switching::descriptor_table
{
segment_descriptor::segment_descriptor(uint128_t flags)
- : _reserved(flags)
- , _access(flags)
- , _flag(flags, segment_descriptor_type::SYSTEM_SEGMENT)
- , _base(flags)
- , _limit(flags)
+ : _reserved(flags >> 96U)
+ , _access((flags >> 40U) << 80U)
+ , _flag((flags >> 52U) << 72U)
+ , _base(((flags >> 64U) << 32U) << 32U | ((flags >> 56U) << 64U) << 24U | (flags >> 16U) << 88U)
+ , _limit(((flags >> 48U) << 72U) << 16U | flags << 112U)
{
+ // Nothing to do.
+ }
+
+ auto segment_descriptor::get_segment_type() const -> segment_descriptor_type
+ {
+ if (!_access.contains_flags(access_byte::CODE_OR_DATA_SEGMENT))
+ {
+ return segment_descriptor_type::SYSTEM_SEGMENT;
+ }
+ return _access.get_type_field().contains_flags(type_field::CODE_SEGMENT) ? segment_descriptor_type::CODE_SEGMENT
+ : segment_descriptor_type::DATA_SEGMENT;
}
} // namespace teachos::arch::context_switching::descriptor_table