Skip to content

Conversation

@latifbhatti
Copy link

This PR implements a Python-based tool to validate memory access permissions using the Physical Memory Protection (PMP) rules defined in the RISC-V Privileged Specification (Chapter 3.7). The tool checks if a given physical address is accessible under the configured PMP rules for a specific privilege mode and operation.
Features

  • Parses PMP configuration files.
  • Calculates PMP regions based on address matching modes (TOR, NA4, NAPOT).
  • Validates memory access for a given address, privilege mode, and operation.
  • Included input validation for hexadecimal addresses, privilege modes, and operations.
  • Added error handling for invalid inputs and edge cases.
  • writed latex code for understanding the rules
  • Reads 128-line configuration files (64 pmpcfg and 64 pmpaddr values).
  • Checks access permissions for M, S, and U privilege modes.
  • Validates R (read), W (write), and X (execute) operations.

Command-Line Interface:
Accepts four arguments: PMP config file, physical address, privilege mode, and operation.
Example Usage

python pmp_check.py pmp_config.txt 0xc3000100 S R

Output:

Access allowed.

Configuration File Format

  • First 64 lines: pmpcfg values (hexadecimal).
  • Next 64 lines: pmpaddr values (hexadecimal).

Testing
Tested with various PMP configurations, including:

  • Valid and invalid physical addresses.
  • Different privilege modes and operations.

References
RISC-V Privileged Specification (Chapter 3.7)

Contributor
latifbhatti

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant