This is an automated email from the ASF dual-hosted git repository.

raiden00 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git


The following commit(s) were added to refs/heads/master by this push:
     new dc7d3470e6 arch/x86_64: Fix wrong RDTSCP implementation
dc7d3470e6 is described below

commit dc7d3470e6329495194194cff35e777eb551c6ab
Author: ouyangxiangzhen <[email protected]>
AuthorDate: Fri Sep 6 19:03:03 2024 +0800

    arch/x86_64: Fix wrong RDTSCP implementation
    
    RDTSCP instruction reads the current value of the processor’s
    time-stamp counter (a 64-bit MSR) into the EDX:EAX registers, and it
    also reads the value of the IA32_TSC_AUX MSR (address C0000103H) into
    the ECX register. However, the current RDTSCP implementation does not
    provide a hint for the compiler that ECX has been changed, resulting in
    register corrupted and subtle errors.
    
    Signed-off-by: ouyangxiangzhen <[email protected]>
---
 arch/x86_64/include/intel64/irq.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86_64/include/intel64/irq.h 
b/arch/x86_64/include/intel64/irq.h
index 90e9372a91..3979c907dc 100644
--- a/arch/x86_64/include/intel64/irq.h
+++ b/arch/x86_64/include/intel64/irq.h
@@ -535,7 +535,7 @@ static inline uint64_t rdtscp(void)
   uint32_t lo;
   uint32_t hi;
 
-  asm volatile("rdtscp" : "=a" (lo), "=d" (hi)::"memory");
+  asm volatile("rdtscp" : "=a" (lo), "=d" (hi)::"ecx", "memory");
   return (uint64_t)lo | (((uint64_t)hi) << 32);
 }
 

Reply via email to