aboutsummaryrefslogtreecommitdiff
path: root/kernel/kapi/cpu.cpp
blob: d632628cb07486a04329953e80509157c7e114a2 (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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include "kapi/cpu.hpp"

#include "kapi/devices.hpp"
#include "kapi/system.hpp"

#include "kernel/devices/cpu.hpp"

#include <kstd/memory>
#include <kstd/print>

#include <cstddef>
#include <cstdint>
#include <utility>

namespace kapi::cpu
{

  namespace
  {
    auto handle_page_fault(kapi::cpu::exception const & context) -> bool
    {
      kstd::println(kstd::print_sink::stderr, "\tFault address: {:#018x}", context.access_address);
      kstd::println(kstd::print_sink::stderr, "\tPresent: {}", context.is_present);
      kstd::println(kstd::print_sink::stderr, "\tWrite: {}", context.is_write_access);
      kstd::println(kstd::print_sink::stderr, "\tUser: {}", context.is_user_mode);

      kapi::system::panic("Halting the system due to an unrecoverable page fault.");
    }
  }  // namespace

  auto dispatch(exception const & context) -> bool
  {
    kstd::println(kstd::print_sink::stderr, "[OS:CPU] {} @ {:#018x}", context.type, context.instruction_pointer);
    switch (context.type)
    {
      case kapi::cpu::exception::type::page_fault:
        return handle_page_fault(context);
      default:
        return false;
    }
  }

  auto core_detected(kapi::devices::bus & bus, std::size_t major, std::size_t minor, std::uint64_t hardware_id,
                     bool is_bsp, kstd::unique_ptr<devices::device> core_interrupt_controller) -> bool
  {
    auto core = kstd::make_unique<kernel::devices::cpu::core>(major, minor, hardware_id, is_bsp);

    core->add_child(std::move(core_interrupt_controller));
    bus.add_child(std::move(core));

    return true;
  }

}  // namespace kapi::cpu