From patchwork Tue May 9 11:20:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Youling Tang X-Patchwork-Id: 68953 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 89DD13857712 for ; Tue, 9 May 2023 11:20:52 +0000 (GMT) X-Original-To: elfutils-devel@sourceware.org Delivered-To: elfutils-devel@sourceware.org Received: from loongson.cn (mail.loongson.cn [114.242.206.163]) by sourceware.org (Postfix) with ESMTP id 28DD53858D37 for ; Tue, 9 May 2023 11:20:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 28DD53858D37 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=loongson.cn Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=loongson.cn Received: from loongson.cn (unknown [113.200.148.30]) by gateway (Coremail) with SMTP id _____8DxyOmILFpk6PQGAA--.11761S3; Tue, 09 May 2023 19:20:40 +0800 (CST) Received: from bogon.localdomain (unknown [113.200.148.30]) by localhost.localdomain (Coremail) with SMTP id AQAAf8Cx08SFLFpkiHhSAA--.17268S2; Tue, 09 May 2023 19:20:37 +0800 (CST) From: Youling Tang To: Mark Wielaard , elfutils-devel@sourceware.org Cc: Hengqi Chen , Liwei Ge Subject: [PATCH v2] backends: Add set_initial_registers_tid callback for LoongArch Date: Tue, 9 May 2023 19:20:31 +0800 Message-Id: <1683631231-5835-1-git-send-email-tangyouling@loongson.cn> X-Mailer: git-send-email 2.1.0 X-CM-TRANSID: AQAAf8Cx08SFLFpkiHhSAA--.17268S2 X-CM-SenderInfo: 5wdqw5prxox03j6o00pqjv00gofq/ X-Coremail-Antispam: 1Uk129KBjvJXoWxXF1kCrWkuw45tr43Cr47CFg_yoWrKFW8pF W3urW5JF18CFZ7Ka93J345Zr1Yqr93Wrn2vF1Sqa1xAr43Zas7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SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: elfutils-devel@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Elfutils-devel mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , Errors-To: elfutils-devel-bounces+patchwork=sourceware.org@sourceware.org Sender: "Elfutils-devel" This patch implements the set_initial_registers_tid hook for LoongArch. Signed-off-by: Liwei Ge Signed-off-by: Youling Tang --- backends/ChangeLog | 6 +++ backends/Makefile.am | 2 +- backends/loongarch_init.c | 1 + backends/loongarch_initreg.c | 88 ++++++++++++++++++++++++++++++++++++ 4 files changed, 96 insertions(+), 1 deletion(-) create mode 100644 backends/loongarch_initreg.c diff --git a/backends/ChangeLog b/backends/ChangeLog index c60d6cdb..ddb4e0af 100644 --- a/backends/ChangeLog +++ b/backends/ChangeLog @@ -1,3 +1,9 @@ +2023-05-09 Youling Tang + + * Makefile.am (loongarch_SRCS): Add loongarch_initreg.c. + * loongarch_initreg.c: New file. + * loongarch_init.c (loongarch_init): Hook set_initial_registers_tid. + 2023-04-07 Youling Tang * Makefile.am (loongarch_SRCS): Add loongarch_corenote.c. diff --git a/backends/Makefile.am b/backends/Makefile.am index c7a953a1..bbb2aac7 100644 --- a/backends/Makefile.am +++ b/backends/Makefile.am @@ -97,7 +97,7 @@ csky_SRCS = csky_attrs.c csky_init.c csky_symbol.c csky_cfi.c \ csky_regs.c csky_initreg.c csky_corenote.c loongarch_SRCS = loongarch_init.c loongarch_symbol.c loongarch_cfi.c \ - loongarch_regs.c loongarch_retval.c \ + loongarch_regs.c loongarch_retval.c loongarch_initreg.c \ loongarch_unwind.c loongarch_corenote.c arc_SRCS = arc_init.c arc_symbol.c diff --git a/backends/loongarch_init.c b/backends/loongarch_init.c index 0b99d113..2f0d46c9 100644 --- a/backends/loongarch_init.c +++ b/backends/loongarch_init.c @@ -54,6 +54,7 @@ loongarch_init (Elf *elf __attribute__ ((unused)), /* gcc/config/ #define DWARF_FRAME_REGISTERS. */ eh->frame_nregs = 74; HOOK (eh, check_special_symbol); + HOOK (eh, set_initial_registers_tid); HOOK (eh, return_value_location); HOOK (eh, unwind); diff --git a/backends/loongarch_initreg.c b/backends/loongarch_initreg.c new file mode 100644 index 00000000..74cb62f5 --- /dev/null +++ b/backends/loongarch_initreg.c @@ -0,0 +1,88 @@ +/* Fetch live process registers from TID. + Copyright (C) 2023 OpenAnolis community LoongArch SIG. + Copyright (C) 2023 Loongson Technology Corporation Limted. + This file is part of elfutils. + + This file is free software; you can redistribute it and/or modify + it under the terms of either + + * the GNU Lesser General Public License as published by the Free + Software Foundation; either version 3 of the License, or (at + your option) any later version + + or + + * the GNU General Public License as published by the Free + Software Foundation; either version 2 of the License, or (at + your option) any later version + + or both in parallel, as here. + + elfutils is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received copies of the GNU General Public License and + the GNU Lesser General Public License along with this program. If + not, see . */ + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include "system.h" +#include +#if defined __loongarch__ && defined __linux__ +# include +# include +# include +#endif + +#define BACKEND loongarch_ +#include "libebl_CPU.h" + +bool +loongarch_set_initial_registers_tid (pid_t tid __attribute__ ((unused)), + ebl_tid_registers_t *setfunc __attribute__ ((unused)), + void *arg __attribute__ ((unused))) +{ +#if !defined __loongarch__ || !defined __linux__ + return false; +#else /* __loongarch__ */ + + /* General registers. */ + struct user_regs_struct gregs; + struct iovec iovec; + iovec.iov_base = &gregs; + iovec.iov_len = sizeof (gregs); + if (ptrace (PTRACE_GETREGSET, tid, NT_PRSTATUS, &iovec) != 0) + return false; + + /* $r0 is constant 0. */ + Dwarf_Word zero = 0; + if (! setfunc (0, 1, &zero, arg)) + return false; + + /* $r1-$r31. */ + if (! setfunc (1, 32, (Dwarf_Word *) &gregs.regs[1], arg)) + return false; + + /* PC. */ + if (! setfunc (-1, 1, (Dwarf_Word *) &gregs.csr_era, arg)) + return false; + + /* Floating-point registers (only 64bits are used). */ + struct user_fp_struct fregs; + iovec.iov_base = &fregs; + iovec.iov_len = sizeof (fregs); + if (ptrace (PTRACE_GETREGSET, tid, NT_FPREGSET, &iovec) != 0) + return false; + + /* $f0-$f31 */ + if (! setfunc (32, 32, (Dwarf_Word *) &fregs.fpr[0], arg)) + return false; + + return true; +#endif /* __loongarch__ */ +}