From 3c55f159b8e2ff80c0f0ab0820de0afc414be7db Mon Sep 17 00:00:00 2001 From: lloyd Date: Tue, 30 Sep 2008 04:35:34 +0000 Subject: Split off part of the core module into libstate (basically the whole lookup/global_state piece). Move timer and mutex directories into utils/ --- src/utils/timer/cpu_counter/info.txt | 36 ++++++++++++++++++++++++ src/utils/timer/cpu_counter/tm_hard.cpp | 49 +++++++++++++++++++++++++++++++++ src/utils/timer/cpu_counter/tm_hard.h | 24 ++++++++++++++++ 3 files changed, 109 insertions(+) create mode 100644 src/utils/timer/cpu_counter/info.txt create mode 100644 src/utils/timer/cpu_counter/tm_hard.cpp create mode 100644 src/utils/timer/cpu_counter/tm_hard.h (limited to 'src/utils/timer/cpu_counter') diff --git a/src/utils/timer/cpu_counter/info.txt b/src/utils/timer/cpu_counter/info.txt new file mode 100644 index 000000000..eef6be5a2 --- /dev/null +++ b/src/utils/timer/cpu_counter/info.txt @@ -0,0 +1,36 @@ +realname "Hardware Timer" + +define TIMER_HARDWARE + +load_on asm_ok + + +tm_hard.cpp +tm_hard.h + + + +gcc + + + +# RDTSC: Pentium and up +i586 +i686 +athlon +pentium4 +pentium-m +amd64 + +ppc # PPC timebase register +ppc64 # PPC timebase register +alpha # rpcc +sparc64 # %tick register +ia64 # ar.itc +s390x +hppa + + + +timer_base + diff --git a/src/utils/timer/cpu_counter/tm_hard.cpp b/src/utils/timer/cpu_counter/tm_hard.cpp new file mode 100644 index 000000000..2f7516930 --- /dev/null +++ b/src/utils/timer/cpu_counter/tm_hard.cpp @@ -0,0 +1,49 @@ +/************************************************* +* Hardware Timer Source File * +* (C) 1999-2007 Jack Lloyd * +*************************************************/ + +#include + +namespace Botan { + +/************************************************* +* Get the timestamp * +*************************************************/ +u64bit Hardware_Timer::clock() const + { + u64bit rtc = 0; + +#if defined(BOTAN_TARGET_ARCH_IS_IA32) || defined(BOTAN_TARGET_ARCH_IS_AMD64) + u32bit rtc_low = 0, rtc_high = 0; + asm volatile("rdtsc" : "=d" (rtc_high), "=a" (rtc_low)); + rtc = (static_cast(rtc_high) << 32) | rtc_low; + +#elif defined(BOTAN_TARGET_ARCH_IS_PPC) || defined(BOTAN_TARGET_ARCH_IS_PPC64) + u32bit rtc_low = 0, rtc_high = 0; + asm volatile("mftbu %0; mftb %1" : "=r" (rtc_high), "=r" (rtc_low)); + rtc = (static_cast(rtc_high) << 32) | rtc_low; + +#elif defined(BOTAN_TARGET_ARCH_IS_ALPHA) + asm volatile("rpcc %0" : "=r" (rtc)); + +#elif defined(BOTAN_TARGET_ARCH_IS_SPARC64) + asm volatile("rd %%tick, %0" : "=r" (rtc)); + +#elif defined(BOTAN_TARGET_ARCH_IS_IA64) + asm volatile("mov %0=ar.itc" : "=r" (rtc)); + +#elif defined(BOTAN_TARGET_ARCH_IS_S390X) + asm volatile("stck 0(%0)" : : "a" (&rtc) : "memory", "cc"); + +#elif defined(BOTAN_TARGET_ARCH_IS_HPPA) + asm volatile("mfctl 16,%0" : "=r" (rtc)); // 64-bit only? + +#else + #error "Unsure how to access hardware timer on this system" +#endif + + return rtc; + } + +} diff --git a/src/utils/timer/cpu_counter/tm_hard.h b/src/utils/timer/cpu_counter/tm_hard.h new file mode 100644 index 000000000..678513f81 --- /dev/null +++ b/src/utils/timer/cpu_counter/tm_hard.h @@ -0,0 +1,24 @@ +/************************************************* +* Hardware Timer Header File * +* (C) 1999-2007 Jack Lloyd * +*************************************************/ + +#ifndef BOTAN_TIMER_HARDWARE_H__ +#define BOTAN_TIMER_HARDWARE_H__ + +#include + +namespace Botan { + +/************************************************* +* Hardware Timer * +*************************************************/ +class Hardware_Timer : public Timer + { + public: + u64bit clock() const; + }; + +} + +#endif -- cgit v1.2.3