~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/perf/arch/loongarch/annotate/instructions.c

Version: ~ [ linux-6.11-rc3 ] ~ [ linux-6.10.4 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.45 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.104 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.164 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.223 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.281 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.319 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0
  2 /*
  3  * Perf annotate functions.
  4  *
  5  * Copyright (C) 2020-2023 Loongson Technology Corporation Limited
  6  */
  7 
  8 static int loongarch_call__parse(struct arch *arch, struct ins_operands *ops, struct map_symbol *ms)
  9 {
 10         char *c, *endptr, *tok, *name;
 11         struct map *map = ms->map;
 12         struct addr_map_symbol target = {
 13                 .ms = { .map = map, },
 14         };
 15 
 16         c = strchr(ops->raw, '#');
 17         if (c++ == NULL)
 18                 return -1;
 19 
 20         ops->target.addr = strtoull(c, &endptr, 16);
 21 
 22         name = strchr(endptr, '<');
 23         name++;
 24 
 25         if (arch->objdump.skip_functions_char &&
 26             strchr(name, arch->objdump.skip_functions_char))
 27                 return -1;
 28 
 29         tok = strchr(name, '>');
 30         if (tok == NULL)
 31                 return -1;
 32 
 33         *tok = '\0';
 34         ops->target.name = strdup(name);
 35         *tok = '>';
 36 
 37         if (ops->target.name == NULL)
 38                 return -1;
 39 
 40         target.addr = map__objdump_2mem(map, ops->target.addr);
 41 
 42         if (maps__find_ams(ms->maps, &target) == 0 &&
 43             map__rip_2objdump(target.ms.map, map__map_ip(target.ms.map, target.addr)) == ops->target.addr)
 44                 ops->target.sym = target.ms.sym;
 45 
 46         return 0;
 47 }
 48 
 49 static struct ins_ops loongarch_call_ops = {
 50         .parse     = loongarch_call__parse,
 51         .scnprintf = call__scnprintf,
 52 };
 53 
 54 static int loongarch_jump__parse(struct arch *arch, struct ins_operands *ops, struct map_symbol *ms)
 55 {
 56         struct map *map = ms->map;
 57         struct symbol *sym = ms->sym;
 58         struct addr_map_symbol target = {
 59                 .ms = { .map = map, },
 60         };
 61         const char *c = strchr(ops->raw, '#');
 62         u64 start, end;
 63 
 64         ops->jump.raw_comment = strchr(ops->raw, arch->objdump.comment_char);
 65         ops->jump.raw_func_start = strchr(ops->raw, '<');
 66 
 67         if (ops->jump.raw_func_start && c > ops->jump.raw_func_start)
 68                 c = NULL;
 69 
 70         if (c++ != NULL)
 71                 ops->target.addr = strtoull(c, NULL, 16);
 72         else
 73                 ops->target.addr = strtoull(ops->raw, NULL, 16);
 74 
 75         target.addr = map__objdump_2mem(map, ops->target.addr);
 76         start = map__unmap_ip(map, sym->start);
 77         end = map__unmap_ip(map, sym->end);
 78 
 79         ops->target.outside = target.addr < start || target.addr > end;
 80 
 81         if (maps__find_ams(ms->maps, &target) == 0 &&
 82             map__rip_2objdump(target.ms.map, map__map_ip(target.ms.map, target.addr)) == ops->target.addr)
 83                 ops->target.sym = target.ms.sym;
 84 
 85         if (!ops->target.outside) {
 86                 ops->target.offset = target.addr - start;
 87                 ops->target.offset_avail = true;
 88         } else {
 89                 ops->target.offset_avail = false;
 90         }
 91 
 92         return 0;
 93 }
 94 
 95 static struct ins_ops loongarch_jump_ops = {
 96         .parse     = loongarch_jump__parse,
 97         .scnprintf = jump__scnprintf,
 98 };
 99 
100 static
101 struct ins_ops *loongarch__associate_ins_ops(struct arch *arch, const char *name)
102 {
103         struct ins_ops *ops = NULL;
104 
105         if (!strcmp(name, "bl"))
106                 ops = &loongarch_call_ops;
107         else if (!strcmp(name, "jirl"))
108                 ops = &ret_ops;
109         else if (!strcmp(name, "b") ||
110                  !strncmp(name, "beq", 3) ||
111                  !strncmp(name, "bne", 3) ||
112                  !strncmp(name, "blt", 3) ||
113                  !strncmp(name, "bge", 3) ||
114                  !strncmp(name, "bltu", 4) ||
115                  !strncmp(name, "bgeu", 4))
116                 ops = &loongarch_jump_ops;
117         else
118                 return NULL;
119 
120         arch__associate_ins_ops(arch, name, ops);
121 
122         return ops;
123 }
124 
125 static
126 int loongarch__annotate_init(struct arch *arch, char *cpuid __maybe_unused)
127 {
128         if (!arch->initialized) {
129                 arch->associate_instruction_ops = loongarch__associate_ins_ops;
130                 arch->initialized = true;
131                 arch->objdump.comment_char = '#';
132         }
133 
134         return 0;
135 }
136 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php