aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/util/perf_regs.c
blob: 43168fb0d9a28a1151721cd3379b1d3234fef0ab (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <errno.h>
#include "perf_regs.h"
#include "event.h"

int perf_reg_value(u64 *valp, struct regs_dump *regs, int id)
{
	int i, idx = 0;
	u64 mask = regs->mask;

	if (regs->cache_mask & (1 << id))
		goto out;

	if (!(mask & (1 << id)))
		return -EINVAL;

	for (i = 0; i < id; i++) {
		if (mask & (1 << i))
			idx++;
	}

	regs->cache_mask |= (1 << id);
	regs->cache_regs[id] = regs->regs[idx];

out:
	*valp = regs->cache_regs[id];
	return 0;
}