X-Git-Url: https://scm.lunaixsky.com/lunaix-os.git/blobdiff_plain/7b0dccbab69e806a63c4504c3ddb82e45241985b..1b471813a2ba287c2ace9cf6c866f330c725b99c:/lunaix-os/includes/hal/cpu.h diff --git a/lunaix-os/includes/hal/cpu.h b/lunaix-os/includes/hal/cpu.h index 1a3173b..fe633d0 100644 --- a/lunaix-os/includes/hal/cpu.h +++ b/lunaix-os/includes/hal/cpu.h @@ -20,35 +20,52 @@ typedef struct typedef struct { - reg16 ss; - reg16 es; reg16 ds; + reg16 es; reg16 fs; reg16 gs; - reg16 cs; } __attribute__((packed)) sg_reg; void cpu_get_brand(char* brand_out); +int +cpu_has_apic(); + #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wreturn-type" static inline reg32 cpu_rcr0() { - asm("mov %cr0, %eax"); + uintptr_t val; + asm volatile("movl %%cr0,%0" : "=r"(val)); + return val; } static inline reg32 cpu_rcr2() { - asm("mov %cr2, %eax"); + uintptr_t val; + asm volatile("movl %%cr2,%0" : "=r"(val)); + return val; } static inline reg32 cpu_rcr3() { - asm("mov %cr3, %eax"); + uintptr_t val; + asm volatile("movl %%cr3,%0" : "=r"(val)); + return val; +} + +static inline reg32 +cpu_reflags() +{ + uintptr_t val; + asm volatile("pushf\n" + "popl %0\n" + : "=r"(val)::); + return val; } #pragma GCC diagnostic pop @@ -73,19 +90,19 @@ cpu_lcr3(reg32 v) static inline void cpu_invplg(void* va) { - asm("invlpg (%0)" ::"r"((uintptr_t)va) : "memory"); + asm volatile("invlpg (%0)" ::"r"((uintptr_t)va) : "memory"); } static inline void cpu_enable_interrupt() { - asm("sti"); + asm volatile("sti"); } static inline void cpu_disable_interrupt() { - asm("cli"); + asm volatile("cli"); } static inline void @@ -98,4 +115,10 @@ cpu_invtlb() : "r"(interm)); } +void +cpu_rdmsr(uint32_t msr_idx, uint32_t* reg_high, uint32_t* reg_low); + +void +cpu_wrmsr(uint32_t msr_idx, uint32_t reg_high, uint32_t reg_low); + #endif \ No newline at end of file