| Kim Phillips | 0fcb1da | 2016-11-30 09:23:44 -0600 | [diff] [blame] | 1 | #include <sys/types.h> |
| 2 | #include <regex.h> |
| 3 | |
| 4 | struct arm64_annotate { |
| 5 | regex_t call_insn, |
| 6 | jump_insn; |
| 7 | }; |
| 8 | |
| 9 | static 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 | |
| 28 | static 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 | /* bl, blr */ |
| 41 | err = regcomp(&arm->call_insn, "^blr?$", REG_EXTENDED); |
| 42 | if (err) |
| 43 | goto out_free_arm; |
| 44 | /* b, b.cond, br, cbz/cbnz, tbz/tbnz */ |
| 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; |
| Kim Phillips | d1f7b02 | 2017-05-03 13:13:56 +0100 | [diff] [blame] | 53 | arch->objdump.comment_char = '/'; |
| Kim Phillips | 0fcb1da | 2016-11-30 09:23:44 -0600 | [diff] [blame] | 54 | arch->objdump.skip_functions_char = '+'; |
| 55 | return 0; |
| 56 | |
| 57 | out_free_call: |
| 58 | regfree(&arm->call_insn); |
| 59 | out_free_arm: |
| 60 | free(arm); |
| 61 | return -1; |
| 62 | } |