blob: a2e8d995975158e23bf8873a913bf0804ed90cc4 [file] [log] [blame]
Sandrine Bailleux277fb762019-10-08 12:10:45 +02001/*
Deepika Bhavnanic249d5e2020-02-06 16:29:45 -06002 * Copyright (c) 2019-2020, Arm Limited. All rights reserved.
Sandrine Bailleux277fb762019-10-08 12:10:45 +02003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include <tftf.h>
8#include <tftf_lib.h>
9#include <tsp.h>
10#include <test_helpers.h>
11
12test_result_t test_mte_instructions(void)
13{
14 SKIP_TEST_IF_AARCH32();
Deepika Bhavnanic249d5e2020-02-06 16:29:45 -060015#ifdef __aarch64__
Sandrine Bailleux277fb762019-10-08 12:10:45 +020016 SKIP_TEST_IF_MTE_SUPPORT_LESS_THAN(MTE_IMPLEMENTED_EL0);
17
Alexei Fedorove3c33002020-12-14 15:18:43 +000018 /*
19 * This code must be compiled with '-march=armv8.5-memtag' option
20 * by setting 'ARM_ARCH_FEATURE=memtag' and 'ARM_ARCH_MINOR=5'
21 * build flags in tftf_config/fvp-cpu-extensions when this CI
22 * configuration is built separately.
23 * Otherwise this compiler's option must be specified explicitly.
24 *
25 * Execute Memory Tagging Extension instructions.
26 */
27 __asm__ volatile (
28 ".arch armv8.5-a+memtag\n"
29 "mov x0, #0xDEAD\n"
30 "irg x0, x0\n"
31 "addg x0, x0, #0x0, #0x0\n"
32 "subg x0, x0, #0x0, #0x0"
33 );
Sandrine Bailleux277fb762019-10-08 12:10:45 +020034
35 return TEST_RESULT_SUCCESS;
Deepika Bhavnanic249d5e2020-02-06 16:29:45 -060036#endif /* __aarch64__ */
Sandrine Bailleux277fb762019-10-08 12:10:45 +020037}
38
39test_result_t test_mte_leakage(void)
40{
41 SKIP_TEST_IF_AARCH32();
Deepika Bhavnanic249d5e2020-02-06 16:29:45 -060042#ifdef __aarch64__
Sandrine Bailleux277fb762019-10-08 12:10:45 +020043 smc_args tsp_svc_params;
44 int gcr_el1;
45
46 SKIP_TEST_IF_MTE_SUPPORT_LESS_THAN(MTE_IMPLEMENTED_ELX);
47 SKIP_TEST_IF_TSP_NOT_PRESENT();
48
49 /* We only test gcr_el1 as writes to other MTE registers are ignored */
50 write_gcr_el1(0xdd);
51
52 /* Standard SMC to ADD two numbers */
53 tsp_svc_params.fid = TSP_STD_FID(TSP_ADD);
54 tsp_svc_params.arg1 = 4;
55 tsp_svc_params.arg2 = 6;
56 tftf_smc(&tsp_svc_params);
57
58 gcr_el1 = read_gcr_el1();
59 if (gcr_el1 != 0xdd) {
60 printf("gcr_el1 has changed to %d\n", gcr_el1);
61 return TEST_RESULT_FAIL;
62 }
63
64 return TEST_RESULT_SUCCESS;
Deepika Bhavnanic249d5e2020-02-06 16:29:45 -060065#endif /* __aarch64__ */
Sandrine Bailleux277fb762019-10-08 12:10:45 +020066}