blob: 437c5d0459ee1ce8fa06c6aa5263f5a6a9173f88 [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
12static exception_handler_t custom_serror_handler;
13
14void register_custom_serror_handler(exception_handler_t handler)
15{
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;
28
Manish Pandeyd6480772023-02-27 13:23:06 +000029 if (custom_serror_handler == NULL) {
30 return false;
31 }
32
Javier Almansa Sobrino7c78f7b2024-10-25 11:44:32 +010033 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 Pandeyd6480772023-02-27 13:23:06 +000050}