fix: improve scheduling, memory, timer implementations

This commit is contained in:
2026-03-24 07:40:37 +01:00
parent 195028d994
commit f902ab48a1
14 changed files with 239 additions and 94 deletions
+19
View File
@@ -12,6 +12,25 @@ namespace Hal {
// Enable SSE/SSE2 — required for userspace programs compiled with SSE.
// CR0: clear EM (bit 2), set MP (bit 1)
// CR4: set OSFXSR (bit 9) and OSXMMEXCPT (bit 10)
// Check if MONITOR/MWAIT is supported (CPUID.01H:ECX bit 3)
inline bool HasMwait() {
uint32_t ecx;
asm volatile("cpuid" : "=c"(ecx) : "a"(1) : "ebx", "edx");
return (ecx & (1 << 3)) != 0;
}
// Idle using MWAIT if available, otherwise HLT.
// MWAIT can enter deeper C-states (C1E/C3/C6) for better
// power and thermal efficiency than HLT (C1 only).
// The monitored address is arbitrary -- we just need MONITOR
// to arm the wake trigger; any interrupt wakes MWAIT.
inline void IdleWait(volatile uint64_t* monitorAddr) {
// MONITOR: set up the address monitoring range
asm volatile("monitor" :: "a"(monitorAddr), "c"(0), "d"(0));
// MWAIT: hint=0x00 (C1 state, platform-dependent deeper states)
asm volatile("mwait" :: "a"(0x00), "c"(0));
}
inline void EnableSSE() {
uint64_t cr0;
asm volatile("mov %%cr0, %0" : "=r"(cr0));