18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0 28c2ecf20Sopenharmony_ci#include <elfutils/libdwfl.h> 38c2ecf20Sopenharmony_ci#include "../../../util/unwind-libdw.h" 48c2ecf20Sopenharmony_ci#include "../../../util/perf_regs.h" 58c2ecf20Sopenharmony_ci#include "../../../util/event.h" 68c2ecf20Sopenharmony_ci 78c2ecf20Sopenharmony_cibool libdw__arch_set_initial_registers(Dwfl_Thread *thread, void *arg) 88c2ecf20Sopenharmony_ci{ 98c2ecf20Sopenharmony_ci struct unwind_info *ui = arg; 108c2ecf20Sopenharmony_ci struct regs_dump *user_regs = &ui->sample->user_regs; 118c2ecf20Sopenharmony_ci Dwarf_Word dwarf_regs[17]; 128c2ecf20Sopenharmony_ci unsigned nregs; 138c2ecf20Sopenharmony_ci 148c2ecf20Sopenharmony_ci#define REG(r) ({ \ 158c2ecf20Sopenharmony_ci Dwarf_Word val = 0; \ 168c2ecf20Sopenharmony_ci perf_reg_value(&val, user_regs, PERF_REG_X86_##r); \ 178c2ecf20Sopenharmony_ci val; \ 188c2ecf20Sopenharmony_ci}) 198c2ecf20Sopenharmony_ci 208c2ecf20Sopenharmony_ci if (user_regs->abi == PERF_SAMPLE_REGS_ABI_32) { 218c2ecf20Sopenharmony_ci dwarf_regs[0] = REG(AX); 228c2ecf20Sopenharmony_ci dwarf_regs[1] = REG(CX); 238c2ecf20Sopenharmony_ci dwarf_regs[2] = REG(DX); 248c2ecf20Sopenharmony_ci dwarf_regs[3] = REG(BX); 258c2ecf20Sopenharmony_ci dwarf_regs[4] = REG(SP); 268c2ecf20Sopenharmony_ci dwarf_regs[5] = REG(BP); 278c2ecf20Sopenharmony_ci dwarf_regs[6] = REG(SI); 288c2ecf20Sopenharmony_ci dwarf_regs[7] = REG(DI); 298c2ecf20Sopenharmony_ci dwarf_regs[8] = REG(IP); 308c2ecf20Sopenharmony_ci nregs = 9; 318c2ecf20Sopenharmony_ci } else { 328c2ecf20Sopenharmony_ci dwarf_regs[0] = REG(AX); 338c2ecf20Sopenharmony_ci dwarf_regs[1] = REG(DX); 348c2ecf20Sopenharmony_ci dwarf_regs[2] = REG(CX); 358c2ecf20Sopenharmony_ci dwarf_regs[3] = REG(BX); 368c2ecf20Sopenharmony_ci dwarf_regs[4] = REG(SI); 378c2ecf20Sopenharmony_ci dwarf_regs[5] = REG(DI); 388c2ecf20Sopenharmony_ci dwarf_regs[6] = REG(BP); 398c2ecf20Sopenharmony_ci dwarf_regs[7] = REG(SP); 408c2ecf20Sopenharmony_ci dwarf_regs[8] = REG(R8); 418c2ecf20Sopenharmony_ci dwarf_regs[9] = REG(R9); 428c2ecf20Sopenharmony_ci dwarf_regs[10] = REG(R10); 438c2ecf20Sopenharmony_ci dwarf_regs[11] = REG(R11); 448c2ecf20Sopenharmony_ci dwarf_regs[12] = REG(R12); 458c2ecf20Sopenharmony_ci dwarf_regs[13] = REG(R13); 468c2ecf20Sopenharmony_ci dwarf_regs[14] = REG(R14); 478c2ecf20Sopenharmony_ci dwarf_regs[15] = REG(R15); 488c2ecf20Sopenharmony_ci dwarf_regs[16] = REG(IP); 498c2ecf20Sopenharmony_ci nregs = 17; 508c2ecf20Sopenharmony_ci } 518c2ecf20Sopenharmony_ci 528c2ecf20Sopenharmony_ci return dwfl_thread_state_registers(thread, 0, nregs, dwarf_regs); 538c2ecf20Sopenharmony_ci} 54