All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/1] cmd: add rdcycle test to RISC-V exception command
@ 2024-08-11 14:41 Heinrich Schuchardt
  2024-08-13  3:27 ` Leo Liang
  0 siblings, 1 reply; 2+ messages in thread
From: Heinrich Schuchardt @ 2024-08-11 14:41 UTC (permalink / raw)
  To: Rick Chen; +Cc: Leo, u-boot, Heinrich Schuchardt

Some versions of KVM don't allow access to the cycle CSR.

Provide a command 'exception rdcycle' for testing.

If the cycle CSR is accessible, we get an output like:

    => exception rdcycle
    cycle = 0x41f7563de

If the cycle CSR is not accessible, we get an output like:

    => exception rdcycle
    Unhandled exception: Illegal instruction

Put subcommands into alphabetical order in long help.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
---
 cmd/riscv/exception.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/cmd/riscv/exception.c b/cmd/riscv/exception.c
index 2b58b1c449c..16e335327f1 100644
--- a/cmd/riscv/exception.c
+++ b/cmd/riscv/exception.c
@@ -36,6 +36,14 @@ static int do_ialign16(struct cmd_tbl *cmdtp, int flag, int argc,
 	return CMD_RET_SUCCESS;
 }
 
+static int do_rdcycle(struct cmd_tbl *cmdtp, int flag, int argc,
+		      char *const argv[])
+{
+	printf("cycle = 0x%lx\n", csr_read(CSR_CYCLE));
+
+	return CMD_RET_SUCCESS;
+}
+
 static int do_unaligned(struct cmd_tbl *cmdtp, int flag, int argc,
 			char *const argv[])
 {
@@ -62,6 +70,8 @@ static struct cmd_tbl cmd_sub[] = {
 			 "", ""),
 	U_BOOT_CMD_MKENT(ialign16, CONFIG_SYS_MAXARGS, 1, do_ialign16,
 			 "", ""),
+	U_BOOT_CMD_MKENT(rdcycle, CONFIG_SYS_MAXARGS, 1, do_rdcycle,
+			 "", ""),
 	U_BOOT_CMD_MKENT(unaligned, CONFIG_SYS_MAXARGS, 1, do_unaligned,
 			 "", ""),
 	U_BOOT_CMD_MKENT(undefined, CONFIG_SYS_MAXARGS, 1, do_undefined,
@@ -74,7 +84,8 @@ U_BOOT_LONGHELP(exception,
 	"  compressed - compressed instruction\n"
 	"  ebreak     - breakpoint\n"
 	"  ialign16   - 16 bit aligned instruction\n"
-	"  undefined  - illegal instruction\n"
-	"  unaligned  - load address misaligned\n");
+	"  rdcycle    - read cycle CSR\n"
+	"  unaligned  - load address misaligned\n"
+	"  undefined  - illegal instruction\n");
 
 #include <exception.h>
-- 
2.45.2


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH 1/1] cmd: add rdcycle test to RISC-V exception command
  2024-08-11 14:41 [PATCH 1/1] cmd: add rdcycle test to RISC-V exception command Heinrich Schuchardt
@ 2024-08-13  3:27 ` Leo Liang
  0 siblings, 0 replies; 2+ messages in thread
From: Leo Liang @ 2024-08-13  3:27 UTC (permalink / raw)
  To: Heinrich Schuchardt; +Cc: Rick Chen, u-boot

On Sun, Aug 11, 2024 at 04:41:23PM +0200, Heinrich Schuchardt wrote:
> [EXTERNAL MAIL]
> 
> Some versions of KVM don't allow access to the cycle CSR.
> 
> Provide a command 'exception rdcycle' for testing.
> 
> If the cycle CSR is accessible, we get an output like:
> 
>     => exception rdcycle
>     cycle = 0x41f7563de
> 
> If the cycle CSR is not accessible, we get an output like:
> 
>     => exception rdcycle
>     Unhandled exception: Illegal instruction
> 
> Put subcommands into alphabetical order in long help.
> 
> Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
> ---
>  cmd/riscv/exception.c | 15 +++++++++++++--
>  1 file changed, 13 insertions(+), 2 deletions(-)

Reviewed-by: Leo Yu-Chi Liang <ycliang@andestech.com>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-08-13  3:27 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-11 14:41 [PATCH 1/1] cmd: add rdcycle test to RISC-V exception command Heinrich Schuchardt
2024-08-13  3:27 ` Leo Liang

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.