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)
16 char *s = strchr(ops->raw, ','), *target, *endptr;
22 ops->source.raw = strdup(ops->raw);
25 if (ops->source.raw == NULL)
29 ops->target.raw = strdup(target);
30 if (ops->target.raw == NULL)
33 ops->target.addr = strtoull(target, &endptr, 16);
37 s = strchr(endptr, '<');
40 endptr = strchr(s + 1, '>');
46 ops->target.name = strdup(s);
49 if (ops->target.name == NULL)
55 zfree(&ops->target.raw);
57 zfree(&ops->source.raw);
61 static int mov__scnprintf(struct ins *ins, char *bf, size_t size,
62 struct ins_operands *ops, int max_ins_name);
64 static struct ins_ops arm64_mov_ops = {
65 .parse = arm64_mov__parse,
66 .scnprintf = mov__scnprintf,
69 static struct ins_ops *arm64__associate_instruction_ops(struct arch *arch, const char *name)
71 struct arm64_annotate *arm = arch->priv;
75 if (!regexec(&arm->jump_insn, name, 2, match, 0))
77 else if (!regexec(&arm->call_insn, name, 2, match, 0))
79 else if (!strcmp(name, "ret"))
84 arch__associate_ins_ops(arch, name, ops);
88 static int arm64__annotate_init(struct arch *arch, char *cpuid __maybe_unused)
90 struct arm64_annotate *arm;
93 if (arch->initialized)
96 arm = zalloc(sizeof(*arm));
101 err = regcomp(&arm->call_insn, "^blr?$", REG_EXTENDED);
104 /* b, b.cond, br, cbz/cbnz, tbz/tbnz */
105 err = regcomp(&arm->jump_insn, "^[ct]?br?\\.?(cc|cs|eq|ge|gt|hi|le|ls|lt|mi|ne|pl)?n?z?$",
110 arch->initialized = true;
112 arch->associate_instruction_ops = arm64__associate_instruction_ops;
113 arch->objdump.comment_char = '/';
114 arch->objdump.skip_functions_char = '+';
118 regfree(&arm->call_insn);
121 return SYMBOL_ANNOTATE_ERRNO__ARCH_INIT_REGEXP;