qemu/tests/tcg/aarch64/mte-4.c
Richard Henderson 36cd5fbdbf tests/tcg/aarch64: Add mte smoke tests
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Message-id: 20210212184902.1251044-32-richard.henderson@linaro.org
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
2021-02-16 13:17:28 +00:00

46 lines
855 B
C

/*
* Memory tagging, re-reading tag checks.
*
* Copyright (c) 2021 Linaro Ltd
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "mte.h"
void __attribute__((noinline)) tagset(void *p, size_t size)
{
size_t i;
for (i = 0; i < size; i += 16) {
asm("stg %0, [%0]" : : "r"(p + i));
}
}
void __attribute__((noinline)) tagcheck(void *p, size_t size)
{
size_t i;
void *c;
for (i = 0; i < size; i += 16) {
asm("ldg %0, [%1]" : "=r"(c) : "r"(p + i), "0"(p));
assert(c == p);
}
}
int main(int ac, char **av)
{
size_t size = getpagesize() * 4;
long excl = 1;
int *p0, *p1;
enable_mte(PR_MTE_TCF_ASYNC);
p0 = alloc_mte_mem(size);
/* Tag the pointer. */
asm("irg %0,%1,%2" : "=r"(p1) : "r"(p0), "r"(excl));
tagset(p1, size);
tagcheck(p1, size);
return 0;
}