Skip to content

Commit 98c7052

Browse files
committed
feat: add support for risc-v
1 parent ce488e5 commit 98c7052

2 files changed

Lines changed: 24 additions & 7 deletions

File tree

app/perfregisterinfo.cpp

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ const int PerfRegisterInfo::s_numRegisters[PerfRegisterInfo::ARCH_INVALID][PerfR
3131
{ 0, 0},
3232
{ 0, 0},
3333
{ 9, 17},
34+
{ 0, 0},
35+
{32, 32},
3436
};
3537

3638
const int PerfRegisterInfo::s_wordWidth[PerfRegisterInfo::ARCH_INVALID][PerfRegisterInfo::s_numAbis] = {
@@ -41,6 +43,8 @@ const int PerfRegisterInfo::s_wordWidth[PerfRegisterInfo::ARCH_INVALID][PerfRegi
4143
{0, 0},
4244
{0, 0},
4345
{4, 8},
46+
{0, 0},
47+
{4, 8},
4448
};
4549

4650
// Perf and Dwarf register layouts are the same for ARM and ARM64
@@ -59,6 +63,9 @@ static int x86_64[] = {0, 3, 2, 1, 4, 5, 6, 7, 16, 17, 18, 19, 20, 21, 22, 23, 8
5963
static int mips[] = { 32, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
6064
18, 19, 20, 21, 22, 23, 24, 25, 28, 29, 30, 31};
6165

66+
static int riscv[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
67+
20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31};
68+
6269
static int none[] = {0};
6370

6471
const int *PerfRegisterInfo::s_perfToDwarf[PerfRegisterInfo::ARCH_INVALID][PerfRegisterInfo::s_numAbis] = {
@@ -70,14 +77,15 @@ const int *PerfRegisterInfo::s_perfToDwarf[PerfRegisterInfo::ARCH_INVALID][PerfR
7077
{none, none },
7178
{x86, x86_64 },
7279
{mips, mips },
80+
{riscv, riscv },
7381
};
7482

7583
const int PerfRegisterInfo::s_perfIp[ARCH_INVALID] = {
76-
15, 32, 0xffff, 0xffff, 0xffff, 0xffff, 8
84+
15, 32, 0xffff, 0xffff, 0xffff, 0xffff, 8, 0xffff, 0
7785
};
7886

7987
const int PerfRegisterInfo::s_perfSp[ARCH_INVALID] = {
80-
13, 31, 0xffff, 0xffff, 0xffff, 0xffff, 7
88+
13, 31, 0xffff, 0xffff, 0xffff, 0xffff, 7, 0xffff, 2
8189
};
8290

8391
const int PerfRegisterInfo::s_dwarfLr[ARCH_INVALID][s_numAbis] = {
@@ -87,7 +95,9 @@ const int PerfRegisterInfo::s_dwarfLr[ARCH_INVALID][s_numAbis] = {
8795
{0xffff, 0xffff},
8896
{0xffff, 0xffff},
8997
{0xffff, 0xffff},
90-
{0xffff, 0xffff}
98+
{0xffff, 0xffff},
99+
{0xffff, 0xffff},
100+
{1, 1}
91101
};
92102

93103
const int PerfRegisterInfo::s_dwarfIp[ARCH_INVALID][s_numAbis] = {
@@ -97,7 +107,9 @@ const int PerfRegisterInfo::s_dwarfIp[ARCH_INVALID][s_numAbis] = {
97107
{0xffff, 0xffff},
98108
{0xffff, 0xffff},
99109
{0xffff, 0xffff},
100-
{8, 16}
110+
{8, 16},
111+
{0xffff, 0xffff},
112+
{0, 0}
101113
};
102114

103115
const int PerfRegisterInfo::s_dummyRegisters[ARCH_INVALID][2] = {
@@ -158,5 +170,8 @@ PerfRegisterInfo::Architecture PerfRegisterInfo::archByName(const QByteArray &na
158170
if (name.startsWith("mips"))
159171
return ARCH_MIPS;
160172

173+
if (name.startsWith("risc"))
174+
return ARCH_RISCV;
175+
161176
return ARCH_INVALID;
162177
}

app/perfregisterinfo.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
class PerfRegisterInfo
2626
{
2727
public:
28-
enum Architecture {
28+
enum Architecture
29+
{
2930
ARCH_ARM = 0,
3031
ARCH_AARCH64,
3132
ARCH_POWERPC,
@@ -34,18 +35,19 @@ class PerfRegisterInfo
3435
ARCH_SPARC,
3536
ARCH_X86,
3637
ARCH_MIPS,
38+
ARCH_RISCV,
3739
ARCH_INVALID
3840
};
3941

4042
static const int s_numAbis = 2; // maybe more for some archs?
4143

42-
static Architecture archByName(const QByteArray &name);
44+
static Architecture archByName(const QByteArray& name);
4345
static const int s_numRegisters[ARCH_INVALID][s_numAbis];
4446
static const int s_wordWidth[ARCH_INVALID][s_numAbis];
4547

4648
// Translation table for converting perf register layout to dwarf register layout
4749
// This is specific to ABI as the different ABIs may have different numbers of registers.
48-
static const int *s_perfToDwarf[ARCH_INVALID][s_numAbis];
50+
static const int* s_perfToDwarf[ARCH_INVALID][s_numAbis];
4951

5052
// location of IP register or equivalent in perf register layout for each arch/abi
5153
// This is not specific to ABI as perf makes sure IP is always in the same spot

0 commit comments

Comments
 (0)