xref: /linux/tools/perf/util/dwarf-regs-powerpc.c (revision 60675d4ca1ef0857e44eba5849b74a3a998d0c0f)
1*285b523cSIan Rogers // SPDX-License-Identifier: GPL-2.0-or-later
2*285b523cSIan Rogers /*
3*285b523cSIan Rogers  * Mapping of DWARF debug register numbers into register names.
4*285b523cSIan Rogers  *
5*285b523cSIan Rogers  * Copyright (C) 2010 Ian Munsie, IBM Corporation.
6*285b523cSIan Rogers  */
7*285b523cSIan Rogers 
8*285b523cSIan Rogers #include <dwarf-regs.h>
9*285b523cSIan Rogers 
10*285b523cSIan Rogers #define PPC_OP(op)	(((op) >> 26) & 0x3F)
11*285b523cSIan Rogers #define PPC_RA(a)	(((a) >> 16) & 0x1f)
12*285b523cSIan Rogers #define PPC_RT(t)	(((t) >> 21) & 0x1f)
13*285b523cSIan Rogers #define PPC_RB(b)	(((b) >> 11) & 0x1f)
14*285b523cSIan Rogers #define PPC_D(D)	((D) & 0xfffe)
15*285b523cSIan Rogers #define PPC_DS(DS)	((DS) & 0xfffc)
16*285b523cSIan Rogers #define OP_LD	58
17*285b523cSIan Rogers #define OP_STD	62
18*285b523cSIan Rogers 
19*285b523cSIan Rogers static int get_source_reg(u32 raw_insn)
20*285b523cSIan Rogers {
21*285b523cSIan Rogers 	return PPC_RA(raw_insn);
22*285b523cSIan Rogers }
23*285b523cSIan Rogers 
24*285b523cSIan Rogers static int get_target_reg(u32 raw_insn)
25*285b523cSIan Rogers {
26*285b523cSIan Rogers 	return PPC_RT(raw_insn);
27*285b523cSIan Rogers }
28*285b523cSIan Rogers 
29*285b523cSIan Rogers static int get_offset_opcode(u32 raw_insn)
30*285b523cSIan Rogers {
31*285b523cSIan Rogers 	int opcode = PPC_OP(raw_insn);
32*285b523cSIan Rogers 
33*285b523cSIan Rogers 	/* DS- form */
34*285b523cSIan Rogers 	if ((opcode == OP_LD) || (opcode == OP_STD))
35*285b523cSIan Rogers 		return PPC_DS(raw_insn);
36*285b523cSIan Rogers 	else
37*285b523cSIan Rogers 		return PPC_D(raw_insn);
38*285b523cSIan Rogers }
39*285b523cSIan Rogers 
40*285b523cSIan Rogers /*
41*285b523cSIan Rogers  * Fills the required fields for op_loc depending on if it
42*285b523cSIan Rogers  * is a source or target.
43*285b523cSIan Rogers  * D form: ins RT,D(RA) -> src_reg1 = RA, offset = D, dst_reg1 = RT
44*285b523cSIan Rogers  * DS form: ins RT,DS(RA) -> src_reg1 = RA, offset = DS, dst_reg1 = RT
45*285b523cSIan Rogers  * X form: ins RT,RA,RB -> src_reg1 = RA, src_reg2 = RB, dst_reg1 = RT
46*285b523cSIan Rogers  */
47*285b523cSIan Rogers void get_powerpc_regs(u32 raw_insn, int is_source,
48*285b523cSIan Rogers 		struct annotated_op_loc *op_loc)
49*285b523cSIan Rogers {
50*285b523cSIan Rogers 	if (is_source)
51*285b523cSIan Rogers 		op_loc->reg1 = get_source_reg(raw_insn);
52*285b523cSIan Rogers 	else
53*285b523cSIan Rogers 		op_loc->reg1 = get_target_reg(raw_insn);
54*285b523cSIan Rogers 
55*285b523cSIan Rogers 	if (op_loc->multi_regs)
56*285b523cSIan Rogers 		op_loc->reg2 = PPC_RB(raw_insn);
57*285b523cSIan Rogers 
58*285b523cSIan Rogers 	/* TODO: Implement offset handling for X Form */
59*285b523cSIan Rogers 	if ((op_loc->mem_ref) && (PPC_OP(raw_insn) != 31))
60*285b523cSIan Rogers 		op_loc->offset = get_offset_opcode(raw_insn);
61*285b523cSIan Rogers }
62