1 // SPDX-License-Identifier: GPL-2.0 2 #ifndef __PERF_UTIL_DISASM_H 3 #define __PERF_UTIL_DISASM_H 4 5 #include "map_symbol.h" 6 7 struct annotation_options; 8 struct disasm_line; 9 struct ins; 10 struct evsel; 11 struct symbol; 12 13 struct arch { 14 const char *name; 15 struct ins *instructions; 16 size_t nr_instructions; 17 size_t nr_instructions_allocated; 18 struct ins_ops *(*associate_instruction_ops)(struct arch *arch, const char *name); 19 bool sorted_instructions; 20 bool initialized; 21 const char *insn_suffix; 22 void *priv; 23 unsigned int model; 24 unsigned int family; 25 int (*init)(struct arch *arch, char *cpuid); 26 bool (*ins_is_fused)(struct arch *arch, const char *ins1, 27 const char *ins2); 28 struct { 29 char comment_char; 30 char skip_functions_char; 31 char register_char; 32 char memory_ref_char; 33 char imm_char; 34 } objdump; 35 }; 36 37 struct ins { 38 const char *name; 39 struct ins_ops *ops; 40 }; 41 42 struct ins_operands { 43 char *raw; 44 struct { 45 char *raw; 46 char *name; 47 struct symbol *sym; 48 u64 addr; 49 s64 offset; 50 bool offset_avail; 51 bool outside; 52 bool multi_regs; 53 } target; 54 union { 55 struct { 56 char *raw; 57 char *name; 58 u64 addr; 59 bool multi_regs; 60 } source; 61 struct { 62 struct ins ins; 63 struct ins_operands *ops; 64 } locked; 65 struct { 66 char *raw_comment; 67 char *raw_func_start; 68 } jump; 69 }; 70 }; 71 72 struct ins_ops { 73 void (*free)(struct ins_operands *ops); 74 int (*parse)(struct arch *arch, struct ins_operands *ops, struct map_symbol *ms); 75 int (*scnprintf)(struct ins *ins, char *bf, size_t size, 76 struct ins_operands *ops, int max_ins_name); 77 }; 78 79 struct annotate_args { 80 struct arch *arch; 81 struct map_symbol ms; 82 struct evsel *evsel; 83 struct annotation_options *options; 84 s64 offset; 85 char *line; 86 int line_nr; 87 char *fileloc; 88 }; 89 90 struct arch *arch__find(const char *name); 91 bool arch__is(struct arch *arch, const char *name); 92 93 struct ins_ops *ins__find(struct arch *arch, const char *name); 94 int ins__scnprintf(struct ins *ins, char *bf, size_t size, 95 struct ins_operands *ops, int max_ins_name); 96 97 bool ins__is_call(const struct ins *ins); 98 bool ins__is_jump(const struct ins *ins); 99 bool ins__is_fused(struct arch *arch, const char *ins1, const char *ins2); 100 bool ins__is_nop(const struct ins *ins); 101 bool ins__is_ret(const struct ins *ins); 102 bool ins__is_lock(const struct ins *ins); 103 104 struct disasm_line *disasm_line__new(struct annotate_args *args); 105 void disasm_line__free(struct disasm_line *dl); 106 107 int disasm_line__scnprintf(struct disasm_line *dl, char *bf, size_t size, 108 bool raw, int max_ins_name); 109 110 int symbol__disassemble(struct symbol *sym, struct annotate_args *args); 111 112 #endif /* __PERF_UTIL_DISASM_H */ 113