diff options
| author | Matteo Gmür <matteo.gmuer1@ost.ch> | 2025-03-13 10:00:42 +0000 |
|---|---|---|
| committer | Matteo Gmür <matteo.gmuer1@ost.ch> | 2025-03-13 10:00:42 +0000 |
| commit | 34c36096e55ac678e29c58f7336b419647e805b6 (patch) | |
| tree | ca144deee44d3b8ba25f94a3cb92f5e01f34aeb4 /arch/x86_64 | |
| parent | b8a0024ee71a64ec0e87a1e2d0c0c7280dc954e6 (diff) | |
| download | teachos-34c36096e55ac678e29c58f7336b419647e805b6.tar.xz teachos-34c36096e55ac678e29c58f7336b419647e805b6.zip | |
Fix segment descriptor bit order of private members
Diffstat (limited to 'arch/x86_64')
| -rw-r--r-- | arch/x86_64/include/arch/context_switching/descriptor_table/segment_descriptor.hpp | 13 | ||||
| -rw-r--r-- | arch/x86_64/src/context_switching/descriptor_table/segment_descriptor.cpp | 16 |
2 files changed, 18 insertions, 11 deletions
diff --git a/arch/x86_64/include/arch/context_switching/descriptor_table/segment_descriptor.hpp b/arch/x86_64/include/arch/context_switching/descriptor_table/segment_descriptor.hpp index b5697e3..06e2e8a 100644 --- a/arch/x86_64/include/arch/context_switching/descriptor_table/segment_descriptor.hpp +++ b/arch/x86_64/include/arch/context_switching/descriptor_table/segment_descriptor.hpp @@ -51,11 +51,14 @@ namespace teachos::arch::context_switching::descriptor_table auto get_segment_type() const -> segment_descriptor_type; private: - uint32_t _reserved = {}; - access_byte _access = {}; - gdt_flags _flag = {}; - uint64_t _base = {}; - std::bitset<20U> _limit = {}; + // The order in private variables starts for the first variable being the rightmost bit. + std::bitset<16U> _limit_1 = {}; ///< First part of the limit field (0 - 15) + std::bitset<24U> _base_1 = {}; ///< First part of the base field (16 - 39) + access_byte _access = {}; ///< Access byte field (40 - 47) + std::bitset<4U> _limit_2 = {}; ///< Second part of the limit field (48 - 51) + gdt_flags _flag = {}; ///< Flags field (52 - 55) + std::bitset<40U> _base_2 = {}; ///< Second part of the base field (56 - 95) + uint32_t _reserved = {}; ///< Reserved field used to ensure this struct is 128 bits big (96 - 127) }; } // namespace teachos::arch::context_switching::descriptor_table 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 ab8eaba..a743ad2 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,22 +3,26 @@ namespace teachos::arch::context_switching::descriptor_table { segment_descriptor::segment_descriptor(uint128_t flags) - : _reserved(flags >> 96U) + : _limit_1(flags << 112U) + , _base_1((flags >> 16U) << 88U) , _access((flags >> 44U) << 80U, (flags >> 40U) << 84U) + , _limit_2((flags >> 48U) << 72U) , _flag((flags >> 52U) << 72U) - , _base(((flags >> 64U) << 32U) << 32U | ((flags >> 56U) << 64U) << 24U | (flags >> 16U) << 88U) - , _limit(((flags >> 48U) << 72U) << 16U | flags << 112U) + , _base_2((flags >> 56U) << 32U) + , _reserved(flags >> 96U) { // Nothing to do. } segment_descriptor::segment_descriptor(access_byte access_byte, gdt_flags flags, uint64_t base, std::bitset<20U> limit) - : _reserved(0U) + : _limit_1((limit.to_ulong() << 4U) >> 16U) + , _base_1((base << 40U) >> 40U) , _access(access_byte) + , _limit_2(limit.to_ulong() >> 16U) , _flag(flags) - , _base(base) - , _limit(limit) + , _base_2(base >> 24U) + , _reserved(0U) { // Nothing to do } |
