3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 * SPDX-License-Identifier: GPL-2.0+
12 * Condition register istructions: mtcr, mfcr, mcrxr,
13 * crand, crandc, cror, crorc, crxor,
14 * crnand, crnor, creqv, mcrf
16 * The mtcrf/mfcr instructions is tested by loading different
17 * values into the condition register (mtcrf), moving its value
18 * to a general-purpose register (mfcr) and comparing this value
19 * with the expected one.
20 * The mcrxr instruction is tested by loading a fixed value
21 * into the XER register (mtspr), moving XER value to the
22 * condition register (mcrxr), moving it to a general-purpose
23 * register (mfcr) and comparing the value of this register with
25 * The rest of instructions is tested by loading a fixed
26 * value into the condition register (mtcrf), executing each
27 * instruction several times to modify all 4-bit condition
28 * fields, moving the value of the conditional register to a
29 * general-purpose register (mfcr) and comparing it with the
36 #if CONFIG_POST & CONFIG_SYS_POST_CPU
38 extern void cpu_post_exec_11 (ulong *code, ulong *res, ulong op1);
39 extern void cpu_post_exec_21x (ulong *code, ulong *op1, ulong *op2, ulong op3);
41 static ulong cpu_post_cr_table1[] =
46 static unsigned int cpu_post_cr_size1 = ARRAY_SIZE(cpu_post_cr_table1);
48 static struct cpu_post_cr_s2 {
51 } cpu_post_cr_table2[] =
62 static unsigned int cpu_post_cr_size2 = ARRAY_SIZE(cpu_post_cr_table2);
64 static struct cpu_post_cr_s3 {
69 } cpu_post_cr_table3[] =
84 static unsigned int cpu_post_cr_size3 = ARRAY_SIZE(cpu_post_cr_table3);
86 static struct cpu_post_cr_s4 {
93 } cpu_post_cr_table4[] =
224 static unsigned int cpu_post_cr_size4 = ARRAY_SIZE(cpu_post_cr_table4);
226 int cpu_post_test_cr (void)
230 unsigned long cr_sav;
231 int flag = disable_interrupts();
233 asm ( "mfcr %0" : "=r" (cr_sav) : );
235 for (i = 0; i < cpu_post_cr_size1 && ret == 0; i++)
237 ulong cr = cpu_post_cr_table1[i];
240 unsigned long code[] =
247 cpu_post_exec_11 (code, &res, cr);
249 ret = res == cr ? 0 : -1;
253 post_log ("Error at cr1 test %d !\n", i);
257 for (i = 0; i < cpu_post_cr_size2 && ret == 0; i++)
259 struct cpu_post_cr_s2 *test = cpu_post_cr_table2 + i;
263 unsigned long code[] =
272 cpu_post_exec_21x (code, &res, &xer, test->xer);
274 ret = xer == 0 && ((res << (4 * test->cr)) & 0xe0000000) == test->xer ?
279 post_log ("Error at cr2 test %d !\n", i);
283 for (i = 0; i < cpu_post_cr_size3 && ret == 0; i++)
285 struct cpu_post_cr_s3 *test = cpu_post_cr_table3 + i;
288 unsigned long code[] =
291 ASM_MCRF(test->cd, test->cs),
296 cpu_post_exec_11 (code, &res, test->cr);
298 ret = res == test->res ? 0 : -1;
302 post_log ("Error at cr3 test %d !\n", i);
306 for (i = 0; i < cpu_post_cr_size4 && ret == 0; i++)
308 struct cpu_post_cr_s4 *test = cpu_post_cr_table4 + i;
311 unsigned long code[] =
314 ASM_12F(test->cmd, test->op3, test->op1, test->op2),
319 cpu_post_exec_11 (code, &res, test->cr);
321 ret = res == test->res ? 0 : -1;
325 post_log ("Error at cr4 test %d !\n", i);
329 asm ( "mtcr %0" : : "r" (cr_sav));