]> git.ipfire.org Git - people/arne_f/kernel.git/blob - tools/perf/arch/arm64/annotate/instructions.c
License cleanup: add SPDX GPL-2.0 license identifier to files with no license
[people/arne_f/kernel.git] / tools / perf / arch / arm64 / annotate / instructions.c
1 // SPDX-License-Identifier: GPL-2.0
2 #include <sys/types.h>
3 #include <regex.h>
4
5 struct arm64_annotate {
6 regex_t call_insn,
7 jump_insn;
8 };
9
10 static struct ins_ops *arm64__associate_instruction_ops(struct arch *arch, const char *name)
11 {
12 struct arm64_annotate *arm = arch->priv;
13 struct ins_ops *ops;
14 regmatch_t match[2];
15
16 if (!regexec(&arm->jump_insn, name, 2, match, 0))
17 ops = &jump_ops;
18 else if (!regexec(&arm->call_insn, name, 2, match, 0))
19 ops = &call_ops;
20 else if (!strcmp(name, "ret"))
21 ops = &ret_ops;
22 else
23 return NULL;
24
25 arch__associate_ins_ops(arch, name, ops);
26 return ops;
27 }
28
29 static int arm64__annotate_init(struct arch *arch)
30 {
31 struct arm64_annotate *arm;
32 int err;
33
34 if (arch->initialized)
35 return 0;
36
37 arm = zalloc(sizeof(*arm));
38 if (!arm)
39 return -1;
40
41 /* bl, blr */
42 err = regcomp(&arm->call_insn, "^blr?$", REG_EXTENDED);
43 if (err)
44 goto out_free_arm;
45 /* b, b.cond, br, cbz/cbnz, tbz/tbnz */
46 err = regcomp(&arm->jump_insn, "^[ct]?br?\\.?(cc|cs|eq|ge|gt|hi|le|ls|lt|mi|ne|pl)?n?z?$",
47 REG_EXTENDED);
48 if (err)
49 goto out_free_call;
50
51 arch->initialized = true;
52 arch->priv = arm;
53 arch->associate_instruction_ops = arm64__associate_instruction_ops;
54 arch->objdump.comment_char = '/';
55 arch->objdump.skip_functions_char = '+';
56 return 0;
57
58 out_free_call:
59 regfree(&arm->call_insn);
60 out_free_arm:
61 free(arm);
62 return -1;
63 }