-
Notifications
You must be signed in to change notification settings - Fork 0
/
TlUh.v
204 lines (181 loc) · 7.92 KB
/
TlUh.v
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
Require Import Kami.AllNotations.
Require Import ProcKami.FU.
Require Import ProcKami.Device.
Require Import ProcKami.MemOps.
Require Import ProcKami.MemOpsFuncs.
Require Import ProcKami.Pipeline.Mem.Ifc.
Require Import ProcKami.Pipeline.Mem.PmaPmp.
Section tluh.
Context {procParams : ProcParams}.
Context (deviceTree : @DeviceTree procParams).
Section tlLink.
Context (tagK : Kind).
Definition InReq := STRUCT_TYPE { "tag" :: tagK; (* TL source ID *)
"req" :: @MemReq _ deviceTree }.
Definition ChannelAReq := STRUCT_TYPE {
"a_opcode" :: TlOpcode;
"a_param" :: TlParam;
"a_size" :: TlSize;
"a_source" :: Bit (size tagK);
"a_address" :: FU.PAddr;
"a_mask" :: Bit (size DataMask);
"a_corrupt" :: Bool;
"a_data" :: Data
}.
(* Note: opcode is always Ack, param is always 0, and size is always the encoding of Rlen. *)
Definition ChannelDRes := STRUCT_TYPE {
"d_opcode" :: TlOpcode;
"d_param" :: TlParam;
"d_size" :: TlSize;
"d_source" :: Bit (size tagK);
"d_sink" :: Void;
"d_denied" :: Bool;
"d_corrupt" :: Bool;
"d_data" :: Data
}.
Section ty.
Variable ty : Kind -> Type.
Local Open Scope kami_expr.
Local Definition getFinalMaskExpr
(sz : TlSize @# ty)
(address : PAddr @# ty)
: Bit (size DataMask) @# ty
:= getMaskExpr sz << (getShiftAmt sz address).
Definition fromKamiReq
(req : InReq @# ty)
: ChannelAReq @# ty
:= STRUCT {
"a_opcode" ::= UniBit (TruncMsb _ TlOpcodeSz) (req @% "req" @% "memOp");
"a_param"
::= UniBit (TruncMsb TlSizeSz TlParamSz)
(UniBit (TruncLsb (TlSizeSz + TlParamSz) TlOpcodeSz)
(req @% "req" @% "memOp"));
"a_size" ::= getSize (req @% "req" @% "memOp");
"a_source" ::= pack (req @% "tag");
"a_address" ::= (req @% "req" @% "paddr");
"a_mask" ::= getFinalMaskExpr (getSize (req @% "req" @% "memOp")) (req @% "req" @% "paddr");
"a_corrupt" ::= $$false;
"a_data" ::= req @% "req" @% "data"
}.
Local Open Scope kami_action.
Definition toKamiReq
(req : ChannelAReq @# ty)
: ActionT ty InReq
:= LETA dtag : Maybe (DTagOffset deviceTree) <- getDTagOffset deviceTree (req @% "a_address" : FU.PAddr @# ty);
LET memReq : Mem.Ifc.MemReq deviceTree
<- STRUCT {
"dtag" ::= #dtag @% "data" @% "dtag";
"offset" ::= #dtag @% "data" @% "offset";
"paddr" ::= req @% "a_address";
"memOp" ::= ({< req @% "a_opcode", req @% "a_param", req @% "a_size" >});
"data" ::= req @% "a_data"
};
Ret (STRUCT {
"tag" ::= unpack tagK (req @% "a_source");
"req" ::= #memReq
} : InReq @# ty).
Local Close Scope kami_action.
(*
NOTE: Murali instructed me to set valid so that it always
indicate that the message is valid.
*)
Definition toKamiRes
(ty : Kind -> Type)
(res : Maybe ChannelDRes @# ty)
: Maybe (Device.Res tagK) @# ty
:= let outRes : Pair Data TlSize @# ty
:= STRUCT {
"fst" ::= res @% "data" @% "d_data";
"snd" ::= res @% "data" @% "d_size"
} : Pair Data TlSize @# ty in
let data : Device.Res tagK @# ty
:= STRUCT {
"tag" ::= unpack tagK (res @% "data" @% "d_source");
"res" ::= outRes
} : Device.Res tagK @# ty in
STRUCT {
"valid" ::= res @% "valid";
"data" ::= data
}.
(*
NOTE: Murali instructed me to set d_denied and d_corrupt
so that they always indicate that the message is valid.
*)
Definition fromKamiRes
(res : Device.Res tagK @# ty)
: ChannelDRes @# ty
:= STRUCT {
"d_opcode" ::= $TlAccessAckData;
"d_param" ::= $0;
"d_size" ::= res @% "res" @% "snd";
"d_source" ::= pack (res @% "tag");
"d_sink" ::= $$(getDefaultConst Void);
"d_denied" ::= $$false;
"d_corrupt" ::= $$false;
"d_data" ::= res @% "res" @% "fst"
}.
Local Close Scope kami_expr.
End ty.
End tlLink.
End tluh.
Section test.
Local Instance testParams : ProcParams
:= {| FU.procName := "blah" ;
FU.Xlen_over_8 := 8;
FU.Flen_over_8 := 8;
FU.pcInit := ($0)%word;
FU.supported_xlens := [];
FU.supported_exts := [];
FU.allow_misaligned := false;
FU.allow_inst_misaligned := false;
FU.has_misaligned_access_exception := false;
FU.lgGranularity := 3;
FU.hasVirtualMem := true |}.
Let testMask sz
:= Z.to_nat (wordVal _ (evalExpr (getMaskExpr (Const type (natToWord TlSizeSz sz))))).
Goal (testMask 3 = bin "11111111"). reflexivity. Qed.
Goal (testMask 2 = bin "00001111"). reflexivity. Qed.
Goal (testMask 1 = bin "00000011"). reflexivity. Qed.
Goal (testMask 0 = bin "00000001"). reflexivity. Qed.
Let init: ConstT (Bit (PAddrSz - 3)) := _ 'h"438ad38".
Let testShiftAmt sz addr
:= (Z.to_nat
(wordVal _
(evalExpr
(getShiftAmt (Const type (natToWord TlSizeSz sz))
({< Const type init, Const type (natToWord 3 addr) >})%kami_expr)))).
Goal (testShiftAmt 3 (bin "000") = 0). reflexivity. Qed.
Goal (testShiftAmt 2 (bin "000") = 0). reflexivity. Qed.
Goal (testShiftAmt 2 (bin "100") = 4). reflexivity. Qed.
Goal (testShiftAmt 1 (bin "000") = 0). reflexivity. Qed.
Goal (testShiftAmt 1 (bin "010") = 2). reflexivity. Qed.
Goal (testShiftAmt 1 (bin "100") = 4). reflexivity. Qed.
Goal (testShiftAmt 1 (bin "110") = 6). reflexivity. Qed.
Goal (testShiftAmt 0 (bin "000") = 0). reflexivity. Qed.
Goal (testShiftAmt 0 (bin "001") = 1). reflexivity. Qed.
Goal (testShiftAmt 0 (bin "010") = 2). reflexivity. Qed.
Goal (testShiftAmt 0 (bin "011") = 3). reflexivity. Qed.
Goal (testShiftAmt 0 (bin "100") = 4). reflexivity. Qed.
Goal (testShiftAmt 0 (bin "101") = 5). reflexivity. Qed.
Goal (testShiftAmt 0 (bin "110") = 6). reflexivity. Qed.
Goal (testShiftAmt 0 (bin "111") = 7). reflexivity. Qed.
Let testFinalMask sz addr
:= Z.to_nat (wordVal _ (evalExpr (getFinalMaskExpr
(Const type (natToWord TlSizeSz sz))
({<Const type init, Const type (natToWord 3 addr)>})%kami_expr))).
Goal (testFinalMask 3 (bin "000") = (bin "11111111")). reflexivity. Qed.
Goal (testFinalMask 2 (bin "000") = (bin "00001111")). reflexivity. Qed.
Goal (testFinalMask 2 (bin "100") = (bin "11110000")). reflexivity. Qed.
Goal (testFinalMask 1 (bin "000") = (bin "00000011")). reflexivity. Qed.
Goal (testFinalMask 1 (bin "010") = (bin "00001100")). reflexivity. Qed.
Goal (testFinalMask 1 (bin "100") = (bin "00110000")). reflexivity. Qed.
Goal (testFinalMask 1 (bin "110") = (bin "11000000")). reflexivity. Qed.
Goal (testFinalMask 0 (bin "000") = (bin "00000001")). reflexivity. Qed.
Goal (testFinalMask 0 (bin "001") = (bin "00000010")). reflexivity. Qed.
Goal (testFinalMask 0 (bin "010") = (bin "00000100")). reflexivity. Qed.
Goal (testFinalMask 0 (bin "011") = (bin "00001000")). reflexivity. Qed.
Goal (testFinalMask 0 (bin "100") = (bin "00010000")). reflexivity. Qed.
Goal (testFinalMask 0 (bin "101") = (bin "00100000")). reflexivity. Qed.
Goal (testFinalMask 0 (bin "110") = (bin "01000000")). reflexivity. Qed.
Goal (testFinalMask 0 (bin "111") = (bin "10000000")). reflexivity. Qed.
End test.