aboutsummaryrefslogtreecommitdiffstats
path: root/modules/tm_hard
diff options
context:
space:
mode:
authorlloyd <[email protected]>2006-05-18 18:33:19 +0000
committerlloyd <[email protected]>2006-05-18 18:33:19 +0000
commita2c99d3270eb73ef2db5704fc54356c6b75096f8 (patch)
treead3d6c4fcc8dd0f403f8105598943616246fe172 /modules/tm_hard
Initial checkin1.5.6
Diffstat (limited to 'modules/tm_hard')
-rw-r--r--modules/tm_hard/modinfo.txt24
-rw-r--r--modules/tm_hard/tm_hard.cpp41
-rw-r--r--modules/tm_hard/tm_hard.h24
3 files changed, 89 insertions, 0 deletions
diff --git a/modules/tm_hard/modinfo.txt b/modules/tm_hard/modinfo.txt
new file mode 100644
index 000000000..d03df5d30
--- /dev/null
+++ b/modules/tm_hard/modinfo.txt
@@ -0,0 +1,24 @@
+realname "Hardware Timer"
+
+define TIMER_HARDWARE
+
+add_file tm_hard.cpp
+add_file tm_hard.h
+
+<cc>
+gcc
+</cc>
+
+<arch>
+# RDTSC: Pentium and up
+i586
+i686
+athlon
+pentium4
+amd64
+
+ppc # PPC timebase register
+ppc64 # PPC timebase register
+alpha # rpcc
+sparc64 # %tick register
+</arch>
diff --git a/modules/tm_hard/tm_hard.cpp b/modules/tm_hard/tm_hard.cpp
new file mode 100644
index 000000000..0005f79c2
--- /dev/null
+++ b/modules/tm_hard/tm_hard.cpp
@@ -0,0 +1,41 @@
+/*************************************************
+* Hardware Timer Source File *
+* (C) 1999-2006 The Botan Project *
+*************************************************/
+
+#include <botan/tm_hard.h>
+#include <botan/config.h>
+
+namespace Botan {
+
+/*************************************************
+* Get the timestamp *
+*************************************************/
+u64bit Hardware_Timer::clock() const
+ {
+ u64bit rtc = 0;
+
+#if !defined(__GNUC__)
+ #error "This module uses GCC-style inline asm"
+#endif
+
+#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 = ((u64bit)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 = ((u64bit)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));
+#else
+ #error "Unsure how to access hardware timer on this system"
+#endif
+
+ return rtc;
+ }
+
+}
diff --git a/modules/tm_hard/tm_hard.h b/modules/tm_hard/tm_hard.h
new file mode 100644
index 000000000..017bc5cad
--- /dev/null
+++ b/modules/tm_hard/tm_hard.h
@@ -0,0 +1,24 @@
+/*************************************************
+* Hardware Timer Header File *
+* (C) 1999-2006 The Botan Project *
+*************************************************/
+
+#ifndef BOTAN_EXT_TIMER_HARDWARE_H__
+#define BOTAN_EXT_TIMER_HARDWARE_H__
+
+#include <botan/timers.h>
+
+namespace Botan {
+
+/*************************************************
+* Hardware Timer *
+*************************************************/
+class Hardware_Timer : public Timer
+ {
+ public:
+ u64bit clock() const;
+ };
+
+}
+
+#endif