File Index
Files and directories
Sign in
FILE

instructions.c

File preview with syntax highlighting.

linux-6.19.14/tools/perf/arch/s390/annotate/instructions.c C
  1// SPDX-License-Identifier: GPL-2.0
  2#include <linux/compiler.h>
  3
  4static int s390_call__parse(struct arch *arch, struct ins_operands *ops,
  5			    struct map_symbol *ms, struct disasm_line *dl __maybe_unused)
  6{
  7	char *endptr, *tok, *name;
  8	struct map *map = ms->map;
  9	struct addr_map_symbol target;
 10
 11	tok = strchr(ops->raw, ',');
 12	if (!tok)
 13		return -1;
 14
 15	ops->target.addr = strtoull(tok + 1, &endptr, 16);
 16
 17	name = strchr(endptr, '<');
 18	if (name == NULL)
 19		return -1;
 20
 21	name++;
 22
 23	if (arch->objdump.skip_functions_char &&
 24	    strchr(name, arch->objdump.skip_functions_char))
 25		return -1;
 26
 27	tok = strchr(name, '>');
 28	if (tok == NULL)
 29		return -1;
 30
 31	*tok = '\0';
 32	ops->target.name = strdup(name);
 33	*tok = '>';
 34
 35	if (ops->target.name == NULL)
 36		return -1;
 37
 38	target = (struct addr_map_symbol) {
 39		.ms = { .map = map__get(map), },
 40		.addr = map__objdump_2mem(map, ops->target.addr),
 41	};
 42
 43	if (maps__find_ams(ms->maps, &target) == 0 &&
 44	    map__rip_2objdump(target.ms.map, map__map_ip(target.ms.map, target.addr)) == ops->target.addr)
 45		ops->target.sym = target.ms.sym;
 46
 47	addr_map_symbol__exit(&target);
 48	return 0;
 49}
 50
 51static struct ins_ops s390_call_ops = {
 52	.parse	   = s390_call__parse,
 53	.scnprintf = call__scnprintf,
 54};
 55
 56static int s390_mov__parse(struct arch *arch __maybe_unused,
 57			   struct ins_operands *ops,
 58			   struct map_symbol *ms __maybe_unused,
 59			   struct disasm_line *dl __maybe_unused)
 60{
 61	char *s = strchr(ops->raw, ','), *target, *endptr;
 62
 63	if (s == NULL)
 64		return -1;
 65
 66	*s = '\0';
 67	ops->source.raw = strdup(ops->raw);
 68	*s = ',';
 69
 70	if (ops->source.raw == NULL)
 71		return -1;
 72
 73	target = ++s;
 74	ops->target.raw = strdup(target);
 75	if (ops->target.raw == NULL)
 76		goto out_free_source;
 77
 78	ops->target.addr = strtoull(target, &endptr, 16);
 79	if (endptr == target)
 80		goto out_free_target;
 81
 82	s = strchr(endptr, '<');
 83	if (s == NULL)
 84		goto out_free_target;
 85	endptr = strchr(s + 1, '>');
 86	if (endptr == NULL)
 87		goto out_free_target;
 88
 89	*endptr = '\0';
 90	ops->target.name = strdup(s + 1);
 91	*endptr = '>';
 92	if (ops->target.name == NULL)
 93		goto out_free_target;
 94
 95	return 0;
 96
 97out_free_target:
 98	zfree(&ops->target.raw);
 99out_free_source:
100	zfree(&ops->source.raw);
101	return -1;
102}
103
104
105static struct ins_ops s390_mov_ops = {
106	.parse	   = s390_mov__parse,
107	.scnprintf = mov__scnprintf,
108};
109
110static struct ins_ops *s390__associate_ins_ops(struct arch *arch, const char *name)
111{
112	struct ins_ops *ops = NULL;
113
114	/* catch all kind of jumps */
115	if (strchr(name, 'j') ||
116	    !strncmp(name, "bct", 3) ||
117	    !strncmp(name, "br", 2))
118		ops = &jump_ops;
119	/* override call/returns */
120	if (!strcmp(name, "bras") ||
121	    !strcmp(name, "brasl") ||
122	    !strcmp(name, "basr"))
123		ops = &s390_call_ops;
124	if (!strcmp(name, "br"))
125		ops = &ret_ops;
126	/* override load/store relative to PC */
127	if (!strcmp(name, "lrl") ||
128	    !strcmp(name, "lgrl") ||
129	    !strcmp(name, "lgfrl") ||
130	    !strcmp(name, "llgfrl") ||
131	    !strcmp(name, "strl") ||
132	    !strcmp(name, "stgrl"))
133		ops = &s390_mov_ops;
134
135	if (ops)
136		arch__associate_ins_ops(arch, name, ops);
137	return ops;
138}
139
140static int s390__cpuid_parse(struct arch *arch, char *cpuid)
141{
142	unsigned int family;
143	char model[16], model_c[16], cpumf_v[16], cpumf_a[16];
144	int ret;
145
146	/*
147	 * cpuid string format:
148	 * "IBM,family,model-capacity,model[,cpum_cf-version,cpum_cf-authorization]"
149	 */
150	ret = sscanf(cpuid, "%*[^,],%u,%[^,],%[^,],%[^,],%s", &family, model_c,
151		     model, cpumf_v, cpumf_a);
152	if (ret >= 2) {
153		arch->family = family;
154		arch->model = 0;
155		return 0;
156	}
157
158	return -1;
159}
160
161static int s390__annotate_init(struct arch *arch, char *cpuid __maybe_unused)
162{
163	int err = 0;
164
165	if (!arch->initialized) {
166		arch->initialized = true;
167		arch->associate_instruction_ops = s390__associate_ins_ops;
168		if (cpuid) {
169			if (s390__cpuid_parse(arch, cpuid))
170				err = SYMBOL_ANNOTATE_ERRNO__ARCH_INIT_CPUID_PARSING;
171		}
172		arch->e_machine = EM_S390;
173		arch->e_flags = 0;
174	}
175
176	return err;
177}
~/ Read-only file preview.