e7c3b774625ca32d5b7c3cf709c035afbb307ec6
1 from nmigen
import Signal
, Module
, If
, Else
2 from nmigen
.cli
import main
4 # The expected form of the data is
6 # Tag (N - 79) / ASID (78 - 64) / PTE (63 - 0)
8 # The purpose of this Module is to check the Permissions of a given PTE
9 # against the requested access permissions.
10 # This module will either validate (by setting the valid bit HIGH) the request
11 # or find a permission fault and invalidate (by setting the valid bit LOW)
13 class PermissionValidator():
14 def __init__(self
, data_size
):
16 self
.data
= Signal(data_size
);
17 self
.xwr
= Signal(3) # Execute, Write, Read
18 self
.super = Signal(1) # Supervisor Mode
19 self
.super_access
= Signal(1) # Supervisor Access
20 self
.asid
= Signal(15) # Address Space IDentifier (ASID)
23 self
.valid
= Signal(1) # Denotes if the permissions are correct
25 def elaborate(self
, platform
):
28 # Check if ASID matches OR entry is global
29 If(data
[64:78] == self
.asid
or data
[5] == 1,
30 # Check Execute, Write, Read (XWR) Permissions
31 If(data
[3] == self
.xwr
[2] and data
[2] == self
.xwr
[1] \
32 and data
[1] == self
.xwr
[0],
35 # Check if entry is in user mode
36 # Check if supervisor has access
39 ).Elif(self
.super_access
== 1,
45 # Check if entry is in user mode