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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [or1ksim/] [testsuite/] [test-code-or1k/] [inst-set-test/] [is-spr-test.S] - Blame information for rev 123

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 123 jeremybenn
/* is-spr-test.S. l.mfspr and l.mtspr instruction test of Or1ksim
2
 *
3
 * Copyright (C) 1999-2006 OpenCores
4
 * Copyright (C) 2010 Embecosm Limited
5
 *
6
 * Contributors various OpenCores participants
7
 * Contributor Jeremy Bennett 
8
 *
9
 * This file is part of OpenRISC 1000 Architectural Simulator.
10
 *
11
 * This program is free software; you can redistribute it and/or modify it
12
 * under the terms of the GNU General Public License as published by the Free
13
 * Software Foundation; either version 3 of the License, or (at your option)
14
 * any later version.
15
 *
16
 * This program is distributed in the hope that it will be useful, but WITHOUT
17
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
19
 * more details.
20
 *
21
 * You should have received a copy of the GNU General Public License along
22
 * with this program.  If not, see .
23
 */
24
 
25
/* ----------------------------------------------------------------------------
26
 * Coding conventions are described in inst-set-test.S
27
 * ------------------------------------------------------------------------- */
28
 
29
/* ----------------------------------------------------------------------------
30
 * Test coverage
31
 *
32
 * The l.mfspr and l.mtspr should OR the immdediate operand with the register
33
 * to determine the SPR address, not add it (Bug 1779).
34
 *
35
 * Having fixed the problem, this is (in good software engineering style), a
36
 * regresison test to go with the fix.
37
 *
38
 * This is not a comprehensive test of either instruction (yet).
39
 *
40
 * Of course what is really needed is a comprehensive instruction test...
41
 * ------------------------------------------------------------------------- */
42
 
43
 
44
#include "inst-set-test.h"
45
 
46
/* ----------------------------------------------------------------------------
47
 * A macro to carry out a test of l.mfspr
48
 *
49
 * MACLO is used as the SPR, since it can be read and cleared using l.macrc
50
 * and can be set using l.maci. op1 and op2 should be chosen to address this
51
 * register.
52
 *
53
 * The value placed in the register is entirely arbitrary - we use 0xdeadbeef.
54
 *
55
 * Arguments
56
 *   op1:       First l.mfspr operand value
57
 *   op2:       Second l.mfspr operand value
58
 * ------------------------------------------------------------------------- */
59
#define TEST_MFSPR(op1, op2)                                             \
60
        l.macrc r2                                                      ;\
61
        LOAD_CONST (r2,0xdeadbeef)                                      ;\
62
        l.maci  r2,1                                                    ;\
63
                                                                        ;\
64
        l.mfspr r3,r0,SPR_SR                                            ;\
65
        LOAD_CONST (r2, ~(SPR_SR_CY | SPR_SR_OV))                       ;\
66
        l.and   r3,r3,r2                /* Clear flags */               ;\
67
        l.mtspr r0,r3,SPR_SR                                            ;\
68
                                                                        ;\
69
        LOAD_CONST (r5,op1)             /* First operand in register */ ;\
70
        l.mtspr r0,r0,SPR_EPCR_BASE     /* Clear record */              ;\
71
50:     l.mfspr r4,r5,op2                                               ;\
72
        l.mfspr r2,r0,SPR_EPCR_BASE     /* What triggered exception */  ;\
73
        PUSH (r2)                       /* Save EPCR for later */       ;\
74
        PUSH (r4)                       /* Save result for later */     ;\
75
                                                                        ;\
76
        PUTS ("  l.mfspr  0x")                                          ;\
77
        PUTH (op1)                                                      ;\
78
        PUTS (" | 0x")                                                  ;\
79
        PUTHH (op2)                                                     ;\
80
        PUTS (": ")                                                     ;\
81
        POP (r4)                                                        ;\
82
        CHECK_RES1 (r4, 0xdeadbeef)                                     ;\
83
                                                                        ;\
84
        LOAD_CONST (r4, 50b)            /* The opcode of interest */    ;\
85
        l.and   r2,r2,r4                                                ;\
86
        l.sfeq  r2,r4                                                   ;\
87
        l.bnf   51f                                                     ;\
88
                                                                        ;\
89
        PUTS ("  - exception triggered: TRUE\n")                        ;\
90
        l.j     52f                                                     ;\
91
        l.nop                                                           ;\
92
                                                                        ;\
93
51:     PUTS ("  - exception triggered: FALSE\n")                       ;\
94
52:
95
 
96
 
97
/* ----------------------------------------------------------------------------
98
 * A macro to carry out a test of l.mtspr
99
 *
100
 * MACLO is used as the SPR, since it can be read and cleared using l.macrc.
101
 * op1 and op2 should be chosen to address this register.
102
 *
103
 * The value placed in the register is entirely arbitrary - we use 0xdeadbeef.
104
 *
105
 * Arguments
106
 *   op1:       First l.mfspr operand value
107
 *   op2:       Second l.mfspr operand value
108
 * ------------------------------------------------------------------------- */
109
#define TEST_MTSPR(op1, op2)                                             \
110
        l.macrc r2                                                      ;\
111
                                                                        ;\
112
        l.mfspr r3,r0,SPR_SR                                            ;\
113
        LOAD_CONST (r2, ~(SPR_SR_CY | SPR_SR_OV))                       ;\
114
        l.and   r3,r3,r2                /* Clear flags */               ;\
115
        l.mtspr r0,r3,SPR_SR                                            ;\
116
                                                                        ;\
117
        LOAD_CONST (r5,op1)             /* First operand in register */ ;\
118
        LOAD_CONST (r4,0xdeadbeef)      /* First operand in register */ ;\
119
        l.mtspr r0,r0,SPR_EPCR_BASE     /* Clear record */              ;\
120
50:     l.mtspr r5,r4,op2                                               ;\
121
        l.mfspr r2,r0,SPR_EPCR_BASE     /* What triggered exception */  ;\
122
        PUSH (r2)                       /* Save EPCR for later */       ;\
123
        l.macrc r4                                                      ;\
124
        PUSH (r4)                       /* Save result for later */     ;\
125
                                                                        ;\
126
        PUTS ("  l.mtspr  0x")                                          ;\
127
        PUTH (op1)                                                      ;\
128
        PUTS (" | 0x")                                                  ;\
129
        PUTHH (op2)                                                     ;\
130
        PUTS (": ")                                                     ;\
131
        POP (r4)                                                        ;\
132
        CHECK_RES1 (r4, 0xdeadbeef)                                     ;\
133
                                                                        ;\
134
        LOAD_CONST (r4, 50b)            /* The opcode of interest */    ;\
135
        l.and   r2,r2,r4                                                ;\
136
        l.sfeq  r2,r4                                                   ;\
137
        l.bnf   51f                                                     ;\
138
                                                                        ;\
139
        PUTS ("  - exception triggered: TRUE\n")                        ;\
140
        l.j     52f                                                     ;\
141
        l.nop                                                           ;\
142
                                                                        ;\
143
51:     PUTS ("  - exception triggered: FALSE\n")                       ;\
144
52:
145
 
146
 
147
/* ----------------------------------------------------------------------------
148
 * Start of code
149
 * ------------------------------------------------------------------------- */
150
        .section .text
151
        .global _start
152
_start:
153
 
154
/* ----------------------------------------------------------------------------
155
 * Test of move from SPR, l.mfspr
156
 *
157
 * MACLO (0x2801) is always used as the test register.
158
 * ------------------------------------------------------------------------- */
159
_mfspr:
160
        LOAD_STR (r3, "l.mfspr\n")
161
        l.jal   _puts
162
        l.nop
163
 
164
        /* Move a test value using zero in the register */
165
        TEST_MFSPR (0x00000000, 0x2801)
166
 
167
        /* Move a test value using zero as the constant */
168
        TEST_MFSPR (0x00002801, 0x0000)
169
 
170
        /* Move a test value using non-zero in both register and constant.
171
           Some of these values will not give the correct result if OR rather
172
           than ADD is used to determine the SPR address */
173
        TEST_MFSPR (0x00002801, 0x2801)
174
        TEST_MFSPR (0x00000801, 0x2000)
175
        TEST_MFSPR (0x00002000, 0x0801)
176
        TEST_MFSPR (0x00002801, 0x0001)
177
        TEST_MFSPR (0x00000800, 0x2801)
178
 
179
/* ----------------------------------------------------------------------------
180
 * Test of move to SPR, l.mtspr
181
 *
182
 * MACLO (0x2801) is always used as the test register.
183
 * ------------------------------------------------------------------------- */
184
_mtspr:
185
        LOAD_STR (r3, "l.mtspr\n")
186
        l.jal   _puts
187
        l.nop
188
 
189
        /* Move a test value using zero in the register */
190
        TEST_MTSPR (0x00000000, 0x2801)
191
 
192
        /* Move a test value using zero as the constant */
193
        TEST_MTSPR (0x00002801, 0x0000)
194
 
195
        /* Move a test value using non-zero in both register and constant.
196
           Some of these values will not give the correct result if OR rather
197
           than ADD is used to determine the SPR address */
198
        TEST_MTSPR (0x00002801, 0x2801)
199
        TEST_MTSPR (0x00000801, 0x2000)
200
        TEST_MTSPR (0x00002000, 0x0801)
201
        TEST_MTSPR (0x00002801, 0x0001)
202
        TEST_MTSPR (0x00000800, 0x2801)
203
 
204
/* ----------------------------------------------------------------------------
205
 * All done
206
 * ------------------------------------------------------------------------- */
207
_exit:
208
        LOAD_STR (r3, "Test completed\n")
209
        l.jal   _puts
210
        l.nop
211
 
212
        TEST_EXIT

powered by: WebSVN 2.1.0

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