comments and whitespace cleanup
[soc.git] / TLB / src / PermissionValidator.py
1 from nmigen import Signal
2 from nmigen.cli import main
3
4 class PermissionValidator():
5 """ The purpose of this Module is to check the Permissions of a given PTE
6 against the requested access permissions.
7
8 This module will either validate (by setting the valid bit HIGH)
9 the request or find a permission fault and invalidate (by setting
10 the valid bit LOW) the request
11 """
12
13 def __init__(self, data_size):
14 """ Arguments:
15 * data_size: (bit count) The size of the data words being processed
16
17 Return:
18 1. Data is valid -> valid is HIGH
19 2. Data is not valid -> valid is LOW
20 """
21 # Input
22 self.data = Signal(data_size);
23 self.xwr = Signal(3) # Execute, Write, Read
24 self.super = Signal(1) # Supervisor Mode
25 self.super_access = Signal(1) # Supervisor Access
26 self.asid = Signal(15) # Address Space IDentifier (ASID)
27
28 # Output
29 self.valid = Signal(1) # Denotes if the permissions are correct
30
31 def elaborate(self, platform):
32 m = Module()
33 m.d.comb += [
34 # Check if ASID matches OR entry is global
35 If(data[64:78] == self.asid or data[5] == 1,
36 # Check Execute, Write, Read (XWR) Permissions
37 If(data[3] == self.xwr[2] and data[2] == self.xwr[1] \
38 and data[1] == self.xwr[0],
39 # Check if supervisor
40 If(self.super == 1,
41 # Check if entry is in user mode
42 # Check if supervisor has access
43 If(data[4] == 0,
44 self.valid.eq(1)
45 ).Elif(self.super_access == 1,
46 self.valid.eq(1)
47 ).Else(
48 self.valid.eq(0)
49 )
50 ).Else(
51 # Check if entry is in user mode
52 If(data[4] == 1,
53 self.valid.eq(1)
54 ).Else(
55 self.valid.eq(0)
56 )
57 )
58 ).Else(
59 self.valid.eq(0)
60 )
61 ).Else(
62 self.valid.eq(0)
63 )
64 ]