From patchwork Mon May 6 22:49:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Francis X-Patchwork-Id: 10932005 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 83FF716C1 for ; Mon, 6 May 2019 22:51:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 704DE28806 for ; Mon, 6 May 2019 22:51:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 63388288D3; Mon, 6 May 2019 22:51:07 +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.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 94B72288CE for ; Mon, 6 May 2019 22:51:06 +0000 (UTC) Received: from localhost ([127.0.0.1]:34956 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNmRt-0000ES-Dy for patchwork-qemu-devel@patchwork.kernel.org; Mon, 06 May 2019 18:51:05 -0400 Received: from eggs.gnu.org ([209.51.188.92]:47548) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNmQy-0007QI-2z for qemu-devel@nongnu.org; Mon, 06 May 2019 18:50:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hNmQu-0003vI-6B for qemu-devel@nongnu.org; Mon, 06 May 2019 18:50:06 -0400 Received: from esa6.hgst.iphmx.com ([216.71.154.45]:19127) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hNmQq-0003qg-NO; Mon, 06 May 2019 18:50:02 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1557183001; x=1588719001; h=from:to:cc:subject:date:message-id: content-transfer-encoding:mime-version; bh=HuqwoaBI1bZMAqgfuNhaSr2Z8EelzZlAfxJnYjvK4V8=; b=EEYUZ8QSAYx4OSngY+yJWcLbqQu46gCv83Yw6WIYb94MsnEd8i1jR7oc xqwDoB8nkSCFNaqHiciEnV+eYg2H9zhs/f+gSgAH4LvMDL42bYLV1c2bb TCqmLP6dYOVXk7LovW9gZlQHz/8jrZcnyin4f3Jhki9X8UpTHkkPrLUMr qam57QIn7WbfCdEm+tsR+OUDQEleb6Un7oC60Gp8bVomHmSwHzB2yVTJ1 TCxhj5L246/jg+ZQtGkqtq2k8TKpWf8esg5fymFJHgkqwU9a2oXaTLiNj CJgirLF4BirW/aImTFIi8eETEkxfp6iLAUfZj25vnC+/HrjXZ0maIfDr3 Q==; X-IronPort-AV: E=Sophos;i="5.60,439,1549900800"; d="scan'208";a="109363130" Received: from mail-by2nam03lp2056.outbound.protection.outlook.com (HELO NAM03-BY2-obe.outbound.protection.outlook.com) ([104.47.42.56]) by ob1.hgst.iphmx.com with ESMTP; 07 May 2019 06:49:55 +0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sharedspace.onmicrosoft.com; s=selector1-wdc-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=HuqwoaBI1bZMAqgfuNhaSr2Z8EelzZlAfxJnYjvK4V8=; b=ZLZV7eZGXPs24xpPLu8HRZqzVKn2L8/qRo9XANtKCbpLGY+S9ZIJcyFgRyvC4Wk22Vob1sjH1q8ALScs7e7ntyqdXldpv3D4dyD4FPQCeCkwhp3lAo5x0aG+YPYqT5HT4TSsYhV8TNidsf+RhyFs5asosjeWGkPDNAVrVFWLx34= Received: from BYAPR04MB4901.namprd04.prod.outlook.com (52.135.232.206) by BYAPR04MB6087.namprd04.prod.outlook.com (20.178.234.33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1856.11; Mon, 6 May 2019 22:49:53 +0000 Received: from BYAPR04MB4901.namprd04.prod.outlook.com ([fe80::4d89:bbf8:952c:3d66]) by BYAPR04MB4901.namprd04.prod.outlook.com ([fe80::4d89:bbf8:952c:3d66%5]) with mapi id 15.20.1856.012; Mon, 6 May 2019 22:49:53 +0000 From: Alistair Francis To: "qemu-devel@nongnu.org" , "qemu-riscv@nongnu.org" Thread-Topic: [PATCH v1 1/1] target/riscv: Allow setting ISA extensions via CPU props Thread-Index: AQHVBF4EAhJoj72DVUSbv3b62S3Vmg== Date: Mon, 6 May 2019 22:49:53 +0000 Message-ID: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: git-send-email 2.21.0 x-clientproxiedby: BYAPR07CA0029.namprd07.prod.outlook.com (2603:10b6:a02:bc::42) To BYAPR04MB4901.namprd04.prod.outlook.com (2603:10b6:a03:4f::14) authentication-results: spf=none (sender IP is ) smtp.mailfrom=Alistair.Francis@wdc.com; x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [199.255.44.172] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 8f35b306-b616-4704-b696-08d6d27526fd x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600141)(711020)(4605104)(4618075)(2017052603328)(7193020); SRVR:BYAPR04MB6087; x-ms-traffictypediagnostic: BYAPR04MB6087: wdcipoutbound: EOP-TRUE x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:330; x-forefront-prvs: 0029F17A3F x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(376002)(136003)(346002)(366004)(39860400002)(396003)(189003)(199004)(7736002)(110136005)(478600001)(71190400001)(4326008)(316002)(68736007)(305945005)(71200400001)(54906003)(118296001)(50226002)(2501003)(8936002)(8676002)(81166006)(25786009)(81156014)(72206003)(36756003)(66556008)(64756008)(66446008)(66946007)(66476007)(73956011)(26005)(102836004)(6506007)(186003)(5660300002)(486006)(386003)(44832011)(476003)(2616005)(53936002)(256004)(14444005)(66066001)(2906002)(6116002)(3846002)(6512007)(52116002)(99286004)(14454004)(86362001)(6486002)(6436002); DIR:OUT; SFP:1102; SCL:1; SRVR:BYAPR04MB6087; H:BYAPR04MB4901.namprd04.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: 5xIdQCE658GrKYKnBdyiHyYVUdR1VTDO5UOJ5YIhhOHwDDf0Brva3SlYsS28b+hScob/0V8RkWBZb9+kHP5FA8N/y9Aj8Z3gn/fXQ6lgS/mQ/VU3jpnoSPWF6awdkhfcCE4eAhEgEgbkscKqr8axvMtFv8MiKYY9yGxMYa29/WJdkK8NikTzON9DOPvzU7XoiF7Qywiszz37YXXG7I1I7DOwDXy+ETGnhRXrqCkz+tPCKI+xALgRfAtJLUZDITL5owYJrNDUmIOquSCeluqtNO/C4UCFUvXGA+EXFhnxRDzugazZBEkTOwJieIm83xagkxDctZKYtRfJG+lTptV6eObThTTSs18FraOTRh+/vcy5DAHYGQMbA45F9JbopN3B7RcL1gBToJKADYEht5xrkSkcDDioGxpqVTg0llQU9TA= MIME-Version: 1.0 X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8f35b306-b616-4704-b696-08d6d27526fd X-MS-Exchange-CrossTenant-originalarrivaltime: 06 May 2019 22:49:53.4227 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: b61c8803-16f3-4c35-9b17-6f65f441df86 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR04MB6087 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 216.71.154.45 Subject: [Qemu-devel] [PATCH v1 1/1] target/riscv: Allow setting ISA extensions via CPU props 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: "alistair23@gmail.com" , "palmer@sifive.com" , Alistair Francis Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP This patch allows us to enable/disable the RISC-V ISA extensions from the QEMU command line. This works with the rv32 and rv64 machines. The idea is that in the future we can now add extensions and leave them disabled by default until enabled by the user. Signed-off-by: Alistair Francis Reviewed-by: Palmer Dabbelt --- Based-on: This is based on my previous series: "RISC-V: Add properties to the CPUs" which has been merged into the RISC-V tree. target/riscv/cpu.c | 70 ++++++++++++++++++++++++++++++++++++++++++++-- target/riscv/cpu.h | 11 ++++++++ 2 files changed, 79 insertions(+), 2 deletions(-) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index 2db173801f..41afed3140 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -23,6 +23,7 @@ #include "cpu.h" #include "exec/exec-all.h" #include "qapi/error.h" +#include "qemu/error-report.h" #include "hw/qdev-properties.h" #include "migration/vmstate.h" @@ -118,7 +119,8 @@ static void riscv_any_cpu_init(Object *obj) static void riscv_base32_cpu_init(Object *obj) { CPURISCVState *env = &RISCV_CPU(obj)->env; - set_misa(env, RV32 | RVI | RVM | RVA | RVF | RVD | RVC | RVS | RVU); + /* We set this in the realise function */ + set_misa(env, 0); } static void rv32gcsu_priv1_09_1_cpu_init(Object *obj) @@ -155,7 +157,8 @@ static void rv32imacu_nommu_cpu_init(Object *obj) static void riscv_base64_cpu_init(Object *obj) { CPURISCVState *env = &RISCV_CPU(obj)->env; - set_misa(env, RV64 | RVI | RVM | RVA | RVF | RVD | RVC | RVS | RVU); + /* We set this in the realise function */ + set_misa(env, 0); } static void rv64gcsu_priv1_09_1_cpu_init(Object *obj) @@ -314,6 +317,7 @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp) RISCVCPUClass *mcc = RISCV_CPU_GET_CLASS(dev); int priv_version = PRIV_VERSION_1_10_0; int user_version = USER_VERSION_2_02_0; + target_ulong target_misa = 0; Error *local_err = NULL; cpu_exec_realizefn(cs, &local_err); @@ -357,6 +361,58 @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp) set_feature(env, RISCV_FEATURE_PMP); } + /* If misa isn't set (rv32 and rv64 machines) set it here */ + if (!env->misa) { + /* Do some ISA extension error checking */ + if (cpu->cfg.ext_i && cpu->cfg.ext_e) { + error_setg(errp, + "I and E extensions are incompatible"); + return; + } + + if (cpu->cfg.ext_g && !(cpu->cfg.ext_i & cpu->cfg.ext_m & + cpu->cfg.ext_a & cpu->cfg.ext_f & + cpu->cfg.ext_d)) { + warn_report("Setting G will also set IMAFD"); + cpu->cfg.ext_i = true; + cpu->cfg.ext_m = true; + cpu->cfg.ext_a = true; + cpu->cfg.ext_f = true; + cpu->cfg.ext_d = true; + } + + /* Set the ISA extensions, checks should have happened above */ + if (cpu->cfg.ext_i) { + target_misa |= RVI; + } + if (cpu->cfg.ext_e) { + target_misa |= RVE; + } + if (cpu->cfg.ext_m) { + target_misa |= RVM; + } + if (cpu->cfg.ext_a) { + target_misa |= RVA; + } + if (cpu->cfg.ext_f) { + target_misa |= RVF; + } + if (cpu->cfg.ext_d) { + target_misa |= RVD; + } + if (cpu->cfg.ext_c) { + target_misa |= RVC; + } + if (cpu->cfg.ext_s) { + target_misa |= RVS; + } + if (cpu->cfg.ext_u) { + target_misa |= RVU; + } + + set_misa(env, RVXLEN | target_misa); + } + riscv_cpu_register_gdb_regs_for_features(cs); qemu_init_vcpu(cs); @@ -379,6 +435,16 @@ static const VMStateDescription vmstate_riscv_cpu = { }; static Property riscv_cpu_properties[] = { + DEFINE_PROP_BOOL("i", RISCVCPU, cfg.ext_i, true), + DEFINE_PROP_BOOL("e", RISCVCPU, cfg.ext_e, false), + DEFINE_PROP_BOOL("g", RISCVCPU, cfg.ext_g, true), + DEFINE_PROP_BOOL("m", RISCVCPU, cfg.ext_m, true), + DEFINE_PROP_BOOL("a", RISCVCPU, cfg.ext_a, true), + DEFINE_PROP_BOOL("f", RISCVCPU, cfg.ext_f, true), + DEFINE_PROP_BOOL("d", RISCVCPU, cfg.ext_d, true), + DEFINE_PROP_BOOL("c", RISCVCPU, cfg.ext_c, true), + DEFINE_PROP_BOOL("s", RISCVCPU, cfg.ext_s, true), + DEFINE_PROP_BOOL("u", RISCVCPU, cfg.ext_u, true), DEFINE_PROP_STRING("priv_spec", RISCVCPU, cfg.priv_spec), DEFINE_PROP_STRING("user_spec", RISCVCPU, cfg.user_spec), DEFINE_PROP_BOOL("mmu", RISCVCPU, cfg.mmu, true), diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index 67d27f45f6..9805e65065 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -229,6 +229,17 @@ typedef struct RISCVCPU { /* Configuration Settings */ struct { + bool ext_i; + bool ext_e; + bool ext_g; + bool ext_m; + bool ext_a; + bool ext_f; + bool ext_d; + bool ext_c; + bool ext_s; + bool ext_u; + char *priv_spec; char *user_spec; bool mmu;