From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-il1-x142.google.com (mail-il1-x142.google.com [IPv6:2607:f8b0:4864:20::142]) by sourceware.org (Postfix) with ESMTPS id 177F3385B835 for ; Sat, 18 Apr 2020 11:17:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 177F3385B835 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=sifive.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=nelson.chu@sifive.com Received: by mail-il1-x142.google.com with SMTP id f82so4837130ilh.8 for ; Sat, 18 Apr 2020 04:17:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=hd8n/ct3l+5tSjGtJ+hs+GijU/K8ogq2eViXQdNwN5Q=; b=jNMWv611em2yhWkLnRQ41+r3cApCCnXNmO2bSi2XqHfFaS3a5WZNGgTLI3F5O8IWPw Ke1G1JWZgCxn1vqkrjhY1YmlNFWGwDlP/6IARGcrEt39wBiPNXMRT9BD+patBH1EPld/ 3hDtwNu9sk1kyWnJSEuoJMsamNwbDMYwRBaIvWgpX/PRr5Wd8FB5fuKJhKVVsSpxxcOY zF8xn0TFHhauK1Dn5+lGm78V/OP2cAavWFg5k8Zorh5XuO5WJgxQuOnN/I9azpmXCFnt sS+uhbCIVhBsr9NYVE5DjFpL8SZy5HY8mHaZzkY86Qo5O5lzNyvGL1Aza+9AndHEX2AP x/Dw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=hd8n/ct3l+5tSjGtJ+hs+GijU/K8ogq2eViXQdNwN5Q=; b=BRwx7GGuGoBicOD5EaGsdKfUiafQWmAY5UPbe9ZKjzY1Uz4ltSOunRoa1OfwxkQ4am HFTK8VamayQ73ejMrGq2Kv93UN1olyv+Q6HJWTTwy4s3KC0nyS+xNKtQbiBlbSBOXipB m3WHPvq3fj0I3nhkl3LJlQf4clagGlkHqkkhExe+jJJ00MAOrdXAZ3aAAqk1l5D8s76v 9Ui5tFU6WgLWod81ivl5ty/L2pqqTBH1Efk/AWJroH332Ed4v7MU4AD8UO6YlNiNkJNA TkDK6l03Z5qKDuu6RD5AeIhvNHDQFOtYtl/fUXRDk1/TWlAcYWgVHRl6D68rMMiHjHCz Ybrg== X-Gm-Message-State: AGi0PuYnsML/ZFSY7DPE++I2y5a+qDWrSR7YGLKouY3+iYfiwaR3zC6Y F4rlNISVxceeB2bZ5ULGFYmNvt4WJvb/MUNYCbxh7eYLlsdsfw== X-Google-Smtp-Source: APiQypKOx2OVj4je0NkqDXco7TK2EPtVX2fviYFjhOjI4BvFxUTRD3YljX7q+gxSPIS61MAGKqTmxnO2PligokRpIm4= X-Received: by 2002:a92:dd09:: with SMTP id n9mr5727847ilm.132.1587208644368; Sat, 18 Apr 2020 04:17:24 -0700 (PDT) MIME-Version: 1.0 References: <1587208075-2462-1-git-send-email-nelson.chu@sifive.com> In-Reply-To: <1587208075-2462-1-git-send-email-nelson.chu@sifive.com> From: Nelson Chu Date: Sat, 18 Apr 2020 19:17:15 +0800 Message-ID: Subject: Re: [PATCH 0/7] RISC-V: Support version controling for ISA standard extensions and CSR To: Binutils , gdb-patches@sourceware.org Cc: Andrew Burgess , Andrew Waterman , asb@lowrisc.org, Kito Cheng , Maxim Blinov , Jim Wilson , Palmer Dabbelt Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-9.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 18 Apr 2020 11:17:27 -0000 Sorry for not sending these patches to Palmer :) CC Palmer. Thanks Nelson On Sat, Apr 18, 2020 at 7:08 PM Nelson Chu wrote: > > Hi binutils and gdb, > > I know every RISCV contirbutors all do the best to maintain the compatibi= lity > between different spec versions. But the specs are changed frequently, a= nd > sometimes it is very hard to keep the compatibility if we don't have a go= od > way to deal with versioning problems. Since different ISA specs define > different instructions, and different privilege specs define different CS= R, > both of them need the version checking and controling mechanism. > > For the ISA versions, you can set them by the RISCV ELF architecture attr= ibute > and assembler option -march, but you have to set them one by one for each > extension. It seems not so friendly for user, so Kito Cheng proposed a g= ood > solution to resolve the problem. That is, support the new assembler opti= ons and > default configure options to reduce the burdens when setting ISA versions= . > The original idea and discussion are come from the following link, > > https://groups.google.com/a/groups.riscv.org/forum/#!msg/sw-dev/aZhMG7NIV= Tk/PTZEaTWiAwAJ) > > =3D=3D=3D New Assembler Options =3D=3D=3D > > * -misa-spec =3D [2p0|2p1|2p2|20190608|20191213] > You can simply choose the ISA spec by this option, and then assembler wil= l set > the version for the standard extensions if you don=E2=80=99t set in the E= LF arch > attributes or -march option. > > * -mriscv-isa-version =3D > The syntax of is same as -march option, but without rv32 or = rv64 > prefix. There are two reasons that you may need this option, > > 1. Some versions of extensions defined in the ISA spec are not matched to= the > toolchain=E2=80=99s implementation. For example, V-ext is defined to ver= sion 0.7 in > ISA spec, but we only have implementations for 0.8 and 0.9. Therefore, y= ou > have to use this option to choose the correct version for V-ext. > > 2. You want to update the version for the specific standard extensions if= the > version are not set in the ELF arch attributes and -march option. > > =3D=3D=3D New Default Configure Options =3D=3D=3D > > * --with-arch =3D > The syntax of is same as -march option. Assembler will chec= k this > if -march option and ELF arch attributes aren=E2=80=99t set. > > * --with-isa-spec =3D [2p0|2p1|2p2|20190608|20191213] > The syntax is same as -misa-spec option. Assembler will check this if > -misa-spec option isn=E2=80=99t set. > > * --with-riscv-isa-version =3D > The syntax of is same as -mriscv-isa-version option. Assemb= ler > will check this if -mriscv-isa-version option isn=E2=80=99t set. > > =3D=3D=3D The Priority of these options =3D=3D=3D > > * ELF arch attributes > Assembler options > Default configure options > * For GAS options, -march > -mriscv-isa-version > -misa-spec > * For configure options, --with-arch > --with-riscv-isa-version > --with-= isa-spec > > =3D=3D=3D Example =3D=3D=3D > > $ cat test.s > .attribute arch, "rv32i1p9fv_zicsr" > > $ riscv32-unknown-elf-as -march-attr -misa-spec=3D2p2 -mriscv-isa-version= =3Di2p1a2p1v0p9 test.s -o test.o > > $ riscv32-unknown-elf-readelf -A test.o > Attribute Section: riscv > File Attributes > Tag_RISCV_arch: "rv32i1p9_f2p0_v0p9_zicsr0p0" > ... > > The above example covers most cases. > > * For i-ext, we already set the version 1p9 in elf attribute, so -misa-sp= ec and > -mriscv-isa-version don't update the version to 2p0 and 2p1. > > * For f-ext, we don't set the version to it, so use the default version 2= p0 > according to the ISA spec 2p2. > > * For v-ext, the default version is 0p7 according to ISA spec 2p2, but we= use > -mriscv-isa-version to update it to 0p9. > > * For a-ext, it isn't enabled by -march or elf attribute, so we don't upd= ate it's > version even if -mriscv-isa-version is set. > > * As for the zicsr extension, it is defined in the lastest ISA spec rathe= r than 2p2, > so set it's version to 0p0. > > > As for the privilege version, I get the related request in the following = link, > https://github.com/riscv/riscv-binutils-gdb/issues/202 > > We also support new assembler options to choose the spec you want, and th= en > assembler will generate the correct CSR address according to the chosen s= pec. > If the obselete CSR name is used, then report the warning message when th= e > -mcsr-check is set, and use the latest defined address for the CSR. Of c= ourse, > you can also choose the spec by setting the orginal RISCV ELF priv attrib= utes. > Beside, the disassembler can show the CSR according to the chosen privile= ge spec > by the new disassmebler option. However, the CSR address is showed direc= tly if > it is invalid for the chosen spec. > > =3D=3D=3D New Assembler Option =3D=3D=3D > > * -mpriv-spec=3D[1p9|1p9p1|1p10|1p11] > This is used to set the privileged spec=E2=80=99s version, and we can dec= ide whether > the CSR is valid or not. > > =3D=3D=3D New Default Configure Option =3D=3D=3D > > * --with-priv-spec =3D [1p9|1p9p1|1p10|1p11] > The syntax is same as -mpriv-spec option. Assembler will check this sett= ing > if -mpriv-spec option isn=E2=80=99t set. > > =3D=3D=3D New Disassmebler Option =3D=3D=3D > > * -Mpriv-spec=3D[1p9|1p9p1|1p10|1p11] > The syntax is same as -mpriv-spec option. The disassembler can show the = CSR > correctly according to the chosen privilege spec. > > > Notes, > > 1. I'm not sure if GDB needs the above version checking, but I think the = current > modifications won't change the behavior of GDB. We still use the DECLARE= _CSR > to generate the gdb/features/riscv/[32|64]bit-csr.xml, that means we only= generate > the CSR which are valid in the latest privilege spec. Also, the objdump = shows > the CSR according to the latest privilege spec by default. > > 2. The default ISA spec is set to 2p2 rather than the lastest version. T= he reason > is that compiler generates the ISA string with fixed 2p0 verisons only fo= r the > RISCV ELF architecture attributes, but not for the -march option. Theref= ore, we > should update the compiler or linker to resolve this problem in the futru= e patches. > > 3. How to extend the default versions and new ISA spec? > You only need to update the riscv_ext_version_table which is defined in t= he > opcodes/riscv-opc.c. > > const struct riscv_ext_version riscv_ext_version_table[] =3D > { > /* name, spec name, major, minor. */ > {"e", "20191213", 1, 9}, > {"e", "20190608", 1, 9}, > {"e", "2p2", 1, 9}, > > {"i", "20191213", 2, 1}, > {"i", "20190608", 2, 1}, > {"i", "2p2", 2, 0}, > ... > }; > > 4. How to extend new privilege spec and new CSR? > > * include/opcode/riscv.h > enum riscv_csr_vclass > { > CSR_CLASS_VNONE, /* Default value */ > > CSR_CLASS_V1P9, /* v1.9 */ > CSR_CLASS_V1P9P1, /* v1.9.1 */ > CSR_CLASS_V1P10, /* v1.10 */ > CSR_CLASS_V1P11, /* v1.11 */ > CSR_CLASS_VDRAFT > }; > > * opcodes/riscv-opc.c > > static const struct priv_version_t priv_versions[] =3D > { > {"1p9", CSR_CLASS_V1P9}, > {"1p9p1", CSR_CLASS_V1P9P1}, > {"1p10", CSR_CLASS_V1P10}, > {"1p11", CSR_CLASS_V1P11}, > > /* Terminate the list. */ > {NULL, 0} > }; > > * include/opcode/riscv-opc.h > > Format, DECLARE_CSR (NAME, VALUE, CLASS, DEFINE_VER, ABORT_VER) > DECLARE_CSR_ALIAS(NAME, VALUE, CLASS, DEFINE_VER, ABORT_VER) > > NAME: CSR name. > VALUE: CSR address > CLASS: ISA dependency > DEFINE_VER: First defined in which privilege spec. > ABORT_VER: Aborted in which privilege spec. If the CSR is still valid i= n > the lastest version, then it should be CSR_CLASS_VDRAFT. > > If the CSR is aborted in the latest spec, or has not only one information= , then > use DECLARE_CSR_ALIAS. Otherwise, use DECLARE_CSR. > > For example, > DECLARE_CSR(ustatus, CSR_USTATUS, CSR_CLASS_I, CSR_CLASS_V1P9, CSR_CLASS_= VDRAFT) > DECLARE_CSR_ALIAS(ubadaddr, CSR_UTVAL, CSR_CLASS_I, CSR_CLASS_V1P9, CSR_C= LASS_V1P10) > > > Thanks > Nelson >