blob: a57514bdb24083fcbd7edd3516206e3fc563deef [file] [log] [blame]
Manish Pandeyd6480772023-02-27 13:23:06 +00001/*
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
Manish V Badarkhe46d02282024-11-18 16:58:37 +000012static serr_exception_handler_t custom_serror_handler;
Manish Pandeyd6480772023-02-27 13:23:06 +000013
Manish V Badarkhe46d02282024-11-18 16:58:37 +000014void register_custom_serror_handler(serr_exception_handler_t handler)
Manish Pandeyd6480772023-02-27 13:23:06 +000015{
16 custom_serror_handler = handler;
17}
18
19void unregister_custom_serror_handler(void)
20{
21 custom_serror_handler = NULL;
22}
23
24bool tftf_serror_handler(void)
25{
Javier Almansa Sobrino7c78f7b2024-10-25 11:44:32 +010026 uint64_t elr_elx = IS_IN_EL2() ? read_elr_el2() : read_elr_el1();
27 bool resume = false;
Manish V Badarkhe46d02282024-11-18 16:58:37 +000028 bool incr_elr_elx = false;
Javier Almansa Sobrino7c78f7b2024-10-25 11:44:32 +010029
Manish Pandeyd6480772023-02-27 13:23:06 +000030 if (custom_serror_handler == NULL) {
31 return false;
32 }
33
Manish V Badarkhe46d02282024-11-18 16:58:37 +000034 resume = custom_serror_handler(&incr_elr_elx);
Javier Almansa Sobrino7c78f7b2024-10-25 11:44:32 +010035
Manish V Badarkhe46d02282024-11-18 16:58:37 +000036 if (resume && incr_elr_elx) {
Javier Almansa Sobrino7c78f7b2024-10-25 11:44:32 +010037 /* Move ELR to next instruction to allow tftf to continue */
38 if (IS_IN_EL2()) {
39 write_elr_el2(elr_elx + 4U);
40 } else {
41 write_elr_el1(elr_elx + 4U);
42 }
43 }
44
45 return resume;
Manish Pandeyd6480772023-02-27 13:23:06 +000046}