Skip to content

Commit a4633e2

Browse files
committed
amd64: save/restore all 64 bits of rax around cpuid
This commit fixes a bug in the timer check. When -fPIC is used we need to save/restore ebx. The code copied from patcher was meant for 32-bit systems and did not work correctly on 64-bit systems. This commit updates the save/restore to use rbx instead of ebx. Fixes #2678 Signed-off-by: Nathan Hjelm <[email protected]>
1 parent dc7d2f5 commit a4633e2

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

opal/include/opal/sys/amd64/timer.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,16 +61,18 @@ opal_sys_timer_get_cycles(void)
6161

6262
static inline bool opal_sys_timer_is_monotonic (void)
6363
{
64-
int32_t cpuid1, cpuid2, tmp;
64+
int64_t tmp;
65+
int32_t cpuid1, cpuid2;
6566
const int32_t level = 0x80000007;
67+
6668
/* cpuid clobbers ebx but it must be restored for -fPIC so save
6769
* then restore ebx */
68-
__asm__ volatile ("xchgl %%ebx, %2\n"
70+
__asm__ volatile ("xchg %%rbx, %2\n"
6971
"cpuid\n"
70-
"xchgl %%ebx, %2\n":
72+
"xchg %%rbx, %2\n":
7173
"=a" (cpuid1), "=d" (cpuid2), "=r" (tmp) :
7274
"a" (level) :
73-
"ecx");
75+
"ecx", "ebx");
7476
/* bit 8 of edx contains the invariant tsc flag */
7577
return !!(cpuid2 & (1 << 8));
7678
}

0 commit comments

Comments
 (0)