diff --git a/examples/sw/simple_system/pmp_smoke_test/Makefile b/examples/sw/simple_system/pmp_smoke_test/Makefile new file mode 100644 index 00000000..41a31c6b --- /dev/null +++ b/examples/sw/simple_system/pmp_smoke_test/Makefile @@ -0,0 +1,14 @@ +# Copyright lowRISC contributors. +# Licensed under the Apache License, Version 2.0, see LICENSE for details. +# SPDX-License-Identifier: Apache-2.0 +# +# Generate a baremetal application + +# Name of the program $(PROGRAM).c will be added as a source file +PROGRAM = pmp_smoke_test +PROGRAM_DIR := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST)))) +# Any extra source files to include in the build. Use the upper case .S +# extension for assembly files +EXTRA_SRCS := + +include ${PROGRAM_DIR}/../common/common.mk diff --git a/examples/sw/simple_system/pmp_smoke_test/pmp_smoke_test.c b/examples/sw/simple_system/pmp_smoke_test/pmp_smoke_test.c new file mode 100644 index 00000000..fd10f6e1 --- /dev/null +++ b/examples/sw/simple_system/pmp_smoke_test/pmp_smoke_test.c @@ -0,0 +1,26 @@ +// Copyright lowRISC contributors. +// Licensed under the Apache License, Version 2.0, see LICENSE for details. +// SPDX-License-Identifier: Apache-2.0 +// +// Basic smoke test for PMP. The test sets up a read-only PMP region then tries +// to write to it. It is intended for use with an external checking method (such +// as the Ibex co-simulation system) and does not report pass or fail. + +volatile unsigned int test_int = 10; + +// Locked read only for lowest region, NA4 matching +#define TEST_PMPCFG0 0x91 + +int main(int argc, char **argv) { + unsigned int pmpaddr0 = ((unsigned int)&test_int) >> 2; + + __asm__ volatile( + "csrw pmpaddr0, %1\n" + "csrw pmpcfg0, %0\n" + : + : "r"(TEST_PMPCFG0), "r"(pmpaddr0)); + + test_int = 12; + + return 0; +}