summaryrefslogtreecommitdiffhomepage
path: root/Private/ArchKit/ArchKit.hpp
blob: 17b70aa7e31227b84a171099f87416198ab1e10a (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
76
/* -------------------------------------------

    Copyright Mahrouss Logic

------------------------------------------- */

#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 kKernelMaxSystemCalls (256)

typedef HCore::Void (*rt_syscall_proc)(HCore::HAL::StackFramePtr);

extern HCore::Array<rt_syscall_proc,
                    kKernelMaxSystemCalls>
    kSyscalls;

EXTERN_C HCore::Void rt_wait_400ns();
EXTERN_C HCore::Void ATTRIBUTE(interrupt) 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;

#include <FirmwareKit/Handover.hxx>

inline HCore::HEL::HandoverInformationHeader* kHandoverHeader;