Sandrine Bailleux | 277fb76 | 2019-10-08 12:10:45 +0200 | [diff] [blame] | 1 | /* |
Deepika Bhavnani | c249d5e | 2020-02-06 16:29:45 -0600 | [diff] [blame] | 2 | * Copyright (c) 2019-2020, Arm Limited. All rights reserved. |
Sandrine Bailleux | 277fb76 | 2019-10-08 12:10:45 +0200 | [diff] [blame] | 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 | |
| 12 | test_result_t test_mte_instructions(void) |
| 13 | { |
| 14 | SKIP_TEST_IF_AARCH32(); |
Deepika Bhavnani | c249d5e | 2020-02-06 16:29:45 -0600 | [diff] [blame] | 15 | #ifdef __aarch64__ |
Sandrine Bailleux | 277fb76 | 2019-10-08 12:10:45 +0200 | [diff] [blame] | 16 | SKIP_TEST_IF_MTE_SUPPORT_LESS_THAN(MTE_IMPLEMENTED_EL0); |
| 17 | |
Alexei Fedorov | e3c3300 | 2020-12-14 15:18:43 +0000 | [diff] [blame^] | 18 | /* |
| 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 Bailleux | 277fb76 | 2019-10-08 12:10:45 +0200 | [diff] [blame] | 34 | |
| 35 | return TEST_RESULT_SUCCESS; |
Deepika Bhavnani | c249d5e | 2020-02-06 16:29:45 -0600 | [diff] [blame] | 36 | #endif /* __aarch64__ */ |
Sandrine Bailleux | 277fb76 | 2019-10-08 12:10:45 +0200 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | test_result_t test_mte_leakage(void) |
| 40 | { |
| 41 | SKIP_TEST_IF_AARCH32(); |
Deepika Bhavnani | c249d5e | 2020-02-06 16:29:45 -0600 | [diff] [blame] | 42 | #ifdef __aarch64__ |
Sandrine Bailleux | 277fb76 | 2019-10-08 12:10:45 +0200 | [diff] [blame] | 43 | 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 Bhavnani | c249d5e | 2020-02-06 16:29:45 -0600 | [diff] [blame] | 65 | #endif /* __aarch64__ */ |
Sandrine Bailleux | 277fb76 | 2019-10-08 12:10:45 +0200 | [diff] [blame] | 66 | } |