aboutsummaryrefslogtreecommitdiff
path: root/arch/x86_64/src/context_switching/main.cpp
blob: 124df93585fc190248bdc91d36a136de7e8ac9e2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include "arch/context_switching/main.hpp"

#include "arch/exception_handling/assert.hpp"
#include "arch/kernel/cpu/if.hpp"
#include "arch/kernel/cpu/jmp.hpp"
#include "arch/kernel/cpu/segment_register.hpp"
#include "arch/kernel/cpu/tr.hpp"

namespace teachos::arch::context_switching
{
  auto initialize_descriptor_tables() -> descriptor_tables
  {
    kernel::cpu::clear_interrupt_flag();

    segment_descriptor_table::update_global_descriptor_table_register();
    interrupt_descriptor_table::update_interrupt_descriptor_table_register();

    interrupt_descriptor_table::segment_selector segment_selector{
        1U, interrupt_descriptor_table::segment_selector::REQUEST_LEVEL_KERNEL};
    kernel::cpu::far_pointer pointer{&kernel::cpu::reload_segment_registers, segment_selector};
    kernel::cpu::jmp(pointer);

    segment_descriptor_table::update_task_state_segment_register();

    kernel::cpu::set_interrupt_flag();

    descriptor_tables tables = {segment_descriptor_table::get_or_create_global_descriptor_table(),
                                interrupt_descriptor_table::get_or_create_interrupt_descriptor_table()};
    return tables;
  }
}  // namespace teachos::arch::context_switching