summaryrefslogtreecommitdiff
path: root/sim/testsuite/sim/or1k/load.S
blob: 3644a8751a0ae81f5b46bca6259c72b96accb391 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
/* Tests the load and store instructions.

   Copyright (C) 2017-2021 Free Software Foundation, Inc.

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 3 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */

# mach: or1k
# output: report(0xdeadbeef);\n
# output: report(0x00000000);\n
# output: report(0x7fffffff);\n
# output: report(0x80000000);\n
# output: report(0xffffffff);\n
# output: report(0x00000000);\n
# output: report(0x7fffffff);\n
# output: report(0x80000000);\n
# output: report(0xffffffff);\n
# output: report(0xdeadbeef);\n
# output: report(0x00000000);\n
# output: report(0x7fffffff);\n
# output: report(0x80000000);\n
# output: report(0xdeadbeef);\n
# output: report(0x00000000);\n
# output: report(0x7fffffff);\n
# output: report(0x80000000);\n
# output: report(0xffffffff);\n
# output: report(0x00000000);\n
# output: report(0x7fffffff);\n
# output: report(0x80000000);\n
# output: report(0xffffffff);\n
# output: report(0xdeadbeef);\n
# output: report(0x00000000);\n
# output: report(0x7fffffff);\n
# output: report(0x80000000);\n
# output: report(0x000000de);\n
# output: report(0x000000ad);\n
# output: report(0x000000be);\n
# output: report(0x000000ef);\n
# output: report(0x000000ef);\n
# output: report(0x000000be);\n
# output: report(0x000000ad);\n
# output: report(0x000000de);\n
# output: report(0xffffffde);\n
# output: report(0xffffffad);\n
# output: report(0xffffffbe);\n
# output: report(0xffffffef);\n
# output: report(0xffffffef);\n
# output: report(0xffffffbe);\n
# output: report(0xffffffad);\n
# output: report(0xffffffde);\n
# output: report(0x0000dead);\n
# output: report(0x0000beef);\n
# output: report(0x0000beef);\n
# output: report(0x0000dead);\n
# output: report(0xffffdead);\n
# output: report(0xffffbeef);\n
# output: report(0xffffbeef);\n
# output: report(0xffffdead);\n
# output: report(0xa1a2a3a4);\n
# output: report(0xb4b3b2b1);\n
# output: report(0x81828384);\n
# output: report(0x53545152);\n
# output: report(0xa0b0c0d0);\n
# output: report(0xa1b1c1d1);\n
# output: report(0xa3b3c3d3);\n
# output: report(0xa2b2c2d2);\n
# output: exit(0)\n

#include "or1k-asm-test-helpers.h"

	.macro TEST_LW  opcode, label, offset
	LOAD_IMMEDIATE r5, \label
	\opcode  r4, \offset(r5)
	REPORT_REG_TO_CONSOLE r4
	.endm

	STANDARD_TEST_ENVIRONMENT

	.section .rodata
	.balign 4

50:     .word   0xdeadbeef
51:     .word   0x00000000
52:     .word   0x7fffffff
53:     .word   0x80000000
54:     .word   0xffffffff

	.section .data
	.balign 4

buffer1:  .word 0x00000000
buffer2:  .word 0x00000000
buffer3:  .word 0x00000000
buffer4:  .word 0x00000000
buffer5:

	.section .text
start_tests:
	PUSH LINK_REGISTER_R9

	/* Test instruction l.lws  */

	/* Load with zero offset.  */
	TEST_LW l.lws 50b, 0
	TEST_LW l.lws 51b, 0
	TEST_LW l.lws 52b, 0
	TEST_LW l.lws 53b, 0
	TEST_LW l.lws 54b, 0

	/* Load with positive offset.  */
	TEST_LW l.lws 50b,  4
	TEST_LW l.lws 50b,  8
	TEST_LW l.lws 50b, 12
	TEST_LW l.lws 50b, 16

	/* Load with negative offset.  */
	TEST_LW l.lws 54b, -16
	TEST_LW l.lws 54b, -12
	TEST_LW l.lws 54b,  -8
	TEST_LW l.lws 54b,  -4

	/* TODO: add here test cases to cover unaligned memory accesses
	   with l.lws.  */

	/* Test instruction l.lwz */

	/* Load with zero offset.  */
	TEST_LW l.lwz 50b, 0
	TEST_LW l.lwz 51b, 0
	TEST_LW l.lwz 52b, 0
	TEST_LW l.lwz 53b, 0
	TEST_LW l.lwz 54b, 0

	/* Load with positive offset.  */
	TEST_LW l.lwz 50b,  4
	TEST_LW l.lwz 50b,  8
	TEST_LW l.lwz 50b, 12
	TEST_LW l.lwz 50b, 16

	/* Load with negative offset.  */
	TEST_LW l.lwz 54b, -16
	TEST_LW l.lwz 54b, -12
	TEST_LW l.lwz 54b,  -8
	TEST_LW l.lwz 54b,  -4

	/* TODO: add here test cases to cover unaligned memory accesses
	   with l.lwz.  */

	/* Test instruction l.lbz  */

	/* Read data at label 50, forwards, byte by byte.  */
	LOAD_IMMEDIATE r5, 50b

	l.lbz r4, 0(r5)
	REPORT_REG_TO_CONSOLE r4

	l.lbz r4, 1(r5)
	REPORT_REG_TO_CONSOLE r4

	l.lbz r4, 2(r5)
	REPORT_REG_TO_CONSOLE r4

	l.lbz r4, 3(r5)
	REPORT_REG_TO_CONSOLE r4

	/* Read data at label 50, backwards, byte by byte.  */
	LOAD_IMMEDIATE r31, 51b

	l.lbz r3, -1(r31)
	REPORT_REG_TO_CONSOLE r3

	l.lbz r3, -2(r31)
	REPORT_REG_TO_CONSOLE r3

	l.lbz r3, -3(r31)
	REPORT_REG_TO_CONSOLE r3

	l.lbz r3, -4(r31)
	REPORT_REG_TO_CONSOLE r3

	/* Test instruction l.lbs  */

	/* Read data at label 50, forwards, byte by byte.  */
	LOAD_IMMEDIATE r5, 50b

	l.lbs r4, 0(r5)
	REPORT_REG_TO_CONSOLE r4

	l.lbs r4, 1(r5)
	REPORT_REG_TO_CONSOLE r4

	l.lbs r4, 2(r5)
	REPORT_REG_TO_CONSOLE r4

	l.lbs r4, 3(r5)
	REPORT_REG_TO_CONSOLE r4

	/* Read data at label 50, backwards, byte by byte.  */
	LOAD_IMMEDIATE r31, 51b

	l.lbs r3, -1(r31)
	REPORT_REG_TO_CONSOLE r3

	l.lbs r3, -2(r31)
	REPORT_REG_TO_CONSOLE r3

	l.lbs r3, -3(r31)
	REPORT_REG_TO_CONSOLE r3

	l.lbs r3, -4(r31)
	REPORT_REG_TO_CONSOLE r3

	/* Test instruction l.lhz  */

	/* Read data at label 50, forwards, half-word by half-word.  */
	LOAD_IMMEDIATE r5, 50b

	l.lhz r4, 0(r5)
	REPORT_REG_TO_CONSOLE r4

	l.lhz r4, 2(r5)
	REPORT_REG_TO_CONSOLE r4

	/* Read data at label 50, backwards, half-word by half-word.  */
	LOAD_IMMEDIATE r31, 51b

	l.lhz r3, -2(r31)
	REPORT_REG_TO_CONSOLE r3

	l.lhz r3, -4(r31)
	REPORT_REG_TO_CONSOLE r3

	/* TODO: add here test cases to cover unaligned memory accesses
	   with l.lhz.  */

	/* Test instruction l.lhs  */

	/* Read data at label 50, forwards, half-word by half-word.  */
	LOAD_IMMEDIATE r5, 50b

	l.lhs r4, 0(r5)
	REPORT_REG_TO_CONSOLE r4

	l.lhs r4, 2(r5)
	REPORT_REG_TO_CONSOLE r4

	/* Read data at label 50, backwards, half-word by half-word.  */
	LOAD_IMMEDIATE r31, 51b

	l.lhs r3, -2(r31)
	REPORT_REG_TO_CONSOLE r3

	l.lhs r3, -4(r31)
	REPORT_REG_TO_CONSOLE r3

	/* TODO: add here test cases to cover unaligned memory accesses
	   with l.lhs.  */

	/* Test instruction l.sb  */

	/* Write 32-bits forwards, byte-to-byte.  */
	LOAD_IMMEDIATE r5, buffer1

	LOAD_IMMEDIATE r10, 0xA1
	LOAD_IMMEDIATE r11, 0xA2
	LOAD_IMMEDIATE r12, 0xA3
	LOAD_IMMEDIATE r13, 0xA4

	l.sb 0(r5), r10
	l.sb 1(r5), r11
	l.sb 2(r5), r12
	l.sb 3(r5), r13

	l.lwz r3, 0(r5)
	REPORT_REG_TO_CONSOLE r3

	/* Write 32-bits backwards, byte-to-byte.  */
	LOAD_IMMEDIATE r6, buffer2

	LOAD_IMMEDIATE r10, 0xB1
	LOAD_IMMEDIATE r11, 0xB2
	LOAD_IMMEDIATE r12, 0xB3
	LOAD_IMMEDIATE r13, 0xB4

	l.sb -1(r6), r10
	l.sb -2(r6), r11
	l.sb -3(r6), r12
	l.sb -4(r6), r13

	l.lwz r3, 0(r5)
	REPORT_REG_TO_CONSOLE r3

	/* TODO: add here test cases to cover unaligned memory accesses
	   with l.sb.  */

	/* Test instruction l.sh  */

	/* Write 32-bits forwards, one half-word at a time.  */
	LOAD_IMMEDIATE r5, buffer1

	LOAD_IMMEDIATE r10, 0x8182
	LOAD_IMMEDIATE r11, 0x8384

	l.sh 0(r5), r10
	l.sh 2(r5), r11

	l.lwz r3, 0(r5)
	REPORT_REG_TO_CONSOLE r3

	/* Write 32-bits backwards, one half-word at a time.  */
	LOAD_IMMEDIATE r6, buffer2

	LOAD_IMMEDIATE r10, 0x5152
	LOAD_IMMEDIATE r11, 0x5354

	l.sh -2(r6), r10
	l.sh -4(r6), r11

	l.lwz r3, 0(r5)
	REPORT_REG_TO_CONSOLE r3

	/* TODO: add here test cases to cover unaligned memory accesses
	   with l.sh.  */

	/* Test instruction l.sw  */
	LOAD_IMMEDIATE r5, buffer1
	LOAD_IMMEDIATE r6, buffer5

	LOAD_IMMEDIATE r10, 0xA0B0C0D0
	LOAD_IMMEDIATE r11, 0xA1B1C1D1
	LOAD_IMMEDIATE r12, 0xA2B2C2D2
	LOAD_IMMEDIATE r13, 0xA3B3C3D3

	l.sw  0(r5), r10
	l.sw  4(r5), r11
	l.sw -4(r6), r12
	l.sw -8(r6), r13

	TEST_LW l.lwz buffer1, 0
	TEST_LW l.lwz buffer2, 0
	TEST_LW l.lwz buffer3, 0
	TEST_LW l.lwz buffer4, 0

	/* TODO: add here test cases to cover unaligned memory accesses
	   with l.sw.  */

	POP LINK_REGISTER_R9
	RETURN_TO_LINK_REGISTER_R9