summaryrefslogtreecommitdiffhomepage
path: root/Private/ArchKit/ArchKit.hpp
blob: ae63c2a160ef8cf98b6f4f760dc2b1420e09c967 (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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*
 *	========================================================
 *
 *	HCore
 * 	Copyright Mahrouss Logic, all rights reserved.
 *
 * 	========================================================
 */

#pragma once

#include <NewKit/Array.hpp>
#include <NewKit/Defines.hpp>
#include <NewKit/Function.hpp>

#ifdef __x86_64__
#include <HALKit/AMD64/HalPageAlloc.hpp>
#include <HALKit/AMD64/Hypervisor.hpp>
#include <HALKit/AMD64/Processor.hpp>
#elif defined(__powerpc64__)
#include <HALKit/PowerPC/Processor.hpp>
#else
#error Unknown architecture
#endif

namespace HCore {
template <SSizeT ID>
class SystemCall {
 public:
  explicit SystemCall() { kcout << "SystemCall::SystemCall"; }

  virtual ~SystemCall() { kcout << "SystemCall::~SystemCall"; }

  SystemCall &operator=(const SystemCall &) = default;
  SystemCall(const SystemCall &) = default;

  // Should not be called alone!
  virtual bool Exec() const {
    kcout << "SystemCall->Exec<RET>()";
    return false;
  }
};

constexpr static inline SSizeT syscall_hash(const char *seed, int mul) {
  SSizeT hash = 0;

  for (SSizeT idx = 0; seed[idx] != 0; ++idx) {
    hash += seed[idx];
    hash ^= mul;
  }

  return hash;
}

bool ke_init_hal();
}  // namespace HCore

#define kMaxSyscalls 0x100
#define kSyscallGate 0x21

extern HCore::Array<void (*)(HCore::Int32 id, HCore::HAL::StackFrame *),
                    kMaxSyscalls>
    kSyscalls;

extern "C" HCore::Void rt_wait_for_io();
extern "C" HCore::Void rt_syscall_handle(HCore::HAL::StackFramePtr stackFrame);
extern "C" HCore::HAL::StackFramePtr rt_get_current_context();
extern "C" HCore::Void rt_do_context_switch(
    HCore::HAL::StackFramePtr stackFrame);

inline HCore::VoidPtr kKernelVirtualStart;
inline HCore::UIntPtr kKernelVirtualSize;

inline HCore::VoidPtr kKernelPhysicalStart;
inline HCore::UIntPtr kKernelPhysicalSize;