1 |
2 |
mballance |
# RISC-V Compliance Test I-CSRRW-01
|
2 |
|
|
#
|
3 |
|
|
# Copyright (c) 2017, Codasip Ltd.
|
4 |
|
|
# Copyright (c) 2018, Imperas Software Ltd. Additions
|
5 |
|
|
# All rights reserved.
|
6 |
|
|
#
|
7 |
|
|
# Redistribution and use in source and binary forms, with or without
|
8 |
|
|
# modification, are permitted provided that the following conditions are met:
|
9 |
|
|
# * Redistributions of source code must retain the above copyright
|
10 |
|
|
# notice, this list of conditions and the following disclaimer.
|
11 |
|
|
# * Redistributions in binary form must reproduce the above copyright
|
12 |
|
|
# notice, this list of conditions and the following disclaimer in the
|
13 |
|
|
# documentation and/or other materials provided with the distribution.
|
14 |
|
|
# * Neither the name of the Codasip Ltd., Imperas Software Ltd. nor the
|
15 |
|
|
# names of its contributors may be used to endorse or promote products
|
16 |
|
|
# derived from this software without specific prior written permission.
|
17 |
|
|
#
|
18 |
|
|
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
19 |
|
|
# IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
20 |
|
|
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
21 |
|
|
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL Codasip Ltd., Imperas Software Ltd.
|
22 |
|
|
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
23 |
|
|
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
24 |
|
|
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
25 |
|
|
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
26 |
|
|
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
27 |
|
|
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
28 |
|
|
#
|
29 |
|
|
# Specification: RV32I Base Integer Instruction Set, Version 2.0
|
30 |
|
|
# Description: Testing instruction CSRRW.
|
31 |
|
|
|
32 |
|
|
#include "compliance_test.h"
|
33 |
|
|
#include "compliance_io.h"
|
34 |
|
|
#include "test_macros.h"
|
35 |
|
|
|
36 |
|
|
# Test Virtual Machine (TVM) used by program.
|
37 |
|
|
RV_COMPLIANCE_RV32M
|
38 |
|
|
|
39 |
|
|
# Test code region.
|
40 |
|
|
RV_COMPLIANCE_CODE_BEGIN
|
41 |
|
|
|
42 |
|
|
RVTEST_IO_INIT
|
43 |
|
|
RVTEST_IO_ASSERT_GPR_EQ(x0, 0x00000000)
|
44 |
|
|
RVTEST_IO_WRITE_STR("# Test Begin Reserved regs ra(x1) a0(x10) t0(x5)\n")
|
45 |
|
|
|
46 |
|
|
# ---------------------------------------------------------------------------------------------
|
47 |
|
|
RVTEST_IO_WRITE_STR("# Test part A - general test of CSRRW\n");
|
48 |
|
|
|
49 |
|
|
# Address for test results
|
50 |
|
|
la x15, test_A_res
|
51 |
|
|
|
52 |
|
|
# Register initialization
|
53 |
|
|
li x1, 1
|
54 |
|
|
li x3, 0
|
55 |
|
|
li x5, -1
|
56 |
|
|
li x27, 0x7FFFFFFF
|
57 |
|
|
li x29, 0x80000000
|
58 |
|
|
csrrw x0, mscratch, x0
|
59 |
|
|
|
60 |
|
|
# Test
|
61 |
|
|
csrrw x2, mscratch, x1
|
62 |
|
|
csrrw x4, mscratch, x3
|
63 |
|
|
csrrw x6, mscratch, x5
|
64 |
|
|
csrrw x28, mscratch, x27
|
65 |
|
|
csrrw x30, mscratch, x29
|
66 |
|
|
csrrw x31, mscratch, x0
|
67 |
|
|
|
68 |
|
|
# Store results
|
69 |
|
|
sw x2, 0(x15)
|
70 |
|
|
sw x4, 4(x15)
|
71 |
|
|
sw x6, 8(x15)
|
72 |
|
|
sw x28, 12(x15)
|
73 |
|
|
sw x30, 16(x15)
|
74 |
|
|
sw x31, 20(x15)
|
75 |
|
|
|
76 |
|
|
//
|
77 |
|
|
// Assert
|
78 |
|
|
//
|
79 |
|
|
RVTEST_IO_CHECK()
|
80 |
|
|
RVTEST_IO_ASSERT_GPR_EQ(x2, 0x00000000)
|
81 |
|
|
RVTEST_IO_ASSERT_GPR_EQ(x4, 0x00000001)
|
82 |
|
|
RVTEST_IO_ASSERT_GPR_EQ(x6, 0x00000000)
|
83 |
|
|
RVTEST_IO_ASSERT_GPR_EQ(x28, 0xFFFFFFFF)
|
84 |
|
|
RVTEST_IO_ASSERT_GPR_EQ(x30, 0x7FFFFFFF)
|
85 |
|
|
RVTEST_IO_ASSERT_GPR_EQ(x31, 0x80000000)
|
86 |
|
|
|
87 |
|
|
RVTEST_IO_WRITE_STR("# Test part A1 - Complete\n");
|
88 |
|
|
|
89 |
|
|
# ---------------------------------------------------------------------------------------------
|
90 |
|
|
RVTEST_IO_WRITE_STR("# Test part B - testing forwarding between instructions\n");
|
91 |
|
|
|
92 |
|
|
# Address for test results
|
93 |
|
|
la x26, test_B_res
|
94 |
|
|
|
95 |
|
|
# Register initialization
|
96 |
|
|
li x1, 0x12345678
|
97 |
|
|
li x2, 0x9ABCDEF0
|
98 |
|
|
|
99 |
|
|
# Test
|
100 |
|
|
csrrw x0, mscratch, x1
|
101 |
|
|
csrrw x3, mscratch, x2
|
102 |
|
|
csrrw x4, mscratch, x3
|
103 |
|
|
csrrw x5, mscratch, x4
|
104 |
|
|
csrrw x6, mscratch, x0
|
105 |
|
|
|
106 |
|
|
# store results
|
107 |
|
|
sw x3, 0(x26)
|
108 |
|
|
sw x4, 4(x26)
|
109 |
|
|
sw x5, 8(x26)
|
110 |
|
|
sw x6, 12(x26)
|
111 |
|
|
|
112 |
|
|
RVTEST_IO_ASSERT_GPR_EQ(x3, 0x12345678)
|
113 |
|
|
RVTEST_IO_ASSERT_GPR_EQ(x4, 0x9ABCDEF0)
|
114 |
|
|
RVTEST_IO_ASSERT_GPR_EQ(x5, 0x00000000)
|
115 |
|
|
RVTEST_IO_ASSERT_GPR_EQ(x6, 0x9ABCDEF0)
|
116 |
|
|
|
117 |
|
|
RVTEST_IO_WRITE_STR("# Test part A2 - Complete\n");
|
118 |
|
|
|
119 |
|
|
# ---------------------------------------------------------------------------------------------
|
120 |
|
|
RVTEST_IO_WRITE_STR("# Test part C - testing writing to x0\n");
|
121 |
|
|
|
122 |
|
|
# Address for test results
|
123 |
|
|
la x1, test_C_res
|
124 |
|
|
|
125 |
|
|
# Register initialization
|
126 |
|
|
li x2, 0x42726E6F
|
127 |
|
|
|
128 |
|
|
# Test
|
129 |
|
|
csrrw x0, mscratch, x2
|
130 |
|
|
csrrw x0, mscratch, x0
|
131 |
|
|
|
132 |
|
|
# store results
|
133 |
|
|
sw x0, 0(x1)
|
134 |
|
|
|
135 |
|
|
RVTEST_IO_ASSERT_GPR_EQ(x0, 0x00000000)
|
136 |
|
|
|
137 |
|
|
RVTEST_IO_WRITE_STR("# Test part A3 - Complete\n");
|
138 |
|
|
|
139 |
|
|
# ---------------------------------------------------------------------------------------------
|
140 |
|
|
RVTEST_IO_WRITE_STR("# Test part D - testing forwarding throught x0\n");
|
141 |
|
|
|
142 |
|
|
# Address for test results
|
143 |
|
|
la x2, test_D_res
|
144 |
|
|
|
145 |
|
|
# Register initialization
|
146 |
|
|
li x27, 0xF7FF8818
|
147 |
|
|
|
148 |
|
|
# Test
|
149 |
|
|
csrrw x0, mscratch, x27
|
150 |
|
|
csrrw x0, mscratch, x0
|
151 |
|
|
csrrw x0, mscratch, x0
|
152 |
|
|
csrrw x5, mscratch, x0
|
153 |
|
|
|
154 |
|
|
# store results
|
155 |
|
|
sw x0, 0(x2)
|
156 |
|
|
sw x5, 4(x2)
|
157 |
|
|
|
158 |
|
|
|
159 |
|
|
RVTEST_IO_ASSERT_GPR_EQ(x0, 0x00000000)
|
160 |
|
|
RVTEST_IO_ASSERT_GPR_EQ(x5, 0x00000000)
|
161 |
|
|
|
162 |
|
|
RVTEST_IO_WRITE_STR("# Test part A4 - Complete\n");
|
163 |
|
|
|
164 |
|
|
# ---------------------------------------------------------------------------------------------
|
165 |
|
|
RVTEST_IO_WRITE_STR("# Test part E - testing csrrw with same dst and src registers\n");
|
166 |
|
|
|
167 |
|
|
# Address for test results
|
168 |
|
|
la x2, test_E_res
|
169 |
|
|
|
170 |
|
|
# Register initialization
|
171 |
|
|
li x7, 0x32165498
|
172 |
|
|
li x6, 0x14725836
|
173 |
|
|
li x5, 0x96385274
|
174 |
|
|
|
175 |
|
|
# Test
|
176 |
|
|
csrrw x0, mscratch, x6
|
177 |
|
|
csrrw x5, mscratch, x5
|
178 |
|
|
csrrw x7, mscratch, x7
|
179 |
|
|
csrrw x8, mscratch, x0
|
180 |
|
|
|
181 |
|
|
# Store results
|
182 |
|
|
sw x5, 0(x2)
|
183 |
|
|
sw x7, 4(x2)
|
184 |
|
|
sw x8, 8(x2)
|
185 |
|
|
|
186 |
|
|
RVTEST_IO_ASSERT_GPR_EQ(x5, 0x00000000)
|
187 |
|
|
RVTEST_IO_ASSERT_GPR_EQ(x7, 0x96385274)
|
188 |
|
|
RVTEST_IO_ASSERT_GPR_EQ(x8, 0x32165498)
|
189 |
|
|
|
190 |
|
|
RVTEST_IO_WRITE_STR("# Test part A5 - Complete\n");
|
191 |
|
|
|
192 |
|
|
RVTEST_IO_WRITE_STR("# Test End\n")
|
193 |
|
|
|
194 |
|
|
# ---------------------------------------------------------------------------------------------
|
195 |
|
|
# HALT
|
196 |
|
|
RV_COMPLIANCE_HALT
|
197 |
|
|
|
198 |
|
|
RV_COMPLIANCE_CODE_END
|
199 |
|
|
|
200 |
|
|
# Input data section.
|
201 |
|
|
.data
|
202 |
|
|
.align 4
|
203 |
|
|
|
204 |
|
|
|
205 |
|
|
# Output data section.
|
206 |
|
|
RV_COMPLIANCE_DATA_BEGIN
|
207 |
|
|
.align 4
|
208 |
|
|
|
209 |
|
|
test_A_res:
|
210 |
|
|
.fill 6, 4, -1
|
211 |
|
|
test_B_res:
|
212 |
|
|
.fill 4, 4, -1
|
213 |
|
|
test_C_res:
|
214 |
|
|
.fill 1, 4, -1
|
215 |
|
|
test_D_res:
|
216 |
|
|
.fill 2, 4, -1
|
217 |
|
|
test_E_res:
|
218 |
|
|
.fill 3, 4, -1
|
219 |
|
|
|
220 |
|
|
RV_COMPLIANCE_DATA_END # End of test output data region.
|