mirror of
https://review.haiku-os.org/haiku
synced 2025-02-21 04:58:56 +01:00
after a0131eaae2884fdced27158c3d34732d1656aca9 mxcsr was possibly also incorrect. fpu control and mxcsr will be restored with fxrstor/xrstor. no need to clear pending exceptions on #MF fix #18656 (and #18624 after reverting). Change-Id: I7dd5e2e4610747c5b82abd6c67e302d264b4be92 Reviewed-on: https://review.haiku-os.org/c/haiku/+/7104 Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org> Reviewed-by: waddlesplash <waddlesplash@gmail.com>
64 lines
1.5 KiB
C
64 lines
1.5 KiB
C
/*
|
|
* Copyright 2014, Paweł Dziepak, pdziepak@quarnos.org.
|
|
* Distributed under the terms of the MIT License.
|
|
*/
|
|
#ifndef _KERNEL_ARCH_X86_64_CPU_H
|
|
#define _KERNEL_ARCH_X86_64_CPU_H
|
|
|
|
|
|
#include <arch_thread_types.h>
|
|
|
|
|
|
extern uint16 gFPUControlDefault;
|
|
extern uint32 gFPUMXCSRDefault;
|
|
|
|
|
|
static inline uint64_t
|
|
x86_read_msr(uint32_t msr)
|
|
{
|
|
uint64_t high, low;
|
|
asm volatile("rdmsr" : "=a" (low), "=d" (high) : "c" (msr));
|
|
return (high << 32) | low;
|
|
}
|
|
|
|
|
|
static inline void
|
|
x86_write_msr(uint32_t msr, uint64_t value)
|
|
{
|
|
asm volatile("wrmsr" : : "a" (value) , "d" (value >> 32), "c" (msr));
|
|
}
|
|
|
|
|
|
static inline void
|
|
x86_context_switch(arch_thread* oldState, arch_thread* newState)
|
|
{
|
|
asm volatile(
|
|
"pushq %%rbp;"
|
|
"movq $1f, %c[rip](%0);"
|
|
"movq %%rsp, %c[rsp](%0);"
|
|
"movq %c[rsp](%1), %%rsp;"
|
|
"jmp *%c[rip](%1);"
|
|
"1:"
|
|
"popq %%rbp;"
|
|
:
|
|
: "a" (oldState), "d" (newState),
|
|
[rsp] "i" (offsetof(arch_thread, current_stack)),
|
|
[rip] "i" (offsetof(arch_thread, instruction_pointer))
|
|
: "rbx", "rcx", "rdi", "rsi", "r8", "r9", "r10", "r11", "r12", "r13",
|
|
"r14", "r15", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5",
|
|
"xmm6", "xmm7", "xmm8", "xmm9", "xmm10", "xmm11", "xmm12", "xmm13",
|
|
"xmm14", "xmm15", "memory");
|
|
asm volatile("ldmxcsr %0" : : "m" (gFPUMXCSRDefault));
|
|
asm volatile("fldcw %0" : : "m" (gFPUControlDefault));
|
|
}
|
|
|
|
|
|
static inline void
|
|
x86_swap_pgdir(uintptr_t root)
|
|
{
|
|
asm volatile("movq %0, %%cr3" : : "r" (root));
|
|
}
|
|
|
|
|
|
#endif // _KERNEL_ARCH_X86_64_CPU_H
|