1*83d290c5STom Rini // SPDX-License-Identifier: GPL-2.0+
2a47a12beSStefan Roese /*
3a47a12beSStefan Roese * (C) Copyright 2002
4a47a12beSStefan Roese * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5a47a12beSStefan Roese */
6a47a12beSStefan Roese
7a47a12beSStefan Roese #include <common.h>
8a47a12beSStefan Roese
9a47a12beSStefan Roese /*
10a47a12beSStefan Roese * CPU test
11a47a12beSStefan Roese * Load instructions: lbz(x)(u), lhz(x)(u), lha(x)(u), lwz(x)(u)
12a47a12beSStefan Roese *
13a47a12beSStefan Roese * All operations are performed on a 16-byte array. The array
14a47a12beSStefan Roese * is 4-byte aligned. The base register points to offset 8.
15a47a12beSStefan Roese * The immediate offset (index register) ranges in [-8 ... +7].
16a47a12beSStefan Roese * The test cases are composed so that they do not
17a47a12beSStefan Roese * cause alignment exceptions.
18a47a12beSStefan Roese * The test contains a pre-built table describing all test cases.
19a47a12beSStefan Roese * The table entry contains:
20a47a12beSStefan Roese * the instruction opcode, the array contents, the value of the index
21a47a12beSStefan Roese * register and the expected value of the destination register.
22a47a12beSStefan Roese * After executing the instruction, the test verifies the
23a47a12beSStefan Roese * value of the destination register and the value of the base
24a47a12beSStefan Roese * register (it must change for "load with update" instructions).
25a47a12beSStefan Roese */
26a47a12beSStefan Roese
27a47a12beSStefan Roese #include <post.h>
28a47a12beSStefan Roese #include "cpu_asm.h"
29a47a12beSStefan Roese
30a47a12beSStefan Roese #if CONFIG_POST & CONFIG_SYS_POST_CPU
31a47a12beSStefan Roese
32a47a12beSStefan Roese extern void cpu_post_exec_22w (ulong *code, ulong *op1, ulong op2, ulong *op3);
33a47a12beSStefan Roese extern void cpu_post_exec_21w (ulong *code, ulong *op1, ulong *op2);
34a47a12beSStefan Roese
35a47a12beSStefan Roese static struct cpu_post_load_s
36a47a12beSStefan Roese {
37a47a12beSStefan Roese ulong cmd;
38a47a12beSStefan Roese uint width;
39a47a12beSStefan Roese int update;
40a47a12beSStefan Roese int index;
41a47a12beSStefan Roese ulong offset;
42a47a12beSStefan Roese } cpu_post_load_table[] =
43a47a12beSStefan Roese {
44a47a12beSStefan Roese {
45a47a12beSStefan Roese OP_LWZ,
46a47a12beSStefan Roese 4,
47a47a12beSStefan Roese 0,
48a47a12beSStefan Roese 0,
49a47a12beSStefan Roese 4
50a47a12beSStefan Roese },
51a47a12beSStefan Roese {
52a47a12beSStefan Roese OP_LHA,
53a47a12beSStefan Roese 3,
54a47a12beSStefan Roese 0,
55a47a12beSStefan Roese 0,
56a47a12beSStefan Roese 2
57a47a12beSStefan Roese },
58a47a12beSStefan Roese {
59a47a12beSStefan Roese OP_LHZ,
60a47a12beSStefan Roese 2,
61a47a12beSStefan Roese 0,
62a47a12beSStefan Roese 0,
63a47a12beSStefan Roese 2
64a47a12beSStefan Roese },
65a47a12beSStefan Roese {
66a47a12beSStefan Roese OP_LBZ,
67a47a12beSStefan Roese 1,
68a47a12beSStefan Roese 0,
69a47a12beSStefan Roese 0,
70a47a12beSStefan Roese 1
71a47a12beSStefan Roese },
72a47a12beSStefan Roese {
73a47a12beSStefan Roese OP_LWZU,
74a47a12beSStefan Roese 4,
75a47a12beSStefan Roese 1,
76a47a12beSStefan Roese 0,
77a47a12beSStefan Roese 4
78a47a12beSStefan Roese },
79a47a12beSStefan Roese {
80a47a12beSStefan Roese OP_LHAU,
81a47a12beSStefan Roese 3,
82a47a12beSStefan Roese 1,
83a47a12beSStefan Roese 0,
84a47a12beSStefan Roese 2
85a47a12beSStefan Roese },
86a47a12beSStefan Roese {
87a47a12beSStefan Roese OP_LHZU,
88a47a12beSStefan Roese 2,
89a47a12beSStefan Roese 1,
90a47a12beSStefan Roese 0,
91a47a12beSStefan Roese 2
92a47a12beSStefan Roese },
93a47a12beSStefan Roese {
94a47a12beSStefan Roese OP_LBZU,
95a47a12beSStefan Roese 1,
96a47a12beSStefan Roese 1,
97a47a12beSStefan Roese 0,
98a47a12beSStefan Roese 1
99a47a12beSStefan Roese },
100a47a12beSStefan Roese {
101a47a12beSStefan Roese OP_LWZX,
102a47a12beSStefan Roese 4,
103a47a12beSStefan Roese 0,
104a47a12beSStefan Roese 1,
105a47a12beSStefan Roese 4
106a47a12beSStefan Roese },
107a47a12beSStefan Roese {
108a47a12beSStefan Roese OP_LHAX,
109a47a12beSStefan Roese 3,
110a47a12beSStefan Roese 0,
111a47a12beSStefan Roese 1,
112a47a12beSStefan Roese 2
113a47a12beSStefan Roese },
114a47a12beSStefan Roese {
115a47a12beSStefan Roese OP_LHZX,
116a47a12beSStefan Roese 2,
117a47a12beSStefan Roese 0,
118a47a12beSStefan Roese 1,
119a47a12beSStefan Roese 2
120a47a12beSStefan Roese },
121a47a12beSStefan Roese {
122a47a12beSStefan Roese OP_LBZX,
123a47a12beSStefan Roese 1,
124a47a12beSStefan Roese 0,
125a47a12beSStefan Roese 1,
126a47a12beSStefan Roese 1
127a47a12beSStefan Roese },
128a47a12beSStefan Roese {
129a47a12beSStefan Roese OP_LWZUX,
130a47a12beSStefan Roese 4,
131a47a12beSStefan Roese 1,
132a47a12beSStefan Roese 1,
133a47a12beSStefan Roese 4
134a47a12beSStefan Roese },
135a47a12beSStefan Roese {
136a47a12beSStefan Roese OP_LHAUX,
137a47a12beSStefan Roese 3,
138a47a12beSStefan Roese 1,
139a47a12beSStefan Roese 1,
140a47a12beSStefan Roese 2
141a47a12beSStefan Roese },
142a47a12beSStefan Roese {
143a47a12beSStefan Roese OP_LHZUX,
144a47a12beSStefan Roese 2,
145a47a12beSStefan Roese 1,
146a47a12beSStefan Roese 1,
147a47a12beSStefan Roese 2
148a47a12beSStefan Roese },
149a47a12beSStefan Roese {
150a47a12beSStefan Roese OP_LBZUX,
151a47a12beSStefan Roese 1,
152a47a12beSStefan Roese 1,
153a47a12beSStefan Roese 1,
154a47a12beSStefan Roese 1
155a47a12beSStefan Roese },
156a47a12beSStefan Roese };
157d2397817SMike Frysinger static unsigned int cpu_post_load_size = ARRAY_SIZE(cpu_post_load_table);
158a47a12beSStefan Roese
cpu_post_test_load(void)159a47a12beSStefan Roese int cpu_post_test_load (void)
160a47a12beSStefan Roese {
161a47a12beSStefan Roese int ret = 0;
162a47a12beSStefan Roese unsigned int i;
163a47a12beSStefan Roese int flag = disable_interrupts();
164a47a12beSStefan Roese
165a47a12beSStefan Roese for (i = 0; i < cpu_post_load_size && ret == 0; i++)
166a47a12beSStefan Roese {
167a47a12beSStefan Roese struct cpu_post_load_s *test = cpu_post_load_table + i;
168a47a12beSStefan Roese uchar data[16] =
169a47a12beSStefan Roese { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
170a47a12beSStefan Roese ulong base0 = (ulong) (data + 8);
171a47a12beSStefan Roese ulong base = base0;
172a47a12beSStefan Roese ulong value;
173a47a12beSStefan Roese
174a47a12beSStefan Roese if (test->index)
175a47a12beSStefan Roese {
176a47a12beSStefan Roese ulong code[] =
177a47a12beSStefan Roese {
178a47a12beSStefan Roese ASM_12(test->cmd, 5, 3, 4),
179a47a12beSStefan Roese ASM_BLR,
180a47a12beSStefan Roese };
181a47a12beSStefan Roese
182a47a12beSStefan Roese cpu_post_exec_22w (code, &base, test->offset, &value);
183a47a12beSStefan Roese }
184a47a12beSStefan Roese else
185a47a12beSStefan Roese {
186a47a12beSStefan Roese ulong code[] =
187a47a12beSStefan Roese {
188a47a12beSStefan Roese ASM_11I(test->cmd, 4, 3, test->offset),
189a47a12beSStefan Roese ASM_BLR,
190a47a12beSStefan Roese };
191a47a12beSStefan Roese
192a47a12beSStefan Roese cpu_post_exec_21w (code, &base, &value);
193a47a12beSStefan Roese }
194a47a12beSStefan Roese
195a47a12beSStefan Roese if (ret == 0)
196a47a12beSStefan Roese {
197a47a12beSStefan Roese if (test->update)
198a47a12beSStefan Roese ret = base == base0 + test->offset ? 0 : -1;
199a47a12beSStefan Roese else
200a47a12beSStefan Roese ret = base == base0 ? 0 : -1;
201a47a12beSStefan Roese }
202a47a12beSStefan Roese
203a47a12beSStefan Roese if (ret == 0)
204a47a12beSStefan Roese {
205a47a12beSStefan Roese switch (test->width)
206a47a12beSStefan Roese {
207a47a12beSStefan Roese case 1:
208a47a12beSStefan Roese ret = *(uchar *)(base0 + test->offset) == value ?
209a47a12beSStefan Roese 0 : -1;
210a47a12beSStefan Roese break;
211a47a12beSStefan Roese case 2:
212a47a12beSStefan Roese ret = *(ushort *)(base0 + test->offset) == value ?
213a47a12beSStefan Roese 0 : -1;
214a47a12beSStefan Roese break;
215a47a12beSStefan Roese case 3:
216a47a12beSStefan Roese ret = *(short *)(base0 + test->offset) == value ?
217a47a12beSStefan Roese 0 : -1;
218a47a12beSStefan Roese break;
219a47a12beSStefan Roese case 4:
220a47a12beSStefan Roese ret = *(ulong *)(base0 + test->offset) == value ?
221a47a12beSStefan Roese 0 : -1;
222a47a12beSStefan Roese break;
223a47a12beSStefan Roese }
224a47a12beSStefan Roese }
225a47a12beSStefan Roese
226a47a12beSStefan Roese if (ret != 0)
227a47a12beSStefan Roese {
228a47a12beSStefan Roese post_log ("Error at load test %d !\n", i);
229a47a12beSStefan Roese }
230a47a12beSStefan Roese }
231a47a12beSStefan Roese
232a47a12beSStefan Roese if (flag)
233a47a12beSStefan Roese enable_interrupts();
234a47a12beSStefan Roese
235a47a12beSStefan Roese return ret;
236a47a12beSStefan Roese }
237a47a12beSStefan Roese
238a47a12beSStefan Roese #endif
239