summaryrefslogtreecommitdiffhomepage
path: root/dev/kernel/HALKit/ARM64/Processor.h
blob: 3a04bed1d6e01d1db800729d1e536f9d07af3b82 (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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/* -------------------------------------------

	Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved.

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

#pragma once

#include <NewKit/Array.h>
#include <NewKit/Defines.h>
#include <NewKit/Utils.h>
#include <FirmwareKit/Handover.h>

#define kCPUBackendName "ARMv8"

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

	/// @brief Memory Manager mapping flags.
	enum
	{
		kMMFlagsPresent = 1 << 0,
		kMMFlagsWr		= 1 << 1,
		kMMFlagsUser	= 1 << 2,
		kMMFlagsNX		= 1 << 3,
		kMMFlagsPCD		= 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);

	EXTERN_C UIntPtr hal_get_phys_address(VoidPtr virtual_address);

	typedef UIntPtr	   Reg;
	typedef Register64 Register;

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

	typedef StackFrame* StackFramePtr;

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

	template <typename DataKind>
	inline void hal_dma_write(UIntPtr address, DataKind value)
	{
		*reinterpret_cast<volatile DataKind*>(address) = value;
	}

	template <typename DataKind>
	inline DataKind hal_dma_read(UIntPtr address)
	{
		return *reinterpret_cast<volatile DataKind*>(address);
	}

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

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

inline Kernel::VoidPtr kKernelPhysicalStart = nullptr;

#include <HALKit/ARM64/Paging.h>