3
0
mirror of https://github.com/Qortal/Brooklyn.git synced 2025-02-13 02:35:54 +00:00

42 lines
705 B
C
Raw Normal View History

2021-05-27 00:09:36 +05:00
// SPDX-License-Identifier: GPL-2.0-only
#ifndef __SELFTESTS_X86_HELPERS_H
#define __SELFTESTS_X86_HELPERS_H
#include <asm/processor-flags.h>
static inline unsigned long get_eflags(void)
{
2021-09-23 21:59:15 +05:00
unsigned long eflags;
asm volatile (
2021-05-27 00:09:36 +05:00
#ifdef __x86_64__
2021-09-23 21:59:15 +05:00
"subq $128, %%rsp\n\t"
"pushfq\n\t"
"popq %0\n\t"
"addq $128, %%rsp"
2021-05-27 00:09:36 +05:00
#else
2021-09-23 21:59:15 +05:00
"pushfl\n\t"
"popl %0"
2021-05-27 00:09:36 +05:00
#endif
2021-09-23 21:59:15 +05:00
: "=r" (eflags) :: "memory");
return eflags;
2021-05-27 00:09:36 +05:00
}
static inline void set_eflags(unsigned long eflags)
{
2021-09-23 21:59:15 +05:00
asm volatile (
2021-05-27 00:09:36 +05:00
#ifdef __x86_64__
2021-09-23 21:59:15 +05:00
"subq $128, %%rsp\n\t"
"pushq %0\n\t"
"popfq\n\t"
"addq $128, %%rsp"
2021-05-27 00:09:36 +05:00
#else
2021-09-23 21:59:15 +05:00
"pushl %0\n\t"
"popfl"
2021-05-27 00:09:36 +05:00
#endif
2021-09-23 21:59:15 +05:00
:: "r" (eflags) : "flags", "memory");
2021-05-27 00:09:36 +05:00
}
#endif /* __SELFTESTS_X86_HELPERS_H */