summaryrefslogtreecommitdiffhomepage
path: root/dev/kernel/HALKit/AMD64/HalAPICController.cc
blob: 1d1fd46bf9430066963a4c02df64d2594f02f80e (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
/* -------------------------------------------

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

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

#include <modules/ACPI/ACPIFactoryInterface.h>
#include <HALKit/AMD64/Processor.h>

#define cIOAPICRegVal (4)
#define cIOAPICRegReg (0)

namespace Kernel::HAL
{
	APICController::APICController(VoidPtr base)
		: fApic(base)
	{
	}

	/// @brief Read from APIC controller.
	/// @param reg register.
	UInt32 APICController::Read(UInt32 reg) noexcept
	{
		MUST_PASS(this->fApic);

		UInt32 volatile* io_apic = (UInt32 volatile*)this->fApic;
		io_apic[cIOAPICRegReg]	 = (reg & 0xFF);

		return io_apic[cIOAPICRegVal];
	}

	/// @brief Write to APIC controller.
	/// @param reg register.
	/// @param value value.
	Void APICController::Write(UInt32 reg, UInt32 value) noexcept
	{
		MUST_PASS(this->fApic);

		UInt32 volatile* io_apic = (UInt32 volatile*)this->fApic;

		io_apic[cIOAPICRegReg] = (reg & 0xFF);
		io_apic[cIOAPICRegVal] = value;
	}
} // namespace Kernel::HAL