aboutsummaryrefslogtreecommitdiff
path: root/security/masscan/files/patch-src_smack1.c
blob: e88a20706b8b4e3c34c0ce27173d63dc6b03ad6f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
--- src/smack1.c.orig	2021-01-31 09:13:30 UTC
+++ src/smack1.c
@@ -119,9 +119,8 @@
 #elif defined(__FreeBSD__)
 #include <sys/types.h>
 #include <machine/cpufunc.h>
-#define __rdtsc rdtsc
-#if (__ARM_ARCH >= 6)  // V6 is the earliest arch that has a standard cyclecount
-unsigned long long rdtsc(void)
+#if (__ARM_ARCH >= 6 && __ARM_ARCH <= 7)  // V6 is the earliest arch that has a standard cyclecount
+unsigned long long __rdtsc(void)
 {
   uint32_t pmccntr;
   uint32_t pmuseren;
@@ -138,6 +137,32 @@ unsigned long long rdtsc(void)
   }
   return 0;
 }
+#elif defined(__aarch64__)
+#define __rdtsc() 0
+#elif defined(__powerpc64__)
+unsigned long long __rdtsc(void)
+{
+  unsigned long long rval;
+  __asm__ __volatile__("mfspr %%r3, 268": "=r" (rval));
+  return rval;
+}
+#elif defined(__powerpc__)
+unsigned long long __rdtsc(void)
+{
+  unsigned int tmp;
+  union { unsigned long long complete; unsigned int part[2]; } ticks;
+  __asm__ ("0:"
+            "mftbu %[hi32]\n"
+            "mftb %[lo32]\n"
+            "mftbu %[tmp]\n"
+            "cmpw %[tmp],%[hi32]\n"
+            "bne 0b\n"
+            : [hi32] "=r"(ticks.part[0]), [lo32] "=r"(ticks.part[1]),
+            [tmp] "=r"(tmp));
+  return ticks.complete;
+}
+#else
+#define __rdtsc rdtsc
 #endif
 #elif defined (__llvm__)
 #if defined(i386) || defined(__i386__)