nand_skip_bad.patch
[u-boot-openmoko/mini2440.git] / post / lib_ppc / three.c
blobc2d7476047f67c23784a9ef364222ae9b2681db3
1 /*
2 * (C) Copyright 2002
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 * See file CREDITS for list of people who contributed to this
6 * project.
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21 * MA 02111-1307 USA
24 #include <common.h>
27 * CPU test
28 * Ternary instructions instr rD,rA,rB
30 * Arithmetic instructions: add, addc, adde, subf, subfc, subfe,
31 * mullw, mulhw, mulhwu, divw, divwu
33 * The test contains a pre-built table of instructions, operands and
34 * expected results. For each table entry, the test will cyclically use
35 * different sets of operand registers and result registers.
38 #ifdef CONFIG_POST
40 #include <post.h>
41 #include "cpu_asm.h"
43 #if CONFIG_POST & CFG_POST_CPU
45 extern void cpu_post_exec_22 (ulong *code, ulong *cr, ulong *res, ulong op1,
46 ulong op2);
47 extern ulong cpu_post_makecr (long v);
49 static struct cpu_post_three_s
51 ulong cmd;
52 ulong op1;
53 ulong op2;
54 ulong res;
55 } cpu_post_three_table[] =
58 OP_ADD,
59 100,
60 200,
61 300
64 OP_ADD,
65 100,
66 -200,
67 -100
70 OP_ADDC,
71 100,
72 200,
73 300
76 OP_ADDC,
77 100,
78 -200,
79 -100
82 OP_ADDE,
83 100,
84 200,
85 300
88 OP_ADDE,
89 100,
90 -200,
91 -100
94 OP_SUBF,
95 100,
96 200,
97 100
100 OP_SUBF,
101 300,
102 200,
103 -100
106 OP_SUBFC,
107 100,
108 200,
112 OP_SUBFC,
113 300,
114 200,
115 -100
118 OP_SUBFE,
119 100,
120 200,
121 200 + ~100
124 OP_SUBFE,
125 300,
126 200,
127 200 + ~300
130 OP_MULLW,
131 200,
132 300,
133 200 * 300
136 OP_MULHW,
137 0x10000000,
138 0x10000000,
139 0x1000000
142 OP_MULHWU,
143 0x80000000,
144 0x80000000,
145 0x40000000
148 OP_DIVW,
149 -20,
154 OP_DIVWU,
155 0x8000,
156 0x200,
157 0x40
160 static unsigned int cpu_post_three_size =
161 sizeof (cpu_post_three_table) / sizeof (struct cpu_post_three_s);
163 int cpu_post_test_three (void)
165 int ret = 0;
166 unsigned int i, reg;
167 int flag = disable_interrupts();
169 for (i = 0; i < cpu_post_three_size && ret == 0; i++)
171 struct cpu_post_three_s *test = cpu_post_three_table + i;
173 for (reg = 0; reg < 32 && ret == 0; reg++)
175 unsigned int reg0 = (reg + 0) % 32;
176 unsigned int reg1 = (reg + 1) % 32;
177 unsigned int reg2 = (reg + 2) % 32;
178 unsigned int stk = reg < 16 ? 31 : 15;
179 unsigned long code[] =
181 ASM_STW(stk, 1, -4),
182 ASM_ADDI(stk, 1, -24),
183 ASM_STW(3, stk, 12),
184 ASM_STW(4, stk, 16),
185 ASM_STW(reg0, stk, 8),
186 ASM_STW(reg1, stk, 4),
187 ASM_STW(reg2, stk, 0),
188 ASM_LWZ(reg1, stk, 12),
189 ASM_LWZ(reg0, stk, 16),
190 ASM_12(test->cmd, reg2, reg1, reg0),
191 ASM_STW(reg2, stk, 12),
192 ASM_LWZ(reg2, stk, 0),
193 ASM_LWZ(reg1, stk, 4),
194 ASM_LWZ(reg0, stk, 8),
195 ASM_LWZ(3, stk, 12),
196 ASM_ADDI(1, stk, 24),
197 ASM_LWZ(stk, 1, -4),
198 ASM_BLR,
200 unsigned long codecr[] =
202 ASM_STW(stk, 1, -4),
203 ASM_ADDI(stk, 1, -24),
204 ASM_STW(3, stk, 12),
205 ASM_STW(4, stk, 16),
206 ASM_STW(reg0, stk, 8),
207 ASM_STW(reg1, stk, 4),
208 ASM_STW(reg2, stk, 0),
209 ASM_LWZ(reg1, stk, 12),
210 ASM_LWZ(reg0, stk, 16),
211 ASM_12(test->cmd, reg2, reg1, reg0) | BIT_C,
212 ASM_STW(reg2, stk, 12),
213 ASM_LWZ(reg2, stk, 0),
214 ASM_LWZ(reg1, stk, 4),
215 ASM_LWZ(reg0, stk, 8),
216 ASM_LWZ(3, stk, 12),
217 ASM_ADDI(1, stk, 24),
218 ASM_LWZ(stk, 1, -4),
219 ASM_BLR,
221 ulong res;
222 ulong cr;
224 if (ret == 0)
226 cr = 0;
227 cpu_post_exec_22 (code, & cr, & res, test->op1, test->op2);
229 ret = res == test->res && cr == 0 ? 0 : -1;
231 if (ret != 0)
233 post_log ("Error at three test %d !\n", i);
237 if (ret == 0)
239 cpu_post_exec_22 (codecr, & cr, & res, test->op1, test->op2);
241 ret = res == test->res &&
242 (cr & 0xe0000000) == cpu_post_makecr (res) ? 0 : -1;
244 if (ret != 0)
246 post_log ("Error at three test %d !\n", i);
252 if (flag)
253 enable_interrupts();
255 return ret;
258 #endif
259 #endif