aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Waterman <andrew@sifive.com>2024-05-20 18:38:12 -0700
committerAndrew Waterman <andrew@sifive.com>2024-05-20 18:38:12 -0700
commit54e2005dc8658bf7bbec52ac54fe4712f7b4362a (patch)
tree94d5acaf1b339f46e93386a40424307034450edf
parentda80ada596eae650761bf9da9a0283b8b8058584 (diff)
parent5ae7523adc17d6014d6bd7db02ee26607c00470d (diff)
downloadriscv-pk-54e2005dc8658bf7bbec52ac54fe4712f7b4362a.zip
riscv-pk-54e2005dc8658bf7bbec52ac54fe4712f7b4362a.tar.gz
riscv-pk-54e2005dc8658bf7bbec52ac54fe4712f7b4362a.tar.bz2
Merge branch 'mylai-mtk-zicfilp-upstream'
-rw-r--r--machine/mentry.S37
-rw-r--r--machine/minit.c3
-rw-r--r--pk/handlers.c16
-rw-r--r--pk/pk.c9
4 files changed, 47 insertions, 18 deletions
diff --git a/machine/mentry.S b/machine/mentry.S
index 4cf9685..9fa60ca 100644
--- a/machine/mentry.S
+++ b/machine/mentry.S
@@ -8,27 +8,30 @@
.align 6
trap_table:
#define BAD_TRAP_VECTOR 0
- .dc.a bad_trap
- .dc.a pmp_trap
- .dc.a illegal_insn_trap
- .dc.a bad_trap
- .dc.a misaligned_load_trap
- .dc.a pmp_trap
- .dc.a misaligned_store_trap
- .dc.a pmp_trap
- .dc.a bad_trap
- .dc.a mcall_trap
- .dc.a bad_trap
+ /* 00 */ .dc.a bad_trap
+ /* 01 */ .dc.a pmp_trap
+ /* 02 */ .dc.a illegal_insn_trap
+ /* 03 */ .dc.a bad_trap
+ /* 04 */ .dc.a misaligned_load_trap
+ /* 05 */ .dc.a pmp_trap
+ /* 06 */ .dc.a misaligned_store_trap
+ /* 07 */ .dc.a pmp_trap
+ /* 08 */ .dc.a bad_trap
+ /* 09 */ .dc.a mcall_trap
+ /* 10 */ .dc.a bad_trap
#ifdef BBL_BOOT_MACHINE
- .dc.a mcall_trap
+ /* 11 */ .dc.a mcall_trap
#else
- .dc.a bad_trap
+ /* 11 */ .dc.a bad_trap
#endif /* BBL_BOOT_MACHINE */
- .dc.a bad_trap
+ /* 12 */ .dc.a bad_trap
#define TRAP_FROM_MACHINE_MODE_VECTOR 13
- .dc.a __trap_from_machine_mode
- .dc.a bad_trap
- .dc.a bad_trap
+ /* 13 */ .dc.a __trap_from_machine_mode
+ /* 14 */ .dc.a bad_trap
+ /* 15 */ .dc.a bad_trap
+ /* 16 */ .dc.a bad_trap
+ /* 17 */ .dc.a bad_trap
+ /* 18 */ .dc.a bad_trap
.option norvc
.section .text.init,"ax",@progbits
diff --git a/machine/minit.c b/machine/minit.c
index afc48d5..55f50cb 100644
--- a/machine/minit.c
+++ b/machine/minit.c
@@ -79,7 +79,8 @@ static void delegate_traps()
(1U << CAUSE_BREAKPOINT) |
(1U << CAUSE_LOAD_PAGE_FAULT) |
(1U << CAUSE_STORE_PAGE_FAULT) |
- (1U << CAUSE_USER_ECALL);
+ (1U << CAUSE_USER_ECALL) |
+ (1U << CAUSE_SOFTWARE_CHECK_FAULT);
write_csr(mideleg, interrupts);
write_csr(medeleg, exceptions);
diff --git a/pk/handlers.c b/pk/handlers.c
index 4b4abaf..2932d94 100644
--- a/pk/handlers.c
+++ b/pk/handlers.c
@@ -90,6 +90,21 @@ static void handle_interrupt(trapframe_t* tf)
clear_csr(sip, SIP_SSIP);
}
+static void handle_software_check_fault(trapframe_t* tf)
+{
+ dump_tf(tf);
+
+ const uint64_t stval = read_csr(stval);
+ switch (stval) {
+ case LANDING_PAD_FAULT:
+ panic("Invalid landing pad!");
+ break;
+ default:
+ panic("Software check fault: unhandled stval: %d", stval);
+ break;
+ }
+}
+
void handle_trap(trapframe_t* tf)
{
if ((intptr_t)tf->cause < 0)
@@ -110,6 +125,7 @@ void handle_trap(trapframe_t* tf)
[CAUSE_MISALIGNED_STORE] = handle_misaligned_store,
[CAUSE_LOAD_PAGE_FAULT] = handle_fault_load,
[CAUSE_STORE_PAGE_FAULT] = handle_fault_store,
+ [CAUSE_SOFTWARE_CHECK_FAULT] = handle_software_check_fault,
};
kassert(tf->cause < ARRAY_SIZE(trap_handlers) && trap_handlers[tf->cause]);
diff --git a/pk/pk.c b/pk/pk.c
index 31d8c79..dbfaa5a 100644
--- a/pk/pk.c
+++ b/pk/pk.c
@@ -13,6 +13,7 @@
elf_info current;
long disabled_hart_mask;
+bool zicfilp_enabled;
static void help()
{
@@ -22,6 +23,7 @@ static void help()
printk(" -h, --help Print this help message\n");
printk(" -p Disable on-demand program paging\n");
printk(" -s Print cycles upon termination\n");
+ printk(" --zicfilp Enable Zicfilp CFI mechanism for user program\n");
shutdown(0);
}
@@ -54,6 +56,11 @@ static void handle_option(const char* arg)
return;
}
+ if (strcmp(arg, "--zicfilp") == 0) {
+ zicfilp_enabled = true;
+ return;
+ }
+
panic("unrecognized option: `%s'", arg);
suggest_help();
}
@@ -177,6 +184,8 @@ static void run_loaded_program(size_t argc, char** argv, uintptr_t kstack_top)
init_tf(&tf, current.entry, stack_top);
__riscv_flush_icache();
write_csr(sscratch, kstack_top);
+ if (zicfilp_enabled)
+ set_csr(senvcfg, SENVCFG_LPE);
start_user(&tf);
}