xref: /rk3399_rockchip-uboot/post/lib_powerpc/two.c (revision a47a12becf66f02a56da91c161e2edb625e9f20c)
1*a47a12beSStefan Roese /*
2*a47a12beSStefan Roese  * (C) Copyright 2002
3*a47a12beSStefan Roese  * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4*a47a12beSStefan Roese  *
5*a47a12beSStefan Roese  * See file CREDITS for list of people who contributed to this
6*a47a12beSStefan Roese  * project.
7*a47a12beSStefan Roese  *
8*a47a12beSStefan Roese  * This program is free software; you can redistribute it and/or
9*a47a12beSStefan Roese  * modify it under the terms of the GNU General Public License as
10*a47a12beSStefan Roese  * published by the Free Software Foundation; either version 2 of
11*a47a12beSStefan Roese  * the License, or (at your option) any later version.
12*a47a12beSStefan Roese  *
13*a47a12beSStefan Roese  * This program is distributed in the hope that it will be useful,
14*a47a12beSStefan Roese  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15*a47a12beSStefan Roese  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16*a47a12beSStefan Roese  * GNU General Public License for more details.
17*a47a12beSStefan Roese  *
18*a47a12beSStefan Roese  * You should have received a copy of the GNU General Public License
19*a47a12beSStefan Roese  * along with this program; if not, write to the Free Software
20*a47a12beSStefan Roese  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21*a47a12beSStefan Roese  * MA 02111-1307 USA
22*a47a12beSStefan Roese  */
23*a47a12beSStefan Roese 
24*a47a12beSStefan Roese #include <common.h>
25*a47a12beSStefan Roese 
26*a47a12beSStefan Roese /*
27*a47a12beSStefan Roese  * CPU test
28*a47a12beSStefan Roese  * Binary instructions		instr rD,rA
29*a47a12beSStefan Roese  *
30*a47a12beSStefan Roese  * Logic instructions:		neg
31*a47a12beSStefan Roese  * Arithmetic instructions:	addme, addze, subfme, subfze
32*a47a12beSStefan Roese 
33*a47a12beSStefan Roese  * The test contains a pre-built table of instructions, operands and
34*a47a12beSStefan Roese  * expected results. For each table entry, the test will cyclically use
35*a47a12beSStefan Roese  * different sets of operand registers and result registers.
36*a47a12beSStefan Roese  */
37*a47a12beSStefan Roese 
38*a47a12beSStefan Roese #include <post.h>
39*a47a12beSStefan Roese #include "cpu_asm.h"
40*a47a12beSStefan Roese 
41*a47a12beSStefan Roese #if CONFIG_POST & CONFIG_SYS_POST_CPU
42*a47a12beSStefan Roese 
43*a47a12beSStefan Roese extern void cpu_post_exec_21 (ulong *code, ulong *cr, ulong *res, ulong op1);
44*a47a12beSStefan Roese extern ulong cpu_post_makecr (long v);
45*a47a12beSStefan Roese 
46*a47a12beSStefan Roese static struct cpu_post_two_s
47*a47a12beSStefan Roese {
48*a47a12beSStefan Roese     ulong cmd;
49*a47a12beSStefan Roese     ulong op;
50*a47a12beSStefan Roese     ulong res;
51*a47a12beSStefan Roese } cpu_post_two_table[] =
52*a47a12beSStefan Roese {
53*a47a12beSStefan Roese     {
54*a47a12beSStefan Roese 	OP_NEG,
55*a47a12beSStefan Roese 	3,
56*a47a12beSStefan Roese 	-3
57*a47a12beSStefan Roese     },
58*a47a12beSStefan Roese     {
59*a47a12beSStefan Roese 	OP_NEG,
60*a47a12beSStefan Roese 	5,
61*a47a12beSStefan Roese 	-5
62*a47a12beSStefan Roese     },
63*a47a12beSStefan Roese     {
64*a47a12beSStefan Roese 	OP_ADDME,
65*a47a12beSStefan Roese 	6,
66*a47a12beSStefan Roese 	5
67*a47a12beSStefan Roese     },
68*a47a12beSStefan Roese     {
69*a47a12beSStefan Roese 	OP_ADDZE,
70*a47a12beSStefan Roese 	5,
71*a47a12beSStefan Roese 	5
72*a47a12beSStefan Roese     },
73*a47a12beSStefan Roese     {
74*a47a12beSStefan Roese 	OP_SUBFME,
75*a47a12beSStefan Roese 	6,
76*a47a12beSStefan Roese 	~6 - 1
77*a47a12beSStefan Roese     },
78*a47a12beSStefan Roese     {
79*a47a12beSStefan Roese 	OP_SUBFZE,
80*a47a12beSStefan Roese 	5,
81*a47a12beSStefan Roese 	~5
82*a47a12beSStefan Roese     },
83*a47a12beSStefan Roese };
84*a47a12beSStefan Roese static unsigned int cpu_post_two_size =
85*a47a12beSStefan Roese     sizeof (cpu_post_two_table) / sizeof (struct cpu_post_two_s);
86*a47a12beSStefan Roese 
87*a47a12beSStefan Roese int cpu_post_test_two (void)
88*a47a12beSStefan Roese {
89*a47a12beSStefan Roese     int ret = 0;
90*a47a12beSStefan Roese     unsigned int i, reg;
91*a47a12beSStefan Roese     int flag = disable_interrupts();
92*a47a12beSStefan Roese 
93*a47a12beSStefan Roese     for (i = 0; i < cpu_post_two_size && ret == 0; i++)
94*a47a12beSStefan Roese     {
95*a47a12beSStefan Roese 	struct cpu_post_two_s *test = cpu_post_two_table + i;
96*a47a12beSStefan Roese 
97*a47a12beSStefan Roese 	for (reg = 0; reg < 32 && ret == 0; reg++)
98*a47a12beSStefan Roese 	{
99*a47a12beSStefan Roese 	    unsigned int reg0 = (reg + 0) % 32;
100*a47a12beSStefan Roese 	    unsigned int reg1 = (reg + 1) % 32;
101*a47a12beSStefan Roese 	    unsigned int stk = reg < 16 ? 31 : 15;
102*a47a12beSStefan Roese 	    unsigned long code[] =
103*a47a12beSStefan Roese 	    {
104*a47a12beSStefan Roese 		ASM_STW(stk, 1, -4),
105*a47a12beSStefan Roese 		ASM_ADDI(stk, 1, -16),
106*a47a12beSStefan Roese 		ASM_STW(3, stk, 8),
107*a47a12beSStefan Roese 		ASM_STW(reg0, stk, 4),
108*a47a12beSStefan Roese 		ASM_STW(reg1, stk, 0),
109*a47a12beSStefan Roese 		ASM_LWZ(reg0, stk, 8),
110*a47a12beSStefan Roese 		ASM_11(test->cmd, reg1, reg0),
111*a47a12beSStefan Roese 		ASM_STW(reg1, stk, 8),
112*a47a12beSStefan Roese 		ASM_LWZ(reg1, stk, 0),
113*a47a12beSStefan Roese 		ASM_LWZ(reg0, stk, 4),
114*a47a12beSStefan Roese 		ASM_LWZ(3, stk, 8),
115*a47a12beSStefan Roese 		ASM_ADDI(1, stk, 16),
116*a47a12beSStefan Roese 		ASM_LWZ(stk, 1, -4),
117*a47a12beSStefan Roese 		ASM_BLR,
118*a47a12beSStefan Roese 	    };
119*a47a12beSStefan Roese 	    unsigned long codecr[] =
120*a47a12beSStefan Roese 	    {
121*a47a12beSStefan Roese 		ASM_STW(stk, 1, -4),
122*a47a12beSStefan Roese 		ASM_ADDI(stk, 1, -16),
123*a47a12beSStefan Roese 		ASM_STW(3, stk, 8),
124*a47a12beSStefan Roese 		ASM_STW(reg0, stk, 4),
125*a47a12beSStefan Roese 		ASM_STW(reg1, stk, 0),
126*a47a12beSStefan Roese 		ASM_LWZ(reg0, stk, 8),
127*a47a12beSStefan Roese 		ASM_11(test->cmd, reg1, reg0) | BIT_C,
128*a47a12beSStefan Roese 		ASM_STW(reg1, stk, 8),
129*a47a12beSStefan Roese 		ASM_LWZ(reg1, stk, 0),
130*a47a12beSStefan Roese 		ASM_LWZ(reg0, stk, 4),
131*a47a12beSStefan Roese 		ASM_LWZ(3, stk, 8),
132*a47a12beSStefan Roese 		ASM_ADDI(1, stk, 16),
133*a47a12beSStefan Roese 		ASM_LWZ(stk, 1, -4),
134*a47a12beSStefan Roese 		ASM_BLR,
135*a47a12beSStefan Roese 	    };
136*a47a12beSStefan Roese 	    ulong res;
137*a47a12beSStefan Roese 	    ulong cr;
138*a47a12beSStefan Roese 
139*a47a12beSStefan Roese 	    if (ret == 0)
140*a47a12beSStefan Roese 	    {
141*a47a12beSStefan Roese 		cr = 0;
142*a47a12beSStefan Roese 		cpu_post_exec_21 (code, & cr, & res, test->op);
143*a47a12beSStefan Roese 
144*a47a12beSStefan Roese 		ret = res == test->res && cr == 0 ? 0 : -1;
145*a47a12beSStefan Roese 
146*a47a12beSStefan Roese 		if (ret != 0)
147*a47a12beSStefan Roese 		{
148*a47a12beSStefan Roese 		    post_log ("Error at two test %d !\n", i);
149*a47a12beSStefan Roese 		}
150*a47a12beSStefan Roese 	    }
151*a47a12beSStefan Roese 
152*a47a12beSStefan Roese 	    if (ret == 0)
153*a47a12beSStefan Roese 	    {
154*a47a12beSStefan Roese 		cpu_post_exec_21 (codecr, & cr, & res, test->op);
155*a47a12beSStefan Roese 
156*a47a12beSStefan Roese 		ret = res == test->res &&
157*a47a12beSStefan Roese 		      (cr & 0xe0000000) == cpu_post_makecr (res) ? 0 : -1;
158*a47a12beSStefan Roese 
159*a47a12beSStefan Roese 		if (ret != 0)
160*a47a12beSStefan Roese 		{
161*a47a12beSStefan Roese 		    post_log ("Error at two test %d !\n", i);
162*a47a12beSStefan Roese 		}
163*a47a12beSStefan Roese 	    }
164*a47a12beSStefan Roese 	}
165*a47a12beSStefan Roese     }
166*a47a12beSStefan Roese 
167*a47a12beSStefan Roese     if (flag)
168*a47a12beSStefan Roese 	enable_interrupts();
169*a47a12beSStefan Roese 
170*a47a12beSStefan Roese     return ret;
171*a47a12beSStefan Roese }
172*a47a12beSStefan Roese 
173*a47a12beSStefan Roese #endif
174