Xen Test Framework
tsx.h
Go to the documentation of this file.
1 
20 #ifndef XTF_X86_TSX_H
21 #define XTF_X86_TSX_H
22 
23 #include <xtf/compiler.h>
24 #include <xtf/extable.h>
25 
26 #define _XBEGIN_STARTED (~0u)
27 #define _XBEGIN_UD EXINFO_SYM(UD, 0)
28 #define _XABORT_EXPLICIT (1u << 0)
29 #define _XABORT_RETRY (1u << 1)
30 #define _XABORT_CONFLICT (1u << 2)
31 #define _XABORT_CAPACITY (1u << 3)
32 #define _XABORT_DEBUG (1u << 4)
33 #define _XABORT_NESTED (1u << 5)
34 #define _XABORT_CODE(x) (((x) >> 24) & 0xff)
35 
36 static inline unsigned int _xbegin(void)
37 {
38  unsigned int ret = _XBEGIN_STARTED;
39 
40  asm volatile (".byte 0xc7, 0xf8, 0, 0, 0, 0" /* xbegin 1f; 1: */
41  : "+a" (ret) :: "memory");
42 
43  return ret;
44 }
45 
46 /* Like _xbegin(), but will catch #UD as well. */
47 static inline unsigned int _xbegin_safe(void)
48 {
49  unsigned int ret = _XBEGIN_STARTED;
50 
51  asm volatile ("1: .byte 0xc7, 0xf8, 0, 0, 0, 0; 2:" /* xbegin 2f; 2: */
52  _ASM_EXTABLE_HANDLER(1b, 2b, %P[rec])
53  : "+a" (ret)
54  : [rec] "p" (ex_record_fault_eax)
55  : "memory");
56 
57  return ret;
58 }
59 
60 static inline int _xtest(void)
61 {
62  int rc;
63 
64  asm volatile (".byte 0x0f, 0x01, 0xd6" /* xtest */
65  ASM_FLAG_OUT(, "; setnz %[rc]")
66  : ASM_FLAG_OUT("=@ccnz", [rc] "=rm") (rc));
67 
68  return rc;
69 }
70 
71 /*
72  * N.B. Should be static inline, but clang can't cope with 'code' being
73  * propagated through a function parameter.
74  */
75 #define _xabort(code) \
76  do { \
77  asm volatile (".byte 0xc6, 0xf8, %c0" /* xabort %0 */ \
78  :: "N" (code) : "memory"); \
79  unreachable(); \
80  } while ( 0 )
81 
82 static inline void _xend(void)
83 {
84  asm volatile (".byte 0x0f, 0x01, 0xd5" /* xend */
85  ::: "memory");
86 }
87 
88 #endif /* XTF_X86_TSX_H */
89 
90 /*
91  * Local variables:
92  * mode: C
93  * c-file-style: "BSD"
94  * c-basic-offset: 4
95  * tab-width: 4
96  * indent-tabs-mode: nil
97  * End:
98  */
#define _XBEGIN_STARTED
Definition: tsx.h:26
static unsigned int _xbegin_safe(void)
Definition: tsx.h:47
bool ex_record_fault_eax(struct cpu_regs *regs, const struct extable_entry *ex)
Record the current fault in %eax.
Definition: extable.c:8
Exception table support.
static int _xtest(void)
Definition: tsx.h:60
#define ASM_FLAG_OUT(yes, no)
Definition: compiler-gcc.h:24
static unsigned int _xbegin(void)
Definition: tsx.h:36
static void _xend(void)
Definition: tsx.h:82
#define _ASM_EXTABLE_HANDLER(fault, fixup, handler)
Create an exception table entry with custom handler.
Definition: extable.h:38