Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 #include <linux/compiler.h>
0003 #include <linux/zalloc.h>
0004 #include <sys/types.h>
0005 #include <regex.h>
0006 #include <stdlib.h>
0007 
0008 struct arm_annotate {
0009     regex_t call_insn,
0010         jump_insn;
0011 };
0012 
0013 static struct ins_ops *arm__associate_instruction_ops(struct arch *arch, const char *name)
0014 {
0015     struct arm_annotate *arm = arch->priv;
0016     struct ins_ops *ops;
0017     regmatch_t match[2];
0018 
0019     if (!regexec(&arm->call_insn, name, 2, match, 0))
0020         ops = &call_ops;
0021     else if (!regexec(&arm->jump_insn, name, 2, match, 0))
0022         ops = &jump_ops;
0023     else
0024         return NULL;
0025 
0026     arch__associate_ins_ops(arch, name, ops);
0027     return ops;
0028 }
0029 
0030 static int arm__annotate_init(struct arch *arch, char *cpuid __maybe_unused)
0031 {
0032     struct arm_annotate *arm;
0033     int err;
0034 
0035     if (arch->initialized)
0036         return 0;
0037 
0038     arm = zalloc(sizeof(*arm));
0039     if (!arm)
0040         return ENOMEM;
0041 
0042 #define ARM_CONDS "(cc|cs|eq|ge|gt|hi|le|ls|lt|mi|ne|pl|vc|vs)"
0043     err = regcomp(&arm->call_insn, "^blx?" ARM_CONDS "?$", REG_EXTENDED);
0044     if (err)
0045         goto out_free_arm;
0046     err = regcomp(&arm->jump_insn, "^bx?" ARM_CONDS "?$", REG_EXTENDED);
0047     if (err)
0048         goto out_free_call;
0049 #undef ARM_CONDS
0050 
0051     arch->initialized = true;
0052     arch->priv    = arm;
0053     arch->associate_instruction_ops   = arm__associate_instruction_ops;
0054     arch->objdump.comment_char    = ';';
0055     arch->objdump.skip_functions_char = '+';
0056     return 0;
0057 
0058 out_free_call:
0059     regfree(&arm->call_insn);
0060 out_free_arm:
0061     free(arm);
0062     return SYMBOL_ANNOTATE_ERRNO__ARCH_INIT_REGEXP;
0063 }