Heinrich Schuchardt | f16e580 | 2025-04-11 07:32:56 +0200 | [diff] [blame^] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
| 2 | /* |
| 3 | * Check current exception level on ARMv8. |
| 4 | */ |
| 5 | #include <efi_loader.h> |
| 6 | #include <efi_selftest.h> |
| 7 | |
| 8 | /** |
| 9 | * current_exception_level() |
| 10 | * |
| 11 | * Return: current exception level, 0 - 3 |
| 12 | */ |
| 13 | static unsigned int current_exception_level(void) |
| 14 | { |
| 15 | unsigned long el; |
| 16 | |
| 17 | asm volatile ( |
| 18 | "MRS %0, CurrentEL" |
| 19 | : "=r" (el) : : ); |
| 20 | |
| 21 | return (el >> 2) & 0x3; |
| 22 | } |
| 23 | |
| 24 | /** |
| 25 | * execute() - execute test |
| 26 | * |
| 27 | * Check that the exception level is not EL3. |
| 28 | */ |
| 29 | static int execute(void) |
| 30 | { |
| 31 | unsigned int el = current_exception_level(); |
| 32 | |
| 33 | efi_st_printf("Exception level EL%u\n", el); |
| 34 | if (el != 1 && el != 2) { |
| 35 | efi_st_error("EL1 or EL2 expected"); |
| 36 | return EFI_ST_FAILURE; |
| 37 | } |
| 38 | |
| 39 | return EFI_ST_SUCCESS; |
| 40 | } |
| 41 | |
| 42 | EFI_UNIT_TEST(el) = { |
| 43 | .name = "exception level", |
| 44 | .phase = EFI_EXECUTE_BEFORE_BOOTTIME_EXIT, |
| 45 | .execute = execute, |
| 46 | }; |