1 // SPDX-License-Identifier: GPL-2.0+ 2 /* 3 * efi_selftest_exception 4 * 5 * Copyright (c) 2018 Heinrich Schuchardt <xypron.glpk@gmx.de> 6 * 7 * Test the handling of exceptions by trying to execute an undefined 8 * instruction. 9 */ 10 11 #include <efi_selftest.h> 12 13 /** 14 * undefined_instruction() - try to executed an undefined instruction 15 */ 16 static void undefined_instruction(void) 17 { 18 #if defined(CONFIG_ARM) 19 /* 20 * 0xe7f...f. is undefined in ARM mode 21 * 0xde.. is undefined in Thumb mode 22 */ 23 asm volatile (".word 0xe7f7defb\n"); 24 #elif defined(CONFIG_RISCV) 25 asm volatile (".word 0xffffffff\n"); 26 #elif defined(CONFIG_X86) 27 asm volatile (".word 0xffff\n"); 28 #endif 29 } 30 31 /** 32 * execute() - execute unit test 33 * 34 * Return: EFI_ST_SUCCESS for success 35 */ 36 static int execute(void) 37 { 38 undefined_instruction(); 39 40 efi_st_error("An undefined instruction exception was not raised\n"); 41 42 return EFI_ST_FAILURE; 43 } 44 45 EFI_UNIT_TEST(exception) = { 46 .name = "exception", 47 .phase = EFI_EXECUTE_BEFORE_BOOTTIME_EXIT, 48 .execute = execute, 49 .on_request = true, 50 }; 51