Provide convenience C wrappers for RDPKRU and WRPKRU instructions.

Reviewed by:	markj
Tested by:	pho
Sponsored by:	The FreeBSD Foundation
MFC after:	3 days
Differential revision:	https://reviews.freebsd.org/D18893
This commit is contained in:
kib 2019-02-19 19:17:20 +00:00
parent 27e3adb11b
commit 7fc374eaa9
2 changed files with 32 additions and 0 deletions

View File

@ -627,6 +627,22 @@ cpu_mwait(u_long extensions, u_int hints)
__asm __volatile("mwait" : : "a" (hints), "c" (extensions));
}
static __inline uint32_t
rdpkru(void)
{
uint32_t res;
__asm __volatile("rdpkru" : "=a" (res) : "c" (0) : "edx");
return (res);
}
static __inline void
wrpkru(uint32_t mask)
{
__asm __volatile("wrpkru" : : "a" (mask), "c" (0), "d" (0));
}
#ifdef _KERNEL
/* This is defined in <machine/specialreg.h> but is too painful to get to */
#ifndef MSR_FSBASE

View File

@ -726,6 +726,22 @@ intr_restore(register_t eflags)
write_eflags(eflags);
}
static __inline uint32_t
rdpkru(void)
{
uint32_t res;
__asm __volatile("rdpkru" : "=a" (res) : "c" (0) : "edx");
return (res);
}
static __inline void
wrpkru(uint32_t mask)
{
__asm __volatile("wrpkru" : : "a" (mask), "c" (0), "d" (0));
}
#else /* !(__GNUCLIKE_ASM && __CC_SUPPORTS___INLINE) */
int breakpoint(void);