3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 * SPDX-License-Identifier: GPL-2.0+
12 * Branch instructions: b, bl, bc
14 * The first 2 instructions (b, bl) are verified by jumping
15 * to a fixed address and checking whether control was transfered
16 * to that very point. For the bl instruction the value of the
17 * link register is checked as well (using mfspr).
18 * To verify the bc instruction various combinations of the BI/BO
19 * fields, the CTR and the condition register values are
20 * checked. The list of such combinations is pre-built and
21 * linked in U-Boot at build time.
27 #if CONFIG_POST & CONFIG_SYS_POST_CPU
29 extern void cpu_post_exec_11 (ulong *code, ulong *res, ulong op1);
30 extern void cpu_post_exec_31 (ulong *code, ulong *ctr, ulong *lr, ulong *jump,
33 static int cpu_post_test_bc (ulong cmd, ulong bo, ulong bi,
34 int pjump, int decr, int link, ulong pctr, ulong cr)
41 unsigned long code[] =
48 ASM_3O(cmd, bo, bi, 8),
56 cpu_post_exec_31 (code, &ctr, &lr, &jump, cr);
59 ret = pjump == jump ? 0 : -1;
63 ret = pctr == ctr + 1 ? 0 : -1;
65 ret = pctr == ctr ? 0 : -1;
70 ret = lr == (ulong) code + 24 ? 0 : -1;
72 ret = lr == 0 ? 0 : -1;
78 int cpu_post_test_b (void)
82 int flag = disable_interrupts();
97 cpu_post_exec_11 (code, &res, 0);
99 ret = res == 0 ? 0 : -1;
103 post_log ("Error at b1 test !\n");
120 cpu_post_exec_11 (code, &res, 0);
122 ret = res == (ulong)code + 12 ? 0 : -1;
126 post_log ("Error at b2 test !\n");
139 for (cc = 0; cc < 4 && ret == 0; cc++)
141 for (cd = 0; cd < 4 && ret == 0; cd++)
143 for (link = 0; link <= 1 && ret == 0; link++)
145 for (cond = 0; cond <= 1 && ret == 0; cond++)
147 for (ctr = 1; ctr <= 2 && ret == 0; ctr++)
150 int cr = cond ? 0x80000000 : 0x00000000;
151 int jumpc = cc >= 2 ||
152 (cc == 0 && !cond) ||
154 int jumpd = cd >= 2 ||
155 (cd == 0 && ctr != 1) ||
156 (cd == 1 && ctr == 1);
157 int jump = jumpc && jumpd;
159 ret = cpu_post_test_bc (link ? OP_BCL : OP_BC,
160 (cc << 3) + (cd << 1), 0, jump, decr, link,
165 post_log ("Error at b3 test %d !\n", i);