1*** Variables ***
2${bin_out_signature}=                           ReTrace\x04
3${triple_and_model}=                            riscv32 rv32imacv
4
5*** Keywords ***
6Create Machine Versatile
7    Execute Command                             using sysbus
8    Execute Command                             include @scripts/single-node/versatile.resc
9
10    Execute Command                             cpu PerformanceInMips 1
11    # the value of quantum is selected here to generate several blocks
12    # of multiple instructions to check if the execution tracer can
13    # disassemble blocks correctly
14    Execute Command                             emulation SetGlobalQuantum "0.000004"
15
16Create Machine RISC-V 64-bit
17    [Arguments]                                 ${pc_hex}  ${memory_per_cpu}
18    Execute Command                             mach create
19    Execute Command                             machine LoadPlatformDescriptionFromString "cpu: CPU.RiscV64 @ sysbus { cpuType: \\"rv64imacv\\"; timeProvider: empty }"
20    IF  ${memory_per_cpu}
21        Execute Command                             machine LoadPlatformDescriptionFromString "mem: Memory.MappedMemory @ sysbus new Bus.BusPointRegistration { address: ${pc_hex}; cpu: cpu } { size: 0x40000 }"
22    ELSE
23        Execute Command                             machine LoadPlatformDescriptionFromString "mem: Memory.MappedMemory @ sysbus ${pc_hex} { size: 0x40000 }"
24    END
25
26    Execute Command                             sysbus.cpu PC ${pc_hex}
27
28Create Machine RISC-V 32-bit
29    [Arguments]                                 ${pc_hex}  ${memory_per_cpu}
30    Execute Command                             mach create
31    Execute Command                             machine LoadPlatformDescriptionFromString "cpu: CPU.RiscV32 @ sysbus { cpuType: \\"rv32imacv\\"; timeProvider: empty }"
32    IF  ${memory_per_cpu}
33        Execute Command                             machine LoadPlatformDescriptionFromString "mem: Memory.MappedMemory @ sysbus new Bus.BusPointRegistration { address: ${pc_hex}; cpu: cpu } { size: 0x40000 }"
34    ELSE
35        Execute Command                             machine LoadPlatformDescriptionFromString "mem: Memory.MappedMemory @ sysbus ${pc_hex} { size: 0x40000 }"
36    END
37
38Trace The Execution On The Versatile Platform
39    [Arguments]                                 ${trace_format}
40    Create Machine Versatile
41    ${trace_file}=                              Allocate Temporary File
42    Execute Command                             cpu CreateExecutionTracing "tracer" @${trace_file} ${trace_format}
43    # exactly the amount of virtual time to execute 16 instructions
44    Execute Command                             emulation RunFor "0.000016"
45    Execute Command                             cpu DisableExecutionTracing
46
47    ${output}=                                  Get File  ${trace_file}
48    ${output_lines}=                            Split To Lines  ${output}
49    RETURN  ${output_lines}
50
51Run And Trace Simple Program On RISC-V
52    [Arguments]                                 ${pc_start_hex}  ${trace_format}  ${is_binary}
53    ${trace_file}=                              Allocate Temporary File
54    Execute Command                             sysbus.cpu CreateExecutionTracing "tracer" "${trace_file}" ${trace_format} ${is_binary}
55
56    ${pc}=                                      Convert To Integer  ${pc_start_hex}
57    Execute Command                             sysbus.cpu PC ${pc}
58    Execute Command                             sysbus WriteDoubleWord ${pc+0} 0x00000013 cpu  # nop
59    Execute Command                             sysbus WriteWord ${pc+4} 0x0001 cpu            # nop
60    Execute Command                             sysbus WriteDoubleWord ${pc+6} 0x00310093 cpu  # addi x1, x2, 003
61
62    Execute Command                             sysbus.cpu Step 3
63    Execute Command                             sysbus.cpu DisableExecutionTracing
64
65    IF  ${is_binary}
66        ${output}=                                  Get Binary File  ${trace_file}
67        RETURN  ${output}
68    ELSE
69        ${output}=                                  Get File  ${trace_file}
70        ${output_lines}=                            Split To Lines  ${output}
71        RETURN  ${output_lines}
72    END
73
74Run RISC-V Program With Vcfg Instruction
75    [Arguments]                                 ${pc_hex}
76    Execute Command                             sysbus.cpu MSTATUS 0x600
77    ${pc}=                                      Convert To Integer  ${pc_hex}
78    Execute Command                             sysbus.cpu PC ${pc}
79    Execute Command                             sysbus WriteDoubleWord ${pc+0} 0x00000013  # nop
80    Execute Command                             sysbus WriteWord ${pc+4} 0x0001            # nop
81    Execute Command                             sysbus WriteDoubleWord ${pc+6} 0x04007057  # vsetvli zero, zero, e8, m1, ta, mu
82
83    Execute Command                             sysbus.cpu Step 3
84
85Run RISC-V Program With Memory Access
86    [Arguments]                                 ${pc_hex}
87    ${pc}=                                      Convert To Integer  ${pc_hex}
88    Execute Command                             sysbus.cpu PC ${pc}
89    Execute Command                             sysbus WriteDoubleWord ${pc+0} 0x305B7 cpu   # lui a1, 48
90    Execute Command                             sysbus WriteWord ${pc+4} 0xe537 cpu          # lui a0, 14
91    Execute Command                             sysbus WriteDoubleWord ${pc+8} 0xb52023 cpu  # sw a1, 0(a0)
92
93    Execute Command                             sysbus.cpu Step 3
94
95Should Be Equal As Bytes
96    [Arguments]                                 ${bytes}  ${str}
97    ${str_bytes}                                Convert To Bytes  ${str}
98    Should Be Equal                             ${bytes}  ${str_bytes}  formatter=repr
99
100Should Dump 64-bit PCs On RISC-V
101    [Arguments]                                 ${memory_per_cpu}
102    Create Machine RISC-V 64-bit                0x2000000000  ${memory_per_cpu}
103
104    ${pcs}=                                     Run And Trace Simple Program On RISC-V  0x2000000000  PC  False
105    Should Contain                              ${pcs}[0]  0x2000000000
106    Should Contain                              ${pcs}[1]  0x2000000004
107    Should Contain                              ${pcs}[2]  0x2000000006
108
109Should Dump Disassembly On RISC-V
110    [Arguments]                                 ${memory_per_cpu}
111    Create Machine RISC-V 32-bit                0x2000  ${memory_per_cpu}
112
113    ${trace}=                                   Run And Trace Simple Program On RISC-V  0x2000  Disassembly  False
114    Should Contain                              ${trace}[0]  nop
115    Should Contain                              ${trace}[1]  nop
116    Should Contain                              ${trace}[2]  addi
117
118Should Be Able To Add Memory Accesses To The Trace On RISC-V
119    [Arguments]                                 ${memory_per_cpu}
120    Create Machine RISC-V 32-bit                0x2000  ${memory_per_cpu}
121
122    ${trace_filepath}=                          Allocate Temporary File
123    Execute Command                             sysbus.cpu CreateExecutionTracing "tracer" "${trace_filepath}" Disassembly
124    Execute Command                             tracer TrackMemoryAccesses
125    Run RISC-V Program With Memory Access       0x2000
126    Execute Command                             sysbus.cpu DisableExecutionTracing
127
128    ${output_file}=                             Get File  ${trace_filepath}
129    ${output_lines}=                            Split To Lines  ${output_file}
130    Should Contain                              ${output_lines}[0]  lui a1, 48
131    Should Contain                              ${output_lines}[1]  lui a0, 14
132    Should Contain                              ${output_lines}[2]  sw a1, 0(a0)
133    Should Contain                              ${output_lines}[3]  MemoryWrite with address 0xE000
134
135Should Be Able To Add Memory Accesses To The Trace In Binary Format On RISC-V
136    [Arguments]                                 ${memory_per_cpu}
137    Create Machine RISC-V 32-bit                0x2000  ${memory_per_cpu}
138
139    ${trace_filepath}=                          Allocate Temporary File
140    Execute Command                             sysbus.cpu CreateExecutionTracing "tracer" "${trace_filepath}" PCAndOpcode True
141    Execute Command                             tracer TrackMemoryAccesses
142    Run RISC-V Program With Memory Access       0x2000
143    Execute Command                             sysbus.cpu DisableExecutionTracing
144
145    ${output_file}=                             Get Binary File  ${trace_filepath}
146    Length Should Be                            ${output_file}  85
147    Should Be Equal As Bytes                    ${output_file}[00:08]  ${bin_out_signature}
148                                                # [0]: pc_width; [1]: include_opcode
149    Should Be Equal As Bytes                    ${output_file}[08:10]  \x04\x01
150                                                # [0]: uses_thumb_flag; [1]: triple_and_model_length;
151    Should Be Equal As Bytes                    ${output_file}[10:12]  \x00\x11
152    Should Be Equal As Bytes                    ${output_file}[12:29]  ${triple_and_model}
153
154                                                # [0:4]: pc; [4]: opcode_length; [5:9]: opcode; [10]: additional_data_type = None
155    Should Be Equal As Bytes                    ${output_file}[29:39]  \x00\x20\x00\x00\x04\xb7\x05\x03\x00\x00
156    Should Be Equal As Bytes                    ${output_file}[39:49]  \x04\x20\x00\x00\x04\x37\xe5\x00\x00\x00
157                                                # [0:4]: pc; [4]: opcode_length; [5:9]: opcode; [10]: additional_data_type = MemoryAccess
158    Should Be Equal As Bytes                    ${output_file}[49:59]  \x08\x20\x00\x00\x04\x23\x20\xb5\x00\x01
159                                                # [0]: access_type; [1-9]: access_address
160    Should Be Equal As Bytes                    ${output_file}[59:69]  \x03\x00\xe0\x00\x00\x00\x00\x00\x00\x00
161                                                # [0-7]: access_value
162    Should Be Equal As Bytes                    ${output_file}[69:77]  \x00\x03\x00\x00\x00\x00\x00\x00
163                                                # [0-7]: physical_access_address
164    Should Be Equal As Bytes                    ${output_file}[77:85]  \xe0\x00\x00\x00\x00\x00\x00\x00
165
166Should Dump 64-bit PCs As Binary On RISC-V
167    [Arguments]                                 ${memory_per_cpu}
168    Create Machine RISC-V 64-bit                0x2000000000  ${memory_per_cpu}
169
170    ${trace}=                                   Run And Trace Simple Program On RISC-V  0x2000000000  PC  True
171    Length Should Be                            ${trace}  37
172    Should Be Equal As Bytes                    ${trace}[00:08]  ${bin_out_signature}
173    Should Be Equal As Bytes                    ${trace}[08:10]  \x08\x00
174
175    Should Be Equal As Bytes                    ${trace}[10:19]  \x00\x00\x00\x00\x20\x00\x00\x00\x00
176    Should Be Equal As Bytes                    ${trace}[19:28]  \x04\x00\x00\x00\x20\x00\x00\x00\x00
177    Should Be Equal As Bytes                    ${trace}[28:37]  \x06\x00\x00\x00\x20\x00\x00\x00\x00
178
179Should Dump 32-bit PCs As Binary On RISC-V
180    [Arguments]                                 ${memory_per_cpu}
181    Create Machine RISC-V 32-bit                0x2000  ${memory_per_cpu}
182
183    ${trace}=                                   Run And Trace Simple Program On RISC-V  0x2000  PC  True
184    Length Should Be                            ${trace}  25
185    Should Be Equal As Bytes                    ${trace}[00:08]  ${bin_out_signature}
186    Should Be Equal As Bytes                    ${trace}[08:10]  \x04\x00
187
188    Should Be Equal As Bytes                    ${trace}[10:15]  \x00\x20\x00\x00\x00
189    Should Be Equal As Bytes                    ${trace}[15:20]  \x04\x20\x00\x00\x00
190    Should Be Equal As Bytes                    ${trace}[20:25]  \x06\x20\x00\x00\x00
191
192Should Dump Opcodes As Binary On RISC-V
193    [Arguments]                                 ${memory_per_cpu}
194    Create Machine RISC-V 32-bit                0x2000  ${memory_per_cpu}
195
196    ${trace}=                                   Run And Trace Simple Program On RISC-V  0x2000  Opcode  True
197    Length Should Be                            ${trace}  45
198    Should Be Equal As Bytes                    ${trace}[00:08]  ${bin_out_signature}
199    Should Be Equal As Bytes                    ${trace}[08:10]  \x00\x01
200                                                # [0]: uses_thumb_flag; [1]: triple_and_model_length;
201    Should Be Equal As Bytes                    ${trace}[10:12]  \x00\x11
202    Should Be Equal As Bytes                    ${trace}[12:29]  ${triple_and_model}
203
204    Should Be Equal As Bytes                    ${trace}[29:35]  \x04\x13\x00\x00\x00\x00
205    Should Be Equal As Bytes                    ${trace}[35:39]  \x02\x01\x00\x00
206    Should Be Equal As Bytes                    ${trace}[39:45]  \x04\x93\x00\x31\x00\x00
207
208Should Dump PCs And Opcodes As Binary On RISC-V
209    [Arguments]                                 ${memory_per_cpu}
210    Create Machine RISC-V 32-bit                0x2000  ${memory_per_cpu}
211
212    ${trace}=                                   Run And Trace Simple Program On RISC-V  0x2000  PCAndOpcode  True
213    Length Should Be                            ${trace}  57
214    Should Be Equal As Bytes                    ${trace}[00:08]  ${bin_out_signature}
215    Should Be Equal As Bytes                    ${trace}[08:10]  \x04\x01
216                                                # [0]: uses_thumb_flag; [1]: triple_and_model_length;
217    Should Be Equal As Bytes                    ${trace}[10:12]  \x00\x11
218    Should Be Equal As Bytes                    ${trace}[12:29]  ${triple_and_model}
219
220    Should Be Equal As Bytes                    ${trace}[29:33]  \x00\x20\x00\x00
221    Should Be Equal As Bytes                    ${trace}[33:39]  \x04\x13\x00\x00\x00\x00
222    Should Be Equal As Bytes                    ${trace}[39:43]  \x04\x20\x00\x00
223    Should Be Equal As Bytes                    ${trace}[43:47]  \x02\x01\x00\x00
224    Should Be Equal As Bytes                    ${trace}[47:51]  \x06\x20\x00\x00
225    Should Be Equal As Bytes                    ${trace}[51:57]  \x04\x93\x00\x31\x00\x00
226
227Should Trace Consecutive Blocks On RISC-V
228    [Arguments]                                 ${memory_per_cpu}
229    Create Machine RISC-V 32-bit                0x0  ${memory_per_cpu}
230    Execute Command                             sysbus.cpu ExecutionMode Continuous
231
232    # "li x1, 0"
233    Execute Command                             sysbus WriteDoubleWord 0x200 0x93 cpu
234    # "li x2, 10"
235    Execute Command                             sysbus WriteDoubleWord 0x204 0x00a00113 cpu
236    # "addi x1, x1, 1"
237    Execute Command                             sysbus WriteDoubleWord 0x208 0x00108093 cpu
238    # "bne x1, x2, 0x214"
239    Execute Command                             sysbus WriteDoubleWord 0x20C 0x00209463 cpu
240    # "j 0x300"
241    Execute Command                             sysbus WriteDoubleWord 0x210 0x0f00006f cpu
242
243    # "c.nop"s (compressed)
244    Execute Command                             sysbus WriteDoubleWord 0x214 0x01 cpu
245    Execute Command                             sysbus WriteDoubleWord 0x216 0x01 cpu
246
247    # "nop"s
248    Execute Command                             sysbus WriteDoubleWord 0x218 0x13 cpu
249    Execute Command                             sysbus WriteDoubleWord 0x21C 0x13 cpu
250    Execute Command                             sysbus WriteDoubleWord 0x220 0x13 cpu
251    Execute Command                             sysbus WriteDoubleWord 0x224 0x13 cpu
252    Execute Command                             sysbus WriteDoubleWord 0x228 0x13 cpu
253    Execute Command                             sysbus WriteDoubleWord 0x22C 0x13 cpu
254    Execute Command                             sysbus WriteDoubleWord 0x230 0x13 cpu
255    Execute Command                             sysbus WriteDoubleWord 0x234 0x13 cpu
256    Execute Command                             sysbus WriteDoubleWord 0x238 0x13 cpu
257    Execute Command                             sysbus WriteDoubleWord 0x23C 0x13 cpu
258
259    # "j +4" - just to break the block
260    # this is to test the block chaining mechanism
261    Execute Command                             sysbus WriteDoubleWord 0x240 0x0040006f cpu
262
263    # "nop"s
264    Execute Command                             sysbus WriteDoubleWord 0x244 0x13 cpu
265    Execute Command                             sysbus WriteDoubleWord 0x248 0x13 cpu
266    Execute Command                             sysbus WriteDoubleWord 0x24C 0x13 cpu
267    Execute Command                             sysbus WriteDoubleWord 0x250 0x13 cpu
268    Execute Command                             sysbus WriteDoubleWord 0x254 0x13 cpu
269    Execute Command                             sysbus WriteDoubleWord 0x258 0x13 cpu
270    Execute Command                             sysbus WriteDoubleWord 0x25C 0x13 cpu
271    Execute Command                             sysbus WriteDoubleWord 0x260 0x13 cpu
272    Execute Command                             sysbus WriteDoubleWord 0x264 0x13 cpu
273    Execute Command                             sysbus WriteDoubleWord 0x268 0x13 cpu
274    Execute Command                             sysbus WriteDoubleWord 0x26C 0x13 cpu
275
276    # "j +4" - just to break the block
277    Execute Command                             sysbus WriteDoubleWord 0x270 0x0040006f cpu
278
279    # "nop"s
280    Execute Command                             sysbus WriteDoubleWord 0x274 0x13 cpu
281    Execute Command                             sysbus WriteDoubleWord 0x278 0x13 cpu
282    Execute Command                             sysbus WriteDoubleWord 0x27C 0x13 cpu
283    Execute Command                             sysbus WriteDoubleWord 0x280 0x13 cpu
284    Execute Command                             sysbus WriteDoubleWord 0x284 0x13 cpu
285    Execute Command                             sysbus WriteDoubleWord 0x288 0x13 cpu
286    Execute Command                             sysbus WriteDoubleWord 0x28C 0x13 cpu
287    Execute Command                             sysbus WriteDoubleWord 0x290 0x13 cpu
288    Execute Command                             sysbus WriteDoubleWord 0x294 0x13 cpu
289    Execute Command                             sysbus WriteDoubleWord 0x298 0x13 cpu
290    Execute Command                             sysbus WriteDoubleWord 0x29C 0x13 cpu
291
292    # "j 0x208"
293    Execute Command                             sysbus WriteDoubleWord 0x2A0 0xf69ff06f cpu
294
295    # "j 0x300"
296    Execute Command                             sysbus WriteDoubleWord 0x300 0x6f cpu
297
298    Execute Command                             sysbus.cpu PC 0x200
299
300    ${FILE}=                                    Allocate Temporary File
301    Execute Command                             sysbus.cpu CreateExecutionTracing "tracer" @${FILE} PC
302
303    # run for 400 instructions
304    Execute Command                             sysbus.cpu PerformanceInMips 1
305    Execute Command                             emulation RunFor "0.000400"
306
307    # should reach the end of the execution
308    ${pc}=                                      Execute Command  sysbus.cpu PC
309    Should Contain                              ${pc}  0x300
310
311    Execute Command                             sysbus.cpu DisableExecutionTracing
312
313    ${content}=                                 Get File  ${FILE}
314    @{pcs}=                                     Split To Lines  ${content}
315
316    Length Should Be                            ${pcs}      400
317    Should Be Equal                             ${pcs[0]}   0x200
318    Should Be Equal                             ${pcs[1]}   0x204
319    Should Be Equal                             ${pcs[2]}   0x208
320    Should Be Equal                             ${pcs[3]}   0x20C
321    # here we skip a jump to 0x300 (it should fire at the very end)
322    Should Be Equal                             ${pcs[4]}   0x214
323    Should Be Equal                             ${pcs[5]}   0x216
324    Should Be Equal                             ${pcs[6]}   0x218
325    Should Be Equal                             ${pcs[7]}   0x21C
326    # first iteration of the loop
327    Should Be Equal                             ${pcs[40]}  0x2A0
328    Should Be Equal                             ${pcs[41]}  0x208
329    # another iteration of the loop
330    Should Be Equal                             ${pcs[79]}  0x2A0
331    Should Be Equal                             ${pcs[80]}  0x208
332    # and another
333    Should Be Equal                             ${pcs[118]}  0x2A0
334    Should Be Equal                             ${pcs[119]}  0x208
335    # and the last one
336    Should Be Equal                             ${pcs[352]}  0x2A0
337    Should Be Equal                             ${pcs[353]}  0x208
338    Should Be Equal                             ${pcs[354]}  0x20C
339    Should Be Equal                             ${pcs[355]}  0x210
340    Should Be Equal                             ${pcs[356]}  0x300
341
342Should Trace In ARM and Thumb State
343    [Arguments]                                 ${memory_per_cpu}
344    Execute Command                             mach create
345    Execute Command                             machine LoadPlatformDescriptionFromString "cpu: CPU.ARMv7A @ sysbus { cpuType: \\"cortex-a9\\" }"
346    IF  ${memory_per_cpu}
347        Execute Command                             machine LoadPlatformDescriptionFromString "mem: Memory.MappedMemory @ sysbus new Bus.BusPointRegistration { address: 0x0; cpu: cpu } { size: 0x1000 }"
348    ELSE
349        Execute Command                             machine LoadPlatformDescriptionFromString "mem: Memory.MappedMemory @ sysbus 0x0 { size: 0x1000 }"
350    END
351
352    # nop (ARM)
353    Execute Command                             sysbus WriteDoubleWord 0x00000000 0xe1a00000 cpu
354    # blx 0x10 (ARM)
355    Execute Command                             sysbus WriteDoubleWord 0x00000004 0xfa000001 cpu
356    # nop (ARM)
357    Execute Command                             sysbus WriteDoubleWord 0x00000008 0xe1a00000 cpu
358    # wfi (ARM)
359    Execute Command                             sysbus WriteDoubleWord 0x0000000c 0xe320f003 cpu
360    # 2x nop (Thumb)
361    Execute Command                             sysbus WriteDoubleWord 0x00000010 0x46c046c0 cpu
362    # bx lr; nop (Thumb)
363    Execute Command                             sysbus WriteDoubleWord 0x00000014 0x46c04770 cpu
364
365    Execute Command                             sysbus.cpu PC 0x0
366
367    ${FILE}=                                    Allocate Temporary File
368    Execute Command                             sysbus.cpu CreateExecutionTracing "tracer" @${FILE} PC
369
370    Execute Command                             emulation RunFor "0.0001"
371
372    # should reach the end of the execution
373    PC Should Be Equal                          0x10
374
375    Execute Command                             sysbus.cpu DisableExecutionTracing
376
377    ${content}=                                 Get File  ${FILE}
378    @{pcs}=                                     Split To Lines  ${content}
379
380    Length Should Be                            ${pcs}      7
381    Should Be Equal                             ${pcs[0]}   0x0
382    Should Be Equal                             ${pcs[1]}   0x4
383    Should Be Equal                             ${pcs[2]}   0x10
384    Should Be Equal                             ${pcs[3]}   0x12
385    Should Be Equal                             ${pcs[4]}   0x14
386    Should Be Equal                             ${pcs[5]}   0x8
387    Should Be Equal                             ${pcs[6]}   0xC
388
389*** Test Cases ***
390Should Dump PCs
391    ${pcs}=                                     Trace The Execution On The Versatile Platform  PC
392
393    Length Should Be                            ${pcs}      16
394    Should Be Equal                             ${pcs[0]}   0x8000
395    Should Be Equal                             ${pcs[1]}   0x8004
396    Should Be Equal                             ${pcs[2]}   0x8008
397    Should Be Equal                             ${pcs[3]}   0x359C08
398    Should Be Equal                             ${pcs[14]}  0x8010
399    Should Be Equal                             ${pcs[15]}  0x8014
400
401Should Dump Opcodes
402    ${opcodes}=                                 Trace The Execution On The Versatile Platform  Opcode
403
404    Length Should Be                            ${opcodes}      16
405    Should Be Equal                             ${opcodes[0]}   0xE321F0D3
406    Should Be Equal                             ${opcodes[1]}   0xEE109F10
407    Should Be Equal                             ${opcodes[2]}   0xEB0D46FE
408    Should Be Equal                             ${opcodes[3]}   0xE28F3030
409    Should Be Equal                             ${opcodes[14]}  0x0A0D470D
410    Should Be Equal                             ${opcodes[15]}  0xE28F302C
411
412Should Dump Opcodes For Isolated Memory
413    Create Machine RISC-V 32-bit                0x2000  memory_per_cpu=True
414
415    ${trace}=                                   Run And Trace Simple Program On RISC-V  0x2000  Opcode  False
416    Should Contain                              ${trace}[0]  0x00000013
417    Should Contain                              ${trace}[1]  0x0001
418    Should Contain                              ${trace}[2]  0x00310093
419
420Should Dump PCs And Opcodes
421    ${trace}=                                   Trace The Execution On The Versatile Platform  PCAndOpcode
422
423    Length Should Be                            ${trace}      16
424    Should Be Equal                             ${trace[0]}   0x8000: 0xE321F0D3
425    Should Be Equal                             ${trace[1]}   0x8004: 0xEE109F10
426    Should Be Equal                             ${trace[2]}   0x8008: 0xEB0D46FE
427    Should Be Equal                             ${trace[3]}   0x359C08: 0xE28F3030
428    Should Be Equal                             ${trace[14]}  0x8010: 0x0A0D470D
429    Should Be Equal                             ${trace[15]}  0x8014: 0xE28F302C
430
431Should Dump PCs And Opcodes For Isolated Memory
432    Create Machine RISC-V 32-bit                0x2000  memory_per_cpu=True
433
434    ${trace}=                                   Run And Trace Simple Program On RISC-V  0x2000  PCAndOpcode  False
435    Should Contain                              ${trace}[0]  0x2000: 0x00000013
436    Should Contain                              ${trace}[1]  0x2004: 0x0001
437    Should Contain                              ${trace}[2]  0x2006: 0x00310093
438
439Should Dump 64-bit PCs
440    Should Dump 64-bit PCs On RISC-V            memory_per_cpu=False
441
442Should Dump 64-bit PCs For Isolated Memory
443    Should Dump 64-bit PCs On RISC-V            memory_per_cpu=True
444
445Should Dump Disassembly
446    Should Dump Disassembly On RISC-V           memory_per_cpu=False
447
448Should Dump Disassembly For Isolated Memory
449    Should Dump Disassembly On RISC-V           memory_per_cpu=True
450
451Should Be Able To Add Accesses To The Memory To The Trace
452    Should Be Able To Add Memory Accesses To The Trace On RISC-V  memory_per_cpu=False
453
454Should Be Able To Add Accesses To The Isolated Memory To The Trace
455    Should Be Able To Add Memory Accesses To The Trace On RISC-V  memory_per_cpu=True
456
457Should Be Able To Add Accesses To The Memory To The Trace In Binary Format
458    Should Be Able To Add Memory Accesses To The Trace In Binary Format On RISC-V  memory_per_cpu=False
459
460Should Be Able To Add Accesses To The Isolated Memory To The Trace In Binary Format
461    Should Be Able To Add Memory Accesses To The Trace In Binary Format On RISC-V  memory_per_cpu=True
462
463Should Dump 64-bit PCs As Binary
464    Should Dump 64-bit PCs As Binary On RISC-V  memory_per_cpu=False
465
466Should Dump 64-bit PCs As Binary For Isolated Memory
467    Should Dump 64-bit PCs As Binary On RISC-V  memory_per_cpu=True
468
469Should Dump 32-bit PCs As Binary
470    Should Dump 32-bit PCs As Binary On RISC-V  memory_per_cpu=False
471
472Should Dump 32-bit PCs As Binary For Isolated Memory
473    Should Dump 32-bit PCs As Binary On RISC-V  memory_per_cpu=True
474
475Should Dump Opcodes As Binary
476    Should Dump Opcodes As Binary On RISC-V     memory_per_cpu=False
477
478Should Dump Opcodes As Binary For Isolated Memory
479    Should Dump Opcodes As Binary On RISC-V     memory_per_cpu=True
480
481Should Dump PCs And Opcodes As Binary
482    Should Dump PCs And Opcodes As Binary On RISC-V  memory_per_cpu=False
483
484Should Dump PCs And Opcodes As Binary For Isolated Memory
485    Should Dump PCs And Opcodes As Binary On RISC-V  memory_per_cpu=True
486
487Should Trace Consecutive Blocks
488    Should Trace Consecutive Blocks On RISC-V   memory_per_cpu=False
489
490Should Trace Consecutive Blocks For Isolated Memory
491    Should Trace Consecutive Blocks On RISC-V   memory_per_cpu=True
492
493Should Trace ARM Core
494    Should Trace In ARM and Thumb State         memory_per_cpu=False
495
496Should Trace ARM Core With Isolated Memory
497    Should Trace In ARM and Thumb State         memory_per_cpu=True
498
499Should Trace The RISC-V Vector Configuration
500    Create Machine RISC-V 32-bit                0x2000  memory_per_cpu=False
501
502    ${trace_filepath}=                          Allocate Temporary File
503    Execute Command                             sysbus.cpu CreateExecutionTracing "trace_name" "${trace_filepath}" Disassembly
504    Execute Command                             trace_name TrackVectorConfiguration
505    Run RISC-V Program With Vcfg Instruction    0x2000
506    Execute Command                             sysbus.cpu DisableExecutionTracing
507
508    ${output_file}=                             Get File  ${trace_filepath}
509    Log                                         ${output_file}
510    ${output_lines}=                            Split To Lines  ${output_file}
511    Length Should Be                            ${output_lines}  4
512    Should Contain                              ${output_lines}[0]  nop
513    Should Contain                              ${output_lines}[1]  nop
514    Should Contain                              ${output_lines}[2]  vsetvli zero, zero, e8, m1, ta, mu
515    Should Contain                              ${output_lines}[3]  Vector configured to VL: 0x0, VTYPE: 0x40
516
517Should Be Able To Add Vector Configuration To The Trace In Binary Format
518    Create Machine RISC-V 32-bit                0x2000  memory_per_cpu=False
519
520    ${trace_filepath}=                          Allocate Temporary File
521    Execute Command                             sysbus.cpu CreateExecutionTracing "trace_name" "${trace_filepath}" PCAndOpcode true
522    Execute Command                             trace_name TrackVectorConfiguration
523    Run RISC-V Program With Vcfg Instruction    0x2000
524    Execute Command                             sysbus.cpu DisableExecutionTracing
525
526    ${output_file}=                             Get Binary File  ${trace_filepath}
527    Length Should Be                            ${output_file}  74
528
529    Should Be Equal As Bytes                    ${output_file}[00:08]  ${bin_out_signature}
530    Should Be Equal As Bytes                    ${output_file}[08:10]  \x04\x01
531                                                # [0]: uses_thumb_flag; [1]: triple_and_model_length;
532    Should Be Equal As Bytes                    ${output_file}[10:12]  \x00\x11
533    Should Be Equal As Bytes                    ${output_file}[12:29]  ${triple_and_model}
534
535                                                # [0:4]: pc; [4]: opcode_length; [5:9]: opcode; [10]: additional_data_type = None
536    Should Be Equal As Bytes                    ${output_file}[29:39]  \x00\x20\x00\x00\x04\x13\x00\x00\x00\x00
537                                                # [0:4]: pc; [4]: opcode_length; [5:7]: opcode; [8]: additional_data_type = None
538    Should Be Equal As Bytes                    ${output_file}[39:47]  \x04\x20\x00\x00\x02\x01\x00\x00
539                                                # [0:4]: pc; [4]: opcode_length; [5:9]: opcode; [10]: additional_data_type = VectorConfiguration
540    Should Be Equal As Bytes                    ${output_file}[47:57]  \x06\x20\x00\x00\x04\x57\x70\x00\x04\x02
541                                                # [0:8]: vl; [8:16]: vtype; [16]: additional_data_type = None
542    Should Be Equal As Bytes                    ${output_file}[57:74]  \x00\x00\x00\x00\x00\x00\x00\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00
543
544Should Show Error When Format Is Incorrect
545    Create Machine RISC-V 32-bit                0x2000  memory_per_cpu=False
546
547    ${trace_filepath}=                          Allocate Temporary File
548    Run Keyword And Expect Error                *don't support binary output file with the*formatting*  Execute Command  sysbus.cpu CreateExecutionTracing "tracer" "${trace_filepath}" Disassembly true
549