Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RISC-V ISAC] - PTE Permissions Check Function Updated #563

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 31 additions & 21 deletions riscv-isac/riscv_isac/coverage.py
Original file line number Diff line number Diff line change
Expand Up @@ -1038,29 +1038,39 @@ def get_pte(pa, pte_addr, pgtb_addr):
return None

def get_pte_prop(prop_name, pte_addr):
'''
Function to return whether a specific Permission is given to the PTE or not
:param prop_name: an input property ., example: 'U' for U bit or 'RWX' for a combination of bits
:param pte_addr: PTE address for which we want to get the information
"""
Function to check specific permissions of a PTE.

:param prop_name: string containing properties to check.
Uppercase letters mean the bits should be set.
Lowercase letters mean the bits should NOT be set.
Example: "uAdW" checks U and D bits are NOT set,
while A and W bits are set.
:param pte_addr: PTE address to examine (int or hex).
:return: 1 if conditions are met, 0 otherwise.
"""
if pte_addr is None:
return 0

bitmask_dict = {
'V': 0x01, 'R': 0x02, 'W': 0x04, 'X': 0x08,
'U': 0x10, 'G': 0x20, 'A': 0x40, 'D': 0x80
}

:type prop_name: str
:type pte_addr: hex/int
# Get permission bits from PTE address
pte_per = pte_addr & 0x3FF

:return: 1 or 0 depending whether the specific (or combination of) permission/s is set or not respectively.
'''
bitmask_dict = {'v': 0x01, 'r': 0x02, 'w': 0x04, 'x': 0x08, 'u': 0x10, 'g': 0x20, 'a': 0x40, 'd': 0x80}

if pte_addr is not None:
# Get the permissions bit out of the pte_addr
pte_per = pte_addr & 0x3FF

# Check each character in prop_name
for char in prop_name.lower():
if char in bitmask_dict and (pte_per & bitmask_dict[char] == 0):
return 0
return 1
else:
return 0
# Check each property in prop_name
for char in prop_name:
# Check if uppercase character should be set or lowercase should NOT be set
bitmask = bitmask_dict.get(char.upper())
if bitmask is None:
return 0 # If unrecognized character, then return overall zero prematurely.

if (char.isupper() and not (pte_per & bitmask)) or (char.islower() and (pte_per & bitmask)):
return 0

return 1

globals()['get_addr'] = check_label_address
globals()['get_mem_val'] = get_mem_val
Expand Down