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

Subversion Repositories fwrisc

[/] [fwrisc/] [trunk/] [ve/] [fwrisc/] [tests/] [riscv-compliance/] [riscv-target/] [riscvOVPsim/] [compliance_io.h] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 mballance
// RISC-V Compliance IO Test Header File
2
 
3
/*
4
 * Copyright (c) 2005-2018 Imperas Software Ltd., www.imperas.com
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at
9
 *
10
 *   http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
15
 * either express or implied.
16
 *
17
 * See the License for the specific language governing permissions and
18
 * limitations under the License.
19
 *
20
 */
21
 
22
 
23
//
24
// In general the following registers are reserved
25
// ra, a0, t0, t1
26
//
27
 
28
#ifndef _COMPLIANCE_IO_H
29
#define _COMPLIANCE_IO_H
30
 
31
#define RVTEST_IO_QUIET
32
 
33
//-----------------------------------------------------------------------
34
// RV IO Macros (Character transfer by custom instruction)
35
//-----------------------------------------------------------------------
36
#define STRINGIFY(x) #x
37
#define TOSTRING(x)  STRINGIFY(x)
38
 
39
#define RVTEST_CUSTOM1 0x0005200B
40
 
41
#ifdef RVTEST_IO_QUIET
42
 
43
#define RVTEST_IO_INIT
44
#define RVTEST_IO_WRITE_STR(_STR)
45
#define RVTEST_IO_CHECK()
46
#define RVTEST_IO_ASSERT_GPR_EQ(_R, _I)
47
#define RVTEST_IO_ASSERT_SFPR_EQ(_F, _R, _I)
48
#define RVTEST_IO_ASSERT_DFPR_EQ(_D, _R, _I)
49
 
50
#else
51
 
52
#define LOCAL_IO_WRITE_GPR(_R)                                          \
53
    mv          a0, _R;                                                 \
54
    jal         FN_WriteA0;
55
 
56
#define LOCAL_IO_WRITE_FPR(_F)                                          \
57
    fmv.x.s     a0, _F;                                                 \
58
    jal         FN_WriteA0;
59
 
60
#define LOCAL_FPD_WRITE_REG(_V1, _V2)                                   \
61
    mv          a0, _V1;                                                \
62
    jal         FN_WriteA0; \
63
    mv          a0, _V2; \
64
    jal         FN_WriteA0; \
65
 
66
#define LOCAL_IO_PUTC(_R)                                               \
67
    .word RVTEST_CUSTOM1;                                               \
68
 
69
#define RVTEST_IO_INIT
70
 
71
// Assertion violation: file file.c, line 1234: (expr)
72
// _R = GPR
73
// _I = Immediate
74
#define RVTEST_IO_ASSERT_GPR_EQ(_R, _I)                                 \
75
    li          t0, _I;                                                 \
76
    beq         _R, t0, 20002f;                                         \
77
    RVTEST_IO_WRITE_STR("Assertion violation: file ");                  \
78
    RVTEST_IO_WRITE_STR(__FILE__);                                      \
79
    RVTEST_IO_WRITE_STR(", line ");                                     \
80
    RVTEST_IO_WRITE_STR(TOSTRING(__LINE__));                            \
81
    RVTEST_IO_WRITE_STR(": ");                                          \
82
    RVTEST_IO_WRITE_STR(# _R);                                          \
83
    RVTEST_IO_WRITE_STR("(");                                           \
84
    LOCAL_IO_WRITE_GPR(_R);                                             \
85
    RVTEST_IO_WRITE_STR(") != ");                                       \
86
    RVTEST_IO_WRITE_STR(# _I);                                          \
87
    RVTEST_IO_WRITE_STR("\n");                                          \
88
    li TESTNUM, 100;                                                    \
89
    RVTEST_FAIL;                                                        \
90
20002:
91
 
92
// _F = FPR
93
// _C = GPR
94
// _I = Immediate
95
#define RVTEST_IO_ASSERT_SFPR_EQ(_F, _C, _I) \
96
    fmv.x.s     t0, _F; \
97
    beq         _C, t0, 20003f;                                         \
98
    RVTEST_IO_WRITE_STR("Assertion violation: file ");                  \
99
    RVTEST_IO_WRITE_STR(__FILE__);                                      \
100
    RVTEST_IO_WRITE_STR(", line ");                                     \
101
    RVTEST_IO_WRITE_STR(TOSTRING(__LINE__));                            \
102
    RVTEST_IO_WRITE_STR(": ");                                          \
103
    RVTEST_IO_WRITE_STR(# _F);                                          \
104
    RVTEST_IO_WRITE_STR("(");                                           \
105
    LOCAL_IO_WRITE_FPR(_F);                                             \
106
    RVTEST_IO_WRITE_STR(") != ");                                       \
107
    RVTEST_IO_WRITE_STR(# _I);                                          \
108
    RVTEST_IO_WRITE_STR("\n");                                          \
109
    li TESTNUM, 100;                                                    \
110
    RVTEST_FAIL;                                                        \
111
20003:
112
 
113
// _D = DFPR
114
// _R = GPR
115
// _I = Immediate
116
#define RVTEST_IO_ASSERT_DFPR_EQ(_D, _R, _I) \
117
    fmv.x.d     t0, _D; \
118
    beq         _R, t0, 20005f;                                         \
119
    RVTEST_IO_WRITE_STR("Assertion violation: file ");                  \
120
    RVTEST_IO_WRITE_STR(__FILE__);                                      \
121
    RVTEST_IO_WRITE_STR(", line ");                                     \
122
    RVTEST_IO_WRITE_STR(TOSTRING(__LINE__));                            \
123
    RVTEST_IO_WRITE_STR(": ");                                          \
124
    RVTEST_IO_WRITE_STR(# _D);                                          \
125
    RVTEST_IO_WRITE_STR("(");                                           \
126
    LOCAL_FPD_WRITE_REG(_D);                                            \
127
    RVTEST_IO_WRITE_STR(") != ");                                       \
128
    RVTEST_IO_WRITE_STR(# _I);                                          \
129
    RVTEST_IO_WRITE_STR("\n");                                          \
130
    li TESTNUM, 100;                                                    \
131
    RVTEST_FAIL;                                                        \
132
20005:
133
 
134
#define RVTEST_IO_WRITE_STR(_STR)                                       \
135
    .section .data.string;                                              \
136
20001:                                                                  \
137
    .string _STR;                                                       \
138
    .section .text.init;                                                \
139
    la a0, 20001b;                                                      \
140
    jal FN_WriteStr;
141
 
142
// generate assertion listing
143
#define RVTEST_IO_CHECK()                                               \
144
    li zero, -1;                                                        \
145
 
146
//
147
// FN_WriteStr: Uses a0, t0
148
//
149
FN_WriteStr:
150
    mv          t0, a0;
151
10000:
152
    lbu         a0, (t0);
153
    addi        t0, t0, 1;
154
    beq         a0, zero, 10000f;
155
    LOCAL_IO_PUTC(a0);
156
    j           10000b;
157
10000:
158
    ret;
159
 
160
//
161
// FN_WriteA0: write register a0(x10) (destroys a0(x10), t0-t2(x5-x7))
162
//
163
FN_WriteA0:
164
        mv          t0, a0
165
        // determine architectural register width
166
        li          a0, -1
167
        srli        a0, a0, 31
168
        srli        a0, a0, 1
169
        bnez        a0, FN_WriteA0_64
170
 
171
FN_WriteA0_32:
172
        // reverse register when xlen is 32
173
        li          t1, 8
174
10000:  slli        t2, t2, 4
175
        andi        a0, t0, 0xf
176
        srli        t0, t0, 4
177
        or          t2, t2, a0
178
        addi        t1, t1, -1
179
        bnez        t1, 10000b
180
        li          t1, 8
181
        j           FN_WriteA0_common
182
 
183
FN_WriteA0_64:
184
        // reverse register when xlen is 64
185
        li          t1, 16
186
10000:  slli        t2, t2, 4
187
        andi        a0, t0, 0xf
188
        srli        t0, t0, 4
189
        or          t2, t2, a0
190
        addi        t1, t1, -1
191
        bnez        t1, 10000b
192
        li          t1, 16
193
 
194
FN_WriteA0_common:
195
        // write reversed characters
196
        li          t0, 10
197
10000:  andi        a0, t2, 0xf
198
        blt         a0, t0, 10001f
199
        addi        a0, a0, 'a'-10
200
        j           10002f
201
10001:  addi        a0, a0, '0'
202
10002:  LOCAL_IO_PUTC(a0)
203
        srli        t2, t2, 4
204
        addi        t1, t1, -1
205
        bnez        t1, 10000b
206
        ret
207
 
208
#endif // RVTEST_IO_QUIET
209
 
210
#endif // _COMPLIANCE_IO_H

powered by: WebSVN 2.1.0

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