Skip to content

Commit

Permalink
From patchwork series 398399
Browse files Browse the repository at this point in the history
  • Loading branch information
Fox Snowpatch committed Mar 9, 2024
1 parent 484dba3 commit ddaffaa
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 0 deletions.
66 changes: 66 additions & 0 deletions tools/perf/arch/powerpc/annotate/instructions.c
@@ -1,6 +1,65 @@
// SPDX-License-Identifier: GPL-2.0
#include <linux/compiler.h>

/*
* powerpc instruction nmemonic table to associate load/store instructions with
* move_ops. mov_ops is used to identify mem_type to associate instruction with
* data type and offset.
*/
static struct ins powerpc__instructions[] = {
{ .name = "lbz", .ops = &mov_ops, },
{ .name = "lbzx", .ops = &mov_ops, },
{ .name = "lbzu", .ops = &mov_ops, },
{ .name = "lbzux", .ops = &mov_ops, },
{ .name = "lhz", .ops = &mov_ops, },
{ .name = "lhzx", .ops = &mov_ops, },
{ .name = "lhzu", .ops = &mov_ops, },
{ .name = "lhzux", .ops = &mov_ops, },
{ .name = "lha", .ops = &mov_ops, },
{ .name = "lhax", .ops = &mov_ops, },
{ .name = "lhau", .ops = &mov_ops, },
{ .name = "lhaux", .ops = &mov_ops, },
{ .name = "lwz", .ops = &mov_ops, },
{ .name = "lwzx", .ops = &mov_ops, },
{ .name = "lwzu", .ops = &mov_ops, },
{ .name = "lwzux", .ops = &mov_ops, },
{ .name = "lwa", .ops = &mov_ops, },
{ .name = "lwax", .ops = &mov_ops, },
{ .name = "lwaux", .ops = &mov_ops, },
{ .name = "ld", .ops = &mov_ops, },
{ .name = "ldx", .ops = &mov_ops, },
{ .name = "ldu", .ops = &mov_ops, },
{ .name = "ldux", .ops = &mov_ops, },
{ .name = "stb", .ops = &mov_ops, },
{ .name = "stbx", .ops = &mov_ops, },
{ .name = "stbu", .ops = &mov_ops, },
{ .name = "stbux", .ops = &mov_ops, },
{ .name = "sth", .ops = &mov_ops, },
{ .name = "sthx", .ops = &mov_ops, },
{ .name = "sthu", .ops = &mov_ops, },
{ .name = "sthux", .ops = &mov_ops, },
{ .name = "stw", .ops = &mov_ops, },
{ .name = "stwx", .ops = &mov_ops, },
{ .name = "stwu", .ops = &mov_ops, },
{ .name = "stwux", .ops = &mov_ops, },
{ .name = "std", .ops = &mov_ops, },
{ .name = "stdx", .ops = &mov_ops, },
{ .name = "stdu", .ops = &mov_ops, },
{ .name = "stdux", .ops = &mov_ops, },
{ .name = "lhbrx", .ops = &mov_ops, },
{ .name = "sthbrx", .ops = &mov_ops, },
{ .name = "lwbrx", .ops = &mov_ops, },
{ .name = "stwbrx", .ops = &mov_ops, },
{ .name = "ldbrx", .ops = &mov_ops, },
{ .name = "stdbrx", .ops = &mov_ops, },
{ .name = "lmw", .ops = &mov_ops, },
{ .name = "stmw", .ops = &mov_ops, },
{ .name = "lswi", .ops = &mov_ops, },
{ .name = "lswx", .ops = &mov_ops, },
{ .name = "stswi", .ops = &mov_ops, },
{ .name = "stswx", .ops = &mov_ops, },
};

static struct ins_ops *powerpc__associate_instruction_ops(struct arch *arch, const char *name)
{
int i;
Expand Down Expand Up @@ -52,6 +111,13 @@ static struct ins_ops *powerpc__associate_instruction_ops(struct arch *arch, con
static int powerpc__annotate_init(struct arch *arch, char *cpuid __maybe_unused)
{
if (!arch->initialized) {
arch->nr_instructions = ARRAY_SIZE(powerpc__instructions);
arch->instructions = calloc(arch->nr_instructions, sizeof(struct ins));
if (arch->instructions == NULL)
return -ENOMEM;

memcpy(arch->instructions, (struct ins *)powerpc__instructions, sizeof(struct ins) * arch->nr_instructions);
arch->nr_instructions_allocated = arch->nr_instructions;
arch->initialized = true;
arch->associate_instruction_ops = powerpc__associate_instruction_ops;
arch->objdump.comment_char = '#';
Expand Down
29 changes: 29 additions & 0 deletions tools/perf/arch/powerpc/util/dwarf-regs.c
Expand Up @@ -98,3 +98,32 @@ int regs_query_register_offset(const char *name)
return roff->ptregs_offset;
return -EINVAL;
}

struct dwarf_regs_idx {
const char *name;
int idx;
};

static const struct dwarf_regs_idx powerpc_regidx_table[] = {
{ "r0", 0 }, { "r1", 1 }, { "r2", 2 }, { "r3", 3 }, { "r4", 4 },
{ "r5", 5 }, { "r6", 6 }, { "r7", 7 }, { "r8", 8 }, { "r9", 9 },
{ "r10", 10 }, { "r11", 11 }, { "r12", 12 }, { "r13", 13 }, { "r14", 14 },
{ "r15", 15 }, { "r16", 16 }, { "r17", 17 }, { "r18", 18 }, { "r19", 19 },
{ "r20", 20 }, { "r21", 21 }, { "r22", 22 }, { "r23", 23 }, { "r24", 24 },
{ "r25", 25 }, { "r26", 26 }, { "r27", 27 }, { "r27", 27 }, { "r28", 28 },
{ "r29", 29 }, { "r30", 30 }, { "r31", 31 },
};

int get_arch_regnum(const char *name)
{
unsigned int i;

if (*name != 'r')
return -EINVAL;

for (i = 0; i < ARRAY_SIZE(powerpc_regidx_table); i++)
if (!strcmp(powerpc_regidx_table[i].name, name))
return powerpc_regidx_table[i].idx;

return -ENOENT;
}
5 changes: 5 additions & 0 deletions tools/perf/util/annotate.c
Expand Up @@ -206,6 +206,11 @@ static struct arch architectures[] = {
{
.name = "powerpc",
.init = powerpc__annotate_init,
.objdump = {
.comment_char = '#',
.register_char = 'r',
.memory_ref_char = '(',
},
},
{
.name = "riscv64",
Expand Down

0 comments on commit ddaffaa

Please sign in to comment.