Linux Perf
instructions.c
Go to the documentation of this file.
1 // SPDX-License-Identifier: GPL-2.0
2 #include <linux/compiler.h>
3 
4 static int s390_call__parse(struct arch *arch, struct ins_operands *ops,
5  struct map_symbol *ms)
6 {
7  char *endptr, *tok, *name;
8  struct map *map = ms->map;
9  struct addr_map_symbol target = {
10  .map = map,
11  };
12 
13  tok = strchr(ops->raw, ',');
14  if (!tok)
15  return -1;
16 
17  ops->target.addr = strtoull(tok + 1, &endptr, 16);
18 
19  name = strchr(endptr, '<');
20  if (name == NULL)
21  return -1;
22 
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  target.addr = map__objdump_2mem(map, ops->target.addr);
40 
41  if (map_groups__find_ams(&target) == 0 &&
42  map__rip_2objdump(target.map, map->map_ip(target.map, target.addr)) == ops->target.addr)
43  ops->target.sym = target.sym;
44 
45  return 0;
46 }
47 
48 static int call__scnprintf(struct ins *ins, char *bf, size_t size,
49  struct ins_operands *ops);
50 
51 static struct ins_ops s390_call_ops = {
53  .scnprintf = call__scnprintf,
54 };
55 
56 static int s390_mov__parse(struct arch *arch __maybe_unused,
57  struct ins_operands *ops,
58  struct map_symbol *ms __maybe_unused)
59 {
60  char *s = strchr(ops->raw, ','), *target, *endptr;
61 
62  if (s == NULL)
63  return -1;
64 
65  *s = '\0';
66  ops->source.raw = strdup(ops->raw);
67  *s = ',';
68 
69  if (ops->source.raw == NULL)
70  return -1;
71 
72  target = ++s;
73  ops->target.raw = strdup(target);
74  if (ops->target.raw == NULL)
75  goto out_free_source;
76 
77  ops->target.addr = strtoull(target, &endptr, 16);
78  if (endptr == target)
79  goto out_free_target;
80 
81  s = strchr(endptr, '<');
82  if (s == NULL)
83  goto out_free_target;
84  endptr = strchr(s + 1, '>');
85  if (endptr == NULL)
86  goto out_free_target;
87 
88  *endptr = '\0';
89  ops->target.name = strdup(s + 1);
90  *endptr = '>';
91  if (ops->target.name == NULL)
92  goto out_free_target;
93 
94  return 0;
95 
96 out_free_target:
97  zfree(&ops->target.raw);
98 out_free_source:
99  zfree(&ops->source.raw);
100  return -1;
101 }
102 
103 static int mov__scnprintf(struct ins *ins, char *bf, size_t size,
104  struct ins_operands *ops);
105 
106 static struct ins_ops s390_mov_ops = {
108  .scnprintf = mov__scnprintf,
109 };
110 
111 static struct ins_ops *s390__associate_ins_ops(struct arch *arch, const char *name)
112 {
113  struct ins_ops *ops = NULL;
114 
115  /* catch all kind of jumps */
116  if (strchr(name, 'j') ||
117  !strncmp(name, "bct", 3) ||
118  !strncmp(name, "br", 2))
119  ops = &jump_ops;
120  /* override call/returns */
121  if (!strcmp(name, "bras") ||
122  !strcmp(name, "brasl") ||
123  !strcmp(name, "basr"))
124  ops = &s390_call_ops;
125  if (!strcmp(name, "br"))
126  ops = &ret_ops;
127  /* override load/store relative to PC */
128  if (!strcmp(name, "lrl") ||
129  !strcmp(name, "lgrl") ||
130  !strcmp(name, "lgfrl") ||
131  !strcmp(name, "llgfrl") ||
132  !strcmp(name, "strl") ||
133  !strcmp(name, "stgrl"))
134  ops = &s390_mov_ops;
135 
136  if (ops)
137  arch__associate_ins_ops(arch, name, ops);
138  return ops;
139 }
140 
141 static int s390__cpuid_parse(struct arch *arch, char *cpuid)
142 {
143  unsigned int family;
144  char model[16], model_c[16], cpumf_v[16], cpumf_a[16];
145  int ret;
146 
147  /*
148  * cpuid string format:
149  * "IBM,family,model-capacity,model[,cpum_cf-version,cpum_cf-authorization]"
150  */
151  ret = sscanf(cpuid, "%*[^,],%u,%[^,],%[^,],%[^,],%s", &family, model_c,
152  model, cpumf_v, cpumf_a);
153  if (ret >= 2) {
154  arch->family = family;
155  arch->model = 0;
156  return 0;
157  }
158 
159  return -1;
160 }
161 
162 static int s390__annotate_init(struct arch *arch, char *cpuid __maybe_unused)
163 {
164  int err = 0;
165 
166  if (!arch->initialized) {
167  arch->initialized = true;
169  if (cpuid)
170  err = s390__cpuid_parse(arch, cpuid);
171  }
172 
173  return err;
174 }
struct map * map
Definition: symbol.h:185
u64(* map_ip)(struct map *, u64)
Definition: map.h:41
static struct ins_ops jump_ops
Definition: annotate.c:82
char skip_functions_char
Definition: annotate.c:76
size_t size
Definition: evsel.c:60
static int s390__cpuid_parse(struct arch *arch, char *cpuid)
Definition: instructions.c:141
struct map * map
Definition: symbol.h:180
static int s390__annotate_init(struct arch *arch, char *cpuid __maybe_unused)
Definition: instructions.c:162
int int err
Definition: 5sec.c:44
Definition: annotate.h:17
char * raw
Definition: annotate.h:23
struct symbol * sym
Definition: annotate.h:27
static int mov__scnprintf(struct ins *ins, char *bf, size_t size, struct ins_operands *ops)
char * name
Definition: annotate.h:26
unsigned int family
Definition: annotate.c:70
struct arch::@33 objdump
const char * name
static int call__scnprintf(struct ins *ins, char *bf, size_t size, struct ins_operands *ops)
struct ins_ops *(* associate_instruction_ops)(struct arch *arch, const char *name)
Definition: annotate.c:65
struct ins_operands::@35 target
static struct ins_ops s390_call_ops
Definition: instructions.c:51
static int s390_mov__parse(struct arch *arch __maybe_unused, struct ins_operands *ops, struct map_symbol *ms __maybe_unused)
Definition: instructions.c:56
u64 map__objdump_2mem(struct map *map, u64 ip)
Definition: map.c:494
u64 map__rip_2objdump(struct map *map, u64 rip)
Definition: map.c:450
#define zfree(ptr)
Definition: util.h:25
static struct ins_ops * s390__associate_ins_ops(struct arch *arch, const char *name)
Definition: instructions.c:111
unsigned int model
Definition: annotate.c:69
static struct ins_ops s390_mov_ops
Definition: instructions.c:106
Definition: jevents.c:228
int(* parse)(struct arch *arch, struct ins_operands *ops, struct map_symbol *ms)
Definition: annotate.h:50
static struct ins_ops ret_ops
Definition: annotate.c:86
struct symbol * sym
Definition: symbol.h:186
bool initialized
Definition: annotate.c:67
int map_groups__find_ams(struct addr_map_symbol *ams)
Definition: map.c:626
Definition: annotate.c:60
static void cpuid(unsigned int op, unsigned int *a, unsigned int *b, unsigned int *c, unsigned int *d)
Definition: header.c:11
static int arch__associate_ins_ops(struct arch *arch, const char *name, struct ins_ops *ops)
Definition: annotate.c:116
struct ins_operands::@36::@38 source
static int s390_call__parse(struct arch *arch, struct ins_operands *ops, struct map_symbol *ms)
Definition: instructions.c:4
Definition: target.h:8
char * target
Definition: builtin-probe.c:59