OpenCores
URL https://opencores.org/ocsvn/fwrisc/fwrisc/trunk

Subversion Repositories fwrisc

[/] [fwrisc/] [trunk/] [ve/] [fwrisc/] [tests/] [fwrisc_instr_tests_system.cpp] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 mballance
/*
2
 * fwrisc_instr_tests_system.cpp
3
 *
4
 * Copyright 2018 Matthew Ballance
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the
7
 * "License"); you may not use this file except in
8
 * compliance with the License.  You may obtain a copy of
9
 * the License at
10
 *
11
 * http://www.apache.org/licenses/LICENSE-2.0
12
 *
13
 * Unless required by applicable law or agreed to in
14
 * writing, software distributed under the License is
15
 * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
16
 * CONDITIONS OF ANY KIND, either express or implied.  See
17
 * the License for the specific language governing
18
 * permissions and limitations under the License.
19
 *
20
 *  Created on: Oct 31, 2018
21
 *      Author: ballance
22
 */
23
 
24
#include "fwrisc_instr_tests_system.h"
25
 
26
fwrisc_instr_tests_system::fwrisc_instr_tests_system() {
27
        // TODO Auto-generated constructor stub
28
 
29
}
30
 
31
fwrisc_instr_tests_system::~fwrisc_instr_tests_system() {
32
        // TODO Auto-generated destructor stub
33
}
34
 
35
TEST_F(fwrisc_instr_tests_system, csrr) {
36
        reg_val_s exp[] = {
37
                        1, 0
38
        };
39
 
40
        const char *program = R"(
41
                entry:
42
                        csrr            x1, mcause
43
 
44
                        j                       done
45
        )";
46
 
47
        runtest(program, exp, sizeof(exp)/sizeof(reg_val_s));
48
}
49
 
50
TEST_F(fwrisc_instr_tests_system, csrw) {
51
        reg_val_s exp[] = {
52
                {1, 5},
53
                {2, 5},
54
                {37, 5}
55
        };
56
 
57
        const char *program = R"(
58
                entry:
59
                        li                      x1, 5
60
                        csrw            mtvec, x1
61
                        csrr            x2, mtvec
62
 
63
                        j                       done
64
        )";
65
 
66
        runtest(program, exp, sizeof(exp)/sizeof(reg_val_s));
67
}
68
 
69
TEST_F(fwrisc_instr_tests_system, csrc) {
70
        reg_val_s exp[] = {
71
                {1,  0x0f},
72
                {2,  0x01},
73
                {37, 0x0e}
74
        };
75
 
76
        const char *program = R"(
77
                entry:
78
                        li                      x1, 0xf
79
                        li                      x2, 0x1
80
                        csrw            mtvec, x1
81
                        csrrc           x1, mtvec, x2
82
 
83
                        j                       done
84
        )";
85
 
86
        runtest(program, exp, sizeof(exp)/sizeof(reg_val_s));
87
}
88
 
89
TEST_F(fwrisc_instr_tests_system, csrs) {
90
        reg_val_s exp[] = {
91
                {1, 1},
92
                {2, 4},
93
                {3, 4},
94
                {4, 5},
95
                {37, 5}
96
        };
97
 
98
        const char *program = R"(
99
                entry:
100
                        li                      x1, 4
101
                        csrw            mtvec, x1
102
                        csrr            x2, mtvec
103
                        li                      x1, 1
104
                        csrrs           x3, mtvec, x1
105
                        csrr            x4, mtvec
106
 
107
                        j                       done
108
        )";
109
 
110
        runtest(program, exp, sizeof(exp)/sizeof(reg_val_s));
111
}
112
 
113
TEST_F(fwrisc_instr_tests_system, csrsi) {
114
        reg_val_s exp[] = {
115
                {2, 4},
116
                {3, 4},
117
                {4, 5},
118
                {37, 5}
119
        };
120
 
121
        const char *program = R"(
122
                entry:
123
                        csrwi           mtvec, 4
124
                        csrr            x2, mtvec
125
                        csrrsi          x3, mtvec, 1
126
                        csrr            x4, mtvec
127
 
128
                        j                       done
129
        )";
130
 
131
        runtest(program, exp, sizeof(exp)/sizeof(reg_val_s));
132
}
133
 
134
TEST_F(fwrisc_instr_tests_system, csrw_csrr) {
135
        reg_val_s exp[] = {
136
                {0x01,  5},
137
                {0x02,  5},
138
                {0x22,  5}
139
        };
140
 
141
        const char *program = R"(
142
                entry:
143
                        li                      x1, 5
144
                        csrw            medeleg, x1
145
                        csrr            x2, medeleg
146
 
147
                        j                       done
148
        )";
149
 
150
        runtest(program, exp, sizeof(exp)/sizeof(reg_val_s));
151
}
152
 
153
TEST_F(fwrisc_instr_tests_system, ecall) {
154
        reg_val_s exp[] = {
155
                {1,    0},
156
                {2,    25},
157
                {0x25, 0},          // MTVEC
158
                {0x29, 0x80000014}, // MEPC
159
                {0x2A, 0x0b}        // MCAUSE
160
        };
161
 
162
        const char *program = R"(
163
                entry:
164
                        la                      x1, pass                // 0x08
165
                        csrw            mtvec, x1               // 0x10
166
                        ecall                                           // 0x14
167
                        j                       done                    // 0x18
168
                pass:
169
                        li                      x1, 0                   // 0x1C
170
                        li                      x2, 25
171
                        csrw            mtvec, x1
172
                        j                       done
173
        )";
174
 
175
        runtest(program, exp, sizeof(exp)/sizeof(reg_val_s));
176
}
177
 
178
TEST_F(fwrisc_instr_tests_system, eret) {
179
        reg_val_s exp[] = {
180
                {1, 0},
181
                {2, 25},
182
                {0x29, 0}
183
        };
184
 
185
        const char *program = R"(
186
                entry:
187
                        la                      x1, pass
188
                        csrw            mepc, x1
189
                        mret
190
                        j                       done
191
                pass:
192
                        li                      x1, 0
193
                        li                      x2, 25
194
                        csrw            mepc, x1
195
                        j                       done
196
        )";
197
 
198
        runtest(program, exp, sizeof(exp)/sizeof(reg_val_s));
199
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.