From patchwork Tue Jan 16 10:47:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 763017 Delivered-To: patch@linaro.org Received: by 2002:a5d:5903:0:b0:337:62d3:c6d5 with SMTP id v3csp1550858wrd; Tue, 16 Jan 2024 02:49:20 -0800 (PST) X-Google-Smtp-Source: AGHT+IH1YCfKuHZvpUPt/SAUpOsM0BAM8pCHHBzZryLwWHLovX+LCMykt1Y/USPudSq0RtOMQl4s X-Received: by 2002:a05:620a:2587:b0:783:6be0:2617 with SMTP id x7-20020a05620a258700b007836be02617mr655524qko.63.1705402160240; Tue, 16 Jan 2024 02:49:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1705402160; cv=none; d=google.com; s=arc-20160816; b=lZFInPd1bO43Omlo2empKSW9VepYYE32/5JLuExP4zU/JxWWtZ6SCjHHbxGX4ug6uP EHhcEXGlq5gxEDe/EGKG3QqekZMNpmmkBqN+Ps7XPErn/SLuJ667OelEvdzxfdAQTALj RS8f5GMTNXpMfRXkMMgMydUw6arS25MXz/OPdxvDV28IemkwcQj82YwtwMf7tYqlKLyS zxMDrO1Z2/k5Ur8sk3ZVa//ELyGJuveDR2Dojo4qFFfe3H8inS/UvbI9uSrLHvLyUuBC MCDV+PYoAOas4Nk/gV4Kty8eoz2wJoXb0IC/e6p0PyZvQVBvuzrDUVPMMObvabs88WJi fGLA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=+LelgKAo158O2Sztxf7zqxBylQHRug/zKMX+/zQHNaU=; fh=9jJHrC5PrJaZEpYolodfKVbyWk7Nrvl/dH0bi7QOqKg=; b=AV/RtH3aS6BJQ2L4twYTaiYKSERsoJkef0fySG0PHYaxdXmWTqSzU6mQkST4RhWU0q VzZAue1xF/FSXLKNjCy1ron+Un9n+V+KFW8bAki7SPAeEtawHb0tAQLy8DMNoEOchKkx k+dz8Y4d7UHrHCzkPjAoGPa3Yu3P2v3HBoDawlHfURrefZAOZi6yC+660NBLsSRondQA RJDfEiUATW7UJlyGXnuZnEkKxs2gdwPz9sXKamALZxhtAlmR8uuGM+8x3zHhx50w9nBu Ri2EHaf0KB3GGnmIRb8ai3DZEDD7rMZoH2G5j9/VnJFohWD/a3//w5PMSTpfDJpD0nBo K0Iw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=l+l5nrHF; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id pe1-20020a05620a850100b00781a14c43besi9211777qkn.674.2024.01.16.02.49.20 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 16 Jan 2024 02:49:20 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=l+l5nrHF; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rPgzm-0002Sk-6C; Tue, 16 Jan 2024 05:48:38 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rPgzX-0002J8-P5 for qemu-devel@nongnu.org; Tue, 16 Jan 2024 05:48:25 -0500 Received: from mail-wr1-x42d.google.com ([2a00:1450:4864:20::42d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rPgzT-0007Cy-KL for qemu-devel@nongnu.org; Tue, 16 Jan 2024 05:48:21 -0500 Received: by mail-wr1-x42d.google.com with SMTP id ffacd0b85a97d-337bcaef29eso249584f8f.0 for ; Tue, 16 Jan 2024 02:48:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1705402097; x=1706006897; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=+LelgKAo158O2Sztxf7zqxBylQHRug/zKMX+/zQHNaU=; b=l+l5nrHF14YlSMFsBToVyTbsS0fB5NAjL2aScuVWGDVltVVwSyvmDIUatQar6V0L/s TnR/vMgcpwwwf7m2+APOUcaqlV3NFyb2El+MsnsxwI13yQr6+fvWwCcmpukPPh1Ptv1M Ji3dEvENgZeRnhaGmWw96QTgbeDZ5kb4q4TPiyIyG9iOThOS4LSuaduff9TiuYeMGlFd RZDQAfOBP6rgM6I9Z8uX3Ja9lIl2izVAgZBVMxEaPrR/Arp728GonXikJ1KUnwI+T1rQ E/iXwiK0z8qTNp+7BFV24GaZiVmSWdDz1rzZoadoqjiPXf/Nzt/8+xQ1yKt7h3uYchOS Y57A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705402097; x=1706006897; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+LelgKAo158O2Sztxf7zqxBylQHRug/zKMX+/zQHNaU=; b=Bjxo4p9eFBLwgXOQZrq1Zf7TuKvAobtYgcdch6KAyqS1YqHD4J2FEYQjOGfOdTDhHs BNn9fxX+MW14wrYxMJ9yftTLFQ5JW/Ck26bz3Q8SdiqmR1YtA2MljDGg2qBTzEAogoUo RZJcy+Qic/tsLmnMQ37p4aItAFPsuVNFchXPSHvkxpqK4WE6aziSghUxYUT0L65feBcI h4saq/MkU4LgvernhOqJ2YEhV3WvjU5xwowiBxkzl334ecMdGSino+ZrA5ULtwMjF7O4 5S+M2MwWVCUXBI2q4ETPgI3Cofz1TT4jz0nKwBd4LtxYOvzcSv17XnNmxsWxBJ79wJhp UE6Q== X-Gm-Message-State: AOJu0YyWfYVJFh3Z53GKUv3wDrrpZ0eHoG59ZPsebU0lfifThtrxelmg DVqhgrwAFDYfJvvqWdHC8NbdhuSRaDvqPg== X-Received: by 2002:adf:ab16:0:b0:337:4e9a:ed44 with SMTP id q22-20020adfab16000000b003374e9aed44mr3875003wrc.11.1705402096799; Tue, 16 Jan 2024 02:48:16 -0800 (PST) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id f6-20020a5d4dc6000000b00336a2566aa2sm14252867wru.61.2024.01.16.02.48.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Jan 2024 02:48:12 -0800 (PST) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id EDC015F8ED; Tue, 16 Jan 2024 10:48:09 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Akihiko Odaki , =?utf-8?q?Alex_Benn=C3=A9e?= , Palmer Dabbelt , Alistair Francis , Bin Meng , Weiwei Li , Daniel Henrique Barboza , Liu Zhiwei , qemu-riscv@nongnu.org (open list:RISC-V TCG CPUs) Subject: [PULL 07/22] target/riscv: Use GDBFeature for dynamic XML Date: Tue, 16 Jan 2024 10:47:54 +0000 Message-Id: <20240116104809.250076-8-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240116104809.250076-1-alex.bennee@linaro.org> References: <20240116104809.250076-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42d; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-x42d.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Akihiko Odaki In preparation for a change to use GDBFeature as a parameter of gdb_register_coprocessor(), convert the internal representation of dynamic feature from plain XML to GDBFeature. Signed-off-by: Akihiko Odaki Message-Id: <20240103173349.398526-29-alex.bennee@linaro.org> Message-Id: <20231213-gdb-v17-3-777047380591@daynix.com> Signed-off-by: Alex Bennée diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index d269d53e59c..8731af50718 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -24,6 +24,7 @@ #include "hw/registerfields.h" #include "hw/qdev-properties.h" #include "exec/cpu-defs.h" +#include "exec/gdbstub.h" #include "qemu/cpu-float.h" #include "qom/object.h" #include "qemu/int128.h" @@ -440,8 +441,8 @@ struct ArchCPU { CPURISCVState env; - char *dyn_csr_xml; - char *dyn_vreg_xml; + GDBFeature dyn_csr_feature; + GDBFeature dyn_vreg_feature; /* Configuration Settings */ RISCVCPUConfig cfg; diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index 7ee4f8520f9..a488361626f 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -1672,9 +1672,9 @@ static const char *riscv_gdb_get_dynamic_xml(CPUState *cs, const char *xmlname) RISCVCPU *cpu = RISCV_CPU(cs); if (strcmp(xmlname, "riscv-csr.xml") == 0) { - return cpu->dyn_csr_xml; + return cpu->dyn_csr_feature.xml; } else if (strcmp(xmlname, "riscv-vector.xml") == 0) { - return cpu->dyn_vreg_xml; + return cpu->dyn_vreg_feature.xml; } return NULL; diff --git a/target/riscv/gdbstub.c b/target/riscv/gdbstub.c index 365040228a1..76b72a95954 100644 --- a/target/riscv/gdbstub.c +++ b/target/riscv/gdbstub.c @@ -214,13 +214,14 @@ static int riscv_gdb_set_virtual(CPURISCVState *cs, uint8_t *mem_buf, int n) return 0; } -static int riscv_gen_dynamic_csr_xml(CPUState *cs, int base_reg) +static GDBFeature *riscv_gen_dynamic_csr_feature(CPUState *cs, int base_reg) { RISCVCPUClass *mcc = RISCV_CPU_GET_CLASS(cs); RISCVCPU *cpu = RISCV_CPU(cs); CPURISCVState *env = &cpu->env; - GString *s = g_string_new(NULL); + GDBFeatureBuilder builder; riscv_csr_predicate_fn predicate; + const char *name; int bitsize = 16 << mcc->misa_mxl_max; int i; @@ -233,9 +234,9 @@ static int riscv_gen_dynamic_csr_xml(CPUState *cs, int base_reg) bitsize = 64; } - g_string_printf(s, ""); - g_string_append_printf(s, ""); - g_string_append_printf(s, ""); + gdb_feature_builder_init(&builder, &cpu->dyn_csr_feature, + "org.gnu.gdb.riscv.csr", "riscv-csr.xml", + base_reg); for (i = 0; i < CSR_TABLE_SIZE; i++) { if (env->priv_ver < csr_ops[i].min_priv_ver) { @@ -243,72 +244,64 @@ static int riscv_gen_dynamic_csr_xml(CPUState *cs, int base_reg) } predicate = csr_ops[i].predicate; if (predicate && (predicate(env, i) == RISCV_EXCP_NONE)) { - if (csr_ops[i].name) { - g_string_append_printf(s, "", base_reg + i); + + gdb_feature_builder_append_reg(&builder, name, bitsize, i, + "int", NULL); } } - g_string_append_printf(s, ""); - - cpu->dyn_csr_xml = g_string_free(s, false); + gdb_feature_builder_end(&builder); #if !defined(CONFIG_USER_ONLY) env->debugger = false; #endif - return CSR_TABLE_SIZE; + return &cpu->dyn_csr_feature; } -static int ricsv_gen_dynamic_vector_xml(CPUState *cs, int base_reg) +static GDBFeature *ricsv_gen_dynamic_vector_feature(CPUState *cs, int base_reg) { RISCVCPU *cpu = RISCV_CPU(cs); - GString *s = g_string_new(NULL); - g_autoptr(GString) ts = g_string_new(""); + GDBFeatureBuilder builder; int reg_width = cpu->cfg.vlen; - int num_regs = 0; int i; - g_string_printf(s, ""); - g_string_append_printf(s, ""); - g_string_append_printf(s, ""); + gdb_feature_builder_init(&builder, &cpu->dyn_vreg_feature, + "org.gnu.gdb.riscv.vector", "riscv-vector.xml", + base_reg); /* First define types and totals in a whole VL */ for (i = 0; i < ARRAY_SIZE(vec_lanes); i++) { int count = reg_width / vec_lanes[i].size; - g_string_printf(ts, "%s", vec_lanes[i].id); - g_string_append_printf(s, - "", - ts->str, vec_lanes[i].gdb_type, count); + gdb_feature_builder_append_tag( + &builder, "", + vec_lanes[i].id, vec_lanes[i].gdb_type, count); } /* Define unions */ - g_string_append_printf(s, ""); + gdb_feature_builder_append_tag(&builder, ""); for (i = 0; i < ARRAY_SIZE(vec_lanes); i++) { - g_string_append_printf(s, "", - vec_lanes[i].suffix, - vec_lanes[i].id); + gdb_feature_builder_append_tag(&builder, + "", + vec_lanes[i].suffix, vec_lanes[i].id); } - g_string_append(s, ""); + gdb_feature_builder_append_tag(&builder, ""); /* Define vector registers */ for (i = 0; i < 32; i++) { - g_string_append_printf(s, - "", - i, reg_width, base_reg++); - num_regs++; + gdb_feature_builder_append_reg(&builder, g_strdup_printf("v%d", i), + reg_width, i, "riscv_vector", "vector"); } - g_string_append_printf(s, ""); + gdb_feature_builder_end(&builder); - cpu->dyn_vreg_xml = g_string_free(s, false); - return num_regs; + return &cpu->dyn_vreg_feature; } void riscv_cpu_register_gdb_regs_for_features(CPUState *cs) @@ -324,10 +317,9 @@ void riscv_cpu_register_gdb_regs_for_features(CPUState *cs) 32, "riscv-32bit-fpu.xml", 0); } if (env->misa_ext & RVV) { - int base_reg = cs->gdb_num_regs; gdb_register_coprocessor(cs, riscv_gdb_get_vector, riscv_gdb_set_vector, - ricsv_gen_dynamic_vector_xml(cs, base_reg), + ricsv_gen_dynamic_vector_feature(cs, cs->gdb_num_regs)->num_regs, "riscv-vector.xml", 0); } switch (mcc->misa_mxl_max) { @@ -347,9 +339,8 @@ void riscv_cpu_register_gdb_regs_for_features(CPUState *cs) } if (cpu->cfg.ext_zicsr) { - int base_reg = cs->gdb_num_regs; gdb_register_coprocessor(cs, riscv_gdb_get_csr, riscv_gdb_set_csr, - riscv_gen_dynamic_csr_xml(cs, base_reg), + riscv_gen_dynamic_csr_feature(cs, cs->gdb_num_regs)->num_regs, "riscv-csr.xml", 0); } }