xref: /openbmc/u-boot/post/lib_powerpc/cmpi.c (revision fabbeb33)
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * (C) Copyright 2002
4  * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5  */
6 
7 #include <common.h>
8 
9 /*
10  * CPU test
11  * Integer compare instructions:	cmpwi, cmplwi
12  *
13  * To verify these instructions the test runs them with
14  * different combinations of operands, reads the condition
15  * register value and compares it with the expected one.
16  * The test contains a pre-built table
17  * containing the description of each test case: the instruction,
18  * the values of the operands, the condition field to save
19  * the result in and the expected result.
20  */
21 
22 #include <post.h>
23 #include "cpu_asm.h"
24 
25 #if CONFIG_POST & CONFIG_SYS_POST_CPU
26 
27 extern void cpu_post_exec_11 (ulong *code, ulong *res, ulong op1);
28 
29 static struct cpu_post_cmpi_s
30 {
31     ulong cmd;
32     ulong op1;
33     ushort op2;
34     ulong cr;
35     ulong res;
36 } cpu_post_cmpi_table[] =
37 {
38     {
39 	OP_CMPWI,
40 	123,
41 	123,
42 	2,
43 	0x02
44     },
45     {
46 	OP_CMPWI,
47 	123,
48 	133,
49 	3,
50 	0x08
51     },
52     {
53 	OP_CMPWI,
54 	123,
55 	-133,
56 	4,
57 	0x04
58     },
59     {
60 	OP_CMPLWI,
61 	123,
62 	123,
63 	2,
64 	0x02
65     },
66     {
67 	OP_CMPLWI,
68 	123,
69 	-133,
70 	3,
71 	0x08
72     },
73     {
74 	OP_CMPLWI,
75 	123,
76 	113,
77 	4,
78 	0x04
79     },
80 };
81 static unsigned int cpu_post_cmpi_size = ARRAY_SIZE(cpu_post_cmpi_table);
82 
83 int cpu_post_test_cmpi (void)
84 {
85     int ret = 0;
86     unsigned int i;
87     int flag = disable_interrupts();
88 
89     for (i = 0; i < cpu_post_cmpi_size && ret == 0; i++)
90     {
91 	struct cpu_post_cmpi_s *test = cpu_post_cmpi_table + i;
92 	unsigned long code[] =
93 	{
94 	    ASM_1IC(test->cmd, test->cr, 3, test->op2),
95 	    ASM_MFCR(3),
96 	    ASM_BLR
97 	};
98 	ulong res;
99 
100 	cpu_post_exec_11 (code, & res, test->op1);
101 
102 	ret = ((res >> (28 - 4 * test->cr)) & 0xe) == test->res ? 0 : -1;
103 
104 	if (ret != 0)
105 	{
106 	    post_log ("Error at cmpi test %d !\n", i);
107 	}
108     }
109 
110     if (flag)
111 	enable_interrupts();
112 
113     return ret;
114 }
115 
116 #endif
117