1// SPDX-License-Identifier: GPL-2.0-only
2#ifndef __SELFTESTS_X86_HELPERS_H
3#define __SELFTESTS_X86_HELPERS_H
4
5#include <asm/processor-flags.h>
6
7static inline unsigned long get_eflags(void)
8{
9	unsigned long eflags;
10
11	asm volatile (
12#ifdef __x86_64__
13		"subq $128, %%rsp\n\t"
14		"pushfq\n\t"
15		"popq %0\n\t"
16		"addq $128, %%rsp"
17#else
18		"pushfl\n\t"
19		"popl %0"
20#endif
21		: "=r" (eflags) :: "memory");
22
23	return eflags;
24}
25
26static inline void set_eflags(unsigned long eflags)
27{
28	asm volatile (
29#ifdef __x86_64__
30		"subq $128, %%rsp\n\t"
31		"pushq %0\n\t"
32		"popfq\n\t"
33		"addq $128, %%rsp"
34#else
35		"pushl %0\n\t"
36		"popfl"
37#endif
38		:: "r" (eflags) : "flags", "memory");
39}
40
41#endif /* __SELFTESTS_X86_HELPERS_H */
42