1a47a12beSStefan Roese /* 2a47a12beSStefan Roese * Copyright (C) 1999 Magnus Damm <kieraypc01.p.y.kie.era.ericsson.se> 3a47a12beSStefan Roese * 4a47a12beSStefan Roese * (C) Copyright 2000 5a47a12beSStefan Roese * Wolfgang Denk, DENX Software Engineering, wd@denx.de. 6a47a12beSStefan Roese * 7*1a459660SWolfgang Denk * SPDX-License-Identifier: GPL-2.0+ 8a47a12beSStefan Roese */ 9a47a12beSStefan Roese #include <common.h> 10a47a12beSStefan Roese 11a47a12beSStefan Roese /* 12a47a12beSStefan Roese * The exception table consists of pairs of addresses: the first is the 13a47a12beSStefan Roese * address of an instruction that is allowed to fault, and the second is 14a47a12beSStefan Roese * the address at which the program should continue. No registers are 15a47a12beSStefan Roese * modified, so it is entirely up to the continuation code to figure out 16a47a12beSStefan Roese * what to do. 17a47a12beSStefan Roese * 18a47a12beSStefan Roese * All the routines below use bits of fixup code that are out of line 19a47a12beSStefan Roese * with the main instruction path. This means when everything is well, 20a47a12beSStefan Roese * we don't even have to jump over them. Further, they do not intrude 21a47a12beSStefan Roese * on our cache or tlb entries. 22a47a12beSStefan Roese */ 23a47a12beSStefan Roese 24a47a12beSStefan Roese DECLARE_GLOBAL_DATA_PTR; 25a47a12beSStefan Roese 26a47a12beSStefan Roese struct exception_table_entry 27a47a12beSStefan Roese { 28a47a12beSStefan Roese unsigned long insn, fixup; 29a47a12beSStefan Roese }; 30a47a12beSStefan Roese 31a47a12beSStefan Roese extern const struct exception_table_entry __start___ex_table[]; 32a47a12beSStefan Roese extern const struct exception_table_entry __stop___ex_table[]; 33a47a12beSStefan Roese 34a47a12beSStefan Roese static inline unsigned long 35a47a12beSStefan Roese search_one_table(const struct exception_table_entry *first, 36a47a12beSStefan Roese const struct exception_table_entry *last, 37a47a12beSStefan Roese unsigned long value) 38a47a12beSStefan Roese { 39a47a12beSStefan Roese long diff; 40a47a12beSStefan Roese while (first <= last) { 41a47a12beSStefan Roese diff = first->insn - value; 42a47a12beSStefan Roese if (diff == 0) 43a47a12beSStefan Roese return first->fixup; 44a47a12beSStefan Roese first++; 45a47a12beSStefan Roese } 46a47a12beSStefan Roese 47a47a12beSStefan Roese return 0; 48a47a12beSStefan Roese } 49a47a12beSStefan Roese 50a47a12beSStefan Roese unsigned long 51a47a12beSStefan Roese search_exception_table(unsigned long addr) 52a47a12beSStefan Roese { 53a47a12beSStefan Roese unsigned long ret; 54a47a12beSStefan Roese 55a47a12beSStefan Roese /* There is only the kernel to search. */ 56a47a12beSStefan Roese ret = search_one_table(__start___ex_table, __stop___ex_table-1, addr); 57a47a12beSStefan Roese /* if the serial port does not hang in exception, printf can be used */ 58a47a12beSStefan Roese #if !defined(CONFIG_SYS_SERIAL_HANG_IN_EXCEPTION) 59a47a12beSStefan Roese debug("Bus Fault @ 0x%08lx, fixup 0x%08lx\n", addr, ret); 60a47a12beSStefan Roese #endif 61a47a12beSStefan Roese if (ret) return ret; 62a47a12beSStefan Roese 63a47a12beSStefan Roese return 0; 64a47a12beSStefan Roese } 65