Moving all source scripts
[soc.git] / TLB / src / PermissionValidator.py
1 from nmigen import Signal
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 #
10 # Arguments:
11 # data_size: (bit count) The size of the data words being processed
12 #
13 # Return:
14 # 1. Data is valid -> valid is HIGH
15 # 2. Data is not valid -> valid is LOW
16 class PermissionValidator():
17 def __init__(self, data_size):
18 # Input
19 self.data = Signal(data_size);
20 self.xwr = Signal(3) # Execute, Write, Read
21 self.super = Signal(1) # Supervisor Mode
22 self.super_access = Signal(1) # Supervisor Access
23 self.asid = Signal(15) # Address Space IDentifier (ASID)
24
25 # Output
26 self.valid = Signal(1) # Denotes if the permissions are correct
27
28 def elaborate(self, platform):
29 m = Module()
30 m.d.comb += [
31 # Check if ASID matches OR entry is global
32 If(data[64:78] == self.asid or data[5] == 1,
33 # Check Execute, Write, Read (XWR) Permissions
34 If(data[3] == self.xwr[2] and data[2] == self.xwr[1] \
35 and data[1] == self.xwr[0],
36 # Check if supervisor
37 If(self.super == 1,
38 # Check if entry is in user mode
39 # Check if supervisor has access
40 If(data[4] == 0,
41 self.valid.eq(1)
42 ).Elif(self.super_access == 1,
43 self.valid.eq(1)
44 ).Else(
45 self.valid.eq(0)
46 )
47 ).Else(
48 # Check if entry is in user mode
49 If(data[4] == 1,
50 self.valid.eq(1)
51 ).Else(
52 self.valid.eq(0)
53 )
54 )
55 ).Else(
56 self.valid.eq(0)
57 )
58 ).Else(
59 self.valid.eq(0)
60 )
61 ]