[examples/sw] Add a pmp smoke test

This commit is contained in:
Greg Chadwick 2022-07-19 18:33:09 +01:00 committed by Greg Chadwick
parent f8b6d468c3
commit bb6427d276
2 changed files with 40 additions and 0 deletions

View file

@ -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

View file

@ -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;
}