From patchwork Fri May 27 13:00:02 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Riku Voipio X-Patchwork-Id: 9138341 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id A1D866075C for ; Fri, 27 May 2016 13:18:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 932B527CB1 for ; Fri, 27 May 2016 13:18:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 85EE725D91; Fri, 27 May 2016 13:18:45 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, FSL_HELO_HOME, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 0253425D91 for ; Fri, 27 May 2016 13:18:45 +0000 (UTC) Received: from localhost ([::1]:45777 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b6Hf2-0007k6-3U for patchwork-qemu-devel@patchwork.kernel.org; Fri, 27 May 2016 09:18:44 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37307) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b6HNm-0007Ph-UD for qemu-devel@nongnu.org; Fri, 27 May 2016 09:00:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b6HNf-0001Ak-US for qemu-devel@nongnu.org; Fri, 27 May 2016 09:00:53 -0400 Received: from mail-lb0-x22a.google.com ([2a00:1450:4010:c04::22a]:36519) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b6HNf-0001AJ-Cn for qemu-devel@nongnu.org; Fri, 27 May 2016 09:00:47 -0400 Received: by mail-lb0-x22a.google.com with SMTP id h1so31607299lbj.3 for ; Fri, 27 May 2016 06:00:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=UX5yc7HG/GaRRIvTTe3S7AjbfXSlERds/YHo3DJfoRU=; b=UBI8bP/1MK6Tnv/4oCeiLsB7/H5zfx5xZKmTDsyxDHsHOhyg5oMw5pCrWLk9kfsNVf J7YM7eqLCBiSbD3dthnwOoYPezpPkP4Fb4iU4uGO8VTG5oRMjV95SMSKp79W7rQSpki8 CKTFb+YUv28MknzvEyQ0DKZmr7DjpzH/eN60o= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=UX5yc7HG/GaRRIvTTe3S7AjbfXSlERds/YHo3DJfoRU=; b=k5I8CG0YbQNWIY9B/14eqUbh9keFNtfTmm+n1q5t5ekKDuLoSWA+jpMoJWjg29rZWx miejCrevMvSwv9uhYwcKH0FsRGj5dIcpeCBBGd3OkUP8eXdocHA//U6RW2xaA9rPz938 P2qkEztVe8Se8AI+XLXRC2POoYxNcpefX1dbKy+pGbZ1UllCoMu7UVU11m7vQq8wAcpo j/xh+rbX5oioMFTnP5IsKAlD/X0ET6+bOQ/d1xAOs+0VRPlxpIsFy+6lXE44Uj8NZbmx 3xm8+up6YYDoREi65JxVOjGAkZVHAyOOIj3nbevd/SyfJnwp3QfjGCrX4TsdYwyek5H+ rh6w== X-Gm-Message-State: ALyK8tIxIRsz+oQ1wEeeGm+1LSSqlFJ4H6D+rdYg1NwIaeGnZXokiNypupjBQp0peHrweeeX X-Received: by 10.112.136.194 with SMTP id qc2mr4574456lbb.60.1464354046457; Fri, 27 May 2016 06:00:46 -0700 (PDT) Received: from beaming.home (91-157-168-132.elisa-laajakaista.fi. [91.157.168.132]) by smtp.gmail.com with ESMTPSA id n16sm2281066lfg.31.2016.05.27.06.00.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 27 May 2016 06:00:45 -0700 (PDT) From: riku.voipio@linaro.org To: qemu-devel@nongnu.org Date: Fri, 27 May 2016 16:00:02 +0300 Message-Id: X-Mailer: git-send-email 2.1.4 In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:4010:c04::22a Subject: [Qemu-devel] [PULL v2 11/38] linux-user: Support for restarting system calls for SH4 targets X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Timothy E Baldwin Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Timothy E Baldwin Update the SH4 main loop and sigreturn code: * on TARGET_ERESTARTSYS, wind guest PC backwards to repeat syscall insn * set all guest CPU state within signal.c code on sigreturn * handle TARGET_QEMU_ESIGRETURN in the main loop as the indication that the main loop should not touch any guest CPU state Signed-off-by: Timothy Edward Baldwin Message-id: 1441497448-32489-12-git-send-email-T.E.Baldwin99@members.leeds.ac.uk Reviewed-by: Peter Maydell [PMM: tweak commit message; drop TARGET_USE_ERESTARTSYS define] Signed-off-by: Peter Maydell Signed-off-by: Riku Voipio --- linux-user/main.c | 6 +++++- linux-user/sh4/target_signal.h | 1 + linux-user/signal.c | 16 ++++++---------- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/linux-user/main.c b/linux-user/main.c index 04a9b9b..75552a0 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -2826,7 +2826,11 @@ void cpu_loop(CPUSH4State *env) env->gregs[0], env->gregs[1], 0, 0); - env->gregs[0] = ret; + if (ret == -TARGET_ERESTARTSYS) { + env->pc -= 2; + } else if (ret != -TARGET_QEMU_ESIGRETURN) { + env->gregs[0] = ret; + } break; case EXCP_INTERRUPT: /* just indicate that signals should be handled asap */ diff --git a/linux-user/sh4/target_signal.h b/linux-user/sh4/target_signal.h index e148da0..f9911aa 100644 --- a/linux-user/sh4/target_signal.h +++ b/linux-user/sh4/target_signal.h @@ -26,4 +26,5 @@ static inline abi_ulong get_sp_from_cpustate(CPUSH4State *state) return state->gregs[15]; } + #endif /* TARGET_SIGNAL_H */ diff --git a/linux-user/signal.c b/linux-user/signal.c index e742347..8b5ddf2 100644 --- a/linux-user/signal.c +++ b/linux-user/signal.c @@ -3202,13 +3202,12 @@ static void setup_sigcontext(struct target_sigcontext *sc, __put_user(mask, &sc->oldmask); } -static void restore_sigcontext(CPUSH4State *regs, struct target_sigcontext *sc, - target_ulong *r0_p) +static void restore_sigcontext(CPUSH4State *regs, struct target_sigcontext *sc) { int i; #define COPY(x) __get_user(regs->x, &sc->sc_##x) - COPY(gregs[1]); + COPY(gregs[0]); COPY(gregs[1]); COPY(gregs[2]); COPY(gregs[3]); COPY(gregs[4]); COPY(gregs[5]); COPY(gregs[6]); COPY(gregs[7]); @@ -3228,7 +3227,6 @@ static void restore_sigcontext(CPUSH4State *regs, struct target_sigcontext *sc, __get_user(regs->fpul, &sc->sc_fpul); regs->tra = -1; /* disable syscall checks */ - __get_user(*r0_p, &sc->sc_gregs[0]); } static void setup_frame(int sig, struct target_sigaction *ka, @@ -3345,7 +3343,6 @@ long do_sigreturn(CPUSH4State *regs) abi_ulong frame_addr; sigset_t blocked; target_sigset_t target_set; - target_ulong r0; int i; int err = 0; @@ -3366,10 +3363,10 @@ long do_sigreturn(CPUSH4State *regs) target_to_host_sigset_internal(&blocked, &target_set); do_sigprocmask(SIG_SETMASK, &blocked, NULL); - restore_sigcontext(regs, &frame->sc, &r0); + restore_sigcontext(regs, &frame->sc); unlock_user_struct(frame, frame_addr, 0); - return r0; + return -TARGET_QEMU_ESIGRETURN; badframe: unlock_user_struct(frame, frame_addr, 0); @@ -3382,7 +3379,6 @@ long do_rt_sigreturn(CPUSH4State *regs) struct target_rt_sigframe *frame; abi_ulong frame_addr; sigset_t blocked; - target_ulong r0; frame_addr = regs->gregs[15]; trace_user_do_rt_sigreturn(regs, frame_addr); @@ -3393,7 +3389,7 @@ long do_rt_sigreturn(CPUSH4State *regs) target_to_host_sigset(&blocked, &frame->uc.tuc_sigmask); do_sigprocmask(SIG_SETMASK, &blocked, NULL); - restore_sigcontext(regs, &frame->uc.tuc_mcontext, &r0); + restore_sigcontext(regs, &frame->uc.tuc_mcontext); if (do_sigaltstack(frame_addr + offsetof(struct target_rt_sigframe, uc.tuc_stack), @@ -3402,7 +3398,7 @@ long do_rt_sigreturn(CPUSH4State *regs) } unlock_user_struct(frame, frame_addr, 0); - return r0; + return -TARGET_QEMU_ESIGRETURN; badframe: unlock_user_struct(frame, frame_addr, 0);