xref: /openbmc/qemu/tests/tcg/aarch64/mte-1.c (revision 2f95279a)
1 /*
2  * Memory tagging, basic pass cases.
3  *
4  * Copyright (c) 2021 Linaro Ltd
5  * SPDX-License-Identifier: GPL-2.0-or-later
6  */
7 
8 #include "mte.h"
9 
10 int main(int ac, char **av)
11 {
12     int *p0, *p1, *p2;
13     long c;
14 
15     enable_mte(PR_MTE_TCF_NONE);
16     p0 = alloc_mte_mem(sizeof(*p0));
17 
18     asm("irg %0,%1,%2" : "=r"(p1) : "r"(p0), "r"(1));
19     assert(p1 != p0);
20     asm("subp %0,%1,%2" : "=r"(c) : "r"(p0), "r"(p1));
21     assert(c == 0);
22 
23     asm("stg %0, [%0]" : : "r"(p1));
24     asm("ldg %0, [%1]" : "=r"(p2) : "r"(p0), "0"(p0));
25     assert(p1 == p2);
26 
27     return 0;
28 }
29