[haiku-commits] haiku: hrev47746 - src/system/libroot/os/arch/x86_64

  • From: pdziepak@xxxxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Tue, 26 Aug 2014 19:03:49 +0200 (CEST)

hrev47746 adds 2 changesets to branch 'master'
old head: 58ec75999542400fe6a281d6f5105b7b80a6be63
new head: 72a446e10b634ced1034f689581a291b6ce8d770
overview: http://cgit.haiku-os.org/haiku/log/?qt=range&q=72a446e+%5E58ec759

----------------------------------------------------------------------------

6d70d75: libroot/x86_64: rewrite system_time[_nsecs]() to C++
  
  No functional change intended, just code deobfuscation.
  
  Signed-off-by: Paweł Dziepak <pdziepak@xxxxxxxxxxx>

72a446e: libroot/x86_64: implement get_cpuid() in user mode
  
  cpuid is available in user mode as well and it doesn't look like there
  are going to be any x86 platforms with significantly different CPUs anytime
  soon.
  
  Signed-off-by: Paweł Dziepak <pdziepak@xxxxxxxxxxx>

                                    [ Paweł Dziepak <pdziepak@xxxxxxxxxxx> ]

----------------------------------------------------------------------------

6 files changed, 53 insertions(+), 84 deletions(-)
src/system/kernel/lib/arch/x86_64/Jamfile        |  3 +-
src/system/libroot/os/arch/x86_64/Jamfile        |  2 +-
.../libroot/os/arch/x86_64/system_info.cpp       |  7 +-
src/system/libroot/os/arch/x86_64/system_time.c  |  4 --
.../libroot/os/arch/x86_64/system_time.cpp       | 45 ++++++++++++
.../libroot/os/arch/x86_64/system_time_asm.S     | 76 --------------------

############################################################################

Commit:      6d70d75a8e4f7c15eee4bc7ef666e62b48297631
URL:         http://cgit.haiku-os.org/haiku/commit/?id=6d70d75
Author:      Paweł Dziepak <pdziepak@xxxxxxxxxxx>
Date:        Tue Aug 26 16:57:07 2014 UTC

libroot/x86_64: rewrite system_time[_nsecs]() to C++

No functional change intended, just code deobfuscation.

Signed-off-by: Paweł Dziepak <pdziepak@xxxxxxxxxxx>

----------------------------------------------------------------------------

diff --git a/src/system/kernel/lib/arch/x86_64/Jamfile 
b/src/system/kernel/lib/arch/x86_64/Jamfile
index 168f14c..7f06e09 100644
--- a/src/system/kernel/lib/arch/x86_64/Jamfile
+++ b/src/system/kernel/lib/arch/x86_64/Jamfile
@@ -14,8 +14,7 @@ SEARCH_SOURCE += [ FDirName $(librootSources) os arch generic 
] ;
 
 KernelMergeObject kernel_os_arch_$(TARGET_ARCH).o :
        byteorder.S
-       system_time_asm.S
-       system_time.c
+       system_time.cpp
 
        generic_atomic.cpp
        : $(TARGET_KERNEL_PIC_CCFLAGS)
diff --git a/src/system/libroot/os/arch/x86_64/Jamfile 
b/src/system/libroot/os/arch/x86_64/Jamfile
index 5aad005..fcf8b59 100644
--- a/src/system/libroot/os/arch/x86_64/Jamfile
+++ b/src/system/libroot/os/arch/x86_64/Jamfile
@@ -18,7 +18,7 @@ for architectureObject in [ MultiArchSubDirSetup x86_64 ] {
                        byteorder.S
                        get_stack_frame.S
                        system_info.cpp
-                       system_time_asm.S
+                       system_time.cpp
                        thread.cpp
                        time.cpp
                        tls.cpp
diff --git a/src/system/libroot/os/arch/x86_64/system_time.c 
b/src/system/libroot/os/arch/x86_64/system_time.c
deleted file mode 100644
index 6b4e3d7..0000000
--- a/src/system/libroot/os/arch/x86_64/system_time.c
+++ /dev/null
@@ -1,4 +0,0 @@
-/*
-       Just a dummy to avoid a special case in the build system. system_time()
-       is implemented in system_time_asm.S.
-*/
diff --git a/src/system/libroot/os/arch/x86_64/system_time.cpp 
b/src/system/libroot/os/arch/x86_64/system_time.cpp
new file mode 100644
index 0000000..47a9824
--- /dev/null
+++ b/src/system/libroot/os/arch/x86_64/system_time.cpp
@@ -0,0 +1,45 @@
+/*
+ * Copyright 2014, Paweł Dziepak, pdziepak@xxxxxxxxxxx.
+ * Distributed under the terms of the MIT License.
+ */
+
+
+#include <stdint.h>
+
+
+static uint64_t cv_factor;
+static uint64_t cv_factor_nsec;
+
+
+extern "C" void
+__x86_setup_system_time(uint64_t cv, uint64_t cv_nsec)
+{
+    cv_factor = cv;
+    cv_factor_nsec = cv_nsec;
+}
+
+
+static inline uint64_t
+rdtsc()
+{
+    uint64_t lo, hi;
+    __asm__("rdtsc" : "=a" (lo), "=d" (hi));
+    return lo | (hi << 32);
+}
+
+
+extern "C" [[gnu::optimize("omit-frame-pointer")]] int64_t
+system_time()
+{
+    __uint128_t time = static_cast<__uint128_t>(rdtsc()) * cv_factor;
+    return time >> 64;
+}
+
+
+extern "C" [[gnu::optimize("omit-frame-pointer")]] int64_t
+system_time_nsecs()
+{
+    __uint128_t t = static_cast<__uint128_t>(rdtsc()) * cv_factor_nsec;
+    return t >> 32;
+}
+
diff --git a/src/system/libroot/os/arch/x86_64/system_time_asm.S 
b/src/system/libroot/os/arch/x86_64/system_time_asm.S
deleted file mode 100644
index 6af491a..0000000
--- a/src/system/libroot/os/arch/x86_64/system_time_asm.S
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * Copyright 2009, Ingo Weinhold, ingo_weinhold@xxxxxx.
- * Copyright 2012, Alex Smith, alex@xxxxxxxxxxxxxxxx.
- * Distributed under the terms of the MIT License.
- *
- * Copyright 2001, Travis Geiselbrecht. All rights reserved.
- * Distributed under the terms of the NewOS License.
- */
-
-
-#include <asm_defs.h>
-
-
-/* saves the conversion factor needed for system_time */
-.lcomm cv_factor                               8
-.lcomm cv_factor_nsecs                 8
-
-
-.text
-
-
-FUNCTION(__x86_setup_system_time):
-       movq    %rdi, cv_factor(%rip)
-       movq    %rsi, cv_factor_nsecs(%rip)
-       ret
-FUNCTION_END(__x86_setup_system_time)
-
-
-/* int64 system_time(); */
-FUNCTION(system_time):
-       // (rdtsc * cv_factor) >> 32.
-       // Factor is pre-shifted left by 32 bits.
-
-       movq    cv_factor(%rip), %rcx
-
-       // Load 64-bit TSC into %eax (low), %edx (high).
-       rdtsc
-
-       // Convert into a single 64-bit value.
-       shl             $32, %rdx
-       orq             %rdx, %rax
-
-       // Multiply by conversion factor, result in %rax (low), %rdx (high).
-       mulq    %rcx
-
-       // Due to pre-shifting of the factor the whole result in high.
-       movq    %rdx, %rax
-       ret
-FUNCTION_END(system_time)
-
-
-/* int64 system_time_nsecs(); */
-FUNCTION(system_time_nsecs):
-       // Same algorithm as system_time(), but with a different factor.
-       // (rdtsc * cv_factor_nsecs) >> 32.
-       // Factor has not been pre-shifted here, otherwise we may lose the upper
-       // 32 bits.
-
-       movq    cv_factor_nsecs(%rip), %rcx
-
-       // Load 64-bit TSC into %eax (low), %edx (high).
-       rdtsc
-
-       // Convert into a single 64-bit value.
-       shl             $32, %rdx
-       orq             %rdx, %rax
-
-       // Multiply by conversion factor, result in %rax (low), %rdx (high).
-       mulq    %rcx
-
-       // Shift the result right by 32 bits.
-       shr             $32, %rax
-       shl             $32, %rdx
-       orq             %rdx, %rax
-       ret
-FUNCTION_END(system_time_nsecs)

############################################################################

Revision:    hrev47746
Commit:      72a446e10b634ced1034f689581a291b6ce8d770
URL:         http://cgit.haiku-os.org/haiku/commit/?id=72a446e
Author:      Paweł Dziepak <pdziepak@xxxxxxxxxxx>
Date:        Tue Aug 26 16:58:21 2014 UTC

libroot/x86_64: implement get_cpuid() in user mode

cpuid is available in user mode as well and it doesn't look like there
are going to be any x86 platforms with significantly different CPUs anytime
soon.

Signed-off-by: Paweł Dziepak <pdziepak@xxxxxxxxxxx>

----------------------------------------------------------------------------

diff --git a/src/system/libroot/os/arch/x86_64/system_info.cpp 
b/src/system/libroot/os/arch/x86_64/system_info.cpp
index 03a3e4c..4a1acdb 100644
--- a/src/system/libroot/os/arch/x86_64/system_info.cpp
+++ b/src/system/libroot/os/arch/x86_64/system_info.cpp
@@ -1,4 +1,5 @@
 /* 
+ * Cp[yright 2014, Paweł Dziepak, pdziepak@xxxxxxxxxxx.
  * Copyright 2003-2004, Axel Dörfler, axeld@xxxxxxxxxxxxxxxx.
  * Distributed under the terms of the MIT License.
  */
@@ -11,6 +12,10 @@
 status_t
 get_cpuid(cpuid_info* info, uint32 eaxRegister, uint32 cpuNum)
 {
-       return _kern_get_cpuid(info, eaxRegister, cpuNum);
+       __asm__("cpuid"
+               : "=a" (info->regs.eax), "=b" (info->regs.ebx), "=c" 
(info->regs.ecx),
+                       "=d" (info->regs.edx)
+               : "a" (eaxRegister), "c" (0));
+       return B_OK;
 }
 


Other related posts:

  • » [haiku-commits] haiku: hrev47746 - src/system/libroot/os/arch/x86_64 - pdziepak