20 #include "pedigree/kernel/processor/Processor.h" 21 #include "PhysicalMemoryManager.h" 22 #include "pedigree/kernel/processor/ProcessorInformation.h" 23 #include "pedigree/kernel/processor/VirtualAddressSpace.h" 24 #include "pedigree/kernel/processor/state.h" 25 #include "pedigree/kernel/processor/x86_common/ProcessorInformation.h" 26 #include "pedigree/kernel/utilities/Vector.h" 29 #include "../x86/VirtualAddressSpace.h" 31 #include "../x64/VirtualAddressSpace.h" 34 #include <machine/mach_pc/LocalApic.h> 35 #include <machine/mach_pc/Pc.h> 53 *
reinterpret_cast<uint64_t *
>(KernelAddressSpace.
m_PhysicalPML4) = 0;
66 size_t nBpNumber, DebugFlags::FaultType &nFaultType,
size_t &nLength,
69 uintptr_t nLinearAddress = 0;
73 asm volatile(
"mov %%db0, %0" :
"=r"(nLinearAddress));
76 asm volatile(
"mov %%db1, %0" :
"=r"(nLinearAddress));
79 asm volatile(
"mov %%db2, %0" :
"=r"(nLinearAddress));
82 asm volatile(
"mov %%db3, %0" :
"=r"(nLinearAddress));
87 asm volatile(
"mov %%db7, %0" :
"=r"(nStatus));
89 bEnabled =
static_cast<bool>(
90 nStatus & (1 << (nBpNumber * 2 + 1)));
91 nFaultType =
static_cast<DebugFlags::FaultType
>(
92 (nStatus >> (nBpNumber * 4 + 16)) & 0x3);
93 switch ((nStatus >> (nBpNumber * 4 + 18)) & 0x3)
109 return nLinearAddress;
113 size_t nBpNumber, uintptr_t nLinearAddress,
114 DebugFlags::FaultType nFaultType,
size_t nLength)
119 asm volatile(
"mov %0, %%db0" ::
"r"(nLinearAddress));
122 asm volatile(
"mov %0, %%db1" ::
"r"(nLinearAddress));
125 asm volatile(
"mov %0, %%db2" ::
"r"(nLinearAddress));
128 asm volatile(
"mov %0, %%db3" ::
"r"(nLinearAddress));
133 asm volatile(
"mov %%db7, %0" :
"=r"(nStatus));
135 size_t lengthField = 0;
152 nStatus |= 1 << (nBpNumber * 2 + 1);
153 nStatus |= (nFaultType & 0x3) << (nBpNumber * 4 + 16);
154 nStatus |= (lengthField & 0x3) << (nBpNumber * 4 + 18);
155 asm volatile(
"mov %0, %%db7" ::
"r"(nStatus));
161 asm volatile(
"mov %%db7, %0" :
"=r"(nStatus));
163 nStatus &= ~(1 << (nBpNumber * 2 + 1));
164 asm volatile(
"mov %0, %%db7" ::
"r"(nStatus));
178 asm volatile(
"pushf\n" 182 return (result != 0);
187 uintptr_t eflags = state.getFlags();
192 state.setFlags(eflags);
198 asm volatile(
"rdmsr" :
"=a"(eax),
"=d"(edx) :
"c"(index));
199 return static_cast<uint64_t
>(eax) | (static_cast<uint64_t>(edx) << 32);
204 uint32_t eax = value, edx = value >> 32;
205 asm volatile(
"wrmsr" ::
"a"(eax),
"d"(edx),
"c"(index));
210 asm volatile(
"invlpg (%0)" ::
"a"(pAddress));
214 uint32_t inEax, uint32_t inEcx, uint32_t &eax, uint32_t &ebx, uint32_t &ecx,
218 :
"=a"(eax),
"=b"(ebx),
"=c"(ecx),
"=d"(edx)
219 :
"a"(inEax),
"c"(inEcx));
222 #if defined(MULTIPROCESSOR) 228 Pc &pc = Pc::instance();
229 uint8_t apicId = pc.getLocalApic().getId();
241 return m_SafeBspProcessorInformation;
243 Pc &pc = Pc::instance();
244 uint8_t apicId = pc.getLocalApic().getId();
250 return m_SafeBspProcessorInformation;
261 asm volatile(
"int $3");
271 asm volatile(
"pause");
278 asm volatile(
"lidt %0; int $3" ::
"m"(zero));
284 __asm__ __volatile__(
"sti; hlt");
static uint64_t readMachineSpecificRegister(uint32_t index)
static X86CommonPhysicalMemoryManager & instance()
static void cpuid(uint32_t inEax, uint32_t inEcx, uint32_t &eax, uint32_t &ebx, uint32_t &ecx, uint32_t &edx)
static bool getInterrupts()
static uintptr_t getDebugBreakpoint(size_t nBpNumber, DebugFlags::FaultType &nFaultType, size_t &nLength, bool &bEnabled)
static void initialisationDone()
static EXPORTED_PUBLIC VirtualAddressSpace & getKernelAddressSpace()
void initialisationDone()
static ProcessorInformation & information()
static void enableDebugBreakpoint(size_t nBpNumber, uintptr_t nLinearAddress, DebugFlags::FaultType nFaultType, size_t nLength)
static void setSingleStep(bool bEnable, InterruptState &state)
static size_t m_Initialised
static void writeMachineSpecificRegister(uint32_t index, uint64_t value)
static void disableDebugBreakpoint(size_t nBpNumber)
static void haltUntilInterrupt()
static void setInterrupts(bool bEnable)
static ProcessorInformation m_ProcessorInformation
static size_t getDebugBreakpointCount()
physical_uintptr_t m_PhysicalPML4
physical_uintptr_t m_PhysicalPageDirectory
static void invalidate(void *pAddress)