1 // SPDX-License-Identifier: GPL-2.0
2 #include <linux/compiler.h>
7 struct arm64_annotate {
12 static int arm64_mov__parse(struct arch *arch __maybe_unused,
13 struct ins_operands *ops,
14 struct map_symbol *ms __maybe_unused,
15 struct disasm_line *dl __maybe_unused)
17 char *s = strchr(ops->raw, ','), *target, *endptr;
23 ops->source.raw = strdup(ops->raw);
26 if (ops->source.raw == NULL)
30 ops->target.raw = strdup(target);
31 if (ops->target.raw == NULL)
34 ops->target.addr = strtoull(target, &endptr, 16);
38 s = strchr(endptr, '<');
41 endptr = strchr(s + 1, '>');
47 ops->target.name = strdup(s);
50 if (ops->target.name == NULL)
56 zfree(&ops->target.raw);
58 zfree(&ops->source.raw);
62 static int mov__scnprintf(struct ins *ins, char *bf, size_t size,
63 struct ins_operands *ops, int max_ins_name);
65 static struct ins_ops arm64_mov_ops = {
66 .parse = arm64_mov__parse,
67 .scnprintf = mov__scnprintf,
70 static struct ins_ops *arm64__associate_instruction_ops(struct arch *arch, const char *name)
72 struct arm64_annotate *arm = arch->priv;
76 if (!regexec(&arm->jump_insn, name, 2, match, 0))
78 else if (!regexec(&arm->call_insn, name, 2, match, 0))
80 else if (!strcmp(name, "ret"))
85 arch__associate_ins_ops(arch, name, ops);
89 static int arm64__annotate_init(struct arch *arch, char *cpuid __maybe_unused)
91 struct arm64_annotate *arm;
94 if (arch->initialized)
97 arm = zalloc(sizeof(*arm));
102 err = regcomp(&arm->call_insn, "^blr?$", REG_EXTENDED);
105 /* b, b.cond, br, cbz/cbnz, tbz/tbnz */
106 err = regcomp(&arm->jump_insn, "^[ct]?br?\\.?(cc|cs|eq|ge|gt|hi|hs|le|lo|ls|lt|mi|ne|pl|vc|vs)?n?z?$",
111 arch->initialized = true;
113 arch->associate_instruction_ops = arm64__associate_instruction_ops;
114 arch->objdump.comment_char = '/';
115 arch->objdump.skip_functions_char = '+';
116 arch->e_machine = EM_AARCH64;
121 regfree(&arm->call_insn);
124 return SYMBOL_ANNOTATE_ERRNO__ARCH_INIT_REGEXP;