blob: ce1edf89db5a9394bf955f170f2ecbd45b5be886 [file] [log] [blame]
Wolfgang Denkb38e0df2007-03-06 18:08:43 +01001/*
2 * (C) Copyright 2002
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
Wolfgang Denkb38e0df2007-03-06 18:08:43 +01006 */
7
8#include <common.h>
9
10/*
11 * CPU test
12 * Ternary instructions instr rA,rS,rB
13 *
14 * Logic instructions: or, orc, xor, nand, nor, eqv
15 * Shift instructions: slw, srw, sraw
16 *
17 * The test contains a pre-built table of instructions, operands and
18 * expected results. For each table entry, the test will cyclically use
19 * different sets of operand registers and result registers.
20 */
21
Wolfgang Denkb38e0df2007-03-06 18:08:43 +010022#include <post.h>
23#include "cpu_asm.h"
24
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020025#if CONFIG_POST & CONFIG_SYS_POST_CPU
Wolfgang Denkb38e0df2007-03-06 18:08:43 +010026
27extern void cpu_post_exec_22 (ulong *code, ulong *cr, ulong *res, ulong op1,
28 ulong op2);
29extern ulong cpu_post_makecr (long v);
30
31static struct cpu_post_threex_s
32{
33 ulong cmd;
34 ulong op1;
35 ulong op2;
36 ulong res;
37} cpu_post_threex_table[] =
38{
39 {
Wolfgang Denka1be4762008-05-20 16:00:29 +020040 OP_OR,
Wolfgang Denkb38e0df2007-03-06 18:08:43 +010041 0x1234,
42 0x5678,
43 0x1234 | 0x5678
44 },
45 {
Wolfgang Denka1be4762008-05-20 16:00:29 +020046 OP_ORC,
Wolfgang Denkb38e0df2007-03-06 18:08:43 +010047 0x1234,
48 0x5678,
49 0x1234 | ~0x5678
50 },
51 {
Wolfgang Denka1be4762008-05-20 16:00:29 +020052 OP_XOR,
Wolfgang Denkb38e0df2007-03-06 18:08:43 +010053 0x1234,
54 0x5678,
55 0x1234 ^ 0x5678
56 },
57 {
Wolfgang Denka1be4762008-05-20 16:00:29 +020058 OP_NAND,
Wolfgang Denkb38e0df2007-03-06 18:08:43 +010059 0x1234,
60 0x5678,
61 ~(0x1234 & 0x5678)
62 },
63 {
Wolfgang Denka1be4762008-05-20 16:00:29 +020064 OP_NOR,
Wolfgang Denkb38e0df2007-03-06 18:08:43 +010065 0x1234,
66 0x5678,
67 ~(0x1234 | 0x5678)
68 },
69 {
Wolfgang Denka1be4762008-05-20 16:00:29 +020070 OP_EQV,
Wolfgang Denkb38e0df2007-03-06 18:08:43 +010071 0x1234,
72 0x5678,
73 ~(0x1234 ^ 0x5678)
74 },
75 {
Wolfgang Denka1be4762008-05-20 16:00:29 +020076 OP_SLW,
Wolfgang Denkb38e0df2007-03-06 18:08:43 +010077 0x80,
78 16,
79 0x800000
80 },
81 {
Wolfgang Denka1be4762008-05-20 16:00:29 +020082 OP_SLW,
Wolfgang Denkb38e0df2007-03-06 18:08:43 +010083 0x80,
84 32,
85 0
86 },
87 {
Wolfgang Denka1be4762008-05-20 16:00:29 +020088 OP_SRW,
Wolfgang Denkb38e0df2007-03-06 18:08:43 +010089 0x800000,
90 16,
91 0x80
92 },
93 {
Wolfgang Denka1be4762008-05-20 16:00:29 +020094 OP_SRW,
Wolfgang Denkb38e0df2007-03-06 18:08:43 +010095 0x800000,
96 32,
97 0
98 },
99 {
Wolfgang Denka1be4762008-05-20 16:00:29 +0200100 OP_SRAW,
Wolfgang Denkb38e0df2007-03-06 18:08:43 +0100101 0x80000000,
102 3,
103 0xf0000000
104 },
105 {
Wolfgang Denka1be4762008-05-20 16:00:29 +0200106 OP_SRAW,
Wolfgang Denkb38e0df2007-03-06 18:08:43 +0100107 0x8000,
108 3,
109 0x1000
110 },
111};
Mike Frysinger83a687b2011-05-10 07:28:35 +0000112static unsigned int cpu_post_threex_size = ARRAY_SIZE(cpu_post_threex_table);
Wolfgang Denkb38e0df2007-03-06 18:08:43 +0100113
114int cpu_post_test_threex (void)
115{
116 int ret = 0;
117 unsigned int i, reg;
118 int flag = disable_interrupts();
119
120 for (i = 0; i < cpu_post_threex_size && ret == 0; i++)
121 {
122 struct cpu_post_threex_s *test = cpu_post_threex_table + i;
123
124 for (reg = 0; reg < 32 && ret == 0; reg++)
125 {
126 unsigned int reg0 = (reg + 0) % 32;
127 unsigned int reg1 = (reg + 1) % 32;
128 unsigned int reg2 = (reg + 2) % 32;
129 unsigned int stk = reg < 16 ? 31 : 15;
Wolfgang Denka1be4762008-05-20 16:00:29 +0200130 unsigned long code[] =
Wolfgang Denkb38e0df2007-03-06 18:08:43 +0100131 {
132 ASM_STW(stk, 1, -4),
133 ASM_ADDI(stk, 1, -24),
134 ASM_STW(3, stk, 12),
135 ASM_STW(4, stk, 16),
136 ASM_STW(reg0, stk, 8),
137 ASM_STW(reg1, stk, 4),
138 ASM_STW(reg2, stk, 0),
139 ASM_LWZ(reg1, stk, 12),
140 ASM_LWZ(reg0, stk, 16),
141 ASM_12X(test->cmd, reg2, reg1, reg0),
142 ASM_STW(reg2, stk, 12),
143 ASM_LWZ(reg2, stk, 0),
144 ASM_LWZ(reg1, stk, 4),
145 ASM_LWZ(reg0, stk, 8),
146 ASM_LWZ(3, stk, 12),
147 ASM_ADDI(1, stk, 24),
148 ASM_LWZ(stk, 1, -4),
149 ASM_BLR,
150 };
Wolfgang Denka1be4762008-05-20 16:00:29 +0200151 unsigned long codecr[] =
Wolfgang Denkb38e0df2007-03-06 18:08:43 +0100152 {
153 ASM_STW(stk, 1, -4),
154 ASM_ADDI(stk, 1, -24),
155 ASM_STW(3, stk, 12),
156 ASM_STW(4, stk, 16),
157 ASM_STW(reg0, stk, 8),
158 ASM_STW(reg1, stk, 4),
159 ASM_STW(reg2, stk, 0),
160 ASM_LWZ(reg1, stk, 12),
161 ASM_LWZ(reg0, stk, 16),
162 ASM_12X(test->cmd, reg2, reg1, reg0) | BIT_C,
163 ASM_STW(reg2, stk, 12),
164 ASM_LWZ(reg2, stk, 0),
165 ASM_LWZ(reg1, stk, 4),
166 ASM_LWZ(reg0, stk, 8),
167 ASM_LWZ(3, stk, 12),
168 ASM_ADDI(1, stk, 24),
169 ASM_LWZ(stk, 1, -4),
170 ASM_BLR,
171 };
172 ulong res;
173 ulong cr;
174
175 if (ret == 0)
176 {
Wolfgang Denka1be4762008-05-20 16:00:29 +0200177 cr = 0;
178 cpu_post_exec_22 (code, & cr, & res, test->op1, test->op2);
Wolfgang Denkb38e0df2007-03-06 18:08:43 +0100179
Wolfgang Denka1be4762008-05-20 16:00:29 +0200180 ret = res == test->res && cr == 0 ? 0 : -1;
Wolfgang Denkb38e0df2007-03-06 18:08:43 +0100181
Wolfgang Denka1be4762008-05-20 16:00:29 +0200182 if (ret != 0)
183 {
Wolfgang Denkec7fbf52013-10-04 17:43:24 +0200184 post_log ("Error at threex test %d !\n", i);
Wolfgang Denka1be4762008-05-20 16:00:29 +0200185 }
Wolfgang Denkb38e0df2007-03-06 18:08:43 +0100186 }
187
188 if (ret == 0)
189 {
Wolfgang Denka1be4762008-05-20 16:00:29 +0200190 cpu_post_exec_22 (codecr, & cr, & res, test->op1, test->op2);
Wolfgang Denkb38e0df2007-03-06 18:08:43 +0100191
Wolfgang Denka1be4762008-05-20 16:00:29 +0200192 ret = res == test->res &&
Wolfgang Denkb38e0df2007-03-06 18:08:43 +0100193 (cr & 0xe0000000) == cpu_post_makecr (res) ? 0 : -1;
194
Wolfgang Denka1be4762008-05-20 16:00:29 +0200195 if (ret != 0)
196 {
Wolfgang Denkec7fbf52013-10-04 17:43:24 +0200197 post_log ("Error at threex test %d !\n", i);
198 }
Wolfgang Denkb38e0df2007-03-06 18:08:43 +0100199 }
200 }
201 }
202
203 if (flag)
Wolfgang Denka1be4762008-05-20 16:00:29 +0200204 enable_interrupts();
Wolfgang Denkb38e0df2007-03-06 18:08:43 +0100205
206 return ret;
207}
208
209#endif