From: WANG Xuerui <i.qemu@xen0n.name>
To: Song Gao <gaosong@loongson.cn>, qemu-devel@nongnu.org
Cc: Xiaojuan Yang <yangxiaojuan@loongson.cn>
Subject: Re: [PATCH v14 19/26] linux-user: Add LoongArch signal support
Date: Sun, 9 Jan 2022 17:25:32 +0800 [thread overview]
Message-ID: <f67a17fe-9d5f-83e8-99c9-f2413b70ee21@xen0n.name> (raw)
In-Reply-To: <20220106094200.1801206-20-gaosong@loongson.cn>
On 1/6/22 17:41, Song Gao wrote:
> Signed-off-by: Song Gao<gaosong@loongson.cn>
> Signed-off-by: Xiaojuan Yang<yangxiaojuan@loongson.cn>
> ---
> linux-user/loongarch64/signal.c | 198 +++++++++++++++++++++++++
> linux-user/loongarch64/target_signal.h | 13 ++
> 2 files changed, 211 insertions(+)
> create mode 100644 linux-user/loongarch64/signal.c
> create mode 100644 linux-user/loongarch64/target_signal.h
>
> diff --git a/linux-user/loongarch64/signal.c b/linux-user/loongarch64/signal.c
> new file mode 100644
> index 0000000000..9f0e6421b2
> --- /dev/null
> +++ b/linux-user/loongarch64/signal.c
> @@ -0,0 +1,198 @@
> +/* SPDX-License-Identifier: GPL-2.0-or-later */
> +/*
> + * LoongArch emulation of Linux signals
> + *
> + * Copyright (c) 2021 Loongson Technology Corporation Limited
> + */
> +
> +#include "qemu/osdep.h"
> +#include "qemu.h"
> +#include "signal-common.h"
> +#include "user-internals.h"
> +#include "linux-user/trace.h"
> +
> +#define FPU_REG_WIDTH 256
> +union fpureg {
> + uint32_t val32[FPU_REG_WIDTH / 32];
> + uint64_t val64[FPU_REG_WIDTH / 64];
> +};
This is code preemptively added to support the LASX extensions? I
remember the LASX extension in 3A4000/MIPS era uses 256-bit vector
registers just like this.
> +
> +struct target_sigcontext {
> + uint64_t sc_pc;
> + uint64_t sc_regs[32];
> + uint32_t sc_flags;
> + uint32_t sc_fcsr;
> + uint32_t sc_vcsr;
> + uint64_t sc_fcc;
> + uint64_t sc_scr[4];
> + union fpureg sc_fpregs[32] __attribute__((aligned(32)));
> + uint8_t sc_reserved[4096] __attribute__((aligned(16)));
> +};
As Richard pointed out, you need to have this synchronized to the
kernel's definition. It's okay to update after SIMD support lands there,
it's not to be considered code churn.
> +
> +struct target_ucontext {
> + target_ulong tuc_flags;
> + struct target_ucontext *tuc_link;
> + target_stack_t tuc_stack;
> + target_sigset_t tuc_sigmask;
> + uint8_t __unused[1024 / 8 - sizeof(target_sigset_t)];
> + struct target_sigcontext tuc_mcontext;
> +};
> +
> +struct target_rt_sigframe {
> + struct target_siginfo rs_info;
> + struct target_ucontext rs_uc;
> +};
> +
> +static uint64_t read_all_fcc(CPULoongArchState *env)
> +{
> + uint64_t ret = 0;
> +
> + for (int i = 0; i < 8; ++i) {
> + ret |= (uint64_t)env->cf[i] << (i * 8);
> + }
> +
> + return ret;
> +}
> +
> +static void write_all_fcc(CPULoongArchState *env, uint64_t val)
> +{
> + for (int i = 0; i < 8; ++i) {
> + env->cf[i] = (val >> (i * 8)) & 1;
> + }
> +}
> +
> +static inline void setup_sigcontext(CPULoongArchState *env,
> + struct target_sigcontext *sc)
> +{
> + int i;
> +
> + __put_user(env->pc, &sc->sc_pc);
> + __put_user(0, &sc->sc_regs[0]);
> + __put_user(env->fcsr0, &sc->sc_fcsr);
> + __put_user(0, &sc->sc_vcsr);
> + sc->sc_fcc = read_all_fcc(env);
> +
> + for (i = 0; i < 4; ++i) {
> + __put_user(0, &sc->sc_scr[i]);
> + }
> +
> + for (i = 1; i < 32; ++i) {
> + __put_user(env->gpr[i], &sc->sc_regs[i]);
> + }
> +
> + for (i = 0; i < 32; ++i) {
> + __put_user(env->fpr[i], &sc->sc_fpregs[i].val64[0]);
> + }
> +}
> +
> +static inline void
> +restore_sigcontext(CPULoongArchState *env, struct target_sigcontext *sc)
> +{
> + int i;
> +
> + __get_user(env->pc, &sc->sc_pc);
> + __get_user(env->fcsr0, &sc->sc_fcsr);
> + write_all_fcc(env, sc->sc_fcc);
> +
> + for (i = 1; i < 32; ++i) {
> + __get_user(env->gpr[i], &sc->sc_regs[i]);
> + }
> +
> + for (i = 0; i < 32; ++i) {
> + __get_user(env->fpr[i], &sc->sc_fpregs[i].val64[0]);
> + }
> +}
> +
> +/*
> + * Determine which stack to use..
Duplicate period (".").
> + */
> +static inline abi_ulong
> +get_sigframe(struct target_sigaction *ka, CPULoongArchState *env,
> + size_t frame_size)
> +{
> + unsigned long sp;
> +
> + sp = target_sigsp(get_sp_from_cpustate(env) - 32, ka);
> +
> + return (sp - frame_size) & ~15;
> +}
> +
> +void setup_rt_frame(int sig, struct target_sigaction *ka,
> + target_siginfo_t *info,
> + target_sigset_t *set, CPULoongArchState *env)
> +{
> + struct target_rt_sigframe *frame;
> + abi_ulong frame_addr;
> + int i;
> +
> + frame_addr = get_sigframe(ka, env, sizeof(*frame));
> + trace_user_setup_rt_frame(env, frame_addr);
> + if (!lock_user_struct(VERIFY_WRITE, frame, frame_addr, 0)) {
> + goto give_sigsegv;
> + }
> +
> + tswap_siginfo(&frame->rs_info, info);
> +
> + __put_user(0, &frame->rs_uc.tuc_flags);
> + __put_user(0, &frame->rs_uc.tuc_link);
> + target_save_altstack(&frame->rs_uc.tuc_stack, env);
> +
> + setup_sigcontext(env, &frame->rs_uc.tuc_mcontext);
> +
> + for (i = 0; i < TARGET_NSIG_WORDS; i++) {
> + __put_user(set->sig[i], &frame->rs_uc.tuc_sigmask.sig[i]);
> + }
> +
> + env->gpr[4] = sig;
> + env->gpr[5] = frame_addr + offsetof(struct target_rt_sigframe, rs_info);
> + env->gpr[6] = frame_addr + offsetof(struct target_rt_sigframe, rs_uc);
> + env->gpr[3] = frame_addr;
> + env->gpr[1] = default_rt_sigreturn;
> +
> + env->pc = ka->_sa_handler;
> + unlock_user_struct(frame, frame_addr, 1);
> + return;
> +
> +give_sigsegv:
> + unlock_user_struct(frame, frame_addr, 1);
> + force_sigsegv(sig);
> +}
> +
> +long do_rt_sigreturn(CPULoongArchState *env)
> +{
> + struct target_rt_sigframe *frame;
> + abi_ulong frame_addr;
> + sigset_t blocked;
> +
> + frame_addr = env->gpr[3];
> + trace_user_do_rt_sigreturn(env, frame_addr);
> + if (!lock_user_struct(VERIFY_READ, frame, frame_addr, 1)) {
> + goto badframe;
> + }
> +
> + target_to_host_sigset(&blocked, &frame->rs_uc.tuc_sigmask);
> + set_sigmask(&blocked);
> +
> + restore_sigcontext(env, &frame->rs_uc.tuc_mcontext);
> + target_restore_altstack(&frame->rs_uc.tuc_stack, env);
> +
> + unlock_user_struct(frame, frame_addr, 0);
> + return -QEMU_ESIGRETURN;
> +
> +badframe:
> + unlock_user_struct(frame, frame_addr, 0);
> + force_sig(TARGET_SIGSEGV);
> + return -QEMU_ESIGRETURN;
> +}
> +
> +void setup_sigtramp(abi_ulong sigtramp_page)
> +{
> + uint32_t *tramp = lock_user(VERIFY_WRITE, sigtramp_page, 8, 0);
> + assert(tramp != NULL);
> +
> + __put_user(0x03822c0b, tramp + 0); /* ori a7, zero, 0x8b */
> + __put_user(0x002b0000, tramp + 1); /* syscall 0 */
> +
> + default_rt_sigreturn = sigtramp_page;
> + unlock_user(tramp, sigtramp_page, 8);
> +}
> diff --git a/linux-user/loongarch64/target_signal.h b/linux-user/loongarch64/target_signal.h
> new file mode 100644
> index 0000000000..ad3aaffcb4
> --- /dev/null
> +++ b/linux-user/loongarch64/target_signal.h
> @@ -0,0 +1,13 @@
> +/* SPDX-License-Identifier: GPL-2.0-or-later */
> +/*
> + * Copyright (c) 2021 Loongson Technology Corporation Limited
> + */
> +
> +#ifndef LOONGARCH_TARGET_SIGNAL_H
> +#define LOONGARCH_TARGET_SIGNAL_H
> +
> +#include "../generic/signal.h"
> +
> +#define TARGET_ARCH_HAS_SIGTRAMP_PAGE 1
> +
> +#endif /* LOONGARCH_TARGET_SIGNAL_H */
next prev parent reply other threads:[~2022-01-09 9:36 UTC|newest]
Thread overview: 53+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-06 9:41 [PATCH v14 00/26] Add LoongArch linux-user emulation support Song Gao
2022-01-06 9:41 ` [PATCH v14 01/26] target/loongarch: Add README Song Gao
2022-01-09 9:24 ` WANG Xuerui
2022-01-06 9:41 ` [PATCH v14 02/26] target/loongarch: Add core definition Song Gao
2022-01-09 9:25 ` WANG Xuerui
2022-01-09 18:49 ` Richard Henderson
2022-01-10 12:34 ` gaosong
2022-01-10 15:20 ` WANG Xuerui
2022-01-10 13:00 ` gaosong
2022-01-10 15:11 ` WANG Xuerui
2022-01-12 9:28 ` gaosong
2022-01-12 10:17 ` gaosong
2022-01-12 10:26 ` WANG Xuerui
2022-01-06 9:41 ` [PATCH v14 03/26] target/loongarch: Add main translation routines Song Gao
2022-01-09 9:25 ` WANG Xuerui
2022-01-06 9:41 ` [PATCH v14 04/26] target/loongarch: Add fixed point arithmetic instruction translation Song Gao
2022-01-06 9:41 ` [PATCH v14 05/26] target/loongarch: Add fixed point shift " Song Gao
2022-01-06 9:41 ` [PATCH v14 06/26] target/loongarch: Add fixed point bit " Song Gao
2022-01-06 9:41 ` [PATCH v14 07/26] target/loongarch: Add fixed point load/store " Song Gao
2022-01-06 9:41 ` [PATCH v14 08/26] target/loongarch: Add fixed point atomic " Song Gao
2022-01-06 9:41 ` [PATCH v14 09/26] target/loongarch: Add fixed point extra " Song Gao
2022-01-06 9:41 ` [PATCH v14 10/26] target/loongarch: Add floating point arithmetic " Song Gao
2022-01-06 9:41 ` [PATCH v14 11/26] target/loongarch: Add floating point comparison " Song Gao
2022-01-06 9:41 ` [PATCH v14 12/26] target/loongarch: Add floating point conversion " Song Gao
2022-01-06 9:41 ` [PATCH v14 13/26] target/loongarch: Add floating point move " Song Gao
2022-01-06 9:41 ` [PATCH v14 14/26] target/loongarch: Add floating point load/store " Song Gao
2022-01-06 9:41 ` [PATCH v14 15/26] target/loongarch: Add branch " Song Gao
2022-01-06 9:41 ` [PATCH v14 16/26] target/loongarch: Add disassembler Song Gao
2022-01-09 9:25 ` WANG Xuerui
2022-01-09 18:51 ` Richard Henderson
2022-01-06 9:41 ` [PATCH v14 17/26] linux-user: Add LoongArch generic header files Song Gao
2022-01-06 9:41 ` [PATCH v14 18/26] linux-user: Add LoongArch specific structures Song Gao
2022-01-07 4:29 ` Richard Henderson
2022-01-06 9:41 ` [PATCH v14 19/26] linux-user: Add LoongArch signal support Song Gao
2022-01-07 4:58 ` Richard Henderson
2022-01-09 9:25 ` WANG Xuerui [this message]
2022-01-06 9:41 ` [PATCH v14 20/26] linux-user: Add LoongArch elf support Song Gao
2022-01-09 9:25 ` WANG Xuerui
2022-01-06 9:41 ` [PATCH v14 21/26] linux-user: Add LoongArch syscall support Song Gao
2022-01-09 9:25 ` WANG Xuerui
2022-01-06 9:41 ` [PATCH v14 22/26] linux-user: Add LoongArch cpu_loop support Song Gao
2022-01-09 9:25 ` WANG Xuerui
2022-01-06 9:41 ` [PATCH v14 23/26] default-configs: Add loongarch linux-user support Song Gao
2022-01-09 9:25 ` WANG Xuerui
2022-01-06 9:41 ` [PATCH v14 24/26] target/loongarch: Add target build suport Song Gao
2022-01-09 9:25 ` WANG Xuerui
2022-01-06 9:41 ` [PATCH v14 25/26] target/loongarch: 'make check-tcg' support Song Gao
2022-01-09 9:25 ` WANG Xuerui
2022-01-06 9:42 ` [PATCH v14 26/26] scripts: add loongarch64 binfmt config Song Gao
2022-01-09 9:25 ` WANG Xuerui
2022-01-07 5:01 ` [PATCH v14 00/26] Add LoongArch linux-user emulation support Richard Henderson
2022-01-07 7:59 ` gaosong
2022-01-09 5:09 ` WANG Xuerui
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=f67a17fe-9d5f-83e8-99c9-f2413b70ee21@xen0n.name \
--to=i.qemu@xen0n.name \
--cc=gaosong@loongson.cn \
--cc=qemu-devel@nongnu.org \
--cc=yangxiaojuan@loongson.cn \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).