18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0 28c2ecf20Sopenharmony_ci// Copyright (C) 2019 Hangzhou C-SKY Microsystems co.,ltd. 38c2ecf20Sopenharmony_ci 48c2ecf20Sopenharmony_ci#include <elfutils/libdwfl.h> 58c2ecf20Sopenharmony_ci#include "../../util/unwind-libdw.h" 68c2ecf20Sopenharmony_ci#include "../../util/perf_regs.h" 78c2ecf20Sopenharmony_ci#include "../../util/event.h" 88c2ecf20Sopenharmony_ci 98c2ecf20Sopenharmony_cibool libdw__arch_set_initial_registers(Dwfl_Thread *thread, void *arg) 108c2ecf20Sopenharmony_ci{ 118c2ecf20Sopenharmony_ci struct unwind_info *ui = arg; 128c2ecf20Sopenharmony_ci struct regs_dump *user_regs = &ui->sample->user_regs; 138c2ecf20Sopenharmony_ci Dwarf_Word dwarf_regs[PERF_REG_CSKY_MAX]; 148c2ecf20Sopenharmony_ci 158c2ecf20Sopenharmony_ci#define REG(r) ({ \ 168c2ecf20Sopenharmony_ci Dwarf_Word val = 0; \ 178c2ecf20Sopenharmony_ci perf_reg_value(&val, user_regs, PERF_REG_CSKY_##r); \ 188c2ecf20Sopenharmony_ci val; \ 198c2ecf20Sopenharmony_ci}) 208c2ecf20Sopenharmony_ci 218c2ecf20Sopenharmony_ci#if defined(__CSKYABIV2__) 228c2ecf20Sopenharmony_ci dwarf_regs[0] = REG(A0); 238c2ecf20Sopenharmony_ci dwarf_regs[1] = REG(A1); 248c2ecf20Sopenharmony_ci dwarf_regs[2] = REG(A2); 258c2ecf20Sopenharmony_ci dwarf_regs[3] = REG(A3); 268c2ecf20Sopenharmony_ci dwarf_regs[4] = REG(REGS0); 278c2ecf20Sopenharmony_ci dwarf_regs[5] = REG(REGS1); 288c2ecf20Sopenharmony_ci dwarf_regs[6] = REG(REGS2); 298c2ecf20Sopenharmony_ci dwarf_regs[7] = REG(REGS3); 308c2ecf20Sopenharmony_ci dwarf_regs[8] = REG(REGS4); 318c2ecf20Sopenharmony_ci dwarf_regs[9] = REG(REGS5); 328c2ecf20Sopenharmony_ci dwarf_regs[10] = REG(REGS6); 338c2ecf20Sopenharmony_ci dwarf_regs[11] = REG(REGS7); 348c2ecf20Sopenharmony_ci dwarf_regs[12] = REG(REGS8); 358c2ecf20Sopenharmony_ci dwarf_regs[13] = REG(REGS9); 368c2ecf20Sopenharmony_ci dwarf_regs[14] = REG(SP); 378c2ecf20Sopenharmony_ci dwarf_regs[15] = REG(LR); 388c2ecf20Sopenharmony_ci dwarf_regs[16] = REG(EXREGS0); 398c2ecf20Sopenharmony_ci dwarf_regs[17] = REG(EXREGS1); 408c2ecf20Sopenharmony_ci dwarf_regs[18] = REG(EXREGS2); 418c2ecf20Sopenharmony_ci dwarf_regs[19] = REG(EXREGS3); 428c2ecf20Sopenharmony_ci dwarf_regs[20] = REG(EXREGS4); 438c2ecf20Sopenharmony_ci dwarf_regs[21] = REG(EXREGS5); 448c2ecf20Sopenharmony_ci dwarf_regs[22] = REG(EXREGS6); 458c2ecf20Sopenharmony_ci dwarf_regs[23] = REG(EXREGS7); 468c2ecf20Sopenharmony_ci dwarf_regs[24] = REG(EXREGS8); 478c2ecf20Sopenharmony_ci dwarf_regs[25] = REG(EXREGS9); 488c2ecf20Sopenharmony_ci dwarf_regs[26] = REG(EXREGS10); 498c2ecf20Sopenharmony_ci dwarf_regs[27] = REG(EXREGS11); 508c2ecf20Sopenharmony_ci dwarf_regs[28] = REG(EXREGS12); 518c2ecf20Sopenharmony_ci dwarf_regs[29] = REG(EXREGS13); 528c2ecf20Sopenharmony_ci dwarf_regs[30] = REG(EXREGS14); 538c2ecf20Sopenharmony_ci dwarf_regs[31] = REG(TLS); 548c2ecf20Sopenharmony_ci dwarf_regs[32] = REG(PC); 558c2ecf20Sopenharmony_ci#else 568c2ecf20Sopenharmony_ci dwarf_regs[0] = REG(SP); 578c2ecf20Sopenharmony_ci dwarf_regs[1] = REG(REGS9); 588c2ecf20Sopenharmony_ci dwarf_regs[2] = REG(A0); 598c2ecf20Sopenharmony_ci dwarf_regs[3] = REG(A1); 608c2ecf20Sopenharmony_ci dwarf_regs[4] = REG(A2); 618c2ecf20Sopenharmony_ci dwarf_regs[5] = REG(A3); 628c2ecf20Sopenharmony_ci dwarf_regs[6] = REG(REGS0); 638c2ecf20Sopenharmony_ci dwarf_regs[7] = REG(REGS1); 648c2ecf20Sopenharmony_ci dwarf_regs[8] = REG(REGS2); 658c2ecf20Sopenharmony_ci dwarf_regs[9] = REG(REGS3); 668c2ecf20Sopenharmony_ci dwarf_regs[10] = REG(REGS4); 678c2ecf20Sopenharmony_ci dwarf_regs[11] = REG(REGS5); 688c2ecf20Sopenharmony_ci dwarf_regs[12] = REG(REGS6); 698c2ecf20Sopenharmony_ci dwarf_regs[13] = REG(REGS7); 708c2ecf20Sopenharmony_ci dwarf_regs[14] = REG(REGS8); 718c2ecf20Sopenharmony_ci dwarf_regs[15] = REG(LR); 728c2ecf20Sopenharmony_ci#endif 738c2ecf20Sopenharmony_ci dwfl_thread_state_register_pc(thread, REG(PC)); 748c2ecf20Sopenharmony_ci 758c2ecf20Sopenharmony_ci return dwfl_thread_state_registers(thread, 0, PERF_REG_CSKY_MAX, 768c2ecf20Sopenharmony_ci dwarf_regs); 778c2ecf20Sopenharmony_ci} 78