aboutsummaryrefslogtreecommitdiff
path: root/kernel/src/test_support/kapi/cpu.cpp
blob: 96dd10a4a40b40589a18c727b3b145b74f4ba960 (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
#include "kernel/test_support/cpu.hpp"

#include <kapi/cpu.hpp>

#include <atomic>
#include <stdexcept>

namespace
{
  auto static initialized = std::atomic_flag{};
}

namespace kapi::cpu
{

  auto init() -> void
  {
    if (initialized.test_and_set())
    {
      throw std::logic_error("kapi::cpu::init() called more than once");
    }

    // TODO: make sure that simulated interrupt can run.
  }

  auto halt() -> void
  {
    throw kernel::tests::cpu::halt{};
  }

}  // namespace kapi::cpu

namespace kernel::tests::cpu
{

  auto deinit() -> void
  {
    if (!initialized.test())
    {
      throw std::logic_error{"kapi::cpu::reset() called before kapi::cpu::init()"};
    }

    initialized.clear();
  }

}  // namespace kernel::tests::cpu