1 /*
2 * Copyright (c) 2023 Institute of Parallel And Distributed Systems (IPADS), Shanghai Jiao Tong University (SJTU)
3 * Licensed under the Mulan PSL v2.
4 * You can use this software according to the terms and conditions of the Mulan PSL v2.
5 * You may obtain a copy of Mulan PSL v2 at:
6 * http://license.coscl.org.cn/MulanPSL2
7 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
8 * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
9 * PURPOSE.
10 * See the Mulan PSL v2 for more details.
11 */
12 #include <mm/extable.h>
13 #include <common/types.h>
14 #include <common/kprint.h>
15
search_extable(vaddr_t addr)16 const struct exception_table_entry *search_extable(vaddr_t addr)
17 {
18 const struct exception_table_entry *e;
19
20 kdebug("searching the extable, start at 0x%lx, end at 0x%lx\n",
21 _extable_start,
22 _extable_end);
23 for (e = _extable_start; e != _extable_end && e->insn != 0; e++) {
24 // kinfo("insn: %lx, fixup: %lx\n", e->insn, e->fixup);
25 if (e->insn == addr) {
26 return e;
27 }
28 }
29
30 return NULL;
31 }
32
fixup_exception(vaddr_t addr,vaddr_t * fix_addr)33 bool fixup_exception(vaddr_t addr, vaddr_t *fix_addr)
34 {
35 const struct exception_table_entry *e;
36
37 e = search_extable(addr);
38 if (!e) {
39 kinfo("fail to fix up exception at address: %lx\n", addr);
40 return false;
41 }
42
43 kdebug("find fixup! fault instr addr: %lx, fix instr addr: %lx\n",
44 addr,
45 e->fixup);
46 *fix_addr = e->fixup;
47
48 return true;
49 }
50