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