blob: 13da667d2d096ed6a62f935c6e6795f179dca1f0 [file] [log] [blame]
Sandrine Bailleux277fb762019-10-08 12:10:45 +02001/*
2 * Copyright (c) 2019, Arm Limited. All rights reserved.
3 *
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();
15#ifdef AARCH64
16 SKIP_TEST_IF_MTE_SUPPORT_LESS_THAN(MTE_IMPLEMENTED_EL0);
17
18 /* irg */
19 __asm__ volatile (".inst 0xD29BD5A9");
20 __asm__ volatile (".inst 0x9ADF1129");
21 /* addg */
22 __asm__ volatile (".inst 0x91800129");
23 /* subg */
24 __asm__ volatile (".inst 0xD1800129");
25
26 return TEST_RESULT_SUCCESS;
27#endif /* AARCH64 */
28}
29
30test_result_t test_mte_leakage(void)
31{
32 SKIP_TEST_IF_AARCH32();
33#ifdef AARCH64
34 smc_args tsp_svc_params;
35 int gcr_el1;
36
37 SKIP_TEST_IF_MTE_SUPPORT_LESS_THAN(MTE_IMPLEMENTED_ELX);
38 SKIP_TEST_IF_TSP_NOT_PRESENT();
39
40 /* We only test gcr_el1 as writes to other MTE registers are ignored */
41 write_gcr_el1(0xdd);
42
43 /* Standard SMC to ADD two numbers */
44 tsp_svc_params.fid = TSP_STD_FID(TSP_ADD);
45 tsp_svc_params.arg1 = 4;
46 tsp_svc_params.arg2 = 6;
47 tftf_smc(&tsp_svc_params);
48
49 gcr_el1 = read_gcr_el1();
50 if (gcr_el1 != 0xdd) {
51 printf("gcr_el1 has changed to %d\n", gcr_el1);
52 return TEST_RESULT_FAIL;
53 }
54
55 return TEST_RESULT_SUCCESS;
56#endif /* AARCH64 */
57}