1 // SPDX-License-Identifier: GPL-2.0+
4 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
11 * Branch instructions: b, bl, bc
13 * The first 2 instructions (b, bl) are verified by jumping
14 * to a fixed address and checking whether control was transferred
15 * to that very point. For the bl instruction the value of the
16 * link register is checked as well (using mfspr).
17 * To verify the bc instruction various combinations of the BI/BO
18 * fields, the CTR and the condition register values are
19 * checked. The list of such combinations is pre-built and
20 * linked in U-Boot at build time.
26 #if CONFIG_POST & CONFIG_SYS_POST_CPU
28 extern void cpu_post_exec_11 (ulong *code, ulong *res, ulong op1);
29 extern void cpu_post_exec_31 (ulong *code, ulong *ctr, ulong *lr, ulong *jump,
32 static int cpu_post_test_bc (ulong cmd, ulong bo, ulong bi,
33 int pjump, int decr, int link, ulong pctr, ulong cr)
40 unsigned long code[] =
47 ASM_3O(cmd, bo, bi, 8),
55 cpu_post_exec_31 (code, &ctr, &lr, &jump, cr);
58 ret = pjump == jump ? 0 : -1;
62 ret = pctr == ctr + 1 ? 0 : -1;
64 ret = pctr == ctr ? 0 : -1;
69 ret = lr == (ulong) code + 24 ? 0 : -1;
71 ret = lr == 0 ? 0 : -1;
77 int cpu_post_test_b (void)
81 int flag = disable_interrupts();
96 cpu_post_exec_11 (code, &res, 0);
98 ret = res == 0 ? 0 : -1;
102 post_log ("Error at b1 test !\n");
119 cpu_post_exec_11 (code, &res, 0);
121 ret = res == (ulong)code + 12 ? 0 : -1;
125 post_log ("Error at b2 test !\n");
138 for (cc = 0; cc < 4 && ret == 0; cc++)
140 for (cd = 0; cd < 4 && ret == 0; cd++)
142 for (link = 0; link <= 1 && ret == 0; link++)
144 for (cond = 0; cond <= 1 && ret == 0; cond++)
146 for (ctr = 1; ctr <= 2 && ret == 0; ctr++)
149 int cr = cond ? 0x80000000 : 0x00000000;
150 int jumpc = cc >= 2 ||
151 (cc == 0 && !cond) ||
153 int jumpd = cd >= 2 ||
154 (cd == 0 && ctr != 1) ||
155 (cd == 1 && ctr == 1);
156 int jump = jumpc && jumpd;
158 ret = cpu_post_test_bc (link ? OP_BCL : OP_BC,
159 (cc << 3) + (cd << 1), 0, jump, decr, link,
164 post_log ("Error at b3 test %d !\n", i);