Skip to content

Commit

Permalink
fake pacga impl + tests build
Browse files Browse the repository at this point in the history
  • Loading branch information
LouisBrunner committed Oct 3, 2024
1 parent 4345d9e commit d7e23ba
Show file tree
Hide file tree
Showing 13 changed files with 107 additions and 19 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -1804,6 +1804,7 @@ configure~
/none/tests/arm/vfpv4_fma

# /none/tests/arm64/
/none/tests/arm64/*.dSYM
/none/tests/arm64/*.stderr.diff*
/none/tests/arm64/*.stderr.out
/none/tests/arm64/*.stdout.diff*
Expand Down
2 changes: 1 addition & 1 deletion VEX/priv/guest_arm64_toIR.c
Original file line number Diff line number Diff line change
Expand Up @@ -3819,7 +3819,7 @@ Bool dis_ARM64_data_processing_register(/*MB_OUT*/DisResult* dres,
UInt dd = INSN(4,0);
// see https://developer.arm.com/documentation/ddi0597/2023-12/Shared-Pseudocode/aarch64-functions-pac?lang=en#impl-aarch64.ComputePACIMPDEF.4
// dd = compute_pac(dd, nn, mm | SP) & 0xFFFFFFFF00000000;
// FIXME: putIReg64orZR(dd, mkU64(0x101010FF00000000));
putIReg64orZR(dd, getIReg64orZR(nn));
DIP("pacga %s, %s, %s (FAKED)\n", nameIRegOrZR(True, dd), nameIRegOrZR(True, nn), nameIRegOrSP(True, mm));
return True;
}
Expand Down
3 changes: 2 additions & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -1480,7 +1480,8 @@ AM_CONDITIONAL(VGCONF_OS_IS_DARWIN_OR_FREEBSD,
-o x$VGCONF_PLATFORM_PRI_CAPS = xAMD64_FREEBSD \
-o x$VGCONF_PLATFORM_PRI_CAPS = xARM64_FREEBSD \
-o x$VGCONF_PLATFORM_PRI_CAPS = xX86_DARWIN \
-o x$VGCONF_PLATFORM_PRI_CAPS = xAMD64_DARWIN)
-o x$VGCONF_PLATFORM_PRI_CAPS = xAMD64_DARWIN \
-o x$VGCONF_PLATFORM_PRI_CAPS = xARM64_DARWIN)


# Sometimes, in the Makefile.am files, it's useful to know whether or not
Expand Down
5 changes: 4 additions & 1 deletion helgrind/tests/tc07_hbl1.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#undef PLAT_x86_darwin
#undef PLAT_amd64_darwin
#undef PLAT_arm64_darwin
#undef PLAT_x86_freebsd
#undef PLAT_amd64_freebsd
#undef PLAT_arm64_freebsd
Expand All @@ -26,6 +27,8 @@
# define PLAT_x86_darwin 1
#elif defined(__APPLE__) && defined(__x86_64__)
# define PLAT_amd64_darwin 1
#elif defined(__APPLE__) && defined(__aarch64__)
# define PLAT_arm64_darwin 1
#elif defined(__FreeBSD__) && defined(__i386__)
# define PLAT_x86_freebsd 1
#elif defined(__FreeBSD__) && defined(__amd64__)
Expand Down Expand Up @@ -86,7 +89,7 @@
: /*out*/ : /*in*/ "r"(&(_lval)) \
: /*trash*/ "r8", "r9", "cc", "memory" \
);
#elif defined(PLAT_arm64_linux) || defined(PLAT_arm64_freebsd)
#elif defined(PLAT_arm64_linux) || defined(PLAT_arm64_freebsd) || defined(PLAT_arm64_darwin)
# define INC(_lval,_lqual) \
__asm__ __volatile__( \
"1:\n" \
Expand Down
7 changes: 5 additions & 2 deletions helgrind/tests/tc08_hbl2.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@
#include <unistd.h>

/* Simple test program, no race. Parent writes atomically to a counter
whilst child reads it. When counter reaches a prearranged value,
whilst child reads it. When counter reaches a prearranged value,
child joins back to parent. Parent (writer) uses hardware bus lock;
child is only reading and so does not need to use a bus lock. */

#undef PLAT_x86_darwin
#undef PLAT_amd64_darwin
#undef PLAT_arm64_darwin
#undef PLAT_x86_freebsd
#undef PLAT_amd64_freebsd
#undef PLAT_arm64_freebsd
Expand All @@ -43,6 +44,8 @@
# define PLAT_x86_darwin 1
#elif defined(__APPLE__) && defined(__x86_64__)
# define PLAT_amd64_darwin 1
#elif defined(__APPLE__) && defined(__aarch64__)
# define PLAT_arm64_darwin 1
#elif defined(__FreeBSD__) && defined(__i386__)
# define PLAT_x86_freebsd 1
#elif defined(__FreeBSD__) && defined(__amd64__)
Expand Down Expand Up @@ -108,7 +111,7 @@
: /*out*/ : /*in*/ "r"(&(_lval)) \
: /*trash*/ "r8", "r9", "cc", "memory" \
);
#elif defined(PLAT_arm64_linux) || defined(PLAT_arm64_freebsd)
#elif defined(PLAT_arm64_linux) || defined(PLAT_arm64_freebsd) || defined(PLAT_arm64_darwin)
# define INC(_lval,_lqual) \
__asm__ __volatile__( \
"1:\n" \
Expand Down
5 changes: 4 additions & 1 deletion helgrind/tests/tc11_XCHG.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#undef PLAT_x86_darwin
#undef PLAT_amd64_darwin
#undef PLAT_arm64_darwin
#undef PLAT_x86_freebsd
#undef PLAT_amd64_freebsd
#undef PLAT_arm64_freebsd
Expand All @@ -28,6 +29,8 @@
# define PLAT_x86_darwin 1
#elif defined(__APPLE__) && defined(__x86_64__)
# define PLAT_amd64_darwin 1
#elif defined(__APPLE__) && defined(__aarch64__)
# define PLAT_arm64_darwin 1
#elif defined(__FreeBSD__) && defined(__i386__)
# define PLAT_x86_freebsd 1
#elif defined(__FreeBSD__) && defined(__amd64__)
Expand Down Expand Up @@ -128,7 +131,7 @@

#elif defined(PLAT_ppc32_linux) || defined(PLAT_ppc64_linux) \
|| defined(PLAT_arm_linux) || defined(PLAT_arm64_linux) \
|| defined(PLAT_arm64_freebsd)
|| defined(PLAT_arm64_freebsd) || defined(PLAT_arm64_darwin)
# if defined(HAVE_BUILTIN_ATOMIC)
# define XCHG_M_R(_addr,_lval) \
do { \
Expand Down
2 changes: 1 addition & 1 deletion none/tests/arm64/atomics_v81.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

#include <stdio.h>
#include <malloc.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>

Expand Down
1 change: 0 additions & 1 deletion none/tests/arm64/crc32.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*/

#include <stdio.h>
#include <malloc.h> // memalign
#include <string.h> // memset
#include <assert.h>

Expand Down
5 changes: 2 additions & 3 deletions none/tests/arm64/integer.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#endif

#include <stdio.h>
#include <malloc.h> // memalign
#include <string.h> // memset
#include <assert.h>

Expand Down Expand Up @@ -317,13 +316,13 @@ TESTINST2("bfm x2, x4, #0, #63", 0xaaaaaaaaaaaaaaaa, x2, x4, 0);

TESTINST3("cmp x4, x5 ; cset x3, ne", 12345LL, 6789LL, x3, x4, x5, 0);
TESTINST3("cmp x4, x5 ; cset x3, eq", 12345LL, 6789LL, x3, x4, x5, 0);

TESTINST3("cmp w4, w5 ; cset x3, ne",
0xAB12345678, 0xCD12345678, x3, x4, x5, 0);

TESTINST3("cmp w4, w5 ; cset x3, eq",
0xCD12345678, 0xCD12345670, x3, x4, x5, 0);

TESTINST3("cmp x4, x5 ; mrs x3, nzcv", 0xdb432311d1e3a1d0, 0xa6325ae016fbd710, x3, x4, x5, 0);
TESTINST3("cmp x4, x5 ; mrs x3, nzcv", 0x192e7217e1ab63b0, 0xfd370f11bfcd4a4a, x3, x4, x5, 0);
TESTINST3("cmp x4, x5 ; mrs x3, nzcv", 0xfd79baaee550b488, 0x5bc94f0d3ee4863a, x3, x4, x5, 0);
Expand Down
4 changes: 2 additions & 2 deletions none/tests/arm64/ldxp_stxp.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#include "tests/malloc.h"
#include <assert.h>

typedef unsigned int UInt;
Expand Down Expand Up @@ -36,7 +36,7 @@ void printBlock ( const char* who,

int main ( void )
{
ULong* block = memalign(16, 6 * sizeof(ULong));
ULong* block = memalign16(6 * sizeof(ULong));
assert(block);

ULong rt1in, rt2in, rt1out, rt2out;
Expand Down
3 changes: 1 addition & 2 deletions none/tests/arm64/memory_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
*/

#include <stdio.h>
#include <malloc.h> // memalign
#include <string.h> // memset
#include "tests/malloc.h"
#include <assert.h>
Expand Down Expand Up @@ -323,7 +322,7 @@ static void show_block_xor ( UChar* block1, UChar* block2, Int n )


// In: rand:
// memory area, xferred vec regs, xferred int regs,
// memory area, xferred vec regs, xferred int regs,
// caller spec:
// addr reg1, addr reg2
//
Expand Down
10 changes: 6 additions & 4 deletions none/tests/faultstatus.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
Check that a fault signal handler gets the expected info
*/
#include <signal.h>
Expand All @@ -23,6 +23,8 @@
# define DIVISION_BY_ZERO_TRIGGERS_FPE 0
#if defined(VGO_freebsd)
# define DIVISION_BY_ZERO_SI_CODE SI_LWP
#elif defined(VGO_darwin)
# define DIVISION_BY_ZERO_SI_CODE FPE_INTDIV
#else
# define DIVISION_BY_ZERO_SI_CODE SI_TKILL
#endif
Expand Down Expand Up @@ -71,7 +73,7 @@ static int testsig(int sig, int want)
if (sig != want) {
fprintf(stderr, " FAIL: expected signal %d, not %d\n", want, sig);
return 0;
}
}
return 1;
}

Expand Down Expand Up @@ -150,7 +152,7 @@ int main()
sa.sa_sigaction = handler;
sa.sa_flags = SA_SIGINFO;
sigfillset(&sa.sa_mask);

for(i = 0; i < sizeof(sigs)/sizeof(*sigs); i++)
sigaction(sigs[i], &sa, NULL);

Expand Down Expand Up @@ -182,7 +184,7 @@ int main()

for(i = 0; i < sizeof(tests)/sizeof(*tests); i++) {
cur_test = &tests[i];

if (sigsetjmp(escape, 1) == 0) {
fprintf(stderr, "Test %d: ", i+1);
tests[i].test();
Expand Down
78 changes: 78 additions & 0 deletions tests/arm64_features.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,84 @@ typedef int Bool;
#define HWCAP2_FRINT (1 << 8)
#endif

#if defined(VGO_darwin)
#include <sys/types.h>
#include <sys/sysctl.h>

#define AT_HWCAP 0
#define AT_HWCAP2 1

#define CHECK_CAP(cap, name) \
(sysctlbyname((name), &hwcap_value, &size, NULL, 0) == 0 && hwcap_value == 1 ? (cap) : 0)

// based on https://github.com/klauspost/cpuid/blob/master/os_darwin_arm64.go
// and my computer `sysctl -a`
unsigned long getauxval(unsigned long type)
{
unsigned long hwcap = 0;
int hwcap_value = 0;
size_t size = 4;

switch (type) {
case AT_HWCAP:
hwcap |= CHECK_CAP(HWCAP_FP, "hw.optional.arm.FEAT_FP");
hwcap |= CHECK_CAP(HWCAP_FP, "hw.optional.floatingpoint"); // double
hwcap |= CHECK_CAP(HWCAP_FP, "hw.optional.arm.FEAT_FP");
hwcap |= CHECK_CAP(HWCAP_ASIMD, "hw.optional.AdvSIMD");
// ??? evtstrm
hwcap |= CHECK_CAP(HWCAP_AES, "hw.optional.arm.FEAT_AES");
hwcap |= CHECK_CAP(HWCAP_PMULL, "hw.optional.arm.FEAT_PMULL");
hwcap |= CHECK_CAP(HWCAP_SHA1, "hw.optional.arm.FEAT_SHA1");
hwcap |= CHECK_CAP(HWCAP_SHA2, "hw.optional.arm.FEAT_SHA256");
hwcap |= CHECK_CAP(HWCAP_CRC32, "hw.optional.FEAT_CRC32");
hwcap |= CHECK_CAP(HWCAP_CRC32, "hw.optional.armv8_crc32"); // double
hwcap |= CHECK_CAP(HWCAP_ATOMICS, "hw.optional.armv8_1_atomics");
hwcap |= CHECK_CAP(HWCAP_FPHP, "hw.optional.arm.FEAT_FP16");
hwcap |= CHECK_CAP(HWCAP_ASIMDHP, "hw.optional.AdvSIMD_HPFPCvt");
// ??? cpuid
hwcap |= CHECK_CAP(HWCAP_ASIMDRDM, "hw.optional.arm.FEAT_RDM");
hwcap |= CHECK_CAP(HWCAP_JSCVT, "hw.optional.arm.FEAT_JSCVT");
hwcap |= CHECK_CAP(HWCAP_FCMA, "hw.optional.arm.FEAT_FCMA");
hwcap |= CHECK_CAP(HWCAP_FCMA, "hw.optional.armv8_3_compnum"); // double
hwcap |= CHECK_CAP(HWCAP_LRCPC, "hw.optional.arm.FEAT_LRCPC");
hwcap |= CHECK_CAP(HWCAP_DCPOP, "hw.optional.arm.FEAT_DPB");
hwcap |= CHECK_CAP(HWCAP_SHA3, "hw.optional.arm.FEAT_SHA3");
hwcap |= CHECK_CAP(HWCAP_SHA3, "hw.optional.armv8_2_sha3"); // double
// ??? sm3
// ??? sm4
hwcap |= CHECK_CAP(HWCAP_ASIMDDP, "hw.optional.arm.FEAT_DotProd");
hwcap |= CHECK_CAP(HWCAP_SHA512, "hw.optional.arm.FEAT_SHA512");
hwcap |= CHECK_CAP(HWCAP_SHA512, "hw.optional.armv8_2_sha512"); // double
hwcap |= CHECK_CAP(HWCAP_SVE, "hw.optional.arm.FEAT_SVE");
// ??? asimdfhm
hwcap |= CHECK_CAP(HWCAP_DIT, "hw.optional.arm.FEAT_DIT");
// ??? uscat
// ??? ilrcpc
hwcap |= CHECK_CAP(HWCAP_FLAGM, "hw.optional.arm.FEAT_FlagM");
hwcap |= CHECK_CAP(HWCAP_SSBS, "hw.optional.arm.FEAT_SSBS");
hwcap |= CHECK_CAP(HWCAP_SB, "hw.optional.arm.FEAT_SB");
// ??? paca
// ??? pacg
return hwcap;
case AT_HWCAP2:
hwcap |= CHECK_CAP(HWCAP2_DCPODP, "hw.optional.arm.FEAT_DPB");
// ??? sve2
// ??? sveaes
// ??? svepmull
// ??? svebitperm
// ??? svesha3
// ??? svesm4
hwcap |= CHECK_CAP(HWCAP2_FLAGM2, "hw.optional.arm.FEAT_FlagM2");
// ??? frint
return hwcap;
default:
return 0UL;
}
}

#undef CHECK_CAP
#endif

unsigned long hwcaps[] = {
HWCAP_FP, HWCAP_ASIMD, HWCAP_EVTSTRM, HWCAP_AES, HWCAP_PMULL,
HWCAP_SHA1, HWCAP_SHA2, HWCAP_CRC32, HWCAP_ATOMICS, HWCAP_FPHP,
Expand Down

0 comments on commit d7e23ba

Please sign in to comment.