1 // SPDX-License-Identifier: GPL-2.0
2 #include <linux/compiler.h>
3 #include <linux/zalloc.h>
4 #include <errno.h>
5 #include <sys/types.h>
6 #include <regex.h>
7 #include <stdlib.h>
8
9 struct arm_annotate {
10 regex_t call_insn,
11 jump_insn;
12 };
13
arm__associate_instruction_ops(struct arch * arch,const char * name)14 static struct ins_ops *arm__associate_instruction_ops(struct arch *arch, const char *name)
15 {
16 struct arm_annotate *arm = arch->priv;
17 struct ins_ops *ops;
18 regmatch_t match[2];
19
20 if (!regexec(&arm->call_insn, name, 2, match, 0))
21 ops = &call_ops;
22 else if (!regexec(&arm->jump_insn, name, 2, match, 0))
23 ops = &jump_ops;
24 else
25 return NULL;
26
27 arch__associate_ins_ops(arch, name, ops);
28 return ops;
29 }
30
arm__annotate_init(struct arch * arch,char * cpuid __maybe_unused)31 static int arm__annotate_init(struct arch *arch, char *cpuid __maybe_unused)
32 {
33 struct arm_annotate *arm;
34 int err;
35
36 if (arch->initialized)
37 return 0;
38
39 arm = zalloc(sizeof(*arm));
40 if (!arm)
41 return ENOMEM;
42
43 #define ARM_CONDS "(cc|cs|eq|ge|gt|hi|le|ls|lt|mi|ne|pl|vc|vs)"
44 err = regcomp(&arm->call_insn, "^blx?" ARM_CONDS "?$", REG_EXTENDED);
45 if (err)
46 goto out_free_arm;
47 err = regcomp(&arm->jump_insn, "^bx?" ARM_CONDS "?$", REG_EXTENDED);
48 if (err)
49 goto out_free_call;
50 #undef ARM_CONDS
51
52 arch->initialized = true;
53 arch->priv = arm;
54 arch->associate_instruction_ops = arm__associate_instruction_ops;
55 arch->objdump.comment_char = ';';
56 arch->objdump.skip_functions_char = '+';
57 arch->e_machine = EM_ARM;
58 arch->e_flags = 0;
59 return 0;
60
61 out_free_call:
62 regfree(&arm->call_insn);
63 out_free_arm:
64 free(arm);
65 return SYMBOL_ANNOTATE_ERRNO__ARCH_INIT_REGEXP;
66 }
67