The Pedigree Project 0.1
LocalApicMode.h
1/* Copyright (c) 2026, Pedigree Developers. SPDX-License-Identifier: ISC */
2#ifndef PEDIGREE_KERNEL_MACHINE_MACH_PC_LOCALAPICMODE_H
3#define PEDIGREE_KERNEL_MACHINE_MACH_PC_LOCALAPICMODE_H
4#include <stdint.h>
5
7 public:
8 enum class Mode { Disabled, XApic, X2Apic, Invalid };
9 static constexpr uint32_t BaseMsr = 0x1B;
10 static constexpr uint64_t Enabled = 1ULL << 11;
11 static constexpr uint64_t Extended = 1ULL << 10;
12 static constexpr uint32_t X2ApicMsrBase = 0x800;
13 static constexpr uint32_t X2ApicIcrMsr = 0x830;
14
15 static constexpr Mode decode(uint64_t apicBase) {
16 return (apicBase & Enabled) ? ((apicBase & Extended) ? Mode::X2Apic : Mode::XApic)
17 : ((apicBase & Extended) ? Mode::Invalid : Mode::Disabled);
18 }
19
20 static constexpr uint32_t x2ApicMsr(uint32_t registerOffset) {
21 return X2ApicMsrBase + (registerOffset >> 4);
22 }
23
24 static constexpr uint64_t x2ApicIcr(uint32_t legacyHigh, uint32_t low) {
25 return (uint64_t{legacyHigh >> 24} << 32) | low;
26 }
27};
28#endif