Optimize CPU functions

This commit is contained in:
Alex 2022-10-17 18:09:21 +03:00
parent efaaab590f
commit d5447c288e
Signed by untrusted user who does not match committer: enderice2
GPG Key ID: EACC3AD603BAB4DD
2 changed files with 41 additions and 42 deletions

View File

@ -96,38 +96,6 @@ namespace CPU
return Hypervisor; return Hypervisor;
} }
void Pause()
{
#if defined(__amd64__) || defined(__i386__)
asmv("pause");
#elif defined(__aarch64__)
asmv("yield");
#endif
}
void Stop()
{
while (1)
{
#if defined(__amd64__) || defined(__i386__)
asmv("cli");
asmv("hlt");
#elif defined(__aarch64__)
asmv("msr daifset, #2");
asmv("wfe");
#endif
}
}
void Halt()
{
#if defined(__amd64__) || defined(__i386__)
asmv("hlt");
#elif defined(__aarch64__)
asmv("wfe");
#endif
}
bool Interrupts(InterruptsType Type) bool Interrupts(InterruptsType Type)
{ {
switch (Type) switch (Type)

View File

@ -136,17 +136,48 @@ namespace CPU
/** /**
* @brief Pause the CPU * @brief Pause the CPU
*/ */
void Pause(); static inline void Pause()
{
#if defined(__amd64__) || defined(__i386__)
asmv("pause");
#elif defined(__aarch64__)
asmv("yield");
#endif
}
/** /**
* @brief Stop the CPU (infinite loop) * @brief Stop the CPU (infinite loop)
*/ */
void Stop(); static inline void Stop()
{
while (1)
{
#if defined(__amd64__) || defined(__i386__)
asmv("CPUStopLoop:\n"
"cli\n"
"hlt\n"
"jmp CPUStopLoop");
#elif defined(__aarch64__)
while (1)
{
asmv("msr daifset, #2");
asmv("wfe");
}
#endif
}
}
/** /**
* @brief Halt the CPU * @brief Halt the CPU
*/ */
void Halt(); static inline void Halt()
{
#if defined(__amd64__) || defined(__i386__)
asmv("hlt");
#elif defined(__aarch64__)
asmv("wfe");
#endif
}
/** /**
* @brief Check if interrupts are enabled * @brief Check if interrupts are enabled
@ -1034,13 +1065,13 @@ namespace CPU
uint64_t rbx; // Base uint64_t rbx; // Base
uint64_t rax; // Accumulator uint64_t rax; // Accumulator
uint64_t InterruptNumber; // Interrupt Number uint64_t InterruptNumber; // Interrupt Number
uint64_t ErrorCode; // Error code uint64_t ErrorCode; // Error code
uint64_t rip; // Instruction Pointer uint64_t rip; // Instruction Pointer
uint64_t cs; // Code Segment uint64_t cs; // Code Segment
RFLAGS rflags; // Register Flags RFLAGS rflags; // Register Flags
uint64_t rsp; // Stack Pointer uint64_t rsp; // Stack Pointer
uint64_t ss; // Stack Segment uint64_t ss; // Stack Segment
} TrapFrame; } TrapFrame;
typedef union CR0 typedef union CR0