1 // SPDX-License-Identifier: GPL-2.0
2 #include <linux/compiler.h>
6 struct arm64_annotate {
11 static int arm64_mov__parse(struct arch *arch __maybe_unused,
12 struct ins_operands *ops,
13 struct map_symbol *ms __maybe_unused)
15 char *s = strchr(ops->raw, ','), *target, *endptr;
21 ops->source.raw = strdup(ops->raw);
24 if (ops->source.raw == NULL)
28 ops->target.raw = strdup(target);
29 if (ops->target.raw == NULL)
32 ops->target.addr = strtoull(target, &endptr, 16);
36 s = strchr(endptr, '<');
39 endptr = strchr(s + 1, '>');
45 ops->target.name = strdup(s);
48 if (ops->target.name == NULL)
54 zfree(&ops->target.raw);
56 zfree(&ops->source.raw);
60 static int mov__scnprintf(struct ins *ins, char *bf, size_t size,
61 struct ins_operands *ops);
63 static struct ins_ops arm64_mov_ops = {
64 .parse = arm64_mov__parse,
65 .scnprintf = mov__scnprintf,
68 static struct ins_ops *arm64__associate_instruction_ops(struct arch *arch, const char *name)
70 struct arm64_annotate *arm = arch->priv;
74 if (!regexec(&arm->jump_insn, name, 2, match, 0))
76 else if (!regexec(&arm->call_insn, name, 2, match, 0))
78 else if (!strcmp(name, "ret"))
83 arch__associate_ins_ops(arch, name, ops);
87 static int arm64__annotate_init(struct arch *arch, char *cpuid __maybe_unused)
89 struct arm64_annotate *arm;
92 if (arch->initialized)
95 arm = zalloc(sizeof(*arm));
100 err = regcomp(&arm->call_insn, "^blr?$", REG_EXTENDED);
103 /* b, b.cond, br, cbz/cbnz, tbz/tbnz */
104 err = regcomp(&arm->jump_insn, "^[ct]?br?\\.?(cc|cs|eq|ge|gt|hi|le|ls|lt|mi|ne|pl)?n?z?$",
109 arch->initialized = true;
111 arch->associate_instruction_ops = arm64__associate_instruction_ops;
112 arch->objdump.comment_char = '/';
113 arch->objdump.skip_functions_char = '+';
117 regfree(&arm->call_insn);