Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 #include <linux/compiler.h>
0003 
0004 static struct ins_ops *powerpc__associate_instruction_ops(struct arch *arch, const char *name)
0005 {
0006     int i;
0007     struct ins_ops *ops;
0008 
0009     /*
0010      * - Interested only if instruction starts with 'b'.
0011      * - Few start with 'b', but aren't branch instructions.
0012      */
0013     if (name[0] != 'b'             ||
0014         !strncmp(name, "bcd", 3)   ||
0015         !strncmp(name, "brinc", 5) ||
0016         !strncmp(name, "bper", 4))
0017         return NULL;
0018 
0019     ops = &jump_ops;
0020 
0021     i = strlen(name) - 1;
0022     if (i < 0)
0023         return NULL;
0024 
0025     /* ignore optional hints at the end of the instructions */
0026     if (name[i] == '+' || name[i] == '-')
0027         i--;
0028 
0029     if (name[i] == 'l' || (name[i] == 'a' && name[i-1] == 'l')) {
0030         /*
0031          * if the instruction ends up with 'l' or 'la', then
0032          * those are considered 'calls' since they update LR.
0033          * ... except for 'bnl' which is branch if not less than
0034          * and the absolute form of the same.
0035          */
0036         if (strcmp(name, "bnl") && strcmp(name, "bnl+") &&
0037             strcmp(name, "bnl-") && strcmp(name, "bnla") &&
0038             strcmp(name, "bnla+") && strcmp(name, "bnla-"))
0039             ops = &call_ops;
0040     }
0041     if (name[i] == 'r' && name[i-1] == 'l')
0042         /*
0043          * instructions ending with 'lr' are considered to be
0044          * return instructions
0045          */
0046         ops = &ret_ops;
0047 
0048     arch__associate_ins_ops(arch, name, ops);
0049     return ops;
0050 }
0051 
0052 static int powerpc__annotate_init(struct arch *arch, char *cpuid __maybe_unused)
0053 {
0054     if (!arch->initialized) {
0055         arch->initialized = true;
0056         arch->associate_instruction_ops = powerpc__associate_instruction_ops;
0057         arch->objdump.comment_char      = '#';
0058     }
0059 
0060     return 0;
0061 }