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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [orpsocv2/] [sw/] [tests/] [or1200/] [sim/] [or1200-cy.S] - Blame information for rev 530

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 502 julius
/*
2
        OR1200 carry bit checking
3
 
4
        Carry generated on all adds which we interpret to be
5
        unsigned. The CPU will generate both CY and OV.
6
        CY is generated when unsigned values generate an extra bit.
7
        OV is when the values, interpreted as signed, cannot have
8
        the result displayed as it is too large.
9
 
10
        OV is not checked here. Just CY generation and inclusion by
11
        the l.addc and l.addic instructions.
12
 
13
        Very basic, testing.
14
 
15
TODO:    Substraction carry out testing.
16
 
17
        Julius Baxter, ORSoC AB, julius.baxter@orsoc.se
18
 
19
*/
20
//////////////////////////////////////////////////////////////////////
21
////                                                              ////
22
//// Copyright (C) 2011 Authors and OPENCORES.ORG                 ////
23
////                                                              ////
24
//// This source file may be used and distributed without         ////
25
//// restriction provided that this copyright statement is not    ////
26
//// removed from the file and that any derivative work contains  ////
27
//// the original copyright notice and the associated disclaimer. ////
28
////                                                              ////
29
//// This source file is free software; you can redistribute it   ////
30
//// and/or modify it under the terms of the GNU Lesser General   ////
31
//// Public License as published by the Free Software Foundation; ////
32
//// either version 2.1 of the License, or (at your option) any   ////
33
//// later version.                                               ////
34
////                                                              ////
35
//// This source is distributed in the hope that it will be       ////
36
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
37
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
38
//// PURPOSE.  See the GNU Lesser General Public License for more ////
39
//// details.                                                     ////
40
////                                                              ////
41
//// You should have received a copy of the GNU Lesser General    ////
42
//// Public License along with this source; if not, download it   ////
43
//// from http://www.opencores.org/lgpl.shtml                     ////
44
////                                                              ////
45
//////////////////////////////////////////////////////////////////////
46
 
47
 
48
#include "spr-defs.h"
49
#include "board.h"
50
#include "or1200-defines.h"
51
 
52
 
53
/* =================================================== [ exceptions ] === */
54
        .section .vectors, "ax"
55
 
56
 
57
/* ---[ 0x100: RESET exception ]----------------------------------------- */
58
        .org 0x100
59
        l.movhi r0, 0
60
        /* Clear status register */
61
        l.ori r1, r0, SPR_SR_SM
62
        l.mtspr r0, r1, SPR_SR
63
        /* Clear timer  */
64
        l.mtspr r0, r0, SPR_TTMR
65
 
66
        /* Jump to program initialisation code */
67
        .global _start
68
        l.movhi r4, hi(_start)
69
        l.ori r4, r4, lo(_start)
70
        l.jr    r4
71
        l.nop
72
 
73
        .org 0x600
74
        l.nop 0x1
75
 
76
 
77
/* ---[ 0x700: Illegal instruction exception ]-------------------------- */
78
        .org 0x700
79
#ifndef OR1200_IMPL_ADDC
80
        // No problem - instruction not supported
81
        l.movhi r3, hi(0x8000000d)
82
        l.ori   r3, r3, lo(0x8000000d)
83
        l.nop   0x2
84
        l.ori   r3, r0, 0
85
#else
86
        l.ori   r3, r0, 1
87
#endif
88
        l.nop   0x1
89
 
90
/* ---[ 0xb00: Range exception ]---------------------------------------- */
91
        .org 0xb00
92
        l.sw    0(r0), r3
93
        l.ori   r3, r0, 0xaaee
94
        l.nop   0x2
95
        l.lwz   r3, 0(r0)
96
        l.rfe
97
 
98
/* =================================================== [ text ] === */
99
        .section .text
100
 
101
/* =================================================== [ start ] === */
102
 
103
        .global _start
104
_start:
105 530 julius
        // Clear regs
106 502 julius
        l.movhi r1, 0
107
        l.movhi r2, 0
108
        l.movhi r3, 0
109
        l.movhi r4, 0
110
        l.movhi r5, 0
111
        l.movhi r6, 0
112
 
113
#ifdef OR1200_IMPL_CY
114
        // Kick off test
115
        l.jal   _main
116
#else
117
        // Not supported, exit test
118
        l.j     _finish
119
#endif
120
        l.nop
121
 
122
 
123
/* =================================================== [ main ] === */
124
 
125
 
126
#define CHECK_CY_CLEAR                  \
127 530 julius
        l.mfspr r6, r0, SPR_SR  ;       \
128
        l.andi  r6, r6, SPR_SR_CY ;     \
129
        l.sfne  r6, r0            ;     \
130 502 julius
        l.bf    _fail             ;     \
131
        l.nop
132
 
133
#define CHECK_CY_SET                    \
134 530 julius
        l.mfspr r6, r0, SPR_SR  ;       \
135
        l.andi  r6, r6, SPR_SR_CY ;     \
136
        l.sfnei r6, SPR_SR_CY     ;     \
137 502 julius
        l.bf    _fail             ;     \
138
        l.nop
139
 
140
        .global _main
141
_main:
142
 
143
        // Set up some values, check the CY bit is cleared from reset
144
        CHECK_CY_CLEAR
145
 
146
        // A large unsigned value
147
        l.movhi r4, 0xffff
148
        l.ori   r4, r4, 0xefff
149
 
150
        // A value large enough to cause carry
151
        l.ori   r5, r0, 0x1001
152
 
153
        l.add   r3, r5, r4      ;// Should set CY
154
        l.nop   0x2
155
        CHECK_CY_SET
156
 
157
        l.add   r3, r0, r0      ;// Should clear CY
158
        CHECK_CY_CLEAR
159
 
160
        l.addi  r3, r4, 0x1001  ;// Should set CY
161
        l.nop   0x2
162
        CHECK_CY_SET
163
 
164
        l.addi  r3, r4, 0x1000  ;// Shouldn't set CY
165
        l.nop   0x2
166
        CHECK_CY_CLEAR
167
 
168
        l.add   r3, r0, r0      ;// Should clear CY
169
        CHECK_CY_CLEAR
170
 
171
        // Check use of carry - l.addc
172
        l.addi  r3, r4, 0x1001  ;// Should set CY
173
        ;; // Consequtive instructions
174
        l.addc  r3, r3, r5      ;// r3 should be 0x1002
175
        l.nop   0x2             ;// Report
176
 
177
        l.sfnei r3, 0x1002
178
        l.bf    _fail
179
        l.nop
180
 
181
        l.add   r3, r4, r5      ;// Should set CY
182
        l.nop                   ;// 1 delay instruction
183
        l.addc  r3, r3, r5      ;// r3 should be 0x1002
184
        l.nop   0x2             ;// Report
185
 
186
        l.sfnei r3, 0x1002
187
        l.bf    _fail
188
        l.nop
189
 
190
        l.add   r3, r4, r5      ;// Should set
191
        l.nop   0x2             ;// 1 delay instruction
192
        l.nop                   ;// 2nd delay instruction
193
        l.addc  r3, r3, r5      ;// r3 should be 0x1002
194
        l.nop   0x2             ;// Report
195
 
196
        l.sfnei r3, 0x1002
197
        l.bf    _fail
198
        l.nop
199
 
200
        l.add   r3, r0, r0      ;// Should clear CY
201
        CHECK_CY_CLEAR
202
 
203
        // Check use of carry - l.addic
204
        l.addi  r3, r4, 0x1001  ;// Should set CY
205
        ;; // Consequtive instructions
206
        l.addic r3, r3, 0x1     ;// r3 should be 2
207
        l.nop   0x2             ;// Report
208
 
209
        l.sfnei r3, 0x2
210
        l.bf    _fail
211
        l.nop
212
 
213
        l.add   r3, r0, r0      ;// Should clear CY
214
        CHECK_CY_CLEAR
215
 
216
        l.add   r3, r4, r5      ;// Should set CY
217
        l.nop                   ;// 1 delay instruction
218
        l.addic r3, r3, 0x1     ;// r3 should be 2
219
        l.nop   0x2             ;// Report
220
 
221
        l.sfnei r3, 0x2
222
        l.bf    _fail
223
        l.nop
224
 
225
        l.add   r3, r0, r0      ;// Should clear CY
226
        CHECK_CY_CLEAR
227
 
228
        l.add   r3, r4, r5      ;// Should set
229
        l.nop   0x2             ;// 1 delay instruction
230
        l.nop                   ;// 2nd delay instruction
231
        l.addic r3, r3, 0x1     ;// r3 should be 2
232
        l.nop   0x2             ;// Report
233
 
234
        l.sfnei r3, 0x2
235
        l.bf    _fail
236
        l.nop
237
 
238
        l.add   r3, r0, r0      ;// Should clear CY
239
        CHECK_CY_CLEAR
240
 
241
        // Add with carry and generate carry with l.addc
242
 
243
        l.add   r3, r4, r5
244
        l.addc  r3, r4, r5
245
        l.nop   0x2
246
 
247
        l.sfnei r3, 0x1
248
        l.bf    _fail
249
        l.nop
250
 
251
        CHECK_CY_SET
252
 
253
        l.add   r3, r0, r0      ;// Should clear CY
254
        CHECK_CY_CLEAR
255
 
256
        // Add with carry and generate carry with l.addic
257
 
258
        l.addi  r3, r4, 0x1001
259
        l.addic r3, r4, 0x1001
260
        l.nop   0x2
261
 
262
        l.sfnei r3, 0x1
263
        l.bf    _fail
264
        l.nop
265
 
266
        CHECK_CY_SET
267
 
268
_finish:
269
        l.movhi r3, hi(0x8000000d)
270
        l.ori   r3, r3, lo(0x8000000d)
271
        l.nop   0x2
272
        l.ori   r3, r0, 0
273
        l.nop   0x1
274
 
275
_fail:
276
        l.ori   r3, r0, 1
277
        l.nop   0x1

powered by: WebSVN 2.1.0

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