blob: 76cfb88d7c7c78afa33c60018b29cc0e228fab8d [file] [log] [blame]
Heinrich Schuchardte86d6ce2018-09-26 19:05:58 +02001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * efi_selftest_exception
4 *
5 * Copyright (c) 2018 Heinrich Schuchardt <xypron.glpk@gmx.de>
6 *
Heinrich Schuchardt702e7782018-09-27 20:44:40 +02007 * Test the handling of exceptions by trying to execute an undefined
Heinrich Schuchardte86d6ce2018-09-26 19:05:58 +02008 * instruction.
9 */
10
11#include <efi_selftest.h>
12
13/**
14 * undefined_instruction() - try to executed an undefined instruction
15 */
16static 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 */
36static int execute(void)
37{
38 undefined_instruction();
39
Heinrich Schuchardt702e7782018-09-27 20:44:40 +020040 efi_st_error("An undefined instruction exception was not raised\n");
Heinrich Schuchardte86d6ce2018-09-26 19:05:58 +020041
42 return EFI_ST_FAILURE;
43}
44
45EFI_UNIT_TEST(exception) = {
46 .name = "exception",
47 .phase = EFI_EXECUTE_BEFORE_BOOTTIME_EXIT,
48 .execute = execute,
49 .on_request = true,
50};