From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id SJI9KX/Rx19ncQAAWB0awg (envelope-from ) for ; Wed, 02 Dec 2020 12:40:15 -0500 Received: by simark.ca (Postfix, from userid 112) id A1D2B1F0AB; Wed, 2 Dec 2020 12:40:15 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=0.4 required=5.0 tests=DKIM_SIGNED,MAILING_LIST_MULTI, RDNS_NONE,T_DKIM_INVALID,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.2 Received: from sourceware.org (unknown [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 578551E58E for ; Wed, 2 Dec 2020 12:40:15 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 62045396D83F; Wed, 2 Dec 2020 17:39:51 +0000 (GMT) Received: from mail-wr1-x444.google.com (mail-wr1-x444.google.com [IPv6:2a00:1450:4864:20::444]) by sourceware.org (Postfix) with ESMTPS id 7C38E396D81D for ; Wed, 2 Dec 2020 17:39:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 7C38E396D81D Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=embecosm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=andrew.burgess@embecosm.com Received: by mail-wr1-x444.google.com with SMTP id o1so4948951wrx.7 for ; Wed, 02 Dec 2020 09:39:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=/MuAEipYgcV5kFH4QVxiKs6ReZDkQlB0vSnusSuGgYU=; b=XieWuX2R5YGjlNmOlwjsUbgxkDUHSZJRS3KQnk4X8BixEKZIu0YOTOjiLiiFJi0Ao/ U8LfUSCYF/bAmjFbaAyS7tkceyWPLEWK/NdAexnDH3WXcBWispP4ryqtqut3lZZKvIla bAd55C36UOE3nXxlPhatSou+DxvJgQb1ezdnzmZp1ymau2MJtO7uYkn0OSCj7nrZTncu f4cnsAgYtZ6VJ7XJTNxTA9NVomhcp6FjMhiWCQ/nuPlZgDYbDqpGmPUa0ZAY3Z5kd+Qm 6Vj8MnvuC+730QNB8EdrrSnH508hcFGW8DatVeUwyVa6DgOUP8SMZ3oV060kwYoc5McI Im/w== 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:mime-version:content-transfer-encoding; bh=/MuAEipYgcV5kFH4QVxiKs6ReZDkQlB0vSnusSuGgYU=; b=fLhJRyxfFYIRj6AMhTNDadiczdXSBAKKHaWl9uF7LdvV/XQYIvuYX6DLvMqCuj9tls fjH7YIZiuwFCynhmSEjj9TwUzwWoHMRRVpq/zYsH8MhM4Hev8pCkYgaYrYISMNUi+0Qz B2alzTQ+NKQWl2F5KYG231oE0BLfRpEsQY/Jv2zS8Z9qqBt1YdnCJFnzEGm++uC78zY+ yGsYtp5aVAyYQ6mnOk8vlpAaTHKfkCXyppxegAdjchStyiKVJRE5gGQP1cfyurHJW7Ze S7ESnjI51YINl0RYmxvMprE6w2PzA/jt0GDp4fKQJ4Y36He209anjUb5Fe/RagURmeFs K18g== X-Gm-Message-State: AOAM533FbHnWwSdTsyVrGZFwfvywRyEYpH9DgN4LiT/3Eb2Gd3asW4Xu 4wYuA+0jdfZoSbhqfme2Hw7Pzg== X-Google-Smtp-Source: ABdhPJxFGbyo6th64y9FKR7037K4Zkb7ZnWXQCH9GyzCuH4jIAsSgaPxi8Ysf/ywl85yxfum359low== X-Received: by 2002:a5d:4b81:: with SMTP id b1mr4776569wrt.372.1606930786584; Wed, 02 Dec 2020 09:39:46 -0800 (PST) Received: from localhost (host109-154-20-215.range109-154.btcentralplus.com. [109.154.20.215]) by smtp.gmail.com with ESMTPSA id f199sm2819636wme.15.2020.12.02.09.39.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Dec 2020 09:39:46 -0800 (PST) From: Andrew Burgess To: binutils@sourceware.org, gdb-patches@sourceware.org Subject: [PATCH 8/8] gdb/riscv: write CSRs into baremetal core dumps Date: Wed, 2 Dec 2020 17:39:32 +0000 Message-Id: <1596bba6bdc41f131291740162ac6c8f0aac7aac.1606930261.git.andrew.burgess@embecosm.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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: , Errors-To: gdb-patches-bounces@sourceware.org Sender: "Gdb-patches" Use the current target description to include CSRs into the RISC-V baremetal core dumps. Every CSR declared in the current target description will be included in the core dump. If a CSR fails to read then the value 0 will be placed into the core dump instead. It will be critical for users that they have the same target description in use when loading the core file as was in use when writing the core file. This should be fine if the user allows the target description to be written into the core file. gdb/ChangeLog: * riscv-non-tdep.c (riscv_csrset): New static global. (riscv_update_csrmap): New function. (riscv_iterate_over_regset_sections): Process CSRs. --- gdb/ChangeLog | 7 +++++ gdb/riscv-none-tdep.c | 60 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+) diff --git a/gdb/riscv-none-tdep.c b/gdb/riscv-none-tdep.c index 0a4215a60e9..b20e2d8f475 100644 --- a/gdb/riscv-none-tdep.c +++ b/gdb/riscv-none-tdep.c @@ -27,6 +27,8 @@ #include "riscv-tdep.h" #include "elf-bfd.h" #include "regset.h" +#include "user-regs.h" +#include "target-descriptions.h" /* Function declarations. */ @@ -250,6 +252,42 @@ static const struct regset riscv_fregset = riscv_fregmap, riscv_supply_regset, regcache_collect_regset }; +/* Define the CSR regset, this is not constant as the regmap field is + updated dynamically based on the current target description. */ + +static struct regset riscv_csrset = +{ + nullptr, regcache_supply_regset, regcache_collect_regset +}; + +/* Update the regmap field of RISCV_CSRSET based on the CSRs available in + the current target description. */ + +static void +riscv_update_csrmap (struct gdbarch *gdbarch, + const struct tdesc_feature *feature_csr) +{ + int i = 0; + + /* Release any previously defined map. */ + delete[] ((struct regcache_map_entry *) riscv_csrset.regmap); + + /* Now create a register map for every csr found in the target + description. */ + struct regcache_map_entry *riscv_csrmap + = new struct regcache_map_entry[feature_csr->registers.size() + 1]; + for (auto &csr : feature_csr->registers) + { + int regnum = user_reg_map_name_to_regnum (gdbarch, csr->name.c_str(), + csr->name.length()); + riscv_csrmap[i++] = {1, regnum, 0}; + } + + /* Mark the end of the array. */ + riscv_csrmap[i] = {0}; + riscv_csrset.regmap = riscv_csrmap; +} + /* Callback for iterate_over_regset_sections that records a single regset in the corefile note section. */ @@ -313,6 +351,28 @@ riscv_iterate_over_regset_sections (struct gdbarch *gdbarch, + register_size (gdbarch, RISCV_CSR_FCSR_REGNUM)); cb (".reg2", sz, sz, &riscv_fregset, NULL, cb_data); } + + /* Read or write the CSRs. The set of CSRs is defined by the current + target description. The user is responsible for ensuring that the + same target description is in use when reading the core file as was + in use when writing the core file. */ + const struct target_desc *tdesc = gdbarch_target_desc (gdbarch); + + /* Do not dump/load any CSRs if there is no target description or the target + description does not contain any CSRs. */ + if (tdesc != nullptr) + { + const struct tdesc_feature *feature_csr + = tdesc_find_feature (tdesc, riscv_feature_name_csr); + if (feature_csr != nullptr && feature_csr->registers.size () > 0) + { + riscv_update_csrmap (gdbarch, feature_csr); + cb (".reg-riscv-csr", + (feature_csr->registers.size() * riscv_isa_xlen (gdbarch)), + (feature_csr->registers.size() * riscv_isa_xlen (gdbarch)), + &riscv_csrset, NULL, cb_data); + } + } } /* Initialize RISC-V bare-metal ABI info. */ -- 2.25.4