From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 0B5C03858C56 for ; Fri, 12 Apr 2024 14:49:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0B5C03858C56 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 0B5C03858C56 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712933349; cv=none; b=dvk47IAgPUakt8PwIMfBvlCuneXpLvZtsC3IMCqOtfp6lug5cDms7kmi7XTPZQO48z0dXjgtPi5f01r8Ee2OgIYF+MEnhf0mYxFoiIyl+XawI/wXdaYJi7ViKkAGAugm+YZ7C5iqRbwp0j+ycoaRGGM56WMdXwkdicU5co55u+0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712933349; c=relaxed/simple; bh=9XT1Kbce+VM87u8LRs0T4ec1Ojb1AhcUI5vPmGRKA6c=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=XwnR3g1pIQPyL8wYhu/BxQo4FFLYEqPH0VWecJ0oh9gi4Ru94vGwei+T6HUk/U6nyQHC0SUul8VsdfS35GPu8agSjSjx8nweixB/aNQeqdtheIdiloGHhzqbqE6DX19pQrA4w9j7zY8ueffJ/bXyJLZC7OpM+UOyPmkLRpskQkQ= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1712933343; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=ob1d7SGc85QDkFte1Cxc1/pSSPVsD1VnL6GfpSLdttw=; b=GlHX4BvQ/PmD1LXuc+aYPd+ZA3HriB4io35F6i1A2KJbTx29+tRyPa77nGyeZiYNqQATjP iQeDc7wjO2Y4J+mUeN5TB54Qqg23b+OC2AIibzXevph7MT4EvRQDOnyzE65DQMtst1h6Ny KZNjFPtoUWU9vdQq4bUENuYVW1mLTkg= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-602-Nrb2SyasMMSGTMKlr7OmgA-1; Fri, 12 Apr 2024 10:49:02 -0400 X-MC-Unique: Nrb2SyasMMSGTMKlr7OmgA-1 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-343cfa7a9ebso578660f8f.0 for ; Fri, 12 Apr 2024 07:49:02 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712933340; x=1713538140; h=mime-version:message-id:date:references:in-reply-to:subject:to:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ob1d7SGc85QDkFte1Cxc1/pSSPVsD1VnL6GfpSLdttw=; b=SPg9B6S6e0d0ONQ/0maTlLHLbAI0I0boKJzgM+CuBqZgWyq/X3tDRW/6VNQMoNiiRU W8NPHU0rW5qzvWqkLfcR0d1gF0qtzuSRFkYvT/ePLTQu+dGEu9QrHWJUfjV8fp7Zykdm x2/sQsyWy1jYDL7G3uG2Pa4YERWzQki9kLa651JE6YyHCAIL7e4xpJkt1O5fc3ek0aXA JrBKibhjaA177GV8YK6Slyl0zEwhhE65wMUyuvNbn14AcZyK36G2e6hYd1pKdHEYO3ED KVQo21JglTnjUWp3FwoFZNugMo3Ffe9sJYVmBRA31R+B3R5sXsjzTgTvi0Jq5d9bli6b cJPw== X-Forwarded-Encrypted: i=1; AJvYcCUm96324GNA2UxxyxhQMMQ7jJ660ARi4QjP39ACEicE24dP00WUIaLRMQ4AHJckkHAcKPhlsTwpxQGYoS70Q3Z6N+fp4IrJnAg9gA== X-Gm-Message-State: AOJu0YzMGYF0QvZmpGxaqcbKD3nHoDvhtib1LnSRBhCKzP1kj/ZSloL7 o0J4Scif7DAjJWyVV4T/ebxbASa9TvQNne8/LSgB/zMXkYjJptYko7WWmXYYIdpACcwHzmStTtq HWozu3sFFZh8SNSbQ8LC4LsL4V7FwJ00j7++fTUsScLv850apRCR9yaN0SR6/C8UYsto= X-Received: by 2002:adf:f6c8:0:b0:343:dc46:bb4b with SMTP id y8-20020adff6c8000000b00343dc46bb4bmr1889462wrp.59.1712933340083; Fri, 12 Apr 2024 07:49:00 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF/viGYL2yWeoT4JED+NYo8Twzq3aqdD9q1f+NrY3uWtplKDwUHZpDlvXvz3+KYnabO+IXikg== X-Received: by 2002:adf:f6c8:0:b0:343:dc46:bb4b with SMTP id y8-20020adff6c8000000b00343dc46bb4bmr1889446wrp.59.1712933339499; Fri, 12 Apr 2024 07:48:59 -0700 (PDT) Received: from localhost (185.223.159.143.dyn.plus.net. [143.159.223.185]) by smtp.gmail.com with ESMTPSA id b10-20020a056000054a00b00341b7d5054bsm4467635wrf.72.2024.04.12.07.48.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Apr 2024 07:48:59 -0700 (PDT) From: Andrew Burgess To: Bernd Edlinger , "gdb-patches@sourceware.org" Subject: Re: [PATCH v2] sim: riscv: Fix some compatibility issues with gcc In-Reply-To: References: Date: Fri, 12 Apr 2024 15:48:58 +0100 Message-ID: <875xwm63hh.fsf@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain X-Spam-Status: No, score=-13.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_SHORT,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Bernd Edlinger writes: > This makes the riscv simulator able to execute a simple > "hello world" program when gcc is configured > with: > > .../gcc-trunk/configure --target=riscv-unknown-elf > > The first problem is that gcc generates rv32 > code by default in this configuration, while > riscv64-unknown-elf generates rv64 code by default. > > So change the riscv/acinclude.m4 to use the same > logic here. I'm sorry, but this change is not OK. At least, I'll need more convincing before this could be merged. Previously, the riscv sim would support ( in theory ) both RV32 and RV64, and would pick the correct word size based on the ELF architecture. What you're finding is that the riscv sim is (apparently) pretty buggy. With just the sim-main.c fix and the model_list.def change I can see the simulator trying to run the RV32 code. But, the problem I see is confusion about whether registers should be sign extended or not. One example of where this goes wrong is this. Consider the instruction: c.li a1,-1 this will result in the value 0xffffffffffffffff being written into the register, even for RV32 code. But as this is 32-bit code, I also see the code build the constant 0xffffffff by shifting and or-ing things together. The code then compares the register containing 0xffffffffffffffff with the register containing 0xffffffff together, and expects them to be the same. Obviously they are not the same, so the code takes an incorrect branch, and everything goes wrong... If we force the build to be RV32 only then the register size will be 32-bits and the above problem is "solved". But it's not really, we're just masking the issue. So I think we need to solve the register size issue first. > > And the second issue is that gcc does by default > generate instructions in INSN_CLASS_C, so move > the M(GC) to top of list, in riscv/model_list.def. I haven't looked at this part of the change yet. But just going by my gut, this doesn't feel right. I would have expected there to be some logic "somewhere" that checks down the model list and looks for a mode with the required extensions. Just moving the one we want/need to the top feels like we're just changing the default. Is the "pick the correct model" code broken? Completely missing? > > Then there was apparently a confusion which cpu > model uses JAL and which ADDIW. Fixed that in > execute_c, case MATCH_C_JAL | MATCH_C_ADDIW. You might consider breaking this change out, as this third part could go in on its own I think. Thanks, Andrew > > With these changes a simple c-prgram can be executed, > however there is still work to do, since when the > program does floating point operations, gcc starts to > generate hardware floating point instructions, with no > obvious opt-out option. > > Note the gcc test suite can be used to test the > simulator in this way: > > make check-gcc RUNTESTFLAGS="--target_board=multi-sim SIM=riscv-unknown-elf-run" > > Now many tests are passed, except those which use > floating point instructions. > > To work around the not supported float instructions the > following gcc configuration can be used, which makes > most of the gcc test cases successfully executed: > > .../gcc-trunk/configure --prefix=... --target=riscv-unknown-elf > --disable-multilib --with-arch=rv32imac --with-abi=ilp32 > > Note: binutils are installed at prefix path and newlib/libgloss in-tree. > > Fixes 3224e32fb84f ("sim: riscv: Add support for compressed integer instructions") > --- > sim/configure | 6 +++--- > sim/riscv/acinclude.m4 | 4 ++-- > sim/riscv/model_list.def | 2 +- > sim/riscv/sim-main.c | 4 ++-- > 4 files changed, 8 insertions(+), 8 deletions(-) > > v2: updated the commit message, with some hints > how to compile a compatible gcc toolchain. > > diff --git a/sim/configure b/sim/configure > index 1ebef377973..fdc0a86d524 100755 > --- a/sim/configure > +++ b/sim/configure > @@ -17479,10 +17479,10 @@ $as_echo "$sim_ppc_xor_endian" >&6; } > > { $as_echo "$as_me:${as_lineno-$LINENO}: checking riscv bitsize" >&5 > $as_echo_n "checking riscv bitsize... " >&6; } > -SIM_RISCV_BITSIZE=64 > +SIM_RISCV_BITSIZE=32 > case $target in #( > - riscv32*) : > - SIM_RISCV_BITSIZE=32 ;; #( > + riscv64*) : > + SIM_RISCV_BITSIZE=64 ;; #( > *) : > ;; > esac > diff --git a/sim/riscv/acinclude.m4 b/sim/riscv/acinclude.m4 > index 0c6290c9c08..e9953c1017d 100644 > --- a/sim/riscv/acinclude.m4 > +++ b/sim/riscv/acinclude.m4 > @@ -15,8 +15,8 @@ dnl along with this program. If not, see . > dnl > dnl NB: This file is included in sim/configure, so keep settings namespaced. > AC_MSG_CHECKING([riscv bitsize]) > -SIM_RISCV_BITSIZE=64 > +SIM_RISCV_BITSIZE=32 > AS_CASE([$target], > - [riscv32*], [SIM_RISCV_BITSIZE=32]) > + [riscv64*], [SIM_RISCV_BITSIZE=64]) > AC_MSG_RESULT([$SIM_RISCV_BITSIZE]) > AC_SUBST(SIM_RISCV_BITSIZE) > diff --git a/sim/riscv/model_list.def b/sim/riscv/model_list.def > index b83557e5539..df9ec897126 100644 > --- a/sim/riscv/model_list.def > +++ b/sim/riscv/model_list.def > @@ -1,9 +1,9 @@ > +M(GC) > M(G) > M(I) > M(IM) > M(IMA) > M(IA) > -M(GC) > M(IC) > M(IMC) > M(IMAC) > diff --git a/sim/riscv/sim-main.c b/sim/riscv/sim-main.c > index adff99921c6..9c0d070aa60 100644 > --- a/sim/riscv/sim-main.c > +++ b/sim/riscv/sim-main.c > @@ -1018,7 +1018,7 @@ execute_c (SIM_CPU *cpu, unsigned_word iw, const struct riscv_opcode *op) > case MATCH_C_JAL | MATCH_C_ADDIW: > /* JAL and ADDIW have the same mask but are only available on RV64 or > RV32 respectively. */ > - if (RISCV_XLEN (cpu) == 64) > + if (RISCV_XLEN (cpu) == 32) > { > imm = EXTRACT_CJTYPE_IMM (iw); > TRACE_INSN (cpu, "c.jal %" PRIxTW, > @@ -1027,7 +1027,7 @@ execute_c (SIM_CPU *cpu, unsigned_word iw, const struct riscv_opcode *op) > pc = riscv_cpu->pc + imm; > TRACE_BRANCH (cpu, "to %#" PRIxTW, pc); > } > - else if (RISCV_XLEN (cpu) == 32) > + else if (RISCV_XLEN (cpu) == 64) > { > imm = EXTRACT_CITYPE_IMM (iw); > TRACE_INSN (cpu, "c.addiw %s, %s, %#" PRIxTW "; // %s += %#" PRIxTW, > -- > 2.39.2