162306a36Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0 262306a36Sopenharmony_ci/* Copyright (C) 2020-2023 Loongson Technology Corporation Limited */ 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/sample.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_LOONGARCH_MAX]; 1562306a36Sopenharmony_ci 1662306a36Sopenharmony_ci#define REG(r) ({ \ 1762306a36Sopenharmony_ci Dwarf_Word val = 0; \ 1862306a36Sopenharmony_ci perf_reg_value(&val, user_regs, PERF_REG_LOONGARCH_##r); \ 1962306a36Sopenharmony_ci val; \ 2062306a36Sopenharmony_ci}) 2162306a36Sopenharmony_ci 2262306a36Sopenharmony_ci dwarf_regs[0] = 0; 2362306a36Sopenharmony_ci dwarf_regs[1] = REG(R1); 2462306a36Sopenharmony_ci dwarf_regs[2] = REG(R2); 2562306a36Sopenharmony_ci dwarf_regs[3] = REG(R3); 2662306a36Sopenharmony_ci dwarf_regs[4] = REG(R4); 2762306a36Sopenharmony_ci dwarf_regs[5] = REG(R5); 2862306a36Sopenharmony_ci dwarf_regs[6] = REG(R6); 2962306a36Sopenharmony_ci dwarf_regs[7] = REG(R7); 3062306a36Sopenharmony_ci dwarf_regs[8] = REG(R8); 3162306a36Sopenharmony_ci dwarf_regs[9] = REG(R9); 3262306a36Sopenharmony_ci dwarf_regs[10] = REG(R10); 3362306a36Sopenharmony_ci dwarf_regs[11] = REG(R11); 3462306a36Sopenharmony_ci dwarf_regs[12] = REG(R12); 3562306a36Sopenharmony_ci dwarf_regs[13] = REG(R13); 3662306a36Sopenharmony_ci dwarf_regs[14] = REG(R14); 3762306a36Sopenharmony_ci dwarf_regs[15] = REG(R15); 3862306a36Sopenharmony_ci dwarf_regs[16] = REG(R16); 3962306a36Sopenharmony_ci dwarf_regs[17] = REG(R17); 4062306a36Sopenharmony_ci dwarf_regs[18] = REG(R18); 4162306a36Sopenharmony_ci dwarf_regs[19] = REG(R19); 4262306a36Sopenharmony_ci dwarf_regs[20] = REG(R20); 4362306a36Sopenharmony_ci dwarf_regs[21] = REG(R21); 4462306a36Sopenharmony_ci dwarf_regs[22] = REG(R22); 4562306a36Sopenharmony_ci dwarf_regs[23] = REG(R23); 4662306a36Sopenharmony_ci dwarf_regs[24] = REG(R24); 4762306a36Sopenharmony_ci dwarf_regs[25] = REG(R25); 4862306a36Sopenharmony_ci dwarf_regs[26] = REG(R26); 4962306a36Sopenharmony_ci dwarf_regs[27] = REG(R27); 5062306a36Sopenharmony_ci dwarf_regs[28] = REG(R28); 5162306a36Sopenharmony_ci dwarf_regs[29] = REG(R29); 5262306a36Sopenharmony_ci dwarf_regs[30] = REG(R30); 5362306a36Sopenharmony_ci dwarf_regs[31] = REG(R31); 5462306a36Sopenharmony_ci dwfl_thread_state_register_pc(thread, REG(PC)); 5562306a36Sopenharmony_ci 5662306a36Sopenharmony_ci return dwfl_thread_state_registers(thread, 0, PERF_REG_LOONGARCH_MAX, dwarf_regs); 5762306a36Sopenharmony_ci} 58