#include <string.h>
#include <stdio.h>
#include <asm/ptrace.h>
+#include <assert.h>
#define REG_RISCV_S0 8
#define REG_RISCV_RA 1
unsigned long _get_register_value(int n)
{
- // return g_registers.regs[n];
const static int reg_map[] = {
[UNW_RISCV_X0] = offsetof(struct user_regs_struct, pc) / sizeof(long),
[UNW_RISCV_X1] = offsetof(struct user_regs_struct, ra) / sizeof(long),
[UNW_RISCV_X30] = offsetof(struct user_regs_struct, t5) / sizeof(long),
[UNW_RISCV_X31] = offsetof(struct user_regs_struct, t6) / sizeof(long),
};
+ // XXX: To match with libunwind, UNW_RISCV_PC should be handled as UNW_RISCV_X0.
+ // This is because user_regs_struct holds PC value as the first member of it.
+ // But it is not a proper use of register name. Originally, UNW_RISCV_X0 is used
+ // to get zero value.
+ if (n == UNW_RISCV_PC)
+ n = UNW_RISCV_X0;
+ assert(n >= UNW_RISCV_X0 && n <= UNW_RISCV_X31);
n = reg_map[n];
return ((elf_greg_t*)&g_registers)[n];
}