From patchwork Thu Jan 11 02:22:04 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Clark X-Patchwork-Id: 10156785 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 70A8D602B3 for ; Thu, 11 Jan 2018 02:43:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5B7F02851D for ; Thu, 11 Jan 2018 02:43:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4DF8728565; Thu, 11 Jan 2018 02:43:37 +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=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, 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 6C9A92851D for ; Thu, 11 Jan 2018 02:43:36 +0000 (UTC) Received: from localhost ([::1]:60796 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eZSq7-0002nj-OG for patchwork-qemu-devel@patchwork.kernel.org; Wed, 10 Jan 2018 21:43:35 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48256) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eZSWt-0003QO-JV for qemu-devel@nongnu.org; Wed, 10 Jan 2018 21:23:45 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eZSWr-0008Sz-Dm for qemu-devel@nongnu.org; Wed, 10 Jan 2018 21:23:43 -0500 Received: from mail-pg0-x243.google.com ([2607:f8b0:400e:c05::243]:43112) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eZSWr-0008SD-2F for qemu-devel@nongnu.org; Wed, 10 Jan 2018 21:23:41 -0500 Received: by mail-pg0-x243.google.com with SMTP id f14so1645654pga.10 for ; Wed, 10 Jan 2018 18:23:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ca5OE13BnRgWLCq9D+2pH5KzDlswCbaFmjVYd1G2/cY=; b=mSp6Z1OKCnO9Sj69TYhhGug17TmArBsPwDNQDbh82IwTissP8bP1T25xadQ5caD9av cOau8vb1bVdpQJYyq71mgYAqui8PZPUdGTO47fsTZBzfE9sVrM7K6LTlCrR9PlIzPCwI LVUQTX3Yuxt5MK8AxIj78dS4UtnpDuvt9us0QiabX3VXEMt1n9NOt9OML6gdYPOCsKVl OJ+l9tyJpvP1WxMd1yaosRuf8vYAB2dMmDA2h1Td9tYkuCDpWw45A1nrzXrj+LiYulBU qyChhtv09Sn5/dd1ON2ooz14noj+LKwlm13UODoA8HXoIIqa3rDq3lVf0TzOC9Um15rB V2hQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=ca5OE13BnRgWLCq9D+2pH5KzDlswCbaFmjVYd1G2/cY=; b=fcvM8E/DLVPzEoXaRErEGWFJo/mJTBR7Bk0waui7afP8PewvzCMcCiEN/3fmWuyHlv 6r0v5G9DQQjHRJOcmLTQ3c57VLBAVOFy8FSruuZdOEGrumWD0uuHQt5vsSkJTiNoIG8Q sjRT7e2DiXePIHDvMRwIoTA+wCLnf6t1TgEyG9PjgMZmRyi0xGKH7X2dEyZVw0bmfbOl ufG/aF+ZJXAru0TrayFpid4mOWUQDPQwL9r1fNkXDDLmQdsDDTvhfYka8nE61nbURE2H Y6/2lHThHRwp/Xt6Z7aBxD29+QtgETc8gAb9q8/u6gz2HXJ+aqfM0Bbx7sNPV8NOeDbe qj+g== X-Gm-Message-State: AKGB3mIpK4KNJ2WLCL++nOghev5+msgPJwQCA/qjS5A7jt6yChY0eGok IdbP+0L0EPgMHvU0N0hvbDqy8TKwPlM= X-Google-Smtp-Source: ACJfBoufsReLJEJ9PglhDZh4jVuxekCPTVykScVssYRgMFk7p4Ynx6mUp2/c5sbo8JzUSjjhg9d+9Q== X-Received: by 10.84.224.5 with SMTP id r5mr13637405plj.307.1515637420053; Wed, 10 Jan 2018 18:23:40 -0800 (PST) Received: from monty.com ([12.206.222.5]) by smtp.gmail.com with ESMTPSA id e12sm33545939pgu.81.2018.01.10.18.23.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 10 Jan 2018 18:23:39 -0800 (PST) From: Michael Clark To: qemu-devel@nongnu.org Date: Wed, 10 Jan 2018 18:22:04 -0800 Message-Id: <1515637324-96034-22-git-send-email-mjc@sifive.com> X-Mailer: git-send-email 2.7.0 In-Reply-To: <1515637324-96034-1-git-send-email-mjc@sifive.com> References: <1515637324-96034-1-git-send-email-mjc@sifive.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c05::243 Subject: [Qemu-devel] [PATCH v3 21/21] RISC-V Build Infrastructure 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: Bastian Koppelmann , Michael Clark , Palmer Dabbelt , Sagar Karandikar , RISC-V Patches Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP This adds RISC-V into the build system enabling the following targets: - riscv32-softmmu - riscv64-softmmu - riscv32-linux-user - riscv64-linux-user This adds defaults configs for RISC-V, enables the build for the RISC-V CPU core, hardware, and Linux User Emulation. The 'qemu-binfmt-conf.sh' script is updated to add the RISC-V ELF magic. Expected checkpatch errors for consistency reasons: ERROR: line over 90 characters FILE: scripts/qemu-binfmt-conf.sh Signed-off-by: Michael Clark --- Makefile.objs | 1 + arch_init.c | 2 ++ configure | 11 +++++++++++ cpus.c | 6 ++++++ default-configs/riscv32-linux-user.mak | 1 + default-configs/riscv32-softmmu.mak | 4 ++++ default-configs/riscv64-linux-user.mak | 1 + default-configs/riscv64-softmmu.mak | 4 ++++ hw/riscv/Makefile.objs | 12 ++++++++++++ include/sysemu/arch_init.h | 1 + qapi-schema.json | 14 +++++++++++++- scripts/qemu-binfmt-conf.sh | 13 ++++++++++++- target/riscv/Makefile.objs | 2 ++ target/riscv/trace-events | 1 + 14 files changed, 71 insertions(+), 2 deletions(-) create mode 100644 default-configs/riscv32-linux-user.mak create mode 100644 default-configs/riscv32-softmmu.mak create mode 100644 default-configs/riscv64-linux-user.mak create mode 100644 default-configs/riscv64-softmmu.mak create mode 100644 hw/riscv/Makefile.objs create mode 100644 target/riscv/Makefile.objs create mode 100644 target/riscv/trace-events diff --git a/Makefile.objs b/Makefile.objs index 285c6f3..ae8658e 100644 --- a/Makefile.objs +++ b/Makefile.objs @@ -164,6 +164,7 @@ trace-events-subdirs += target/mips trace-events-subdirs += target/sparc trace-events-subdirs += target/s390x trace-events-subdirs += target/ppc +trace-events-subdirs += target/riscv trace-events-subdirs += qom trace-events-subdirs += linux-user trace-events-subdirs += qapi diff --git a/arch_init.c b/arch_init.c index a0b8ed6..dcf356b 100644 --- a/arch_init.c +++ b/arch_init.c @@ -69,6 +69,8 @@ int graphic_depth = 32; #define QEMU_ARCH QEMU_ARCH_OPENRISC #elif defined(TARGET_PPC) #define QEMU_ARCH QEMU_ARCH_PPC +#elif defined(TARGET_RISCV) +#define QEMU_ARCH QEMU_ARCH_RISCV #elif defined(TARGET_S390X) #define QEMU_ARCH QEMU_ARCH_S390X #elif defined(TARGET_SH4) diff --git a/configure b/configure index 6a04082..a8151f9 100755 --- a/configure +++ b/configure @@ -6565,6 +6565,14 @@ case "$target_name" in echo "TARGET_ABI32=y" >> $config_target_mak gdb_xml_files="power64-core.xml power-fpu.xml power-altivec.xml power-spe.xml power-vsx.xml" ;; + riscv32) + TARGET_BASE_ARCH=riscv + TARGET_ABI_DIR=riscv + ;; + riscv64) + TARGET_BASE_ARCH=riscv + TARGET_ABI_DIR=riscv + ;; sh4|sh4eb) TARGET_ARCH=sh4 bflt="yes" @@ -6730,6 +6738,9 @@ for i in $ARCH $TARGET_BASE_ARCH ; do ppc*) disas_config "PPC" ;; + riscv) + disas_config "RISCV" + ;; s390*) disas_config "S390" ;; diff --git a/cpus.c b/cpus.c index e8139de..499be10 100644 --- a/cpus.c +++ b/cpus.c @@ -1995,6 +1995,9 @@ CpuInfoList *qmp_query_cpus(Error **errp) #elif defined(TARGET_SPARC) SPARCCPU *sparc_cpu = SPARC_CPU(cpu); CPUSPARCState *env = &sparc_cpu->env; +#elif defined(TARGET_RISCV) + RISCVCPU *riscv_cpu = RISCV_CPU(cpu); + CPURISCVState *env = &riscv_cpu->env; #elif defined(TARGET_MIPS) MIPSCPU *mips_cpu = MIPS_CPU(cpu); CPUMIPSState *env = &mips_cpu->env; @@ -2028,6 +2031,9 @@ CpuInfoList *qmp_query_cpus(Error **errp) #elif defined(TARGET_TRICORE) info->value->arch = CPU_INFO_ARCH_TRICORE; info->value->u.tricore.PC = env->PC; +#elif defined(TARGET_RISCV) + info->value->arch = CPU_INFO_ARCH_RISCV; + info->value->u.riscv.pc = env->pc; #else info->value->arch = CPU_INFO_ARCH_OTHER; #endif diff --git a/default-configs/riscv32-linux-user.mak b/default-configs/riscv32-linux-user.mak new file mode 100644 index 0000000..865b362 --- /dev/null +++ b/default-configs/riscv32-linux-user.mak @@ -0,0 +1 @@ +# Default configuration for riscv-linux-user diff --git a/default-configs/riscv32-softmmu.mak b/default-configs/riscv32-softmmu.mak new file mode 100644 index 0000000..f9e7421 --- /dev/null +++ b/default-configs/riscv32-softmmu.mak @@ -0,0 +1,4 @@ +# Default configuration for riscv-softmmu + +CONFIG_SERIAL=y +CONFIG_VIRTIO=y diff --git a/default-configs/riscv64-linux-user.mak b/default-configs/riscv64-linux-user.mak new file mode 100644 index 0000000..865b362 --- /dev/null +++ b/default-configs/riscv64-linux-user.mak @@ -0,0 +1 @@ +# Default configuration for riscv-linux-user diff --git a/default-configs/riscv64-softmmu.mak b/default-configs/riscv64-softmmu.mak new file mode 100644 index 0000000..f9e7421 --- /dev/null +++ b/default-configs/riscv64-softmmu.mak @@ -0,0 +1,4 @@ +# Default configuration for riscv-softmmu + +CONFIG_SERIAL=y +CONFIG_VIRTIO=y diff --git a/hw/riscv/Makefile.objs b/hw/riscv/Makefile.objs new file mode 100644 index 0000000..a0c31ae --- /dev/null +++ b/hw/riscv/Makefile.objs @@ -0,0 +1,12 @@ +obj-y += riscv_elf.o +obj-y += riscv_htif.o +obj-y += riscv_hart.o +obj-y += sifive_e300.o +obj-y += sifive_clint.o +obj-y += sifive_prci.o +obj-y += sifive_plic.o +obj-y += sifive_u500.o +obj-y += sifive_uart.o +obj-y += spike_v1_09.o +obj-y += spike_v1_10.o +obj-y += virt.o diff --git a/include/sysemu/arch_init.h b/include/sysemu/arch_init.h index 8751c46..63c6152 100644 --- a/include/sysemu/arch_init.h +++ b/include/sysemu/arch_init.h @@ -24,6 +24,7 @@ enum { QEMU_ARCH_MOXIE = (1 << 15), QEMU_ARCH_TRICORE = (1 << 16), QEMU_ARCH_NIOS2 = (1 << 17), + QEMU_ARCH_RISCV = (1 << 18), }; extern const uint32_t arch_type; diff --git a/qapi-schema.json b/qapi-schema.json index 5c06745..42d91f3 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -413,7 +413,7 @@ # Since: 2.6 ## { 'enum': 'CpuInfoArch', - 'data': ['x86', 'sparc', 'ppc', 'mips', 'tricore', 'other' ] } + 'data': ['x86', 'sparc', 'ppc', 'mips', 'tricore', 'riscv', 'other' ] } ## # @CpuInfo: @@ -452,6 +452,7 @@ 'ppc': 'CpuInfoPPC', 'mips': 'CpuInfoMIPS', 'tricore': 'CpuInfoTricore', + 'riscv': 'CpuInfoRISCV', 'other': 'CpuInfoOther' } } ## @@ -512,6 +513,17 @@ { 'struct': 'CpuInfoTricore', 'data': { 'PC': 'int' } } ## +# @CpuInfoRISCV: +# +# Additional information about a virtual RISCV CPU +# +# @pc: the instruction pointer +# +# Since 2.12 +## +{ 'struct': 'CpuInfoRISCV', 'data': { 'pc': 'int' } } + +## # @CpuInfoOther: # # No additional information is available about the virtual CPU diff --git a/scripts/qemu-binfmt-conf.sh b/scripts/qemu-binfmt-conf.sh index 8afc3eb..c5ac660 100755 --- a/scripts/qemu-binfmt-conf.sh +++ b/scripts/qemu-binfmt-conf.sh @@ -4,7 +4,7 @@ qemu_target_list="i386 i486 alpha arm sparc32plus ppc ppc64 ppc64le m68k \ mips mipsel mipsn32 mipsn32el mips64 mips64el \ -sh4 sh4eb s390x aarch64 hppa" +sh4 sh4eb s390x aarch64 hppa riscv32 riscv64" i386_magic='\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x03\x00' i386_mask='\xff\xff\xff\xff\xff\xfe\xfe\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff' @@ -96,6 +96,14 @@ hppa_magic='\x7f\x45\x4c\x46\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 hppa_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff' hppa_family=hppa +riscv32_magic='\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\xf3\x00' +riscv32_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff' +riscv32_family=riscv + +riscv64_magic='\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\xf3\x00' +riscv64_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff' +riscv64_family=riscv + qemu_get_family() { cpu=${HOST_ARCH:-$(uname -m)} case "$cpu" in @@ -117,6 +125,9 @@ qemu_get_family() { sparc*) echo "sparc" ;; + riscv*) + echo "riscv" + ;; *) echo "$cpu" ;; diff --git a/target/riscv/Makefile.objs b/target/riscv/Makefile.objs new file mode 100644 index 0000000..b9e9877 --- /dev/null +++ b/target/riscv/Makefile.objs @@ -0,0 +1,2 @@ +obj-y += translate.o op_helper.o helper.o cpu.o fpu_helper.o \ + user_atomic.o gdbstub.o pmp.o diff --git a/target/riscv/trace-events b/target/riscv/trace-events new file mode 100644 index 0000000..9284b1f --- /dev/null +++ b/target/riscv/trace-events @@ -0,0 +1 @@ +# See docs/devel/tracing.txt for syntax documentation.