X-Git-Url: https://scm.lunaixsky.com/lunaix-os.git/blobdiff_plain/bffa3430fbbaaad29bec0b5bee9c1f0bfc7fd068..34f6af4f61e0eec9c96113e07f140b609b4113c8:/lunaix-os/arch/x86/includes/asm/x86_cpu.h diff --git a/lunaix-os/arch/x86/includes/asm/x86_cpu.h b/lunaix-os/arch/x86/includes/asm/x86_cpu.h new file mode 100644 index 0000000..0dde3e0 --- /dev/null +++ b/lunaix-os/arch/x86/includes/asm/x86_cpu.h @@ -0,0 +1,78 @@ +#ifndef __LUNAIX_CPU_X86_H +#define __LUNAIX_CPU_X86_H + +#include "cpu.h" +#include "x86_crx.h" + +#ifdef CONFIG_ARCH_X86_64 +# define _POP "popq " +# define _MOV "movq " +#else +# define _POP "popl " +# define _MOV "movl " +#endif + +/** + * @brief Load current processor state + * + * @return reg_t + */ +static inline reg_t +cpu_ldstate() +{ + ptr_t val; + asm volatile("pushf\n" + _POP "%0\n" + : "=r"(val)::); + return val; +} + +/** + * @brief Load current processor config + * + * @return reg_t + */ +static inline reg_t +cpu_ldconfig() +{ + reg_t val; + asm volatile(_MOV "%%cr0,%0" : "=r"(val)); + return val; +} + +/** + * @brief Change current processor state + * + * @return reg_t + */ +static inline void +cpu_chconfig(reg_t val) +{ + asm(_MOV "%0, %%cr0" ::"r"(val)); +} + +/** + * @brief Change current virtual memory space + * + * @return reg_t + */ +static inline void +cpu_chvmspace(reg_t val) +{ + asm(_MOV "%0, %%cr3" ::"r"(val)); +} + +/** + * @brief Read exeception address + * + * @return ptr_t + */ +static inline ptr_t +cpu_ldeaddr() +{ + ptr_t val; + asm volatile(_MOV "%%cr2,%0" : "=r"(val)); + return val; +} + +#endif /* __LUNAIX_CPU_X86_H */