summaryrefslogtreecommitdiff
path: root/lib/exceptions/aarch64
diff options
context:
space:
mode:
authorOlivier Deprez <olivier.deprez@arm.com>2022-01-13 13:44:53 +0000
committerManish Pandey <manish.pandey2@arm.com>2022-02-09 15:34:05 +0000
commitc8f6a6769694c1aed3ba01d649126168f4385eec (patch)
tree5ed7b4995dde50cf2f1808598832ae1bb57f89ae /lib/exceptions/aarch64
parenta7ccb402229b3b9419ec17f311576ffdf1e037b7 (diff)
feat(tftf): introduce handler for synchronous exceptions
Introduce a handler for synchronous exceptions (for aarch64) which currently is treated as unhandled exception. Also, added the capability to allow registering a custom handler by tftf framework to allow graceful exit while doing negative tests. Signed-off-by: Olivier Deprez <olivier.deprez@arm.com> Signed-off-by: Manish Pandey <manish.pandey2@arm.com> Change-Id: I4d8d1f5af9951edfe8f068ce85f7d434b2ec070f
Diffstat (limited to 'lib/exceptions/aarch64')
-rw-r--r--lib/exceptions/aarch64/sync.c45
1 files changed, 45 insertions, 0 deletions
diff --git a/lib/exceptions/aarch64/sync.c b/lib/exceptions/aarch64/sync.c
new file mode 100644
index 0000000..49b6bd8
--- /dev/null
+++ b/lib/exceptions/aarch64/sync.c
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2022, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+#include <stdbool.h>
+
+#include <arch_helpers.h>
+#include <debug.h>
+#include <sync.h>
+
+static exception_handler_t custom_sync_exception_handler;
+
+void register_custom_sync_exception_handler(exception_handler_t handler)
+{
+ custom_sync_exception_handler = handler;
+}
+
+void unregister_custom_sync_exception_handler(void)
+{
+ custom_sync_exception_handler = NULL;
+}
+
+bool tftf_sync_exception_handler(void)
+{
+ uint64_t elr_elx = IS_IN_EL2() ? read_elr_el2() : read_elr_el1();
+ bool resume = false;
+
+ if (custom_sync_exception_handler == NULL) {
+ return false;
+ }
+
+ resume = custom_sync_exception_handler();
+
+ if (resume) {
+ /* Move ELR to next instruction to allow tftf to continue */
+ if (IS_IN_EL2()) {
+ write_elr_el2(elr_elx + 4U);
+ } else {
+ write_elr_el1(elr_elx + 4U);
+ }
+ }
+
+ return resume;
+}