18c2ecf20Sopenharmony_ci#ifndef _ASM_X86_INSN_EVAL_H
28c2ecf20Sopenharmony_ci#define _ASM_X86_INSN_EVAL_H
38c2ecf20Sopenharmony_ci/*
48c2ecf20Sopenharmony_ci * A collection of utility functions for x86 instruction analysis to be
58c2ecf20Sopenharmony_ci * used in a kernel context. Useful when, for instance, making sense
68c2ecf20Sopenharmony_ci * of the registers indicated by operands.
78c2ecf20Sopenharmony_ci */
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ci#include <linux/compiler.h>
108c2ecf20Sopenharmony_ci#include <linux/bug.h>
118c2ecf20Sopenharmony_ci#include <linux/err.h>
128c2ecf20Sopenharmony_ci#include <asm/ptrace.h>
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ci#define INSN_CODE_SEG_ADDR_SZ(params) ((params >> 4) & 0xf)
158c2ecf20Sopenharmony_ci#define INSN_CODE_SEG_OPND_SZ(params) (params & 0xf)
168c2ecf20Sopenharmony_ci#define INSN_CODE_SEG_PARAMS(oper_sz, addr_sz) (oper_sz | (addr_sz << 4))
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_cibool insn_has_rep_prefix(struct insn *insn);
198c2ecf20Sopenharmony_civoid __user *insn_get_addr_ref(struct insn *insn, struct pt_regs *regs);
208c2ecf20Sopenharmony_ciint insn_get_modrm_rm_off(struct insn *insn, struct pt_regs *regs);
218c2ecf20Sopenharmony_ciint insn_get_modrm_reg_off(struct insn *insn, struct pt_regs *regs);
228c2ecf20Sopenharmony_ciunsigned long insn_get_seg_base(struct pt_regs *regs, int seg_reg_idx);
238c2ecf20Sopenharmony_ciint insn_get_code_seg_params(struct pt_regs *regs);
248c2ecf20Sopenharmony_ciunsigned long insn_get_effective_ip(struct pt_regs *regs);
258c2ecf20Sopenharmony_ciint insn_fetch_from_user(struct pt_regs *regs,
268c2ecf20Sopenharmony_ci			 unsigned char buf[MAX_INSN_SIZE]);
278c2ecf20Sopenharmony_ciint insn_fetch_from_user_inatomic(struct pt_regs *regs,
288c2ecf20Sopenharmony_ci				  unsigned char buf[MAX_INSN_SIZE]);
298c2ecf20Sopenharmony_cibool insn_decode_from_regs(struct insn *insn, struct pt_regs *regs,
308c2ecf20Sopenharmony_ci			   unsigned char buf[MAX_INSN_SIZE], int buf_size);
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_ci#endif /* _ASM_X86_INSN_EVAL_H */
33