CPU: Add an idle_loop method

This commit is contained in:
apio 2022-12-07 12:26:09 +01:00 committed by Gitea
parent 287c4ab060
commit fd6a74e61c
2 changed files with 13 additions and 3 deletions

View File

@ -13,6 +13,8 @@ namespace CPU
[[noreturn]] void efficient_halt(); [[noreturn]] void efficient_halt();
void idle_loop();
void switch_kernel_stack(u64 top); void switch_kernel_stack(u64 top);
void enable_interrupts(); void enable_interrupts();

View File

@ -1,14 +1,14 @@
#include "arch/CPU.h" #include "arch/CPU.h"
#include "arch/x86_64/CPU.h"
#include "Log.h" #include "Log.h"
#include "arch/Timer.h" #include "arch/Timer.h"
#include "arch/x86_64/CPU.h"
#include "arch/x86_64/IO.h" #include "arch/x86_64/IO.h"
#include <cpuid.h> #include <cpuid.h>
#include <luna/Check.h>
#include <luna/Result.h>
#include <luna/String.h> #include <luna/String.h>
#include <luna/SystemError.h> #include <luna/SystemError.h>
#include <luna/Types.h> #include <luna/Types.h>
#include <luna/Check.h>
#include <luna/Result.h>
extern "C" void enable_sse(); extern "C" void enable_sse();
extern "C" void enable_write_protect(); extern "C" void enable_write_protect();
@ -430,6 +430,14 @@ namespace CPU
goto loop; // Safeguard: if we ever wake up, start our low-power rest again goto loop; // Safeguard: if we ever wake up, start our low-power rest again
} }
void idle_loop()
{
asm volatile("sti");
loop:
asm volatile("hlt");
goto loop;
}
void switch_kernel_stack(u64 top) void switch_kernel_stack(u64 top)
{ {
task_state_segment.rsp[0] = top; task_state_segment.rsp[0] = top;