blob: 28c17df71e49b695afb229cee43455e1f0971ad4 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Wolfgang Denkb38e0df2007-03-06 18:08:43 +01002/*
3 * (C) Copyright 2002
4 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
Wolfgang Denkb38e0df2007-03-06 18:08:43 +01005 */
6
7#include <common.h>
8
9/*
10 * CPU test
11 * Ternary instructions instr rA,rS,UIMM
12 *
13 * Logic instructions: ori, oris, xori, xoris
14 *
15 * The test contains a pre-built table of instructions, operands and
16 * expected results. For each table entry, the test will cyclically use
17 * different sets of operand registers and result registers.
18 */
19
Wolfgang Denkb38e0df2007-03-06 18:08:43 +010020#include <post.h>
21#include "cpu_asm.h"
22
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020023#if CONFIG_POST & CONFIG_SYS_POST_CPU
Wolfgang Denkb38e0df2007-03-06 18:08:43 +010024
25extern void cpu_post_exec_21 (ulong *code, ulong *cr, ulong *res, ulong op);
26extern ulong cpu_post_makecr (long v);
27
28static struct cpu_post_threei_s
29{
30 ulong cmd;
31 ulong op1;
32 ushort op2;
33 ulong res;
34} cpu_post_threei_table[] =
35{
36 {
Wolfgang Denka1be4762008-05-20 16:00:29 +020037 OP_ORI,
Wolfgang Denkb38e0df2007-03-06 18:08:43 +010038 0x80000000,
39 0xffff,
40 0x8000ffff
41 },
42 {
Wolfgang Denka1be4762008-05-20 16:00:29 +020043 OP_ORIS,
Wolfgang Denkb38e0df2007-03-06 18:08:43 +010044 0x00008000,
45 0xffff,
46 0xffff8000
47 },
48 {
Wolfgang Denka1be4762008-05-20 16:00:29 +020049 OP_XORI,
Wolfgang Denkb38e0df2007-03-06 18:08:43 +010050 0x8000ffff,
51 0xffff,
52 0x80000000
53 },
54 {
Wolfgang Denka1be4762008-05-20 16:00:29 +020055 OP_XORIS,
Wolfgang Denkb38e0df2007-03-06 18:08:43 +010056 0x00008000,
57 0xffff,
58 0xffff8000
59 },
60};
Mike Frysinger83a687b2011-05-10 07:28:35 +000061static unsigned int cpu_post_threei_size = ARRAY_SIZE(cpu_post_threei_table);
Wolfgang Denkb38e0df2007-03-06 18:08:43 +010062
63int cpu_post_test_threei (void)
64{
65 int ret = 0;
66 unsigned int i, reg;
67 int flag = disable_interrupts();
68
69 for (i = 0; i < cpu_post_threei_size && ret == 0; i++)
70 {
71 struct cpu_post_threei_s *test = cpu_post_threei_table + i;
72
73 for (reg = 0; reg < 32 && ret == 0; reg++)
74 {
75 unsigned int reg0 = (reg + 0) % 32;
76 unsigned int reg1 = (reg + 1) % 32;
77 unsigned int stk = reg < 16 ? 31 : 15;
Wolfgang Denka1be4762008-05-20 16:00:29 +020078 unsigned long code[] =
Wolfgang Denkb38e0df2007-03-06 18:08:43 +010079 {
80 ASM_STW(stk, 1, -4),
81 ASM_ADDI(stk, 1, -16),
82 ASM_STW(3, stk, 8),
83 ASM_STW(reg0, stk, 4),
84 ASM_STW(reg1, stk, 0),
85 ASM_LWZ(reg0, stk, 8),
86 ASM_11IX(test->cmd, reg1, reg0, test->op2),
87 ASM_STW(reg1, stk, 8),
88 ASM_LWZ(reg1, stk, 0),
89 ASM_LWZ(reg0, stk, 4),
90 ASM_LWZ(3, stk, 8),
91 ASM_ADDI(1, stk, 16),
92 ASM_LWZ(stk, 1, -4),
93 ASM_BLR,
94 };
95 ulong res;
96 ulong cr;
97
Wolfgang Denka1be4762008-05-20 16:00:29 +020098 cr = 0;
Wolfgang Denkb38e0df2007-03-06 18:08:43 +010099 cpu_post_exec_21 (code, & cr, & res, test->op1);
100
101 ret = res == test->res && cr == 0 ? 0 : -1;
102
103 if (ret != 0)
104 {
Wolfgang Denkec7fbf52013-10-04 17:43:24 +0200105 post_log ("Error at threei test %d !\n", i);
Wolfgang Denkb38e0df2007-03-06 18:08:43 +0100106 }
107 }
108 }
109
110 if (flag)
Wolfgang Denka1be4762008-05-20 16:00:29 +0200111 enable_interrupts();
Wolfgang Denkb38e0df2007-03-06 18:08:43 +0100112
113 return ret;
114}
115
116#endif