Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1kNL06-0008Rl-FJ for mharc-qemu-riscv@gnu.org; Tue, 29 Sep 2020 15:09:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45536) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kNL01-0008Ph-W8 for qemu-riscv@nongnu.org; Tue, 29 Sep 2020 15:09:19 -0400 Received: from mail-pj1-x1033.google.com ([2607:f8b0:4864:20::1033]:55296) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kNKzz-0002Xb-B0 for qemu-riscv@nongnu.org; Tue, 29 Sep 2020 15:09:17 -0400 Received: by mail-pj1-x1033.google.com with SMTP id q4so3181116pjh.5 for ; Tue, 29 Sep 2020 12:09:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=gF7U3/jFgPv3TblNHnCBDh61EFdqDZn8LPCdRe1tYeA=; b=Wurc+q7mYZJb8qU6JOzWLUq5baQ+sU3uAiM17kTbI+iZO0vGa7XBOAAA7vkdj4/UOf Bxh2ADbHWgPnlBHTqKi4hzzqlqa3YOlu0H4VASjWSYpa0ElBl1Je6/Gr73If5F2KlB7Y fSZH7YFOQja+zmgVUO39HXHtVTB8mCjdC857wSNkKlzousmR8AResBJi17L5FWPzNOVC paaMvn5n+xL9sLsCFp5pukPITmAgzXpxxsjP3kmm7G2krg1vAnZtgBR5kRmgzYyxJoL+ 8Fez0ZiSCj6deqQrP+Xftliq4Zj57L2kqvVwTyc5sixT5seYSUENYrd8+VaHPTUoBR6D jQbw== 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; bh=gF7U3/jFgPv3TblNHnCBDh61EFdqDZn8LPCdRe1tYeA=; b=XxIosqG+pb7Yjs35UH6ygYHL4P4kjlWEnv1BpC0TBYrQVxnxhH9HzZpXFiiOFx51HT zlr6+RWW+Vgn+657HczcwInkaIr7XZrgQGBc3NJ5QTeUG7V1me4PEeC1YVRDt00wUnPA N4lQ+nTST7OR6m1DNcEbQGxPPJo2k6yJY/lFfZbhXYZBo2cDyia+0PRCwumXWOipRyVU 3uC330lX2ozeJGsDPLyMPtVZQjsjaPOmLgHnwWkwxs4ZivINb0+TZGxXcn6rr6FyjBBo MnpT0M7G5eLAO4gD23nVdSuTOASeBRWlbkqMti1LP9XGUF+PRIAQAIlPxyyEoBFphPap 38aA== X-Gm-Message-State: AOAM5307hTs7F2GBnb2Gxq0RzxzKIDFy/RgMz46wxFC3iwNheW/Cia9Q fOA167lyMbqwUKAjwulg3bzXvA== X-Google-Smtp-Source: ABdhPJwCC52m9S3H6CC/rid5NJMCNlXYkAoPyiI9hHZh1/YedDhfiPJfPPleYIMwqXwbJ224yqJEDw== X-Received: by 2002:a17:90a:1f07:: with SMTP id u7mr5090177pja.219.1601406554134; Tue, 29 Sep 2020 12:09:14 -0700 (PDT) Received: from localhost.localdomain (122-116-72-36.HINET-IP.hinet.net. [122.116.72.36]) by smtp.gmail.com with ESMTPSA id v8sm6003950pgg.58.2020.09.29.12.09.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Sep 2020 12:09:13 -0700 (PDT) From: frank.chang@sifive.com To: qemu-devel@nongnu.org, qemu-riscv@nongnu.org Cc: Hsiangkai Wang , Greentime Hu , Frank Chang , =?UTF-8?q?Alex=20Benn=C3=A9e?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Palmer Dabbelt , Alistair Francis , Sagar Karandikar , Bastian Koppelmann Subject: [RFC v5 66/68] target/riscv: gdb: support vector registers for rv64 & rv32 Date: Wed, 30 Sep 2020 03:04:41 +0800 Message-Id: <20200929190448.31116-67-frank.chang@sifive.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200929190448.31116-1-frank.chang@sifive.com> References: <20200929190448.31116-1-frank.chang@sifive.com> Received-SPF: pass client-ip=2607:f8b0:4864:20::1033; envelope-from=frank.chang@sifive.com; helo=mail-pj1-x1033.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. 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 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-riscv@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 29 Sep 2020 19:09:19 -0000 From: Hsiangkai Wang Signed-off-by: Hsiangkai Wang Signed-off-by: Greentime Hu Signed-off-by: Frank Chang --- gdb-xml/riscv-32bit-csr.xml | 7 ++ gdb-xml/riscv-64bit-csr.xml | 7 ++ target/riscv/cpu.c | 1 + target/riscv/cpu.h | 25 ++++++ target/riscv/gdbstub.c | 172 +++++++++++++++++++++++++++++++++++- 5 files changed, 210 insertions(+), 2 deletions(-) diff --git a/gdb-xml/riscv-32bit-csr.xml b/gdb-xml/riscv-32bit-csr.xml index 3d2031da7d..1901071470 100644 --- a/gdb-xml/riscv-32bit-csr.xml +++ b/gdb-xml/riscv-32bit-csr.xml @@ -248,4 +248,11 @@ + + + + + + + diff --git a/gdb-xml/riscv-64bit-csr.xml b/gdb-xml/riscv-64bit-csr.xml index 9039456293..28a7c9a9f3 100644 --- a/gdb-xml/riscv-64bit-csr.xml +++ b/gdb-xml/riscv-64bit-csr.xml @@ -248,4 +248,11 @@ + + + + + + + diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index 17c138bb90..b6cd217054 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -556,6 +556,7 @@ static void riscv_cpu_class_init(ObjectClass *c, void *data) #elif defined(TARGET_RISCV64) cc->gdb_core_xml_file = "riscv-64bit-cpu.xml"; #endif + cc->gdb_get_dynamic_xml = riscv_gdb_get_dynamic_xml; cc->gdb_stop_before_watchpoint = true; cc->disas_set_info = riscv_cpu_disas_set_info; #ifndef CONFIG_USER_ONLY diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index ca78b7f352..12f11fc2a1 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -102,6 +102,16 @@ FIELD(VTYPE, VEDIV, 8, 2) FIELD(VTYPE, RESERVED, 10, sizeof(target_ulong) * 8 - 11) FIELD(VTYPE, VILL, sizeof(target_ulong) * 8 - 1, 1) +/** + * DynamicGDBXMLInfo: + * @desc: Contains the XML descriptions. + * @num: Number of the registers in this XML seen by GDB. + */ +typedef struct DynamicGDBXMLInfo { + char *desc; + int num; +} DynamicGDBXMLInfo; + struct CPURISCVState { target_ulong gpr[32]; uint64_t fpr[32]; /* assume both F and D extensions */ @@ -296,6 +306,8 @@ typedef struct RISCVCPU { bool pmp; uint64_t resetvec; } cfg; + + DynamicGDBXMLInfo dyn_vreg_xml; } RISCVCPU; static inline int riscv_has_ext(CPURISCVState *env, target_ulong ext) @@ -489,6 +501,19 @@ typedef struct { void riscv_get_csr_ops(int csrno, riscv_csr_operations *ops); void riscv_set_csr_ops(int csrno, riscv_csr_operations *ops); +/* + * Helpers to dynamically generates XML descriptions of the + * vector registers. Returns the number of registers in each set. + */ +int ricsv_gen_dynamic_vector_xml(CPUState *cpu, int base_reg); + +/* + * Returns the dynamically generated XML for the gdb stub. + * Returns a pointer to the XML contents for the specified XML file or NULL + * if the XML name doesn't match the predefined one. + */ +const char *riscv_gdb_get_dynamic_xml(CPUState *cpu, const char *xmlname); + void riscv_cpu_register_gdb_regs_for_features(CPUState *cs); #endif /* RISCV_CPU_H */ diff --git a/target/riscv/gdbstub.c b/target/riscv/gdbstub.c index f7c5212e27..41e686265d 100644 --- a/target/riscv/gdbstub.c +++ b/target/riscv/gdbstub.c @@ -268,6 +268,39 @@ static int csr_register_map[] = { CSR_MUCOUNTEREN, CSR_MSCOUNTEREN, CSR_MHCOUNTEREN, + CSR_VSTART, + CSR_VXSAT, + CSR_VXRM, + CSR_VCSR, + CSR_VL, + CSR_VTYPE, + CSR_VLENB, +}; + +struct TypeSize { + const char *gdb_type; + const char *id; + int size; + const char suffix; +}; + +static const struct TypeSize vec_lanes[] = { + /* quads */ + { "uint128", "quads", 128, 'q' }, + /* 64 bit */ + { "uint64", "longs", 64, 'l' }, + /* 32 bit */ + { "uint32", "words", 32, 'w' }, + /* 16 bit */ + { "uint16", "shorts", 16, 's' }, + /* + * TODO: currently there is no reliable way of telling + * if the remote gdb actually understands ieee_half so + * we don't expose it in the target description for now. + * { "ieee_half", 16, 'h', 'f' }, + */ + /* bytes */ + { "uint8", "bytes", 8, 'b' }, }; int riscv_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n) @@ -351,6 +384,65 @@ static int riscv_gdb_set_fpu(CPURISCVState *env, uint8_t *mem_buf, int n) return 0; } +static int riscv_gdb_get_vector(CPURISCVState *env, GByteArray *buf, int n) +{ + uint16_t vlenb = env_archcpu(env)->cfg.vlen >> 3; + if (n < 32) { + int i; + int cnt = 0; + for (i = 0; i < vlenb; i += 8) { + cnt += gdb_get_reg64(buf, + env->vreg[(n * vlenb + i) / 8]); + } + return cnt; + } else if (n >= 32 && n <= 38) { + int csrno; + switch (n) { + case 32: + csrno = CSR_VSTART; + break; + case 33: + csrno = CSR_VXSAT; + break; + case 34: + csrno = CSR_VXRM; + break; + case 35: + csrno = CSR_VCSR; + break; + case 36: + csrno = CSR_VL; + break; + case 37: + csrno = CSR_VTYPE; + break; + case 38: + csrno = CSR_VLENB; + break; + } + + target_ulong val = 0; + int result = riscv_csrrw_debug(env, csrno, &val, 0, 0); + if (result == 0) { + return gdb_get_regl(buf, val); + } + } + return 0; +} + +static int riscv_gdb_set_vector(CPURISCVState *env, uint8_t *mem_buf, int n) +{ + uint16_t vlenb = env_archcpu(env)->cfg.vlen >> 3; + if (n < 32) { + int i; + for (i = 0; i < vlenb; i += 8) { + env->vreg[(n * vlenb + i) / 8] = ldq_p(mem_buf + i); + } + return vlenb; + } + return 0; +} + static int riscv_gdb_get_csr(CPURISCVState *env, GByteArray *buf, int n) { if (n < ARRAY_SIZE(csr_register_map)) { @@ -405,6 +497,66 @@ static int riscv_gdb_set_virtual(CPURISCVState *cs, uint8_t *mem_buf, int n) return 0; } +int ricsv_gen_dynamic_vector_xml(CPUState *cs, int base_reg) +{ + RISCVCPU *cpu = RISCV_CPU(cs); + GString *s = g_string_new(NULL); + DynamicGDBXMLInfo *info = &cpu->dyn_vreg_xml; + g_autoptr(GString) ts = g_string_new(""); + int i, reg_width = cpu->cfg.vlen; + info->num = 0; + g_string_printf(s, ""); + g_string_append_printf(s, ""); + g_string_append_printf(s, ""); + + /* 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); + } + + /* Define unions */ + g_string_append_printf(s, ""); + for (i = 0; i < ARRAY_SIZE(vec_lanes); i++) { + g_string_append_printf(s, "", + vec_lanes[i].suffix, + vec_lanes[i].id); + } + g_string_append(s, ""); + + /* Define vector registers */ + for (i = 0; i < 32; i++) { + g_string_append_printf(s, + "", + i, reg_width, base_reg++); + info->num++; + } + + /* Define vector CSRs */ + const char *vector_csrs[7] = { + "vstart", "vxsat", "vxrm", "vcsr", + "vl", "vtype", "vlenb" + }; + + for (i = 0; i < 7; i++) { + g_string_append_printf(s, + "", + vector_csrs[i], TARGET_LONG_BITS, base_reg++); + info->num++; + } + + g_string_append_printf(s, ""); + cpu->dyn_vreg_xml.desc = g_string_free(s, false); + return cpu->dyn_vreg_xml.num; +} + void riscv_cpu_register_gdb_regs_for_features(CPUState *cs) { RISCVCPU *cpu = RISCV_CPU(cs); @@ -416,17 +568,33 @@ void riscv_cpu_register_gdb_regs_for_features(CPUState *cs) gdb_register_coprocessor(cs, riscv_gdb_get_fpu, riscv_gdb_set_fpu, 36, "riscv-32bit-fpu.xml", 0); } + if (env->misa & RVV) { + gdb_register_coprocessor(cs, riscv_gdb_get_vector, riscv_gdb_set_vector, + ricsv_gen_dynamic_vector_xml(cs, + cs->gdb_num_regs), + "riscv-vector.xml", 0); + } #if defined(TARGET_RISCV32) gdb_register_coprocessor(cs, riscv_gdb_get_csr, riscv_gdb_set_csr, - 241, "riscv-32bit-csr.xml", 0); + 248, "riscv-32bit-csr.xml", 0); gdb_register_coprocessor(cs, riscv_gdb_get_virtual, riscv_gdb_set_virtual, 1, "riscv-32bit-virtual.xml", 0); #elif defined(TARGET_RISCV64) gdb_register_coprocessor(cs, riscv_gdb_get_csr, riscv_gdb_set_csr, - 241, "riscv-64bit-csr.xml", 0); + 248, "riscv-64bit-csr.xml", 0); gdb_register_coprocessor(cs, riscv_gdb_get_virtual, riscv_gdb_set_virtual, 1, "riscv-64bit-virtual.xml", 0); #endif } + +const char *riscv_gdb_get_dynamic_xml(CPUState *cs, const char *xmlname) +{ + RISCVCPU *cpu = RISCV_CPU(cs); + + if (strcmp(xmlname, "riscv-vector.xml") == 0) { + return cpu->dyn_vreg_xml.desc; + } + return NULL; +} -- 2.17.1