summaryrefslogtreecommitdiffstats
path: root/lib/efi_selftest/efi_selftest_exception.c
diff options
context:
space:
mode:
authorHeinrich Schuchardt <xypron.glpk@gmx.de>2018-09-26 19:05:58 +0200
committerAlexander Graf <agraf@suse.de>2018-12-02 21:59:36 +0100
commit1c32bb101026eb8f693544824f015a6c3cfefe60 (patch)
tree1015fcf3856f9f566e3bd360c0f3c35bcba9d749 /lib/efi_selftest/efi_selftest_exception.c
parentf6e7b65380ddebea6f31a8456042074f59c17c98 (diff)
downloadu-boot-1c32bb101026eb8f693544824f015a6c3cfefe60.tar.gz
u-boot-1c32bb101026eb8f693544824f015a6c3cfefe60.tar.xz
u-boot-1c32bb101026eb8f693544824f015a6c3cfefe60.zip
efi_selftest: test handling of exceptions
Test the handling of execptions by trying to execute an undefined instruction. For 32bit ARM we expect \selftest to be listed as loaded image. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Signed-off-by: Alexander Graf <agraf@suse.de>
Diffstat (limited to 'lib/efi_selftest/efi_selftest_exception.c')
-rw-r--r--lib/efi_selftest/efi_selftest_exception.c50
1 files changed, 50 insertions, 0 deletions
diff --git a/lib/efi_selftest/efi_selftest_exception.c b/lib/efi_selftest/efi_selftest_exception.c
new file mode 100644
index 0000000000..2ac1796c3b
--- /dev/null
+++ b/lib/efi_selftest/efi_selftest_exception.c
@@ -0,0 +1,50 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * efi_selftest_exception
+ *
+ * Copyright (c) 2018 Heinrich Schuchardt <xypron.glpk@gmx.de>
+ *
+ * Test the handling of execptions by trying to execute an undefined
+ * instruction.
+ */
+
+#include <efi_selftest.h>
+
+/**
+ * undefined_instruction() - try to executed an undefined instruction
+ */
+static void undefined_instruction(void)
+{
+#if defined(CONFIG_ARM)
+ /*
+ * 0xe7f...f. is undefined in ARM mode
+ * 0xde.. is undefined in Thumb mode
+ */
+ asm volatile (".word 0xe7f7defb\n");
+#elif defined(CONFIG_RISCV)
+ asm volatile (".word 0xffffffff\n");
+#elif defined(CONFIG_X86)
+ asm volatile (".word 0xffff\n");
+#endif
+}
+
+/**
+ * execute() - execute unit test
+ *
+ * Return: EFI_ST_SUCCESS for success
+ */
+static int execute(void)
+{
+ undefined_instruction();
+
+ efi_st_error("An undefined instruction exeption was not raised\n");
+
+ return EFI_ST_FAILURE;
+}
+
+EFI_UNIT_TEST(exception) = {
+ .name = "exception",
+ .phase = EFI_EXECUTE_BEFORE_BOOTTIME_EXIT,
+ .execute = execute,
+ .on_request = true,
+};