Automatic Copyright Year update after running gdb/copyright.py
[binutils-gdb.git] / sim / testsuite / or1k / load.S
blob6a03a323fdcd15fa7ef77a3e702f3c6dc3705a0a
1 /* Tests the load and store instructions.
3    Copyright (C) 2017-2022 Free Software Foundation, Inc.
5    This program is free software; you can redistribute it and/or modify
6    it under the terms of the GNU General Public License as published by
7    the Free Software Foundation; either version 3 of the License, or
8    (at your option) any later version.
10    This program is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13    GNU General Public License for more details.
15    You should have received a copy of the GNU General Public License
16    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
18 # mach: or1k
19 # output: report(0xdeadbeef);\n
20 # output: report(0x00000000);\n
21 # output: report(0x7fffffff);\n
22 # output: report(0x80000000);\n
23 # output: report(0xffffffff);\n
24 # output: report(0x00000000);\n
25 # output: report(0x7fffffff);\n
26 # output: report(0x80000000);\n
27 # output: report(0xffffffff);\n
28 # output: report(0xdeadbeef);\n
29 # output: report(0x00000000);\n
30 # output: report(0x7fffffff);\n
31 # output: report(0x80000000);\n
32 # output: report(0xdeadbeef);\n
33 # output: report(0x00000000);\n
34 # output: report(0x7fffffff);\n
35 # output: report(0x80000000);\n
36 # output: report(0xffffffff);\n
37 # output: report(0x00000000);\n
38 # output: report(0x7fffffff);\n
39 # output: report(0x80000000);\n
40 # output: report(0xffffffff);\n
41 # output: report(0xdeadbeef);\n
42 # output: report(0x00000000);\n
43 # output: report(0x7fffffff);\n
44 # output: report(0x80000000);\n
45 # output: report(0x000000de);\n
46 # output: report(0x000000ad);\n
47 # output: report(0x000000be);\n
48 # output: report(0x000000ef);\n
49 # output: report(0x000000ef);\n
50 # output: report(0x000000be);\n
51 # output: report(0x000000ad);\n
52 # output: report(0x000000de);\n
53 # output: report(0xffffffde);\n
54 # output: report(0xffffffad);\n
55 # output: report(0xffffffbe);\n
56 # output: report(0xffffffef);\n
57 # output: report(0xffffffef);\n
58 # output: report(0xffffffbe);\n
59 # output: report(0xffffffad);\n
60 # output: report(0xffffffde);\n
61 # output: report(0x0000dead);\n
62 # output: report(0x0000beef);\n
63 # output: report(0x0000beef);\n
64 # output: report(0x0000dead);\n
65 # output: report(0xffffdead);\n
66 # output: report(0xffffbeef);\n
67 # output: report(0xffffbeef);\n
68 # output: report(0xffffdead);\n
69 # output: report(0xa1a2a3a4);\n
70 # output: report(0xb4b3b2b1);\n
71 # output: report(0x81828384);\n
72 # output: report(0x53545152);\n
73 # output: report(0xa0b0c0d0);\n
74 # output: report(0xa1b1c1d1);\n
75 # output: report(0xa3b3c3d3);\n
76 # output: report(0xa2b2c2d2);\n
77 # output: exit(0)\n
79 #include "or1k-asm-test-helpers.h"
81         .macro TEST_LW  opcode, label, offset
82         LOAD_IMMEDIATE r5, \label
83         \opcode  r4, \offset(r5)
84         REPORT_REG_TO_CONSOLE r4
85         .endm
87         STANDARD_TEST_ENVIRONMENT
89         .section .rodata
90         .balign 4
92 50:     .word   0xdeadbeef
93 51:     .word   0x00000000
94 52:     .word   0x7fffffff
95 53:     .word   0x80000000
96 54:     .word   0xffffffff
98         .section .data
99         .balign 4
101 buffer1:  .word 0x00000000
102 buffer2:  .word 0x00000000
103 buffer3:  .word 0x00000000
104 buffer4:  .word 0x00000000
105 buffer5:
107         .section .text
108 start_tests:
109         PUSH LINK_REGISTER_R9
111         /* Test instruction l.lws  */
113         /* Load with zero offset.  */
114         TEST_LW l.lws 50b, 0
115         TEST_LW l.lws 51b, 0
116         TEST_LW l.lws 52b, 0
117         TEST_LW l.lws 53b, 0
118         TEST_LW l.lws 54b, 0
120         /* Load with positive offset.  */
121         TEST_LW l.lws 50b,  4
122         TEST_LW l.lws 50b,  8
123         TEST_LW l.lws 50b, 12
124         TEST_LW l.lws 50b, 16
126         /* Load with negative offset.  */
127         TEST_LW l.lws 54b, -16
128         TEST_LW l.lws 54b, -12
129         TEST_LW l.lws 54b,  -8
130         TEST_LW l.lws 54b,  -4
132         /* TODO: add here test cases to cover unaligned memory accesses
133            with l.lws.  */
135         /* Test instruction l.lwz */
137         /* Load with zero offset.  */
138         TEST_LW l.lwz 50b, 0
139         TEST_LW l.lwz 51b, 0
140         TEST_LW l.lwz 52b, 0
141         TEST_LW l.lwz 53b, 0
142         TEST_LW l.lwz 54b, 0
144         /* Load with positive offset.  */
145         TEST_LW l.lwz 50b,  4
146         TEST_LW l.lwz 50b,  8
147         TEST_LW l.lwz 50b, 12
148         TEST_LW l.lwz 50b, 16
150         /* Load with negative offset.  */
151         TEST_LW l.lwz 54b, -16
152         TEST_LW l.lwz 54b, -12
153         TEST_LW l.lwz 54b,  -8
154         TEST_LW l.lwz 54b,  -4
156         /* TODO: add here test cases to cover unaligned memory accesses
157            with l.lwz.  */
159         /* Test instruction l.lbz  */
161         /* Read data at label 50, forwards, byte by byte.  */
162         LOAD_IMMEDIATE r5, 50b
164         l.lbz r4, 0(r5)
165         REPORT_REG_TO_CONSOLE r4
167         l.lbz r4, 1(r5)
168         REPORT_REG_TO_CONSOLE r4
170         l.lbz r4, 2(r5)
171         REPORT_REG_TO_CONSOLE r4
173         l.lbz r4, 3(r5)
174         REPORT_REG_TO_CONSOLE r4
176         /* Read data at label 50, backwards, byte by byte.  */
177         LOAD_IMMEDIATE r31, 51b
179         l.lbz r3, -1(r31)
180         REPORT_REG_TO_CONSOLE r3
182         l.lbz r3, -2(r31)
183         REPORT_REG_TO_CONSOLE r3
185         l.lbz r3, -3(r31)
186         REPORT_REG_TO_CONSOLE r3
188         l.lbz r3, -4(r31)
189         REPORT_REG_TO_CONSOLE r3
191         /* Test instruction l.lbs  */
193         /* Read data at label 50, forwards, byte by byte.  */
194         LOAD_IMMEDIATE r5, 50b
196         l.lbs r4, 0(r5)
197         REPORT_REG_TO_CONSOLE r4
199         l.lbs r4, 1(r5)
200         REPORT_REG_TO_CONSOLE r4
202         l.lbs r4, 2(r5)
203         REPORT_REG_TO_CONSOLE r4
205         l.lbs r4, 3(r5)
206         REPORT_REG_TO_CONSOLE r4
208         /* Read data at label 50, backwards, byte by byte.  */
209         LOAD_IMMEDIATE r31, 51b
211         l.lbs r3, -1(r31)
212         REPORT_REG_TO_CONSOLE r3
214         l.lbs r3, -2(r31)
215         REPORT_REG_TO_CONSOLE r3
217         l.lbs r3, -3(r31)
218         REPORT_REG_TO_CONSOLE r3
220         l.lbs r3, -4(r31)
221         REPORT_REG_TO_CONSOLE r3
223         /* Test instruction l.lhz  */
225         /* Read data at label 50, forwards, half-word by half-word.  */
226         LOAD_IMMEDIATE r5, 50b
228         l.lhz r4, 0(r5)
229         REPORT_REG_TO_CONSOLE r4
231         l.lhz r4, 2(r5)
232         REPORT_REG_TO_CONSOLE r4
234         /* Read data at label 50, backwards, half-word by half-word.  */
235         LOAD_IMMEDIATE r31, 51b
237         l.lhz r3, -2(r31)
238         REPORT_REG_TO_CONSOLE r3
240         l.lhz r3, -4(r31)
241         REPORT_REG_TO_CONSOLE r3
243         /* TODO: add here test cases to cover unaligned memory accesses
244            with l.lhz.  */
246         /* Test instruction l.lhs  */
248         /* Read data at label 50, forwards, half-word by half-word.  */
249         LOAD_IMMEDIATE r5, 50b
251         l.lhs r4, 0(r5)
252         REPORT_REG_TO_CONSOLE r4
254         l.lhs r4, 2(r5)
255         REPORT_REG_TO_CONSOLE r4
257         /* Read data at label 50, backwards, half-word by half-word.  */
258         LOAD_IMMEDIATE r31, 51b
260         l.lhs r3, -2(r31)
261         REPORT_REG_TO_CONSOLE r3
263         l.lhs r3, -4(r31)
264         REPORT_REG_TO_CONSOLE r3
266         /* TODO: add here test cases to cover unaligned memory accesses
267            with l.lhs.  */
269         /* Test instruction l.sb  */
271         /* Write 32-bits forwards, byte-to-byte.  */
272         LOAD_IMMEDIATE r5, buffer1
274         LOAD_IMMEDIATE r10, 0xA1
275         LOAD_IMMEDIATE r11, 0xA2
276         LOAD_IMMEDIATE r12, 0xA3
277         LOAD_IMMEDIATE r13, 0xA4
279         l.sb 0(r5), r10
280         l.sb 1(r5), r11
281         l.sb 2(r5), r12
282         l.sb 3(r5), r13
284         l.lwz r3, 0(r5)
285         REPORT_REG_TO_CONSOLE r3
287         /* Write 32-bits backwards, byte-to-byte.  */
288         LOAD_IMMEDIATE r6, buffer2
290         LOAD_IMMEDIATE r10, 0xB1
291         LOAD_IMMEDIATE r11, 0xB2
292         LOAD_IMMEDIATE r12, 0xB3
293         LOAD_IMMEDIATE r13, 0xB4
295         l.sb -1(r6), r10
296         l.sb -2(r6), r11
297         l.sb -3(r6), r12
298         l.sb -4(r6), r13
300         l.lwz r3, 0(r5)
301         REPORT_REG_TO_CONSOLE r3
303         /* TODO: add here test cases to cover unaligned memory accesses
304            with l.sb.  */
306         /* Test instruction l.sh  */
308         /* Write 32-bits forwards, one half-word at a time.  */
309         LOAD_IMMEDIATE r5, buffer1
311         LOAD_IMMEDIATE r10, 0x8182
312         LOAD_IMMEDIATE r11, 0x8384
314         l.sh 0(r5), r10
315         l.sh 2(r5), r11
317         l.lwz r3, 0(r5)
318         REPORT_REG_TO_CONSOLE r3
320         /* Write 32-bits backwards, one half-word at a time.  */
321         LOAD_IMMEDIATE r6, buffer2
323         LOAD_IMMEDIATE r10, 0x5152
324         LOAD_IMMEDIATE r11, 0x5354
326         l.sh -2(r6), r10
327         l.sh -4(r6), r11
329         l.lwz r3, 0(r5)
330         REPORT_REG_TO_CONSOLE r3
332         /* TODO: add here test cases to cover unaligned memory accesses
333            with l.sh.  */
335         /* Test instruction l.sw  */
336         LOAD_IMMEDIATE r5, buffer1
337         LOAD_IMMEDIATE r6, buffer5
339         LOAD_IMMEDIATE r10, 0xA0B0C0D0
340         LOAD_IMMEDIATE r11, 0xA1B1C1D1
341         LOAD_IMMEDIATE r12, 0xA2B2C2D2
342         LOAD_IMMEDIATE r13, 0xA3B3C3D3
344         l.sw  0(r5), r10
345         l.sw  4(r5), r11
346         l.sw -4(r6), r12
347         l.sw -8(r6), r13
349         TEST_LW l.lwz buffer1, 0
350         TEST_LW l.lwz buffer2, 0
351         TEST_LW l.lwz buffer3, 0
352         TEST_LW l.lwz buffer4, 0
354         /* TODO: add here test cases to cover unaligned memory accesses
355            with l.sw.  */
357         POP LINK_REGISTER_R9
358         RETURN_TO_LINK_REGISTER_R9