113b7b8142
The goal of this commit is to allow RV64 binaries compiled for the 'F' extension to run on a target that supports both the 'F' and 'D' extensions. The 'D' extension depends on the 'F' extension and chapter 9 of the RISC-V ISA manual implies that running a program compiled for 'F' on a 'D' target should be fine. To support this the gdbarch now holds two feature sets, one represents the features that are present on the target, and one represents the features requested in the ELF flags. The existing error checks are relaxed slightly to allow binaries compiled for 32-bit 'F' extension to run on targets with the 64-bit 'D' extension. A new set of functions called riscv_abi_{xlen,flen} are added to compliment the existing riscv_isa_{xlen,flen}, and some callers to the isa functions now call the abi functions when that is appropriate. In riscv_call_arg_struct two asserts are removed, these asserts no longer make sense. The asserts were both like this: gdb_assert (TYPE_LENGTH (ainfo->type) <= (cinfo->flen + cinfo->xlen)); And were made in two cases, when passing structures like these: struct { integer field1; float field2; }; or, struct { float field1; integer field2; }; When running on an RV64 target which only has 32-bit float then the integer field could be 64-bits, while if the float field is 32-bits the overall size of the structure can be 128-bits (with 32-bits of padding). In this case the assertion would fail, however, the code isn't incorrect, so its safe to just remove the assertion. This was tested by running on an RV64IMFDC target using a compiler configured for RV64IMFC, and comparing the results with those obtained when using a compiler configured for RV64IMFDC. The only regressions I see (now) are in gdb.base/store.exp and are related too different code generation choices GCC makes between the two targets. Finally, this commit does not make any attempt to support running binaries compiled for RV32 on an RV64 target, though nothing in here should prevent that being supported in the future. gdb/ChangeLog: * arch/riscv.h (struct riscv_gdbarch_features) <hw_float_abi>: Delete. <operator==>: Update with for removed field. <hash>: Likewise. * riscv-tdep.h (struct gdbarch_tdep) <features>: Renamed to... <isa_features>: ...this. <abi_features>: New field. (riscv_isa_flen): Update comment. (riscv_abi_xlen): New declaration. (riscv_abi_flen): New declaration. * riscv-tdep.c (riscv_isa_xlen): Update to get answer from isa_features. (riscv_abi_xlen): New function. (riscv_isa_flen): Update to get answer from isa_features. (riscv_abi_flen): New function. (riscv_has_fp_abi): Update to get answer from abi_features. (riscv_call_info::riscv_call_info): Use abi xlen and flen, not isa xlen and flen. (riscv_call_info) <xlen, flen>: Update comment. (riscv_call_arg_struct): Remove invalid assertions (riscv_features_from_gdbarch_info): Update now hw_float_abi field is removed. (riscv_gdbarch_init): Gather isa features and abi features separately, ensure both match on the gdbarch when reusing an old gdbarch. Relax an error check to allow 32-bit abi float to run on a target with 64-bit float hardware.
76 lines
2.6 KiB
C++
76 lines
2.6 KiB
C++
/* Common target-dependent functionality for RISC-V
|
|
|
|
Copyright (C) 2018-2019 Free Software Foundation, Inc.
|
|
|
|
This file is part of GDB.
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation; either version 3 of the License, or
|
|
(at your option) any later version.
|
|
|
|
This program 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 General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
|
|
|
#ifndef ARCH_RISCV_H
|
|
#define ARCH_RISCV_H
|
|
|
|
#include "common/tdesc.h"
|
|
|
|
/* The set of RISC-V architectural features that we track that impact how
|
|
we configure the actual gdbarch instance. We hold one of these in the
|
|
gdbarch_tdep structure, and use it to distinguish between different
|
|
RISC-V gdbarch instances.
|
|
|
|
The information in here ideally comes from the target description,
|
|
however, if the target doesn't provide a target description then we will
|
|
create a default target description by first populating one of these
|
|
based on what we know about the binary being executed, and using that to
|
|
drive default target description creation. */
|
|
|
|
struct riscv_gdbarch_features
|
|
{
|
|
/* The size of the x-registers in bytes. This is either 4 (RV32), 8
|
|
(RV64), or 16 (RV128). No other value is valid. Initialise to the
|
|
invalid 0 value so we can spot if one of these is used
|
|
uninitialised. */
|
|
int xlen = 0;
|
|
|
|
/* The size of the f-registers in bytes. This is either 4 (RV32), 8
|
|
(RV64), or 16 (RV128). This can also hold the value 0 to indicate
|
|
that there are no f-registers. No other value is valid. */
|
|
int flen = 0;
|
|
|
|
/* Equality operator. */
|
|
bool operator== (const struct riscv_gdbarch_features &rhs) const
|
|
{
|
|
return (xlen == rhs.xlen && flen == rhs.flen);
|
|
}
|
|
|
|
/* Inequality operator. */
|
|
bool operator!= (const struct riscv_gdbarch_features &rhs) const
|
|
{
|
|
return !((*this) == rhs);
|
|
}
|
|
|
|
/* Used by std::unordered_map to hash feature sets. */
|
|
std::size_t hash () const noexcept
|
|
{
|
|
std::size_t val = ((xlen & 0x1f) << 5 | (flen & 0x1f) << 0);
|
|
return val;
|
|
}
|
|
};
|
|
|
|
/* Create and return a target description that is compatible with
|
|
FEATURES. */
|
|
|
|
const target_desc *riscv_create_target_description
|
|
(struct riscv_gdbarch_features features);
|
|
|
|
#endif /* ARCH_RISCV_H */
|