blob: 393c56830d9d6cd4aa445df1880c629a30b6a8b0 [file] [log] [blame]
wdenka46d8212002-09-12 22:01:13 +00001/*
2 * (C) Copyright 2002
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4 *
5 * See file CREDITS for list of people who contributed to this
6 * project.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21 * MA 02111-1307 USA
22 */
23
24#include <common.h>
25
26/*
27 * CPU test
28 * Load instructions: lbz(x)(u), lhz(x)(u), lha(x)(u), lwz(x)(u)
29 *
30 * All operations are performed on a 16-byte array. The array
31 * is 4-byte aligned. The base register points to offset 8.
32 * The immediate offset (index register) ranges in [-8 ... +7].
33 * The test cases are composed so that they do not
34 * cause alignment exceptions.
35 * The test contains a pre-built table describing all test cases.
36 * The table entry contains:
37 * the instruction opcode, the array contents, the value of the index
38 * register and the expected value of the destination register.
39 * After executing the instruction, the test verifies the
40 * value of the destination register and the value of the base
41 * register (it must change for "load with update" instructions).
42 */
43
44#ifdef CONFIG_POST
45
46#include <post.h>
47#include "cpu_asm.h"
48
49#if CONFIG_POST & CFG_POST_CPU
50
51extern void cpu_post_exec_22w (ulong *code, ulong *op1, ulong op2, ulong *op3);
52extern void cpu_post_exec_21w (ulong *code, ulong *op1, ulong *op2);
53
54static struct cpu_post_load_s
55{
56 ulong cmd;
57 uint width;
58 int update;
59 int index;
60 ulong offset;
61} cpu_post_load_table[] =
62{
63 {
wdenk8bde7f72003-06-27 21:31:46 +000064 OP_LWZ,
wdenka46d8212002-09-12 22:01:13 +000065 4,
66 0,
67 0,
68 4
69 },
70 {
wdenk8bde7f72003-06-27 21:31:46 +000071 OP_LHA,
wdenka46d8212002-09-12 22:01:13 +000072 3,
73 0,
74 0,
75 2
76 },
77 {
wdenk8bde7f72003-06-27 21:31:46 +000078 OP_LHZ,
wdenka46d8212002-09-12 22:01:13 +000079 2,
80 0,
81 0,
82 2
83 },
84 {
wdenk8bde7f72003-06-27 21:31:46 +000085 OP_LBZ,
wdenka46d8212002-09-12 22:01:13 +000086 1,
87 0,
88 0,
89 1
90 },
91 {
wdenk8bde7f72003-06-27 21:31:46 +000092 OP_LWZU,
wdenka46d8212002-09-12 22:01:13 +000093 4,
94 1,
95 0,
96 4
97 },
98 {
wdenk8bde7f72003-06-27 21:31:46 +000099 OP_LHAU,
wdenka46d8212002-09-12 22:01:13 +0000100 3,
101 1,
102 0,
103 2
104 },
105 {
wdenk8bde7f72003-06-27 21:31:46 +0000106 OP_LHZU,
wdenka46d8212002-09-12 22:01:13 +0000107 2,
108 1,
109 0,
110 2
111 },
112 {
wdenk8bde7f72003-06-27 21:31:46 +0000113 OP_LBZU,
wdenka46d8212002-09-12 22:01:13 +0000114 1,
115 1,
116 0,
117 1
118 },
119 {
wdenk8bde7f72003-06-27 21:31:46 +0000120 OP_LWZX,
wdenka46d8212002-09-12 22:01:13 +0000121 4,
122 0,
123 1,
124 4
125 },
126 {
wdenk8bde7f72003-06-27 21:31:46 +0000127 OP_LHAX,
wdenka46d8212002-09-12 22:01:13 +0000128 3,
129 0,
130 1,
131 2
132 },
133 {
wdenk8bde7f72003-06-27 21:31:46 +0000134 OP_LHZX,
wdenka46d8212002-09-12 22:01:13 +0000135 2,
136 0,
137 1,
138 2
139 },
140 {
wdenk8bde7f72003-06-27 21:31:46 +0000141 OP_LBZX,
wdenka46d8212002-09-12 22:01:13 +0000142 1,
143 0,
144 1,
145 1
146 },
147 {
wdenk8bde7f72003-06-27 21:31:46 +0000148 OP_LWZUX,
wdenka46d8212002-09-12 22:01:13 +0000149 4,
150 1,
151 1,
152 4
153 },
154 {
wdenk8bde7f72003-06-27 21:31:46 +0000155 OP_LHAUX,
wdenka46d8212002-09-12 22:01:13 +0000156 3,
157 1,
158 1,
159 2
160 },
161 {
wdenk8bde7f72003-06-27 21:31:46 +0000162 OP_LHZUX,
wdenka46d8212002-09-12 22:01:13 +0000163 2,
164 1,
165 1,
166 2
167 },
168 {
wdenk8bde7f72003-06-27 21:31:46 +0000169 OP_LBZUX,
wdenka46d8212002-09-12 22:01:13 +0000170 1,
171 1,
172 1,
173 1
174 },
175};
176static unsigned int cpu_post_load_size =
177 sizeof (cpu_post_load_table) / sizeof (struct cpu_post_load_s);
178
179int cpu_post_test_load (void)
180{
181 int ret = 0;
182 unsigned int i;
183
184 for (i = 0; i < cpu_post_load_size && ret == 0; i++)
185 {
186 struct cpu_post_load_s *test = cpu_post_load_table + i;
187 uchar data[16] =
188 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
wdenk8bde7f72003-06-27 21:31:46 +0000189 ulong base0 = (ulong) (data + 8);
wdenka46d8212002-09-12 22:01:13 +0000190 ulong base = base0;
191 ulong value;
192
193 if (test->index)
194 {
195 ulong code[] =
196 {
wdenk8bde7f72003-06-27 21:31:46 +0000197 ASM_12(test->cmd, 5, 3, 4),
wdenka46d8212002-09-12 22:01:13 +0000198 ASM_BLR,
199 };
200
201 cpu_post_exec_22w (code, &base, test->offset, &value);
202 }
203 else
204 {
205 ulong code[] =
206 {
wdenk8bde7f72003-06-27 21:31:46 +0000207 ASM_11I(test->cmd, 4, 3, test->offset),
wdenka46d8212002-09-12 22:01:13 +0000208 ASM_BLR,
209 };
210
211 cpu_post_exec_21w (code, &base, &value);
212 }
213
214 if (ret == 0)
215 {
216 if (test->update)
217 ret = base == base0 + test->offset ? 0 : -1;
218 else
219 ret = base == base0 ? 0 : -1;
220 }
221
222 if (ret == 0)
223 {
224 switch (test->width)
225 {
226 case 1:
wdenk8bde7f72003-06-27 21:31:46 +0000227 ret = *(uchar *)(base0 + test->offset) == value ?
wdenka46d8212002-09-12 22:01:13 +0000228 0 : -1;
wdenk8bde7f72003-06-27 21:31:46 +0000229 break;
wdenka46d8212002-09-12 22:01:13 +0000230 case 2:
wdenk8bde7f72003-06-27 21:31:46 +0000231 ret = *(ushort *)(base0 + test->offset) == value ?
wdenka46d8212002-09-12 22:01:13 +0000232 0 : -1;
wdenk8bde7f72003-06-27 21:31:46 +0000233 break;
wdenka46d8212002-09-12 22:01:13 +0000234 case 3:
wdenk8bde7f72003-06-27 21:31:46 +0000235 ret = *(short *)(base0 + test->offset) == value ?
wdenka46d8212002-09-12 22:01:13 +0000236 0 : -1;
wdenk8bde7f72003-06-27 21:31:46 +0000237 break;
wdenka46d8212002-09-12 22:01:13 +0000238 case 4:
wdenk8bde7f72003-06-27 21:31:46 +0000239 ret = *(ulong *)(base0 + test->offset) == value ?
wdenka46d8212002-09-12 22:01:13 +0000240 0 : -1;
wdenk8bde7f72003-06-27 21:31:46 +0000241 break;
wdenka46d8212002-09-12 22:01:13 +0000242 }
243 }
244
245 if (ret != 0)
246 {
wdenk8bde7f72003-06-27 21:31:46 +0000247 post_log ("Error at load test %d !\n", i);
wdenka46d8212002-09-12 22:01:13 +0000248 }
249 }
250
251 return ret;
252}
253
254#endif
255#endif