-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsystem3mmu.smv
128 lines (119 loc) · 3.59 KB
/
system3mmu.smv
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
MODULE UART (proc, proc2UARTvalue, proc2UARTAddress)
VAR
Rx : unsigned word [ 8 ]; -- byte from the outside
Tx : array 0 .. 8 of unsigned word [ 8 ]; --array of bytes that is written from the internal memory
uart2CPU : unsigned word [ 8 ]; -- the data the UART writes to the CPU
uart2mem : unsigned word [ 8 ]; -- the data the UART writes to RAM (no DMA)
uart2memValue : unsigned word [ 8 ]; -- external
ASSIGN
next (Tx[0]) :=
case
proc = write2UART & proc2UARTAddress = 0 : proc2UARTvalue;
TRUE : (Tx[0]);
esac;
next (Tx[1]) :=
case
proc = write2UART & proc2UARTAddress = 1 : proc2UARTvalue;
TRUE : (Tx[1]);
esac;
next (Tx[2]) :=
case
proc = write2UART & proc2UARTAddress = 2 : proc2UARTvalue;
TRUE : (Tx[2]);
esac;
next (Tx[3]) :=
case
proc = write2UART & proc2UARTAddress = 3 : proc2UARTvalue;
TRUE : (Tx[3]);
esac;
next (Tx[4]) :=
case
proc = write2UART & proc2UARTAddress = 4 : proc2UARTvalue;
TRUE : (Tx[4]);
esac;
next (Tx[5]) :=
case
proc = write2UART & proc2UARTAddress = 5 : proc2UARTvalue;
TRUE : (Tx[5]);
esac;
next (Tx[6]) :=
case
proc = write2UART & proc2UARTAddress = 6 : proc2UARTvalue;
TRUE : (Tx[6]);
esac;
next (Tx[7]) :=
case
proc = write2UART & proc2UARTAddress = 7 : proc2UARTvalue;
TRUE : (Tx[7]);
esac;
next (uart2CPU) :=
case
proc = read2UART : Rx;
TRUE : Rx;
esac;
-- memory model
-- the secure address is address 513
MODULE PTE -- page table entry
VAR
ptes : array 0 .. 4 of unsigned word [ 8 ]; -- valid, virtual page, modified, protection, page frame
MODULE MMU (proc, proc2memValue, pageNumber, proc2memAddress, mmu2mainValue)
VAR
tlb : array 0 .. 8 of unsigned word [ 8 ];
mem2read : 0 .. 8;
ASSIGN
next (tlb[0]) :=
case
proc = write : tlb[pageNumber];
TRUE : tlb[0];
esac;
next (mmu2mainValue[0]) :=
case
proc = read & proc2memAddress = 0 | proc2memAddress = 32 & tlb[0] != 0uo8_0: tlb[0];
TRUE : 0uo8_0; -- respond void if data in TLB is void
esac;
next (mem2read) :=
case
proc = read & proc2memAddress = 0 | proc2memAddress = 32 & tlb[0] = 0uo8_0: proc2memAddress;
TRUE : mem2read;
esac;
MODULE MEM (proc, uart2memValue, mmu)
DEFINE
secureAddress := 7;
VAR
data : array 0 .. 16 of unsigned word [ 8 ];
mem2proc : unsigned word [ 8 ];
ASSIGN
next (mem2proc) :=
case
proc = read : data[mmu.mem2read];
TRUE : mem2proc;
esac;
next (data[secureAddress]) :=
case
proc = write & mmu.pageNumber = secureAddress : mmu.tlb[mmu.pageNumber];
TRUE : data[secureAddress];
esac;
next (data[0]) :=
case
proc = write & mmu.pageNumber = 0 : mmu.tlb[mmu.pageNumber];
TRUE : data[secureAddress];
esac;
MODULE main
VAR
proc : {idle, read, write, read2UART, write2UART, setDMAaddress};
data : array 0 .. 8 of unsigned word [ 8 ];
pageNumber : 0 .. 7;
proc2UARTAddress : 0 .. 7;
proc2memAddress : 0..7; -- the data the CPU writes to memory
proc2memValue : unsigned word [ 8 ]; -- the data the CPU writes to memory
proc2UARTvalue : unsigned word [ 8 ]; -- the data the CPU writes to the UART
mmu : MMU (proc, proc2memValue, pageNumber, proc2memAddress, data);
memory : MEM (proc, uart2mem, mmu);
uart0 : UART (proc, proc2UARTvalue, proc2UARTAddress);
ASSIGN
--if we write to the UART then after a while it will appear on Tx
LTLSPEC G proc = write2UART & proc2UARTAddress = 0 -> F (next (uart0.Tx[0]) =
proc2UARTvalue)
-- if we write to the UART but not to the secure memory, then the secure memory is constant
LTLSPEC G (pageNumber != memory.secureAddress) -> G
(memory.data[memory.secureAddress] = next (memory.data[memory.secureAddress]))