blob: 7dbb9ef7f8d9f4f32b92daa9190af68a592529ad [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
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;
Deepika Bhavnanic249d5e2020-02-06 16:29:45 -060027#endif /* __aarch64__ */
Sandrine Bailleux277fb762019-10-08 12:10:45 +020028}
29
30test_result_t test_mte_leakage(void)
31{
32 SKIP_TEST_IF_AARCH32();
Deepika Bhavnanic249d5e2020-02-06 16:29:45 -060033#ifdef __aarch64__
Sandrine Bailleux277fb762019-10-08 12:10:45 +020034 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;
Deepika Bhavnanic249d5e2020-02-06 16:29:45 -060056#endif /* __aarch64__ */
Sandrine Bailleux277fb762019-10-08 12:10:45 +020057}