86050d23da6f12261fe9142d5ce2298d9a75d7b2
[soc.git] / TLB / PermissionValidator.py
1 from nmigen import *
2 from nmigen.cli import main
3
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)
8 # the request
9 class PermissionValidator():
10 def __init__(self, data_size):
11 # Input
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)
17
18 # Output
19 self.valid = Signal(1) # Denotes if the permissions are correct
20
21 def elaborate(self, platform):
22 m = Module()
23 m.d.comb += [
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],
28 # Check if supervisor
29 If(self.super == 1,
30 # Check if entry is in user mode
31 # Check if supervisor has access
32 If(data[4] == 0,
33 self.valid.eq(1)
34 ).Elif(self.super_access == 1,
35 self.valid.eq(1)
36 ).Else(
37 self.valid.eq(0)
38 )
39 ).Else(
40 # Check if entry is in user mode
41 If(data[4] == 1,
42 self.valid.eq(1)
43 ).Else(
44 self.valid.eq(0)
45 )
46 )
47 ).Else(
48 self.valid.eq(0)
49 )
50 ).Else(
51 self.valid.eq(0)
52 )
53 ]