Skip to content

Commit

Permalink
security/masscan: fix build on powerpc*
Browse files Browse the repository at this point in the history
Implement rdtsc, similar to ARM. Builds fine with clang.
  • Loading branch information
pkubaj committed Sep 12, 2021
1 parent 127ab8c commit ff93196
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
6 changes: 0 additions & 6 deletions security/masscan/Makefile
Expand Up @@ -17,12 +17,6 @@ CFLAGS+= -Wno-format

PLIST_FILES= bin/masscan man/man8/masscan.8.gz

.include <bsd.port.options.mk>

.if ${ARCH} == powerpc64 || ${ARCH} == powerpc
USE_GCC= yes
.endif

do-install:
${INSTALL_PROGRAM} ${WRKSRC}/bin/masscan ${STAGEDIR}${PREFIX}/bin
${INSTALL_MAN} ${WRKSRC}/doc/masscan.8 ${STAGEDIR}${MANPREFIX}/man/man8
Expand Down
27 changes: 25 additions & 2 deletions security/masscan/files/patch-src_smack1.c
@@ -1,6 +1,6 @@
--- src/smack1.c.orig 2021-01-31 09:13:30 UTC
+++ src/smack1.c
@@ -119,8 +119,7 @@
@@ -119,9 +119,8 @@
#elif defined(__FreeBSD__)
#include <sys/types.h>
#include <machine/cpufunc.h>
Expand All @@ -10,12 +10,35 @@
unsigned long long rdtsc(void)
{
uint32_t pmccntr;
@@ -138,6 +137,10 @@ unsigned long long rdtsc(void)
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
Expand Down

0 comments on commit ff93196

Please sign in to comment.