162306a36Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0 262306a36Sopenharmony_ci// Copyright (C) 2019 Hangzhou C-SKY Microsystems co.,ltd. 362306a36Sopenharmony_ci 462306a36Sopenharmony_ci#include <elfutils/libdwfl.h> 562306a36Sopenharmony_ci#include "perf_regs.h" 662306a36Sopenharmony_ci#include "../../util/unwind-libdw.h" 762306a36Sopenharmony_ci#include "../../util/perf_regs.h" 862306a36Sopenharmony_ci#include "../../util/event.h" 962306a36Sopenharmony_ci 1062306a36Sopenharmony_cibool libdw__arch_set_initial_registers(Dwfl_Thread *thread, void *arg) 1162306a36Sopenharmony_ci{ 1262306a36Sopenharmony_ci struct unwind_info *ui = arg; 1362306a36Sopenharmony_ci struct regs_dump *user_regs = &ui->sample->user_regs; 1462306a36Sopenharmony_ci Dwarf_Word dwarf_regs[PERF_REG_CSKY_MAX]; 1562306a36Sopenharmony_ci 1662306a36Sopenharmony_ci#define REG(r) ({ \ 1762306a36Sopenharmony_ci Dwarf_Word val = 0; \ 1862306a36Sopenharmony_ci perf_reg_value(&val, user_regs, PERF_REG_CSKY_##r); \ 1962306a36Sopenharmony_ci val; \ 2062306a36Sopenharmony_ci}) 2162306a36Sopenharmony_ci 2262306a36Sopenharmony_ci#if defined(__CSKYABIV2__) 2362306a36Sopenharmony_ci dwarf_regs[0] = REG(A0); 2462306a36Sopenharmony_ci dwarf_regs[1] = REG(A1); 2562306a36Sopenharmony_ci dwarf_regs[2] = REG(A2); 2662306a36Sopenharmony_ci dwarf_regs[3] = REG(A3); 2762306a36Sopenharmony_ci dwarf_regs[4] = REG(REGS0); 2862306a36Sopenharmony_ci dwarf_regs[5] = REG(REGS1); 2962306a36Sopenharmony_ci dwarf_regs[6] = REG(REGS2); 3062306a36Sopenharmony_ci dwarf_regs[7] = REG(REGS3); 3162306a36Sopenharmony_ci dwarf_regs[8] = REG(REGS4); 3262306a36Sopenharmony_ci dwarf_regs[9] = REG(REGS5); 3362306a36Sopenharmony_ci dwarf_regs[10] = REG(REGS6); 3462306a36Sopenharmony_ci dwarf_regs[11] = REG(REGS7); 3562306a36Sopenharmony_ci dwarf_regs[12] = REG(REGS8); 3662306a36Sopenharmony_ci dwarf_regs[13] = REG(REGS9); 3762306a36Sopenharmony_ci dwarf_regs[14] = REG(SP); 3862306a36Sopenharmony_ci dwarf_regs[15] = REG(LR); 3962306a36Sopenharmony_ci dwarf_regs[16] = REG(EXREGS0); 4062306a36Sopenharmony_ci dwarf_regs[17] = REG(EXREGS1); 4162306a36Sopenharmony_ci dwarf_regs[18] = REG(EXREGS2); 4262306a36Sopenharmony_ci dwarf_regs[19] = REG(EXREGS3); 4362306a36Sopenharmony_ci dwarf_regs[20] = REG(EXREGS4); 4462306a36Sopenharmony_ci dwarf_regs[21] = REG(EXREGS5); 4562306a36Sopenharmony_ci dwarf_regs[22] = REG(EXREGS6); 4662306a36Sopenharmony_ci dwarf_regs[23] = REG(EXREGS7); 4762306a36Sopenharmony_ci dwarf_regs[24] = REG(EXREGS8); 4862306a36Sopenharmony_ci dwarf_regs[25] = REG(EXREGS9); 4962306a36Sopenharmony_ci dwarf_regs[26] = REG(EXREGS10); 5062306a36Sopenharmony_ci dwarf_regs[27] = REG(EXREGS11); 5162306a36Sopenharmony_ci dwarf_regs[28] = REG(EXREGS12); 5262306a36Sopenharmony_ci dwarf_regs[29] = REG(EXREGS13); 5362306a36Sopenharmony_ci dwarf_regs[30] = REG(EXREGS14); 5462306a36Sopenharmony_ci dwarf_regs[31] = REG(TLS); 5562306a36Sopenharmony_ci dwarf_regs[32] = REG(PC); 5662306a36Sopenharmony_ci#else 5762306a36Sopenharmony_ci dwarf_regs[0] = REG(SP); 5862306a36Sopenharmony_ci dwarf_regs[1] = REG(REGS9); 5962306a36Sopenharmony_ci dwarf_regs[2] = REG(A0); 6062306a36Sopenharmony_ci dwarf_regs[3] = REG(A1); 6162306a36Sopenharmony_ci dwarf_regs[4] = REG(A2); 6262306a36Sopenharmony_ci dwarf_regs[5] = REG(A3); 6362306a36Sopenharmony_ci dwarf_regs[6] = REG(REGS0); 6462306a36Sopenharmony_ci dwarf_regs[7] = REG(REGS1); 6562306a36Sopenharmony_ci dwarf_regs[8] = REG(REGS2); 6662306a36Sopenharmony_ci dwarf_regs[9] = REG(REGS3); 6762306a36Sopenharmony_ci dwarf_regs[10] = REG(REGS4); 6862306a36Sopenharmony_ci dwarf_regs[11] = REG(REGS5); 6962306a36Sopenharmony_ci dwarf_regs[12] = REG(REGS6); 7062306a36Sopenharmony_ci dwarf_regs[13] = REG(REGS7); 7162306a36Sopenharmony_ci dwarf_regs[14] = REG(REGS8); 7262306a36Sopenharmony_ci dwarf_regs[15] = REG(LR); 7362306a36Sopenharmony_ci#endif 7462306a36Sopenharmony_ci dwfl_thread_state_register_pc(thread, REG(PC)); 7562306a36Sopenharmony_ci 7662306a36Sopenharmony_ci return dwfl_thread_state_registers(thread, 0, PERF_REG_CSKY_MAX, 7762306a36Sopenharmony_ci dwarf_regs); 7862306a36Sopenharmony_ci} 79