X-Git-Url: https://scm.lunaixsky.com/lunaix-os.git/blobdiff_plain/cd09c4b222e4ddf45a42522563ae2471a829d1c8..37fb1e9cee287c9ae8c065ff517c508eb5f9d7dd:/lunaix-os/includes/hal/cpu.h diff --git a/lunaix-os/includes/hal/cpu.h b/lunaix-os/includes/hal/cpu.h index 2a06f29..1a3173b 100644 --- a/lunaix-os/includes/hal/cpu.h +++ b/lunaix-os/includes/hal/cpu.h @@ -1,36 +1,101 @@ #ifndef __LUNAIX_CPU_H #define __LUNAIX_CPU_H -typedef unsigned long reg32; +#include + +typedef unsigned int reg32; typedef unsigned short reg16; -typedef struct { +typedef struct +{ + reg32 eax; + reg32 ebx; + reg32 ecx; + reg32 edx; reg32 edi; - reg32 esi; reg32 ebp; + reg32 esi; reg32 esp; - reg32 ebx; - reg32 edx; - reg32 ecx; - reg32 eax; -} __attribute__((packed)) registers; +} __attribute__((packed)) gp_regs; + +typedef struct +{ + reg16 ss; + reg16 es; + reg16 ds; + reg16 fs; + reg16 gs; + reg16 cs; +} __attribute__((packed)) sg_reg; + +void +cpu_get_brand(char* brand_out); + +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wreturn-type" +static inline reg32 +cpu_rcr0() +{ + asm("mov %cr0, %eax"); +} -reg32 cpu_r_cr0(); +static inline reg32 +cpu_rcr2() +{ + asm("mov %cr2, %eax"); +} -reg32 cpu_r_cr2(); +static inline reg32 +cpu_rcr3() +{ + asm("mov %cr3, %eax"); +} +#pragma GCC diagnostic pop -reg32 cpu_r_cr3(); +static inline void +cpu_lcr0(reg32 v) +{ + asm("mov %0, %%cr0" ::"r"(v)); +} -void cpu_w_cr0(reg32 v); +static inline void +cpu_lcr2(reg32 v) +{ + asm("mov %0, %%cr2" ::"r"(v)); +} -void cpu_w_cr2(reg32 v); +static inline void +cpu_lcr3(reg32 v) +{ + asm("mov %0, %%cr3" ::"r"(v)); +} -void cpu_w_cr3(reg32 v); +static inline void +cpu_invplg(void* va) +{ + asm("invlpg (%0)" ::"r"((uintptr_t)va) : "memory"); +} -void cpu_get_model(char* model_out); +static inline void +cpu_enable_interrupt() +{ + asm("sti"); +} -int cpu_brand_string_supported(); +static inline void +cpu_disable_interrupt() +{ + asm("cli"); +} -void cpu_get_brand(char* brand_out); +static inline void +cpu_invtlb() +{ + reg32 interm; + asm("movl %%cr3, %0\n" + "movl %0, %%cr3" + : "=r"(interm) + : "r"(interm)); +} -#endif /* __LUNAIX_CPU_H */ +#endif \ No newline at end of file