diff options
| author | Matteo Gmür <matteo.gmuer1@ost.ch> | 2025-04-04 15:05:59 +0000 |
|---|---|---|
| committer | Matteo Gmür <matteo.gmuer1@ost.ch> | 2025-04-04 15:06:01 +0000 |
| commit | 8b66e4cd1d1487fefbae459f556396db61497a6b (patch) | |
| tree | 5c16241f3bce1671798809f2da9dc2e6f44dd6ee | |
| parent | f19681f4dfaaa0bdd3f22e76c48abda3c68bfe0c (diff) | |
| download | teachos-8b66e4cd1d1487fefbae459f556396db61497a6b.tar.xz teachos-8b66e4cd1d1487fefbae459f556396db61497a6b.zip | |
Multiplication by two for segment selector index
3 files changed, 8 insertions, 4 deletions
diff --git a/arch/x86_64/include/arch/context_switching/interrupt_descriptor_table/segment_selector.hpp b/arch/x86_64/include/arch/context_switching/interrupt_descriptor_table/segment_selector.hpp index 2c90152..b31f9e8 100644 --- a/arch/x86_64/include/arch/context_switching/interrupt_descriptor_table/segment_selector.hpp +++ b/arch/x86_64/include/arch/context_switching/interrupt_descriptor_table/segment_selector.hpp @@ -43,8 +43,12 @@ namespace teachos::arch::context_switching::interrupt_descriptor_table /** * @brief Constructor. * - * @param index Index into the local or global descriptor table. Processor multiplies the index value by 16 (number - * of bytes in segment descriptor) and adds the result to the base address. + * @param index Index into the local or global descriptor table. Processor multiplies the index value by 8 (number + * of bytes in 32-bit segment descriptor) and adds the result to the base GDT or LDT address. Because it only + * multiplies by 8, but we are using long mode the constructor additionally multiplies the given value by two. This + * is done because 64-bit segment descriptor are twice as big in size. If we wouldn't multiply by two, index 1 would + * result in the middle between the second part of the null entry and the first part of the code kernel segment and + * therefore be invalid. * @param flags Allows to set flags for the flags field using the unscoped enum contained in this class, used to * allow for direct integer conversion. */ diff --git a/arch/x86_64/src/context_switching/interrupt_descriptor_table/segment_selector.cpp b/arch/x86_64/src/context_switching/interrupt_descriptor_table/segment_selector.cpp index 62aed9b..b1b316d 100644 --- a/arch/x86_64/src/context_switching/interrupt_descriptor_table/segment_selector.cpp +++ b/arch/x86_64/src/context_switching/interrupt_descriptor_table/segment_selector.cpp @@ -4,7 +4,7 @@ namespace teachos::arch::context_switching::interrupt_descriptor_table { segment_selector::segment_selector(uint16_t index, uint8_t flags) : _flags(flags) - , _index(index) + , _index(index * 2U) { // Nothing to do. } diff --git a/arch/x86_64/src/context_switching/main.cpp b/arch/x86_64/src/context_switching/main.cpp index ac53735..6614065 100644 --- a/arch/x86_64/src/context_switching/main.cpp +++ b/arch/x86_64/src/context_switching/main.cpp @@ -16,7 +16,7 @@ namespace teachos::arch::context_switching interrupt_descriptor_table::update_interrupt_descriptor_table_register(); interrupt_descriptor_table::segment_selector segment_selector{ - 2U, interrupt_descriptor_table::segment_selector::REQUEST_LEVEL_KERNEL}; + 1U, interrupt_descriptor_table::segment_selector::REQUEST_LEVEL_KERNEL}; kernel::cpu::far_pointer pointer{&boot::reload_segment_register, segment_selector}; kernel::cpu::jmp(pointer); |
