From patchwork Fri Jan 29 09:32:40 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: alvise rigo X-Patchwork-Id: 8161071 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 7E9089F38B for ; Fri, 29 Jan 2016 09:39:53 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 106A620361 for ; Fri, 29 Jan 2016 09:39:52 +0000 (UTC) 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.kernel.org (Postfix) with ESMTPS id 73C112014A for ; Fri, 29 Jan 2016 09:39:50 +0000 (UTC) Received: from localhost ([::1]:60761 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aP5Wv-0002cp-Sr for patchwork-qemu-devel@patchwork.kernel.org; Fri, 29 Jan 2016 04:39:49 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33738) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aP5Qb-0007lX-P2 for qemu-devel@nongnu.org; Fri, 29 Jan 2016 04:33:19 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aP5QX-0000YF-Km for qemu-devel@nongnu.org; Fri, 29 Jan 2016 04:33:17 -0500 Received: from mail-wm0-x236.google.com ([2a00:1450:400c:c09::236]:35131) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aP5QX-0000Xz-2V for qemu-devel@nongnu.org; Fri, 29 Jan 2016 04:33:13 -0500 Received: by mail-wm0-x236.google.com with SMTP id r129so60078994wmr.0 for ; Fri, 29 Jan 2016 01:33:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtualopensystems-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=BYI53fZJ/vn6XLoWBTEUwMcsPQDBha39L5LnNnqvZ3s=; b=GVfka/wTsm3a3GrFDgJrwDn5tQ7uDYkuZmWZEsfP3y9DhUoWH/DPxtG3lPJ5fZOVkP 3shbDp2cFeQI7HCeCSJYUcn76vQmI2I6aOZmivW3CyGyG9wUq9pJf79zPAejtTUatcTm QTp1nzrP7wbZDEyUnDDqpEV4W1UihLOHsrKVPkU3hU15e/9Br2ovZjFLnGF97itPWaNw 9XtbP8qbWYewsIPFocl5NY4mqnVMILonsu/V+rKbY9Zrx1GaUnDrKEm4NKt0u+LreujM jWhEoNP1kmSgewC1ArPsfl+7uMUJEpPicxKLVzR3kk0JYfNQFj4H9Lj/y902qAfRsK23 mAyg== 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=BYI53fZJ/vn6XLoWBTEUwMcsPQDBha39L5LnNnqvZ3s=; b=VJRE/dpI446ByWlv3r2+Rd4fnKpPXd0Uoieclk1zen4G52bowigyQK3uA+04fF1idJ SKoa1zjyb7AWiWnzwZ4mPD2HxWDZTDUPCkdWtt3XWzEsvw18fBVxECGWNY6Z/3R3QF3C 7GfeZYLL0XkgO8wh652XcUBsTBTeqFDpOBws5GcSEE8bJRRgltP91jwHQY7T9l13gKCX RHGQyEYk5711mnyS4rDKirYdfvWij8s1Hj1N85qsDWwNWcfgYddmHFMjZ4VeKObOozd3 6884V1H8LSlAfFkmsmJ4udMUq3OyipeZMmJeiLrvzyMJQVDww5pb7NkylWW80ycdRA5e +oaQ== X-Gm-Message-State: AG10YOSZ2mpa/SP8Uk+PgFH3T7BSZOupyCZXRYCWdurbzz6UE2/OjpctxEYtrtW0r6ojQQ== X-Received: by 10.28.225.8 with SMTP id y8mr7952685wmg.98.1454059992432; Fri, 29 Jan 2016 01:33:12 -0800 (PST) Received: from localhost.localdomain (LPuteaux-656-1-278-113.w80-15.abo.wanadoo.fr. [80.15.154.113]) by smtp.googlemail.com with ESMTPSA id o7sm14765451wjf.45.2016.01.29.01.33.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 29 Jan 2016 01:33:11 -0800 (PST) From: Alvise Rigo To: qemu-devel@nongnu.org, mttcg@listserver.greensocs.com Date: Fri, 29 Jan 2016 10:32:40 +0100 Message-Id: <1454059965-23402-12-git-send-email-a.rigo@virtualopensystems.com> X-Mailer: git-send-email 2.7.0 In-Reply-To: <1454059965-23402-1-git-send-email-a.rigo@virtualopensystems.com> References: <1454059965-23402-1-git-send-email-a.rigo@virtualopensystems.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c09::236 Cc: claudio.fontana@huawei.com, pbonzini@redhat.com, jani.kokkonen@huawei.com, tech@virtualopensystems.com, alex.bennee@linaro.org, rth@twiddle.net Subject: [Qemu-devel] [RFC v7 11/16] tcg: Create new runtime helpers for excl accesses X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Introduce a set of new runtime helpers to handle exclusive instructions. These helpers are used as hooks to call the respective LL/SC helpers in softmmu_llsc_template.h from TCG code. The helpers ending with an "a" make an alignment check. Suggested-by: Jani Kokkonen Suggested-by: Claudio Fontana Signed-off-by: Alvise Rigo --- Makefile.target | 2 +- include/exec/helper-gen.h | 3 ++ include/exec/helper-proto.h | 1 + include/exec/helper-tcg.h | 3 ++ tcg-llsc-helper.c | 104 ++++++++++++++++++++++++++++++++++++++++++++ tcg-llsc-helper.h | 61 ++++++++++++++++++++++++++ tcg/tcg-llsc-gen-helper.h | 67 ++++++++++++++++++++++++++++ 7 files changed, 240 insertions(+), 1 deletion(-) create mode 100644 tcg-llsc-helper.c create mode 100644 tcg-llsc-helper.h create mode 100644 tcg/tcg-llsc-gen-helper.h diff --git a/Makefile.target b/Makefile.target index 34ddb7e..faf32a2 100644 --- a/Makefile.target +++ b/Makefile.target @@ -135,7 +135,7 @@ obj-y += arch_init.o cpus.o monitor.o gdbstub.o balloon.o ioport.o numa.o obj-y += qtest.o bootdevice.o obj-y += hw/ obj-$(CONFIG_KVM) += kvm-all.o -obj-y += memory.o cputlb.o +obj-y += memory.o cputlb.o tcg-llsc-helper.o obj-y += memory_mapping.o obj-y += dump.o obj-y += migration/ram.o migration/savevm.o diff --git a/include/exec/helper-gen.h b/include/exec/helper-gen.h index 0d0da3a..f8483a9 100644 --- a/include/exec/helper-gen.h +++ b/include/exec/helper-gen.h @@ -60,6 +60,9 @@ static inline void glue(gen_helper_, name)(dh_retvar_decl(ret) \ #include "trace/generated-helpers.h" #include "trace/generated-helpers-wrappers.h" #include "tcg-runtime.h" +#if defined(CONFIG_SOFTMMU) +#include "tcg-llsc-gen-helper.h" +#endif #undef DEF_HELPER_FLAGS_0 #undef DEF_HELPER_FLAGS_1 diff --git a/include/exec/helper-proto.h b/include/exec/helper-proto.h index effdd43..90be2fd 100644 --- a/include/exec/helper-proto.h +++ b/include/exec/helper-proto.h @@ -29,6 +29,7 @@ dh_ctype(ret) HELPER(name) (dh_ctype(t1), dh_ctype(t2), dh_ctype(t3), \ #include "helper.h" #include "trace/generated-helpers.h" #include "tcg-runtime.h" +#include "tcg/tcg-llsc-gen-helper.h" #undef DEF_HELPER_FLAGS_0 #undef DEF_HELPER_FLAGS_1 diff --git a/include/exec/helper-tcg.h b/include/exec/helper-tcg.h index 79fa3c8..6228a7f 100644 --- a/include/exec/helper-tcg.h +++ b/include/exec/helper-tcg.h @@ -38,6 +38,9 @@ #include "helper.h" #include "trace/generated-helpers.h" #include "tcg-runtime.h" +#ifdef CONFIG_SOFTMMU +#include "tcg-llsc-gen-helper.h" +#endif #undef DEF_HELPER_FLAGS_0 #undef DEF_HELPER_FLAGS_1 diff --git a/tcg-llsc-helper.c b/tcg-llsc-helper.c new file mode 100644 index 0000000..646b4ba --- /dev/null +++ b/tcg-llsc-helper.c @@ -0,0 +1,104 @@ +/* + * Runtime helpers for atomic istruction emulation + * + * Copyright (c) 2015 Virtual Open Systems + * + * Authors: + * Alvise Rigo + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see . + */ + +#include "exec/cpu_ldst.h" +#include "exec/helper-head.h" +#include "tcg-llsc-helper.h" + +#define LDEX_HELPER(SUFF, OPC, FUNC) \ +uint32_t HELPER(ldlink_i##SUFF)(CPUArchState *env, target_ulong addr, \ + uint32_t index) \ +{ \ + CPUArchState *state = env; \ + TCGMemOpIdx op; \ + \ + op = make_memop_idx((OPC), index); \ + \ + return (uint32_t)FUNC(state, addr, op, GETRA()); \ +} + +#define STEX_HELPER(SUFF, DATA_TYPE, OPC, FUNC) \ +target_ulong HELPER(stcond_i##SUFF)(CPUArchState *env, target_ulong addr, \ + uint32_t val, uint32_t index) \ +{ \ + CPUArchState *state = env; \ + TCGMemOpIdx op; \ + \ + op = make_memop_idx((OPC), index); \ + \ + return (target_ulong)FUNC(state, addr, val, op, GETRA()); \ +} + + +LDEX_HELPER(8, MO_UB, helper_ret_ldlinkub_mmu) +LDEX_HELPER(16_be, MO_BEUW, helper_be_ldlinkuw_mmu) +LDEX_HELPER(16_bea, MO_BEUW | MO_ALIGN, helper_be_ldlinkuw_mmu) +LDEX_HELPER(32_be, MO_BEUL, helper_be_ldlinkul_mmu) +LDEX_HELPER(32_bea, MO_BEUL | MO_ALIGN, helper_be_ldlinkul_mmu) +LDEX_HELPER(16_le, MO_LEUW, helper_le_ldlinkuw_mmu) +LDEX_HELPER(16_lea, MO_LEUW | MO_ALIGN, helper_le_ldlinkuw_mmu) +LDEX_HELPER(32_le, MO_LEUL, helper_le_ldlinkul_mmu) +LDEX_HELPER(32_lea, MO_LEUL | MO_ALIGN, helper_le_ldlinkul_mmu) + +STEX_HELPER(8, uint8_t, MO_UB, helper_ret_stcondb_mmu) +STEX_HELPER(16_be, uint16_t, MO_BEUW, helper_be_stcondw_mmu) +STEX_HELPER(16_bea, uint16_t, MO_BEUW | MO_ALIGN, helper_be_stcondw_mmu) +STEX_HELPER(32_be, uint32_t, MO_BEUL, helper_be_stcondl_mmu) +STEX_HELPER(32_bea, uint32_t, MO_BEUL | MO_ALIGN, helper_be_stcondl_mmu) +STEX_HELPER(16_le, uint16_t, MO_LEUW, helper_le_stcondw_mmu) +STEX_HELPER(16_lea, uint16_t, MO_LEUW | MO_ALIGN, helper_le_stcondw_mmu) +STEX_HELPER(32_le, uint32_t, MO_LEUL, helper_le_stcondl_mmu) +STEX_HELPER(32_lea, uint32_t, MO_LEUL | MO_ALIGN, helper_le_stcondl_mmu) + +#define LDEX_HELPER_64(SUFF, OPC, FUNC) \ +uint64_t HELPER(ldlink_i##SUFF)(CPUArchState *env, target_ulong addr, \ + uint32_t index) \ +{ \ + CPUArchState *state = env; \ + TCGMemOpIdx op; \ + \ + op = make_memop_idx((OPC), index); \ + \ + return FUNC(state, addr, op, GETRA()); \ +} + +#define STEX_HELPER_64(SUFF, OPC, FUNC) \ +target_ulong HELPER(stcond_i##SUFF)(CPUArchState *env, target_ulong addr, \ + uint64_t val, uint32_t index) \ +{ \ + CPUArchState *state = env; \ + TCGMemOpIdx op; \ + \ + op = make_memop_idx((OPC), index); \ + \ + return (target_ulong)FUNC(state, addr, val, op, GETRA()); \ +} + +LDEX_HELPER_64(64_be, MO_BEQ, helper_be_ldlinkq_mmu) +LDEX_HELPER_64(64_bea, MO_BEQ | MO_ALIGN, helper_be_ldlinkq_mmu) +LDEX_HELPER_64(64_le, MO_LEQ, helper_le_ldlinkq_mmu) +LDEX_HELPER_64(64_lea, MO_LEQ | MO_ALIGN, helper_le_ldlinkq_mmu) + +STEX_HELPER_64(64_be, MO_BEQ, helper_be_stcondq_mmu) +STEX_HELPER_64(64_bea, MO_BEQ | MO_ALIGN, helper_be_stcondq_mmu) +STEX_HELPER_64(64_le, MO_LEQ, helper_le_stcondq_mmu) +STEX_HELPER_64(64_lea, MO_LEQ | MO_ALIGN, helper_le_stcondq_mmu) diff --git a/tcg-llsc-helper.h b/tcg-llsc-helper.h new file mode 100644 index 0000000..8f7adf0 --- /dev/null +++ b/tcg-llsc-helper.h @@ -0,0 +1,61 @@ +#ifndef HELPER_LLSC_HEAD_H +#define HELPER_LLSC_HEAD_H 1 + +uint32_t HELPER(ldlink_i8)(CPUArchState *env, target_ulong addr, + uint32_t index); +uint32_t HELPER(ldlink_i16_be)(CPUArchState *env, target_ulong addr, + uint32_t index); +uint32_t HELPER(ldlink_i32_be)(CPUArchState *env, target_ulong addr, + uint32_t index); +uint64_t HELPER(ldlink_i64_be)(CPUArchState *env, target_ulong addr, + uint32_t index); +uint32_t HELPER(ldlink_i16_le)(CPUArchState *env, target_ulong addr, + uint32_t index); +uint32_t HELPER(ldlink_i32_le)(CPUArchState *env, target_ulong addr, + uint32_t index); +uint64_t HELPER(ldlink_i64_le)(CPUArchState *env, target_ulong addr, + uint32_t index); + +target_ulong HELPER(stcond_i8)(CPUArchState *env, target_ulong addr, + uint32_t val, uint32_t index); +target_ulong HELPER(stcond_i16_be)(CPUArchState *env, target_ulong addr, + uint32_t val, uint32_t index); +target_ulong HELPER(stcond_i32_be)(CPUArchState *env, target_ulong addr, + uint32_t val, uint32_t index); +target_ulong HELPER(stcond_i64_be)(CPUArchState *env, target_ulong addr, + uint64_t val, uint32_t index); +target_ulong HELPER(stcond_i16_le)(CPUArchState *env, target_ulong addr, + uint32_t val, uint32_t index); +target_ulong HELPER(stcond_i32_le)(CPUArchState *env, target_ulong addr, + uint32_t val, uint32_t index); +target_ulong HELPER(stcond_i64_le)(CPUArchState *env, target_ulong addr, + uint64_t val, uint32_t index); + +/* Aligned versions */ +uint32_t HELPER(ldlink_i16_bea)(CPUArchState *env, target_ulong addr, + uint32_t index); +uint32_t HELPER(ldlink_i32_bea)(CPUArchState *env, target_ulong addr, + uint32_t index); +uint64_t HELPER(ldlink_i64_bea)(CPUArchState *env, target_ulong addr, + uint32_t index); +uint32_t HELPER(ldlink_i16_lea)(CPUArchState *env, target_ulong addr, + uint32_t index); +uint32_t HELPER(ldlink_i32_lea)(CPUArchState *env, target_ulong addr, + uint32_t index); +uint64_t HELPER(ldlink_i64_lea)(CPUArchState *env, target_ulong addr, + uint32_t index); + +target_ulong HELPER(stcond_i16_bea)(CPUArchState *env, target_ulong addr, + uint32_t val, uint32_t index); +target_ulong HELPER(stcond_i32_bea)(CPUArchState *env, target_ulong addr, + uint32_t val, uint32_t index); +target_ulong HELPER(stcond_i64_bea)(CPUArchState *env, target_ulong addr, + uint64_t val, uint32_t index); +target_ulong HELPER(stcond_i16_lea)(CPUArchState *env, target_ulong addr, + uint32_t val, uint32_t index); +target_ulong HELPER(stcond_i32_lea)(CPUArchState *env, target_ulong addr, + uint32_t val, uint32_t index); +target_ulong HELPER(stcond_i64_lea)(CPUArchState *env, target_ulong addr, + uint64_t val, uint32_t index); + +#endif diff --git a/tcg/tcg-llsc-gen-helper.h b/tcg/tcg-llsc-gen-helper.h new file mode 100644 index 0000000..01c0a67 --- /dev/null +++ b/tcg/tcg-llsc-gen-helper.h @@ -0,0 +1,67 @@ +#if TARGET_LONG_BITS == 32 +#define TYPE i32 +#else +#define TYPE i64 +#endif + +DEF_HELPER_3(ldlink_i8, i32, env, TYPE, i32) +DEF_HELPER_3(ldlink_i16_be, i32, env, TYPE, i32) +DEF_HELPER_3(ldlink_i32_be, i32, env, TYPE, i32) +DEF_HELPER_3(ldlink_i64_be, i64, env, TYPE, i32) +DEF_HELPER_3(ldlink_i16_le, i32, env, TYPE, i32) +DEF_HELPER_3(ldlink_i32_le, i32, env, TYPE, i32) +DEF_HELPER_3(ldlink_i64_le, i64, env, TYPE, i32) + +DEF_HELPER_4(stcond_i8, TYPE, env, TYPE, i32, i32) +DEF_HELPER_4(stcond_i16_be, TYPE, env, TYPE, i32, i32) +DEF_HELPER_4(stcond_i32_be, TYPE, env, TYPE, i32, i32) +DEF_HELPER_4(stcond_i64_be, TYPE, env, TYPE, i64, i32) +DEF_HELPER_4(stcond_i16_le, TYPE, env, TYPE, i32, i32) +DEF_HELPER_4(stcond_i32_le, TYPE, env, TYPE, i32, i32) +DEF_HELPER_4(stcond_i64_le, TYPE, env, TYPE, i64, i32) + +/* Aligned versions */ +DEF_HELPER_3(ldlink_i16_bea, i32, env, TYPE, i32) +DEF_HELPER_3(ldlink_i32_bea, i32, env, TYPE, i32) +DEF_HELPER_3(ldlink_i64_bea, i64, env, TYPE, i32) +DEF_HELPER_3(ldlink_i16_lea, i32, env, TYPE, i32) +DEF_HELPER_3(ldlink_i32_lea, i32, env, TYPE, i32) +DEF_HELPER_3(ldlink_i64_lea, i64, env, TYPE, i32) + +DEF_HELPER_4(stcond_i16_bea, TYPE, env, TYPE, i32, i32) +DEF_HELPER_4(stcond_i32_bea, TYPE, env, TYPE, i32, i32) +DEF_HELPER_4(stcond_i64_bea, TYPE, env, TYPE, i64, i32) +DEF_HELPER_4(stcond_i16_lea, TYPE, env, TYPE, i32, i32) +DEF_HELPER_4(stcond_i32_lea, TYPE, env, TYPE, i32, i32) +DEF_HELPER_4(stcond_i64_lea, TYPE, env, TYPE, i64, i32) + +/* Convenient aliases */ +#ifdef TARGET_WORDS_BIGENDIAN +#define gen_helper_stcond_i16 gen_helper_stcond_i16_be +#define gen_helper_stcond_i32 gen_helper_stcond_i32_be +#define gen_helper_stcond_i64 gen_helper_stcond_i64_be +#define gen_helper_ldlink_i16 gen_helper_ldlink_i16_be +#define gen_helper_ldlink_i32 gen_helper_ldlink_i32_be +#define gen_helper_ldlink_i64 gen_helper_ldlink_i64_be +#define gen_helper_stcond_i16a gen_helper_stcond_i16_bea +#define gen_helper_stcond_i32a gen_helper_stcond_i32_bea +#define gen_helper_stcond_i64a gen_helper_stcond_i64_bea +#define gen_helper_ldlink_i16a gen_helper_ldlink_i16_bea +#define gen_helper_ldlink_i32a gen_helper_ldlink_i32_bea +#define gen_helper_ldlink_i64a gen_helper_ldlink_i64_bea +#else +#define gen_helper_stcond_i16 gen_helper_stcond_i16_le +#define gen_helper_stcond_i32 gen_helper_stcond_i32_le +#define gen_helper_stcond_i64 gen_helper_stcond_i64_le +#define gen_helper_ldlink_i16 gen_helper_ldlink_i16_le +#define gen_helper_ldlink_i32 gen_helper_ldlink_i32_le +#define gen_helper_ldlink_i64 gen_helper_ldlink_i64_le +#define gen_helper_stcond_i16a gen_helper_stcond_i16_lea +#define gen_helper_stcond_i32a gen_helper_stcond_i32_lea +#define gen_helper_stcond_i64a gen_helper_stcond_i64_lea +#define gen_helper_ldlink_i16a gen_helper_ldlink_i16_lea +#define gen_helper_ldlink_i32a gen_helper_ldlink_i32_lea +#define gen_helper_ldlink_i64a gen_helper_ldlink_i64_lea +#endif + +#undef TYPE