Manish Pandey | d648077 | 2023-02-27 13:23:06 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2023, Arm Limited. All rights reserved. |
| 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | #include <stdbool.h> |
| 7 | |
| 8 | #include <arch_helpers.h> |
| 9 | #include <debug.h> |
| 10 | #include <serror.h> |
| 11 | |
| 12 | static exception_handler_t custom_serror_handler; |
| 13 | |
| 14 | void register_custom_serror_handler(exception_handler_t handler) |
| 15 | { |
| 16 | custom_serror_handler = handler; |
| 17 | } |
| 18 | |
| 19 | void unregister_custom_serror_handler(void) |
| 20 | { |
| 21 | custom_serror_handler = NULL; |
| 22 | } |
| 23 | |
| 24 | bool tftf_serror_handler(void) |
| 25 | { |
Javier Almansa Sobrino | 7c78f7b | 2024-10-25 11:44:32 +0100 | [diff] [blame^] | 26 | uint64_t elr_elx = IS_IN_EL2() ? read_elr_el2() : read_elr_el1(); |
| 27 | bool resume = false; |
| 28 | |
Manish Pandey | d648077 | 2023-02-27 13:23:06 +0000 | [diff] [blame] | 29 | if (custom_serror_handler == NULL) { |
| 30 | return false; |
| 31 | } |
| 32 | |
Javier Almansa Sobrino | 7c78f7b | 2024-10-25 11:44:32 +0100 | [diff] [blame^] | 33 | resume = custom_serror_handler(); |
| 34 | |
| 35 | /* |
| 36 | * TODO: if there is a test exepecting an Aync EA and expects to resume, |
| 37 | * then there needs to be additional info from test handler as to whether |
| 38 | * elr can be incremented or not. |
| 39 | */ |
| 40 | if (resume) { |
| 41 | /* Move ELR to next instruction to allow tftf to continue */ |
| 42 | if (IS_IN_EL2()) { |
| 43 | write_elr_el2(elr_elx + 4U); |
| 44 | } else { |
| 45 | write_elr_el1(elr_elx + 4U); |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | return resume; |
Manish Pandey | d648077 | 2023-02-27 13:23:06 +0000 | [diff] [blame] | 50 | } |