From nobody Fri May 17 11:59:11 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1680688722286508.12902753735375; Wed, 5 Apr 2023 02:58:42 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pjzta-0001qS-HZ; Wed, 05 Apr 2023 05:57:38 -0400 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 1pjztY-0001pG-32; Wed, 05 Apr 2023 05:57:36 -0400 Received: from smtp25.cstnet.cn ([159.226.251.25] helo=cstnet.cn) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pjztV-00077V-Ao; Wed, 05 Apr 2023 05:57:35 -0400 Received: from localhost.localdomain (unknown [180.175.29.170]) by APP-05 (Coremail) with SMTP id zQCowACHjxcBRi1kENNKDg--.27388S3; Wed, 05 Apr 2023 17:57:23 +0800 (CST) From: Weiwei Li To: qemu-riscv@nongnu.org, qemu-devel@nongnu.org Cc: palmer@dabbelt.com, alistair.francis@wdc.com, bin.meng@windriver.com, dbarboza@ventanamicro.com, zhiwei_liu@linux.alibaba.com, wangjunqiang@iscas.ac.cn, lazyparser@gmail.com, Weiwei Li Subject: [PATCH v4 1/1] hw/riscv: Add signature dump function for spike to run ACT tests Date: Wed, 5 Apr 2023 17:57:20 +0800 Message-Id: <20230405095720.75848-2-liweiwei@iscas.ac.cn> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230405095720.75848-1-liweiwei@iscas.ac.cn> References: <20230405095720.75848-1-liweiwei@iscas.ac.cn> MIME-Version: 1.0 Content-Transfer-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k0rVWUJVWUCwCI42IY6I8E87Iv67AKxVWUJV W8JwCI42IY6I8E87Iv6xkF7I0E14v26r4j6r4UJbIYCTnIWIevJa73UjIFyTuYvjfU5SoX UUUUU X-Originating-IP: [180.175.29.170] X-CM-SenderInfo: 5olzvxxzhlqxpvfd2hldfou0/ Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=159.226.251.25; envelope-from=liweiwei@iscas.ac.cn; helo=cstnet.cn X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1680688723585100002 Content-Type: text/plain; charset="utf-8" Add signature and signature-granularity properties in spike to specify the = target signatrue file and the line size for signature data. Recgonize the signature section between begin_signature and end_signature s= ymbols when loading elf of ACT tests. Then dump signature data in signature sectio= n just before the ACT tests exit. Signed-off-by: Weiwei Li Signed-off-by: Junqiang Wang Reviewed-by: LIU Zhiwei Reviewed-by: Alistair Francis --- hw/char/riscv_htif.c | 44 +++++++++++++++++++++++++++++++++++- hw/riscv/spike.c | 13 +++++++++++ include/hw/char/riscv_htif.h | 3 +++ 3 files changed, 59 insertions(+), 1 deletion(-) diff --git a/hw/char/riscv_htif.c b/hw/char/riscv_htif.c index 098de50e35..37d3ccc76b 100644 --- a/hw/char/riscv_htif.c +++ b/hw/char/riscv_htif.c @@ -29,6 +29,8 @@ #include "chardev/char-fe.h" #include "qemu/timer.h" #include "qemu/error-report.h" +#include "exec/address-spaces.h" +#include "sysemu/dma.h" =20 #define RISCV_DEBUG_HTIF 0 #define HTIF_DEBUG(fmt, ...) = \ @@ -51,7 +53,10 @@ /* PK system call number */ #define PK_SYS_WRITE 64 =20 -static uint64_t fromhost_addr, tohost_addr; +const char *sig_file; +uint8_t line_size =3D 16; + +static uint64_t fromhost_addr, tohost_addr, begin_sig_addr, end_sig_addr; =20 void htif_symbol_callback(const char *st_name, int st_info, uint64_t st_va= lue, uint64_t st_size) @@ -68,6 +73,10 @@ void htif_symbol_callback(const char *st_name, int st_in= fo, uint64_t st_value, error_report("HTIF tohost must be 8 bytes"); exit(1); } + } else if (strcmp("begin_signature", st_name) =3D=3D 0) { + begin_sig_addr =3D st_value; + } else if (strcmp("end_signature", st_name) =3D=3D 0) { + end_sig_addr =3D st_value; } } =20 @@ -163,6 +172,39 @@ static void htif_handle_tohost_write(HTIFState *s, uin= t64_t val_written) if (payload & 0x1) { /* exit code */ int exit_code =3D payload >> 1; + + /* + * Dump signature data if sig_file is specified and + * begin/end_signature symbols exist. + */ + if (sig_file && begin_sig_addr && end_sig_addr) { + uint64_t sig_len =3D end_sig_addr - begin_sig_addr; + char *sig_data =3D g_malloc(sig_len); + dma_memory_read(&address_space_memory, begin_sig_addr, + sig_data, sig_len, MEMTXATTRS_UNSPECIF= IED); + FILE *signature =3D fopen(sig_file, "w"); + if (signature =3D=3D NULL) { + error_report("Unable to open %s with error %s", + sig_file, strerror(errno)); + exit(1); + } + + for (int i =3D 0; i < sig_len; i +=3D line_size) { + for (int j =3D line_size; j > 0; j--) { + if (i + j <=3D sig_len) { + fprintf(signature, "%02x", + sig_data[i + j - 1] & 0xff); + } else { + fprintf(signature, "%02x", 0); + } + } + fprintf(signature, "\n"); + } + + fclose(signature); + g_free(sig_data); + } + exit(exit_code); } else { uint64_t syscall[8]; diff --git a/hw/riscv/spike.c b/hw/riscv/spike.c index a584d5b3a2..2c5546560a 100644 --- a/hw/riscv/spike.c +++ b/hw/riscv/spike.c @@ -332,6 +332,11 @@ static void spike_board_init(MachineState *machine) htif_custom_base); } =20 +static void spike_set_signature(Object *obj, const char *val, Error **errp) +{ + sig_file =3D g_strdup(val); +} + static void spike_machine_instance_init(Object *obj) { } @@ -350,6 +355,14 @@ static void spike_machine_class_init(ObjectClass *oc, = void *data) mc->get_default_cpu_node_id =3D riscv_numa_get_default_cpu_node_id; mc->numa_mem_supported =3D true; mc->default_ram_id =3D "riscv.spike.ram"; + object_class_property_add_str(oc, "signature", NULL, spike_set_signatu= re); + object_class_property_set_description(oc, "signature", + "File to write ACT test signatur= e"); + object_class_property_add_uint8_ptr(oc, "signature-granularity", + &line_size, OBJ_PROP_FLAG_WRITE); + object_class_property_set_description(oc, "signature-granularity", + "Size of each line in ACT signat= ure " + "file"); } =20 static const TypeInfo spike_machine_typeinfo =3D { diff --git a/include/hw/char/riscv_htif.h b/include/hw/char/riscv_htif.h index 5958c5b986..df493fdf6b 100644 --- a/include/hw/char/riscv_htif.h +++ b/include/hw/char/riscv_htif.h @@ -40,6 +40,9 @@ typedef struct HTIFState { uint64_t pending_read; } HTIFState; =20 +extern const char *sig_file; +extern uint8_t line_size; + /* HTIF symbol callback */ void htif_symbol_callback(const char *st_name, int st_info, uint64_t st_va= lue, uint64_t st_size); --=20 2.25.1