18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci#ifndef _ASM_X86_EXTABLE_H
38c2ecf20Sopenharmony_ci#define _ASM_X86_EXTABLE_H
48c2ecf20Sopenharmony_ci/*
58c2ecf20Sopenharmony_ci * The exception table consists of triples of addresses relative to the
68c2ecf20Sopenharmony_ci * exception table entry itself. The first address is of an instruction
78c2ecf20Sopenharmony_ci * that is allowed to fault, the second is the target at which the program
88c2ecf20Sopenharmony_ci * should continue. The third is a handler function to deal with the fault
98c2ecf20Sopenharmony_ci * caused by the instruction in the first field.
108c2ecf20Sopenharmony_ci *
118c2ecf20Sopenharmony_ci * All the routines below use bits of fixup code that are out of line
128c2ecf20Sopenharmony_ci * with the main instruction path.  This means when everything is well,
138c2ecf20Sopenharmony_ci * we don't even have to jump over them.  Further, they do not intrude
148c2ecf20Sopenharmony_ci * on our cache or tlb entries.
158c2ecf20Sopenharmony_ci */
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_cistruct exception_table_entry {
188c2ecf20Sopenharmony_ci	int insn, fixup, handler;
198c2ecf20Sopenharmony_ci};
208c2ecf20Sopenharmony_cistruct pt_regs;
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_ci#define ARCH_HAS_RELATIVE_EXTABLE
238c2ecf20Sopenharmony_ci
248c2ecf20Sopenharmony_ci#define swap_ex_entry_fixup(a, b, tmp, delta)			\
258c2ecf20Sopenharmony_ci	do {							\
268c2ecf20Sopenharmony_ci		(a)->fixup = (b)->fixup + (delta);		\
278c2ecf20Sopenharmony_ci		(b)->fixup = (tmp).fixup - (delta);		\
288c2ecf20Sopenharmony_ci		(a)->handler = (b)->handler + (delta);		\
298c2ecf20Sopenharmony_ci		(b)->handler = (tmp).handler - (delta);		\
308c2ecf20Sopenharmony_ci	} while (0)
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_cienum handler_type {
338c2ecf20Sopenharmony_ci	EX_HANDLER_NONE,
348c2ecf20Sopenharmony_ci	EX_HANDLER_FAULT,
358c2ecf20Sopenharmony_ci	EX_HANDLER_UACCESS,
368c2ecf20Sopenharmony_ci	EX_HANDLER_OTHER
378c2ecf20Sopenharmony_ci};
388c2ecf20Sopenharmony_ci
398c2ecf20Sopenharmony_ciextern int fixup_exception(struct pt_regs *regs, int trapnr,
408c2ecf20Sopenharmony_ci			   unsigned long error_code, unsigned long fault_addr);
418c2ecf20Sopenharmony_ciextern int fixup_bug(struct pt_regs *regs, int trapnr);
428c2ecf20Sopenharmony_ciextern enum handler_type ex_get_fault_handler_type(unsigned long ip);
438c2ecf20Sopenharmony_ciextern void early_fixup_exception(struct pt_regs *regs, int trapnr);
448c2ecf20Sopenharmony_ci
458c2ecf20Sopenharmony_ci#endif
46