Print registers in supervisor

This commit is contained in:
Rodrigo Arias Mallo 2024-08-21 11:42:12 +02:00
parent 706d858347
commit 2c5f8a8ccf

View File

@ -1,5 +1,5 @@
diff --git a/lib/sbi/sbi_irqchip.c b/lib/sbi/sbi_irqchip.c
index 0ae604a..177fb6b 100644
index 0ae604a..54449c7 100644
--- a/lib/sbi/sbi_irqchip.c
+++ b/lib/sbi/sbi_irqchip.c
@@ -9,6 +9,9 @@
@ -25,7 +25,7 @@ index 0ae604a..177fb6b 100644
return 0;
}
@@ -47,8 +52,158 @@ void sbi_irqchip_exit(struct sbi_scratch *scratch)
@@ -47,8 +52,161 @@ void sbi_irqchip_exit(struct sbi_scratch *scratch)
{
const struct sbi_platform *plat = sbi_platform_ptr(scratch);
@ -61,19 +61,21 @@ index 0ae604a..177fb6b 100644
+#define MSTATUS_MPP_MASK (3 << 11)
+#define MSTATUS_MPP_SUPERVISOR (1 << 11)
+
+static void dumpregs(void)
+static void dumpregs(int machine)
+{
+ char *prefix = "\t";
+ char *suffix = "\t";
+ sbi_printf("Registers:\n");
+ sbi_printf("%sMIE%s: 0x%" PRILX "\n",
+ prefix, suffix, csr_read(CSR_MIE));
+ sbi_printf("%sMIP%s: 0x%" PRILX "\n",
+ prefix, suffix, csr_read(CSR_MIP));
+ sbi_printf("%sMSTATUS%s: 0x%" PRILX "\n",
+ prefix, suffix, csr_read(CSR_MSTATUS));
+ sbi_printf("%sMIDELEG%s: 0x%" PRILX "\n",
+ prefix, suffix, csr_read(CSR_MIDELEG));
+ if (machine) {
+ sbi_printf("%sMIE%s: 0x%" PRILX "\n",
+ prefix, suffix, csr_read(CSR_MIE));
+ sbi_printf("%sMIP%s: 0x%" PRILX "\n",
+ prefix, suffix, csr_read(CSR_MIP));
+ sbi_printf("%sMSTATUS%s: 0x%" PRILX "\n",
+ prefix, suffix, csr_read(CSR_MSTATUS));
+ sbi_printf("%sMIDELEG%s: 0x%" PRILX "\n",
+ prefix, suffix, csr_read(CSR_MIDELEG));
+ }
+ sbi_printf("%sSIE%s: 0x%" PRILX "\n",
+ prefix, suffix, csr_read(CSR_SIE));
+ sbi_printf("%sSIP%s: 0x%" PRILX "\n",
@ -105,6 +107,7 @@ index 0ae604a..177fb6b 100644
+static int supervisor_mode_code(void)
+{
+ sbi_printf("Hello from supervisor\n");
+ dumpregs(0);
+ sbi_printf("Waiting for interrupt...\n");
+ int i = 0;
+ char *s = "-\\|/";
@ -141,7 +144,7 @@ index 0ae604a..177fb6b 100644
+ csr_set(CSR_STVEC, &supervisor_trap_entry);
+ sbi_printf("Enabled supervisor delegation:\n");
+
+ dumpregs();
+ dumpregs(1);
+
+ /* Configure PLIC aux timer input */
+ volatile unsigned *plic_priority = (unsigned *)(PLIC_BASE + PLIC_PRIORITY_OFFSET + PLIC_TIMER_PORT * 4);
@ -177,7 +180,7 @@ index 0ae604a..177fb6b 100644
+ sbi_printf("Timer alarm programmed\n");
+ sbi_printf("Switching to supervisor\n");
+
+ dumpregs();
+ dumpregs(1);
+
+ switch_to_supervisor_mode(&supervisor_mode_code);
+