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