blob: b5b47bafb274438d73dc62bc8f856ecfbf0b9529 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Wolfgang Denkad5bb452007-03-06 18:08:43 +01002/*
3 * (C) Copyright 2002
4 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
Wolfgang Denkad5bb452007-03-06 18:08:43 +01005 */
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
Wolfgang Denkad5bb452007-03-06 18:08:43 +010022#include <post.h>
23#include "cpu_asm.h"
24
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020025#if CONFIG_POST & CONFIG_SYS_POST_CPU
Wolfgang Denkad5bb452007-03-06 18:08:43 +010026
27extern void cpu_post_exec_11 (ulong *code, ulong *res, ulong op1);
28
29static 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};
Mike Frysingerd2397812011-05-10 07:28:35 +000081static unsigned int cpu_post_cmpi_size = ARRAY_SIZE(cpu_post_cmpi_table);
Wolfgang Denkad5bb452007-03-06 18:08:43 +010082
83int cpu_post_test_cmpi (void)
84{
85 int ret = 0;
86 unsigned int i;
Stefan Roesef2302d42008-08-06 14:05:38 +020087 int flag = disable_interrupts();
Wolfgang Denkad5bb452007-03-06 18:08:43 +010088
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;
Wolfgang Denk53677ef2008-05-20 16:00:29 +020092 unsigned long code[] =
Wolfgang Denkad5bb452007-03-06 18:08:43 +010093 {
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
Stefan Roesef2302d42008-08-06 14:05:38 +0200110 if (flag)
111 enable_interrupts();
112
Wolfgang Denkad5bb452007-03-06 18:08:43 +0100113 return ret;
114}
115
116#endif