1*** Variables ***
2&{mtvec_write_opcodes}                          0x10=0x30585073  0x11=0x3058d073  0x12=0x30595073  0x13=0x3059d073  0x14=0x305a5073
3&{stvec_write_opcodes}                          0x10=0x10585073  0x11=0x1058d073  0x12=0x10595073  0x13=0x1059d073  0x14=0x105a5073
4
5*** Keywords ***
6Create Machine
7    [Arguments]                                 ${interrupt_mode}
8
9    Execute Command                             using sysbus
10    Execute Command                             mach create
11    Execute Command                             machine LoadPlatformDescriptionFromString "cpu: CPU.RiscV32 @ sysbus { cpuType: \\"rv32imac\\"; timeProvider: empty; privilegedArchitecture: PrivilegedArchitecture.Priv1_10; interruptMode: InterruptMode.${interruptMode} }"
12    Execute Command                             machine LoadPlatformDescriptionFromString "mem: Memory.MappedMemory @ sysbus 0x0 { size: 0x10000000 }"
13
14    Execute Command                             cpu TbCacheEnabled false
15
16
17MTVEC Should Be Equal
18    [Arguments]                                 ${value}
19    ${reg}=  Execute Command                    cpu MTVEC
20    Should Be Equal                             ${reg.strip()}             ${value}
21
22
23STVEC Should Be Equal
24    [Arguments]                                 ${value}
25    ${reg}=  Execute Command                    cpu STVEC
26    Should Be Equal                             ${reg.strip()}             ${value}
27
28
29Set MTVEC By Software
30    [Arguments]                                 ${value}
31    Execute Command                             cpu PC 0x0
32    ${opcode}=  Get From Dictionary             ${mtvec_write_opcodes}  ${value}
33    Execute Command                             sysbus WriteDoubleWord 0x0 ${opcode}
34    Execute Command                             cpu Step
35
36    # this is a hack giving time for the logger to handle all messages
37    # (including the one generated by setting the MTVEC value)
38    Sleep                                       1s
39
40
41Set STVEC By Software
42    [Arguments]                                 ${value}
43    Execute Command                             cpu PC 0x0
44    ${opcode}=  Get From Dictionary             ${stvec_write_opcodes}  ${value}
45    Execute Command                             sysbus WriteDoubleWord 0x0 ${opcode}
46    Execute Command                             cpu Step
47
48    # this is a hack giving time for the logger to handle all messages
49    # (including the one generated by setting the STVEC value)
50    Sleep                                       1s
51
52*** Test Cases ***
53Should Not Correct MTVEC From Monitor in Auto Mode
54    Create Log Tester                           0
55    Create Machine                              Auto
56
57    MTVEC Should Be Equal                       0x1010
58
59    Execute Command                             cpu MTVEC 0x50
60    MTVEC Should Be Equal                       0x50
61    Should Not Be In Log                        modifying MTVEC
62
63    Execute Command                             cpu MTVEC 0x51
64    MTVEC Should Be Equal                       0x51
65    Should Not Be In Log                        modifying MTVEC
66
67    Execute Command                             cpu MTVEC 0x52
68    MTVEC Should Be Equal                       0x52
69    Should Not Be In Log                        modifying MTVEC
70
71    Execute Command                             cpu MTVEC 0x53
72    MTVEC Should Be Equal                       0x53
73    Should Not Be In Log                        modifying MTVEC
74
75    Execute Command                             cpu MTVEC 0x54
76    MTVEC Should Be Equal                       0x54
77    Should Not Be In Log                        modifying MTVEC
78
79
80Should Not Correct STVEC From Monitor in Auto Mode
81    Create Log Tester                           0
82    Create Machine                              Auto
83
84    STVEC Should Be Equal                       0x0
85
86    Execute Command                             cpu STVEC 0x50
87    STVEC Should Be Equal                       0x50
88    Should Not Be In Log                        modifying STVEC
89
90    Execute Command                             cpu STVEC 0x51
91    STVEC Should Be Equal                       0x51
92    Should Not Be In Log                        modifying STVEC
93
94    Execute Command                             cpu STVEC 0x52
95    STVEC Should Be Equal                       0x52
96    Should Not Be In Log                        modifying STVEC
97
98    Execute Command                             cpu STVEC 0x53
99    STVEC Should Be Equal                       0x53
100    Should Not Be In Log                        modifying STVEC
101
102    Execute Command                             cpu STVEC 0x54
103    STVEC Should Be Equal                       0x54
104    Should Not Be In Log                        modifying STVEC
105
106
107Should Not Correct MTVEC Written By Software in Auto Mode
108    Create Log Tester                           0
109    Create Machine                              Auto
110
111    MTVEC Should Be Equal                       0x1010
112
113    Set MTVEC By Software                       0x10
114    MTVEC Should Be Equal                       0x10
115    Should Not Be In Log                        MTVEC value written to CSR corrected
116
117    Set MTVEC By Software                       0x11
118    MTVEC Should Be Equal                       0x11
119    Should Not Be In Log                        MTVEC value written to CSR corrected
120
121    Set MTVEC By Software                       0x12
122    Wait For Log Entry                          MTVEC value written to CSR corrected
123    MTVEC Should Be Equal                       0x10
124
125    Set MTVEC By Software                       0x13
126    Wait For Log Entry                          MTVEC value written to CSR corrected
127    MTVEC Should Be Equal                       0x11
128
129    Set MTVEC By Software                       0x14
130    MTVEC Should Be Equal                       0x14
131    Should Not Be In Log                        MTVEC value written to CSR corrected
132
133
134Should Not Correct STVEC Written By Software in Auto Mode
135    Create Log Tester                           0
136    Create Machine                              Auto
137
138    STVEC Should Be Equal                       0x0
139
140    Set STVEC By Software                       0x10
141    STVEC Should Be Equal                       0x10
142    Should Not Be In Log                        STVEC value written to CSR corrected
143
144    Set STVEC By Software                       0x11
145    STVEC Should Be Equal                       0x11
146    Should Not Be In Log                        STVEC value written to CSR corrected
147
148    Set STVEC By Software                       0x12
149    Wait For Log Entry                          STVEC value written to CSR corrected
150    STVEC Should Be Equal                       0x10
151
152    Set STVEC By Software                       0x13
153    Wait For Log Entry                          STVEC value written to CSR corrected
154    STVEC Should Be Equal                       0x11
155
156    Set STVEC By Software                       0x14
157    STVEC Should Be Equal                       0x14
158    Should Not Be In Log                        STVEC value written to CSR corrected
159
160
161Should Correct MTVEC From Monitor in Direct Mode
162    Create Log Tester                           0
163    Create Machine                              Direct
164
165    MTVEC Should Be Equal                       0x1010
166
167    Execute Command                             cpu MTVEC 0x50
168    MTVEC Should Be Equal                       0x50
169    Should Not Be In Log                        modifying MTVEC
170
171    Execute Command                             cpu MTVEC 0x51
172    Wait For Log Entry                          modifying MTVEC
173    MTVEC Should Be Equal                       0x50
174
175    Execute Command                             cpu MTVEC 0x52
176    Wait For Log Entry                          modifying MTVEC
177    MTVEC Should Be Equal                       0x50
178
179    Execute Command                             cpu MTVEC 0x53
180    Wait For Log Entry                          modifying MTVEC
181    MTVEC Should Be Equal                       0x50
182
183    Execute Command                             cpu MTVEC 0x54
184    MTVEC Should Be Equal                       0x54
185    Should Not Be In Log                        modifying MTVEC
186
187
188Should Correct STVEC From Monitor in Direct Mode
189    Create Log Tester                           0
190    Create Machine                              Direct
191
192    STVEC Should Be Equal                       0x0
193
194    Execute Command                             cpu STVEC 0x50
195    STVEC Should Be Equal                       0x50
196    Should Not Be In Log                        modifying STVEC
197
198    Execute Command                             cpu STVEC 0x51
199    Wait For Log Entry                          modifying STVEC
200    STVEC Should Be Equal                       0x50
201
202    Execute Command                             cpu STVEC 0x52
203    Wait For Log Entry                          modifying STVEC
204    STVEC Should Be Equal                       0x50
205
206    Execute Command                             cpu STVEC 0x53
207    Wait For Log Entry                          modifying STVEC
208    STVEC Should Be Equal                       0x50
209
210    Execute Command                             cpu STVEC 0x54
211    STVEC Should Be Equal                       0x54
212    Should Not Be In Log                        modifying STVEC
213
214
215Should Correct MTVEC Written By Software in Direct Mode
216    Create Log Tester                           0
217    Create Machine                              Direct
218
219    MTVEC Should Be Equal                       0x1010
220
221    Set MTVEC By Software                       0x10
222    MTVEC Should Be Equal                       0x10
223    Should Not Be In Log                        MTVEC value written to CSR corrected
224
225    Set MTVEC By Software                       0x11
226    Wait For Log Entry                          MTVEC value written to CSR corrected
227    MTVEC Should Be Equal                       0x10
228
229    Set MTVEC By Software                       0x12
230    Wait For Log Entry                          MTVEC value written to CSR corrected
231    MTVEC Should Be Equal                       0x10
232
233    Set MTVEC By Software                       0x13
234    Wait For Log Entry                          MTVEC value written to CSR corrected
235    MTVEC Should Be Equal                       0x10
236
237    Set MTVEC By Software                       0x14
238    MTVEC Should Be Equal                       0x14
239    Should Not Be In Log                        MTVEC value written to CSR corrected
240
241
242Should Correct STVEC Written By Software in Direct Mode
243    Create Log Tester                           0
244    Create Machine                              Direct
245
246    STVEC Should Be Equal                       0x0
247
248    Set STVEC By Software                       0x10
249    STVEC Should Be Equal                       0x10
250    Should Not Be In Log                        STVEC value written to CSR corrected
251
252    Set STVEC By Software                       0x11
253    Wait For Log Entry                          STVEC value written to CSR corrected
254    STVEC Should Be Equal                       0x10
255
256    Set STVEC By Software                       0x12
257    Wait For Log Entry                          STVEC value written to CSR corrected
258    STVEC Should Be Equal                       0x10
259
260    Set STVEC By Software                       0x13
261    Wait For Log Entry                          STVEC value written to CSR corrected
262    STVEC Should Be Equal                       0x10
263
264    Set STVEC By Software                       0x14
265    STVEC Should Be Equal                       0x14
266    Should Not Be In Log                        STVEC value written to CSR corrected
267
268
269Should Correct MTVEC From Monitor in Vectored Mode
270    Create Log Tester                           0
271    Create Machine                              Vectored
272
273    Wait For Log Entry                          Vectored interrupt mode set - updating MTVEC
274    MTVEC Should Be Equal                       0x1011
275
276    Execute Command                             cpu MTVEC 0x50
277    Wait For Log Entry                          modifying MTVEC
278    MTVEC Should Be Equal                       0x51
279
280    Execute Command                             cpu MTVEC 0x51
281    MTVEC Should Be Equal                       0x51
282    Should Not Be In Log                        modifying MTVEC
283
284    Execute Command                             cpu MTVEC 0x52
285    Wait For Log Entry                          modifying MTVEC
286    MTVEC Should Be Equal                       0x51
287
288    Execute Command                             cpu MTVEC 0x53
289    Wait For Log Entry                          modifying MTVEC
290    MTVEC Should Be Equal                       0x51
291
292    Execute Command                             cpu MTVEC 0x54
293    Wait For Log Entry                          modifying MTVEC
294    MTVEC Should Be Equal                       0x55
295
296
297Should Correct STVEC From Monitor in Vectored Mode
298    Create Log Tester                           0
299    Create Machine                              Vectored
300
301    Wait For Log Entry                          Vectored interrupt mode set - updating STVEC
302    STVEC Should Be Equal                       0x1
303
304    Execute Command                             cpu STVEC 0x50
305    Wait For Log Entry                          modifying STVEC
306    STVEC Should Be Equal                       0x51
307
308    Execute Command                             cpu STVEC 0x51
309    STVEC Should Be Equal                       0x51
310    Should Not Be In Log                        modifying STVEC
311
312    Execute Command                             cpu STVEC 0x52
313    Wait For Log Entry                          modifying STVEC
314    STVEC Should Be Equal                       0x51
315
316    Execute Command                             cpu STVEC 0x53
317    Wait For Log Entry                          modifying STVEC
318    STVEC Should Be Equal                       0x51
319
320    Execute Command                             cpu STVEC 0x54
321    Wait For Log Entry                          modifying STVEC
322    STVEC Should Be Equal                       0x55
323
324
325Should Correct MTVEC Written By Software in Vectored Mode
326    Create Log Tester                           0
327    Create Machine                              Vectored
328
329    MTVEC Should Be Equal                       0x1011
330
331    Set MTVEC By Software                       0x10
332    Wait For Log Entry                          MTVEC value written to CSR corrected
333    MTVEC Should Be Equal                       0x11
334
335    Set MTVEC By Software                       0x11
336    MTVEC Should Be Equal                       0x11
337    Should Not Be In Log                        MTVEC value written to CSR corrected
338
339    Set MTVEC By Software                       0x12
340    Wait For Log Entry                          MTVEC value written to CSR corrected
341    MTVEC Should Be Equal                       0x11
342
343    Set MTVEC By Software                       0x13
344    Wait For Log Entry                          MTVEC value written to CSR corrected
345    MTVEC Should Be Equal                       0x11
346
347    Set MTVEC By Software                       0x14
348    Wait For Log Entry                          MTVEC value written to CSR corrected
349    MTVEC Should Be Equal                       0x15
350
351
352Should Correct STVEC Written By Software in Vectored Mode
353    Create Log Tester                           0
354    Create Machine                              Vectored
355
356    STVEC Should Be Equal                       0x1
357
358    Set STVEC By Software                       0x10
359    Wait For Log Entry                          STVEC value written to CSR corrected
360    STVEC Should Be Equal                       0x11
361
362    Set STVEC By Software                       0x11
363    STVEC Should Be Equal                       0x11
364    Should Not Be In Log                        STVEC value written to CSR corrected
365
366    Set STVEC By Software                       0x12
367    Wait For Log Entry                          STVEC value written to CSR corrected
368    STVEC Should Be Equal                       0x11
369
370    Set STVEC By Software                       0x13
371    Wait For Log Entry                          STVEC value written to CSR corrected
372    STVEC Should Be Equal                       0x11
373
374    Set STVEC By Software                       0x14
375    Wait For Log Entry                          STVEC value written to CSR corrected
376    STVEC Should Be Equal                       0x15
377