-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests/riscv: Add pmp noexecute RAM test
- Loading branch information
1 parent
2fdb99e
commit 58d374c
Showing
9 changed files
with
112 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
BOARD ?= hifive1b | ||
|
||
include ../Makefile.cpu_common | ||
|
||
USEMODULE += pmp_noexec_ram | ||
|
||
include $(RIOTBASE)/Makefile.include |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# mpu_noexec_ram | ||
|
||
Tests for the `pmp_noexec_ram` pseudomodule. | ||
Only supported on RISC-V devices with PMP. | ||
|
||
## Output | ||
|
||
With `USEMODULE += pmp_noexec_ram` in `Makefile` this application should | ||
execute a kernel panic, stating `Instruction access fault` (0x01) in the | ||
`mcause` reigster. Without this pseudomodule activated, the hard fault | ||
will be triggered by `Illegal instruction` (0x02) instead. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* Copyright (C) 2023 Bennet Blischke <bennet.blischke@haw-hamburg.de> | ||
* | ||
* This file is subject to the terms and conditions of the GNU Lesser | ||
* General Public License v2.1. See the file LICENSE in the top level | ||
* directory for more details. | ||
*/ | ||
|
||
/** | ||
* @ingroup tests | ||
* @{ | ||
* | ||
* @file | ||
* @brief Test application for the pmp_noexec_ram pseudo-module | ||
* | ||
* @author Sören Tempel <tempel@uni-bremen.de> | ||
* @author Bennet Blischke <bennet.blischke@haw-hamburg.de> | ||
* | ||
* @} | ||
*/ | ||
|
||
#include <stdio.h> | ||
#include <stdint.h> | ||
|
||
#include "cpu.h" | ||
#include "pmp.h" | ||
|
||
#define JMPBUF_SIZE 3 | ||
|
||
int main(void) | ||
{ | ||
uint32_t buf[JMPBUF_SIZE]; | ||
|
||
/* Fill the buffer with invalid instructions */ | ||
for (unsigned i = 0; i < JMPBUF_SIZE; i++) { | ||
buf[i] = UINT32_MAX; | ||
} | ||
|
||
puts("Attempting to jump to stack buffer ...\n"); | ||
__asm__ volatile ("jr %0" :: "r" ((uint8_t*)&buf)); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# Copyright (C) 2020 Sören Tempel <tempel@uni-bremen.de> | ||
# | ||
# This file is subject to the terms and conditions of the GNU Lesser | ||
# General Public License v2.1. See the file LICENSE in the top level | ||
# directory for more details. | ||
|
||
import sys | ||
from testrunner import run | ||
|
||
|
||
def testfunc(child): | ||
child.expect_exact("MEM MANAGE HANDLER\r\n") | ||
|
||
|
||
if __name__ == "__main__": | ||
sys.exit(run(testfunc, timeout=10)) |