The Pedigree Project 0.1
LocalApicLint0Policy.h
1/*
2 * Copyright (c) 2026, Pedigree Developers
3 *
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted.
6 */
7
8#ifndef PEDIGREE_KERNEL_MACHINE_MACH_PC_LOCALAPICLINT0POLICY_H
9#define PEDIGREE_KERNEL_MACHINE_MACH_PC_LOCALAPICLINT0POLICY_H
10#include "pedigree/kernel/processor/types.h"
11
12#include <config.h>
13
16 public:
17 static constexpr uint32_t ApicBaseMsr = 0x1B;
18 static constexpr uint64_t BootstrapProcessor = 1ULL << 8;
19 static constexpr uint32_t ProgrammableFields = 0x0001A7FF;
20 static constexpr uint32_t ExtInt = 7U << 8;
21 static constexpr uint32_t Masked = 1U << 16;
22 static constexpr uint32_t BootstrapValue = ExtInt;
23 static constexpr uint32_t ApplicationProcessorValue = Masked | 0xFF;
24
25 static bool isBootstrapProcessor(uint64_t apicBase) {
26 return (apicBase & BootstrapProcessor) != 0;
27 }
28
29 static uint32_t configuredValue(uint32_t current, uint64_t apicBase) {
30 const uint32_t desired =
31 isBootstrapProcessor(apicBase) ? BootstrapValue : ApplicationProcessorValue;
32 return (current & ~ProgrammableFields) | desired;
33 }
34
35 static bool routesLegacyPic(uint32_t value) {
36 return (value & (Masked | 0x700)) == ExtInt;
37 }
38
39 static bool matchesRole(uint32_t value, uint64_t apicBase) {
40 const uint32_t expected =
41 isBootstrapProcessor(apicBase) ? BootstrapValue : ApplicationProcessorValue;
42 return (value & ProgrammableFields) == expected;
43 }
44};
45
46#endif