1 from nmigen
import Signal
, Module
2 from nmigen
.cli
import main
4 # The purpose of this Module is to check the Permissions of a given PTE
5 # against the requested access permissions.
6 # This module will either validate (by setting the valid bit HIGH) the request
7 # or find a permission fault and invalidate (by setting the valid bit LOW)
9 class PermissionValidator():
10 def __init__(self
, data_size
):
12 self
.data
= Signal(data_size
);
13 self
.xwr
= Signal(3) # Execute, Write, Read
14 self
.super = Signal(1) # Supervisor Mode
15 self
.super_access
= Signal(1) # Supervisor Access
16 self
.asid
= Signal(15) # Address Space IDentifier (ASID)
19 self
.valid
= Signal(1) # Denotes if the permissions are correct
21 def elaborate(self
, platform
):
24 # Check if ASID matches OR entry is global
25 If(data
[98:113] == self
.asid
or data
[5] == 1,
26 # Check Execute, Write, Read (XWR) Permissions
27 If(data
[3] == self
.xwr
[2] and data
[2] == self
.xwr
[1] and data
[1] == self
.xwr
[0],
30 # Check if entry is in user mode
31 # Check if supervisor has access
34 ).Elif(self
.super_access
== 1,
40 # Check if entry is in user mode