From patchwork Wed Feb 28 11:56:39 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: 776467 Delivered-To: patch@linaro.org Received: by 2002:adf:e94d:0:b0:33d:f458:43ce with SMTP id m13csp251291wrn; Wed, 28 Feb 2024 03:59:45 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCWhGh4fi6j1MHgx8sRjHmiiIGZcktE76mZtFIS/MlvXCJXJMEgiI+m6emstFkFe6u8D29FSWQsZf/uXlP4SpaJa X-Google-Smtp-Source: AGHT+IH/YsjPHZoyfvc2rv4EhpXXqhjXMbctbpO4/HHikA8CJ7XjZGZ4oh0pKEBSDHIrREuxd/co X-Received: by 2002:a05:6358:6520:b0:17a:c9b2:607c with SMTP id v32-20020a056358652000b0017ac9b2607cmr14873303rwg.27.1709121585636; Wed, 28 Feb 2024 03:59:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709121585; cv=none; d=google.com; s=arc-20160816; b=LDw+ih9bGucmT7ylouAcn47PPwu7djszUqNvkXJH00+cxpLMaGsQlH2a+uHim/x4at 1p93QaJzZIZlfHarH2bRsm33QymdIRp/m3WBobH75NqldK5FcG5Gb9a2dhh3auJ5Xysu YCnh3Oa4vgwjggBLGJx9p3hIz7iW4CSoMHQeJcmthO6NuVt5sMqipGScTP2h0PzPb/G2 hVgGF0nX/oC41rWgUFrAzUP8mhEEQi5udUcW97x5j6CwBRokK7X2G1IoogPGCWjeg9Nk qiVFQI91lgVFeOEV6Ln1pIM03TFsxMAEOEM7TzwrL2xboh1qeh33TWAVkEFtK4siEhf4 i5Nw== 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=AbQdVw/YztuyMtaq/sRI5jSQkRgrESmuKm2t9XrlKQQ=; fh=9jJHrC5PrJaZEpYolodfKVbyWk7Nrvl/dH0bi7QOqKg=; b=M/kNTfEyY4A8cHeAxFsqppDnDNzE/kpBfEDnF5xoSyoPO9oAmC0N5IOX8ajm95xO91 3j9LcuUvFE6odROjqHXeqqdyxjSjXLcxF1MR+Sqiusqotlzwdtj0g/yDS3S0bYoKR3Ll ukcIYO/ll311kjR5NFhtMnOQYsisnpWisdEZ08jiTci5ayKwmRUTc2b4gaR+ru4adPtn 76aez3JEOI4c7RZt4Zy9C3kY9w63xPi4gaudzH7VUT90EYEV8iOUvKIPQU1Hq6cnTwMi 3b6xC1voZ6RAceI8KpFiZ/ne+jTVyQXMW2O5rDwwFMwBQVyCppP6fD9UzyXH5XHzsqRx 08rw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=SEBEXdPN; 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 u12-20020ae9c00c000000b007879b80f197si9549992qkk.680.2024.02.28.03.59.45 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 28 Feb 2024 03:59:45 -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=SEBEXdPN; 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 1rfIYo-0005sm-EC; Wed, 28 Feb 2024 06:57:18 -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 1rfIYm-0005rE-PV for qemu-devel@nongnu.org; Wed, 28 Feb 2024 06:57:16 -0500 Received: from mail-wm1-x331.google.com ([2a00:1450:4864:20::331]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rfIYh-0005jx-Ts for qemu-devel@nongnu.org; Wed, 28 Feb 2024 06:57:16 -0500 Received: by mail-wm1-x331.google.com with SMTP id 5b1f17b1804b1-412ad940fe8so12042785e9.2 for ; Wed, 28 Feb 2024 03:57:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709121430; x=1709726230; 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=AbQdVw/YztuyMtaq/sRI5jSQkRgrESmuKm2t9XrlKQQ=; b=SEBEXdPNSxnfBQ4lPQKJO1nzXTi6LPuuwXxCXfOnv2UItvPetywdmHqSyRbG/YkMio uXGluKf687OujLMiZh1sOa5fkIYWRHotQIF9uhnJbwGpClWU4KDHK2UKSlUlRb+lnV8R Hu7sCw277q7l+1TdteDOBw7VZZTgmXAHwHSYhPfOnxQ92vmAsxfNyfFucwoAQJruloGd fTpwE0Eh1k8Bje94zLXMDEmRTQlKRc6McqnS4FQ6vQQpKkzEnaaNWux96K2ugnH338ms 5p9elheeAiFhZG19Vc9X4unl8rWmTH0ch2BWy0aRoDxyJGbgXhPA4sJSGRDtS9EkZZeU t1vA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709121430; x=1709726230; 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=AbQdVw/YztuyMtaq/sRI5jSQkRgrESmuKm2t9XrlKQQ=; b=m2fBNvS0KG0BZMF7fBmzHKWK/L+oc14QmCXCQKiRonDenMcZj2ji5HoaZti04I92HL pSvsLM+1R2u78iySPG8y88WUgJZ3xk6pnhyIG7rZSV3Ui3e2mjEj6pPh+EIBNzvec5ah u6U3OAfEWDEvkxQuGGJ15/gPN62jfgH95Coh5aXQ07j5tWUjfWNJUQkdqIUtSOYlOchR EX8EklA9cMkv77vNs8MuvxwAfzHjeuMz9JejELf73toPiocAD1QOISzI15fU9DHAfYLH gt2fbpH6GKDK+MVvoYCdH1Tk6TUro3JwqHP48sCe9kygY/RTxESW8K8cLR0Zg/Q0TNHR q6Cg== X-Gm-Message-State: AOJu0YyguEt1gqihkX3REo+RAl+dhWc3jpcty8yvdyq3uEDUie19H8Ee 6Kr+UJItSlz7gu7awBaJe8PIEx7oKvz5N+sE/IB31MlxwjHTknd0ErMO+hUnDr8= X-Received: by 2002:a05:600c:458c:b0:411:a751:322b with SMTP id r12-20020a05600c458c00b00411a751322bmr9819514wmo.18.1709121430344; Wed, 28 Feb 2024 03:57:10 -0800 (PST) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id m20-20020a7bca54000000b0041290251dc2sm1862297wml.14.2024.02.28.03.57.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 03:57:06 -0800 (PST) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 864445F902; Wed, 28 Feb 2024 11:57:02 +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/29] target/riscv: Use GDBFeature for dynamic XML Date: Wed, 28 Feb 2024 11:56:39 +0000 Message-Id: <20240228115701.1416107-8-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240228115701.1416107-1-alex.bennee@linaro.org> References: <20240228115701.1416107-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::331; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x331.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=unavailable 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: <20231213-gdb-v17-3-777047380591@daynix.com> Signed-off-by: Alex Bennée Message-Id: <20240227144335.1196131-8-alex.bennee@linaro.org> diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index f52dce78baa..5d291a70925 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" @@ -445,8 +446,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 1b8d001d237..1b62e269b90 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -2305,9 +2305,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 ca9b71f7bbc..d8da84fa52e 100644 --- a/target/riscv/gdbstub.c +++ b/target/riscv/gdbstub.c @@ -214,14 +214,15 @@ 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; int bitsize = riscv_cpu_max_xlen(mcc); + const char *name; int i; #if !defined(CONFIG_USER_ONLY) @@ -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(""); - int reg_width = cpu->cfg.vlenb << 3; - int num_regs = 0; + int reg_width = cpu->cfg.vlenb; + GDBFeatureBuilder builder; 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); } }