From: Weiwei Li <liweiwei@iscas.ac.cn>
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 <liweiwei@iscas.ac.cn>
Subject: [PATCH v3 1/1] hw/riscv: Add signature dump function for spike to run ACT tests
Date: Tue, 7 Mar 2023 11:29:15 +0800 [thread overview]
Message-ID: <20230307032915.10059-2-liweiwei@iscas.ac.cn> (raw)
In-Reply-To: <20230307032915.10059-1-liweiwei@iscas.ac.cn>
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 symbols
when loading elf of ACT tests. Then dump signature data in signature section just
before the ACT tests exit.
Signed-off-by: Weiwei Li <liweiwei@iscas.ac.cn>
Signed-off-by: Junqiang Wang <wangjunqiang@iscas.ac.cn>
Reviewed-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com>
---
hw/char/riscv_htif.c | 39 +++++++++++++++++++++++++++++++++++-
hw/riscv/spike.c | 13 ++++++++++++
include/hw/char/riscv_htif.h | 3 +++
3 files changed, 54 insertions(+), 1 deletion(-)
diff --git a/hw/char/riscv_htif.c b/hw/char/riscv_htif.c
index 098de50e35..297c98c215 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"
#define RISCV_DEBUG_HTIF 0
#define HTIF_DEBUG(fmt, ...) \
@@ -51,7 +53,10 @@
/* PK system call number */
#define PK_SYS_WRITE 64
-static uint64_t fromhost_addr, tohost_addr;
+const char *sig_file;
+uint8_t line_size = 16;
+
+static uint64_t fromhost_addr, tohost_addr, sig_addr, sig_len;
void htif_symbol_callback(const char *st_name, int st_info, uint64_t st_value,
uint64_t st_size)
@@ -68,6 +73,10 @@ void htif_symbol_callback(const char *st_name, int st_info, uint64_t st_value,
error_report("HTIF tohost must be 8 bytes");
exit(1);
}
+ } else if (strcmp("begin_signature", st_name) == 0) {
+ sig_addr = st_value;
+ } else if (strcmp("end_signature", st_name) == 0) {
+ sig_len = st_value - sig_addr;
}
}
@@ -161,6 +170,34 @@ static void htif_handle_tohost_write(HTIFState *s, uint64_t val_written)
/* frontend syscall handler, shutdown and exit code support */
if (cmd == HTIF_SYSTEM_CMD_SYSCALL) {
if (payload & 0x1) {
+ /* Dump signature data to sig_file if specified */
+ if (sig_file) {
+ char *sig_data = g_malloc(sig_len);
+ dma_memory_read(&address_space_memory, sig_addr, sig_data,
+ sig_len, MEMTXATTRS_UNSPECIFIED);
+ FILE *signature = fopen(sig_file, "w");
+ if (signature == NULL) {
+ error_report("open %s: %s", sig_file,
+ strerror(errno));
+ exit(1);
+ }
+
+ for (int i = 0; i < sig_len; i += line_size) {
+ for (int j = line_size; j > 0; j--) {
+ if (i + j <= 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 code */
int exit_code = payload >> 1;
exit(exit_code);
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);
}
+static void spike_set_signature(Object *obj, const char *val, Error **errp)
+{
+ sig_file = 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 = riscv_numa_get_default_cpu_node_id;
mc->numa_mem_supported = true;
mc->default_ram_id = "riscv.spike.ram";
+ object_class_property_add_str(oc, "signature", NULL, spike_set_signature);
+ object_class_property_set_description(oc, "signature",
+ "File to write ACT test signature");
+ 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 signature "
+ "file");
}
static const TypeInfo spike_machine_typeinfo = {
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;
+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_value,
uint64_t st_size);
--
2.25.1
next prev parent reply other threads:[~2023-03-07 3:30 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-07 3:29 [PATCH v3 0/1] hw/riscv: Add ACT related support Weiwei Li
2023-03-07 3:29 ` Weiwei Li [this message]
2023-04-05 4:56 ` [PATCH v3 1/1] hw/riscv: Add signature dump function for spike to run ACT tests Alistair Francis
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230307032915.10059-2-liweiwei@iscas.ac.cn \
--to=liweiwei@iscas.ac.cn \
--cc=alistair.francis@wdc.com \
--cc=bin.meng@windriver.com \
--cc=dbarboza@ventanamicro.com \
--cc=lazyparser@gmail.com \
--cc=palmer@dabbelt.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-riscv@nongnu.org \
--cc=wangjunqiang@iscas.ac.cn \
--cc=zhiwei_liu@linux.alibaba.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).