blob: 16e642238e15f08e7aad9438ea2d50c900dbf7c2 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Wolfgang Denkad5bb452007-03-06 18:08:43 +01002/*
3 * (C) Copyright 2002
4 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
Wolfgang Denkad5bb452007-03-06 18:08:43 +01005 */
6
7#include <common.h>
8
9/*
10 * CPU test
11 * Shift instructions: rlwimi
12 *
13 * The test contains a pre-built table of instructions, operands and
14 * expected results. For each table entry, the test will cyclically use
15 * different sets of operand registers and result registers.
16 */
17
Wolfgang Denkad5bb452007-03-06 18:08:43 +010018#include <post.h>
19#include "cpu_asm.h"
20
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020021#if CONFIG_POST & CONFIG_SYS_POST_CPU
Wolfgang Denkad5bb452007-03-06 18:08:43 +010022
23extern void cpu_post_exec_22 (ulong *code, ulong *cr, ulong *res, ulong op1,
24 ulong op2);
25extern ulong cpu_post_makecr (long v);
26
27static struct cpu_post_rlwimi_s
28{
29 ulong cmd;
30 ulong op0;
31 ulong op1;
32 uchar op2;
33 uchar mb;
34 uchar me;
35 ulong res;
36} cpu_post_rlwimi_table[] =
37{
38 {
Wolfgang Denk53677ef2008-05-20 16:00:29 +020039 OP_RLWIMI,
Wolfgang Denkad5bb452007-03-06 18:08:43 +010040 0xff00ffff,
41 0x0000aa00,
42 8,
43 8,
44 15,
45 0xffaaffff
46 },
47};
Mike Frysingerd2397812011-05-10 07:28:35 +000048static unsigned int cpu_post_rlwimi_size = ARRAY_SIZE(cpu_post_rlwimi_table);
Wolfgang Denkad5bb452007-03-06 18:08:43 +010049
50int cpu_post_test_rlwimi (void)
51{
52 int ret = 0;
53 unsigned int i, reg;
54 int flag = disable_interrupts();
55
56 for (i = 0; i < cpu_post_rlwimi_size && ret == 0; i++)
57 {
58 struct cpu_post_rlwimi_s *test = cpu_post_rlwimi_table + i;
59
60 for (reg = 0; reg < 32 && ret == 0; reg++)
61 {
62 unsigned int reg0 = (reg + 0) % 32;
63 unsigned int reg1 = (reg + 1) % 32;
64 unsigned int stk = reg < 16 ? 31 : 15;
Wolfgang Denk53677ef2008-05-20 16:00:29 +020065 unsigned long code[] =
Wolfgang Denkad5bb452007-03-06 18:08:43 +010066 {
67 ASM_STW(stk, 1, -4),
68 ASM_ADDI(stk, 1, -20),
69 ASM_STW(3, stk, 8),
70 ASM_STW(4, stk, 12),
71 ASM_STW(reg0, stk, 4),
72 ASM_STW(reg1, stk, 0),
73 ASM_LWZ(reg1, stk, 8),
74 ASM_LWZ(reg0, stk, 12),
75 ASM_113(test->cmd, reg1, reg0, test->op2, test->mb, test->me),
76 ASM_STW(reg1, stk, 8),
77 ASM_LWZ(reg1, stk, 0),
78 ASM_LWZ(reg0, stk, 4),
79 ASM_LWZ(3, stk, 8),
80 ASM_ADDI(1, stk, 20),
81 ASM_LWZ(stk, 1, -4),
82 ASM_BLR,
83 };
Wolfgang Denk53677ef2008-05-20 16:00:29 +020084 unsigned long codecr[] =
Wolfgang Denkad5bb452007-03-06 18:08:43 +010085 {
86 ASM_STW(stk, 1, -4),
87 ASM_ADDI(stk, 1, -20),
88 ASM_STW(3, stk, 8),
89 ASM_STW(4, stk, 12),
90 ASM_STW(reg0, stk, 4),
91 ASM_STW(reg1, stk, 0),
92 ASM_LWZ(reg1, stk, 8),
93 ASM_LWZ(reg0, stk, 12),
94 ASM_113(test->cmd, reg1, reg0, test->op2, test->mb, test->me) |
95 BIT_C,
96 ASM_STW(reg1, stk, 8),
97 ASM_LWZ(reg1, stk, 0),
98 ASM_LWZ(reg0, stk, 4),
99 ASM_LWZ(3, stk, 8),
100 ASM_ADDI(1, stk, 20),
101 ASM_LWZ(stk, 1, -4),
102 ASM_BLR,
103 };
104 ulong res;
105 ulong cr;
106
107 if (ret == 0)
108 {
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200109 cr = 0;
110 cpu_post_exec_22 (code, & cr, & res, test->op0, test->op1);
Wolfgang Denkad5bb452007-03-06 18:08:43 +0100111
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200112 ret = res == test->res && cr == 0 ? 0 : -1;
Wolfgang Denkad5bb452007-03-06 18:08:43 +0100113
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200114 if (ret != 0)
115 {
Wolfgang Denk93e14592013-10-04 17:43:24 +0200116 post_log ("Error at rlwimi test %d !\n", i);
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200117 }
Wolfgang Denkad5bb452007-03-06 18:08:43 +0100118 }
119
120 if (ret == 0)
121 {
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200122 cpu_post_exec_22 (codecr, & cr, & res, test->op0, test->op1);
Wolfgang Denkad5bb452007-03-06 18:08:43 +0100123
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200124 ret = res == test->res &&
Wolfgang Denkad5bb452007-03-06 18:08:43 +0100125 (cr & 0xe0000000) == cpu_post_makecr (res) ? 0 : -1;
126
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200127 if (ret != 0)
128 {
Wolfgang Denk93e14592013-10-04 17:43:24 +0200129 post_log ("Error at rlwimi test %d !\n", i);
130 }
Wolfgang Denkad5bb452007-03-06 18:08:43 +0100131 }
132 }
133 }
134
135 if (flag)
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200136 enable_interrupts();
Wolfgang Denkad5bb452007-03-06 18:08:43 +0100137
138 return ret;
139}
140
141#endif