summaryrefslogtreecommitdiffhomepage
path: root/src/kernel/HALKit/ARM64/Processor.h
blob: 6fa633037c73df8a8df407b97997aa303d023eae (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
77
78
79
80
// SPDX-License-Identifier: Apache-2.0
// Copyright 2024-2026, Amlal El Mahrouss (amlal@nekernel.org)
// Licensed under the Apache License, Version 2.0 (see LICENSE file)
// Official repository: https://github.com/ne-foss-org/nekernel

#ifndef HALKIT_PROCESSOR_H
#define HALKIT_PROCESSOR_H

#ifdef __NE_ARM64__

#include <FirmwareKit/Handover.h>
#include <NeKit/Array.h>
#include <NeKit/Config.h>
#include <NeKit/Utils.h>

#define kCPUBackendName "aarch64"

namespace Kernel::HAL {
struct PACKED Register64 final {
  UShort  Limit;
  UIntPtr Base;
};

/// @brief Memory Manager mapping flags.
enum {
  kMMFlagsInvalid = 1 << 0,
  kMMFlagsPresent = 1 << 1,
  kMMFlagsWr      = 1 << 2,
  kMMFlagsUser    = 1 << 3,
  kMMFlagsNX      = 1 << 4,
  kMMFlagsCount   = 4,
};

/// @brief Set a PTE from pd_base.
/// @param virt_addr a valid virtual address.
/// @param phys_addr point to physical address.
/// @param flags the flags to put on the page.
/// @return Status code of page manip.
EXTERN_C Int32 mm_map_page(VoidPtr virtual_address, VoidPtr physical_address, UInt32 flags,
                           UInt32 level = 2);

EXTERN_C UIntPtr mm_get_page_addr(VoidPtr virtual_address);

typedef UIntPtr    Reg;
typedef Register64 Register;

/// @note let's keep the same name as AMD64 HAL.
struct PACKED StackFrame {
  Reg IP;
  Reg SP;
  Reg R8;
  Reg R9;
  Reg R10;
  Reg R11;
  Reg R12;
  Reg R13;
  Reg R14;
  Reg R15;
};

typedef StackFrame* StackFramePtr;

inline Void rt_halt() {
  while (Yes) {
  }
}

inline Void hal_wfi(Void) {
  asm volatile("wfi");
}
}  // namespace Kernel::HAL

inline Kernel::VoidPtr kKernelBitMpStart = nullptr;
inline Kernel::UIntPtr kKernelBitMpSize  = 0UL;

#include <HALKit/ARM64/Paging.h>

#endif  // __NE_ARM64__

#endif