From c8f6a6769694c1aed3ba01d649126168f4385eec Mon Sep 17 00:00:00 2001 From: Olivier Deprez Date: Thu, 13 Jan 2022 13:44:53 +0000 Subject: 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 Signed-off-by: Manish Pandey Change-Id: I4d8d1f5af9951edfe8f068ce85f7d434b2ec070f --- lib/exceptions/aarch64/sync.c | 45 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 lib/exceptions/aarch64/sync.c (limited to 'lib/exceptions/aarch64') 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 + +#include +#include +#include + +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; +} -- cgit v1.2.3