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