diff options
| author | Carlos Maiolino <[email protected]> | 2025-07-10 22:18:39 +0200 |
|---|---|---|
| committer | Carlos Maiolino <[email protected]> | 2025-07-10 22:18:39 +0200 |
| commit | 8c6fc0c15415b32080a848bbde640e104098cf13 (patch) | |
| tree | 04a21bd28f9dc82c8e216390d6208ed93b9bcd11 /riscv/riscv-probe/examples/user | |
Initial drop
Add some riscv code
Signed-off-by: Carlos Maiolino <[email protected]>
Diffstat (limited to 'riscv/riscv-probe/examples/user')
| -rw-r--r-- | riscv/riscv-probe/examples/user/rules.mk | 1 | ||||
| -rw-r--r-- | riscv/riscv-probe/examples/user/user.c | 27 |
2 files changed, 28 insertions, 0 deletions
diff --git a/riscv/riscv-probe/examples/user/rules.mk b/riscv/riscv-probe/examples/user/rules.mk new file mode 100644 index 0000000..63c6868 --- /dev/null +++ b/riscv/riscv-probe/examples/user/rules.mk @@ -0,0 +1 @@ +user_objs = user.o diff --git a/riscv/riscv-probe/examples/user/user.c b/riscv/riscv-probe/examples/user/user.c new file mode 100644 index 0000000..e37397f --- /dev/null +++ b/riscv/riscv-probe/examples/user/user.c @@ -0,0 +1,27 @@ +#include "femto.h" + +#ifdef __riscv +#include "arch/riscv/encoding.h" +#include "arch/riscv/machine.h" +#endif + +int main(int argc, char **argv) +{ + /* + * Set up PMP (Physical Memory Protection) + * + * PMP is optional; bit if implemented enforcement is mandatory + * and user-mode is prevented access to all memory by default. + * We should change this code to restrict user mode to its .text + * .rodata, .data, .bss and devices. + */ +#ifdef __riscv + if (pmp_entry_count() > 0) { + pmp_allow_all(); + } + mode_set_and_continue(PRV_U); + puts("riscv-user-mode"); +#else + puts("architecture-not-supported"); +#endif +} |
