blob: f49c85e6b9dacdaee6bb51d10e000936e28f61f5 [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>
Simon Glass36bf4462019-11-14 12:57:42 -07008#include <irq_func.h>
Wolfgang Denkad5bb452007-03-06 18:08:43 +01009
10/*
11 * CPU test
12 * Ternary instructions instr rA,rS,UIMM
13 *
14 * Logic instructions: ori, oris, xori, xoris
15 *
16 * The test contains a pre-built table of instructions, operands and
17 * expected results. For each table entry, the test will cyclically use
18 * different sets of operand registers and result registers.
19 */
20
Wolfgang Denkad5bb452007-03-06 18:08:43 +010021#include <post.h>
22#include "cpu_asm.h"
23
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020024#if CONFIG_POST & CONFIG_SYS_POST_CPU
Wolfgang Denkad5bb452007-03-06 18:08:43 +010025
26extern void cpu_post_exec_21 (ulong *code, ulong *cr, ulong *res, ulong op);
27extern ulong cpu_post_makecr (long v);
28
29static struct cpu_post_threei_s
30{
31 ulong cmd;
32 ulong op1;
33 ushort op2;
34 ulong res;
35} cpu_post_threei_table[] =
36{
37 {
Wolfgang Denk53677ef2008-05-20 16:00:29 +020038 OP_ORI,
Wolfgang Denkad5bb452007-03-06 18:08:43 +010039 0x80000000,
40 0xffff,
41 0x8000ffff
42 },
43 {
Wolfgang Denk53677ef2008-05-20 16:00:29 +020044 OP_ORIS,
Wolfgang Denkad5bb452007-03-06 18:08:43 +010045 0x00008000,
46 0xffff,
47 0xffff8000
48 },
49 {
Wolfgang Denk53677ef2008-05-20 16:00:29 +020050 OP_XORI,
Wolfgang Denkad5bb452007-03-06 18:08:43 +010051 0x8000ffff,
52 0xffff,
53 0x80000000
54 },
55 {
Wolfgang Denk53677ef2008-05-20 16:00:29 +020056 OP_XORIS,
Wolfgang Denkad5bb452007-03-06 18:08:43 +010057 0x00008000,
58 0xffff,
59 0xffff8000
60 },
61};
Mike Frysingerd2397812011-05-10 07:28:35 +000062static unsigned int cpu_post_threei_size = ARRAY_SIZE(cpu_post_threei_table);
Wolfgang Denkad5bb452007-03-06 18:08:43 +010063
64int cpu_post_test_threei (void)
65{
66 int ret = 0;
67 unsigned int i, reg;
68 int flag = disable_interrupts();
69
70 for (i = 0; i < cpu_post_threei_size && ret == 0; i++)
71 {
72 struct cpu_post_threei_s *test = cpu_post_threei_table + i;
73
74 for (reg = 0; reg < 32 && ret == 0; reg++)
75 {
76 unsigned int reg0 = (reg + 0) % 32;
77 unsigned int reg1 = (reg + 1) % 32;
78 unsigned int stk = reg < 16 ? 31 : 15;
Wolfgang Denk53677ef2008-05-20 16:00:29 +020079 unsigned long code[] =
Wolfgang Denkad5bb452007-03-06 18:08:43 +010080 {
81 ASM_STW(stk, 1, -4),
82 ASM_ADDI(stk, 1, -16),
83 ASM_STW(3, stk, 8),
84 ASM_STW(reg0, stk, 4),
85 ASM_STW(reg1, stk, 0),
86 ASM_LWZ(reg0, stk, 8),
87 ASM_11IX(test->cmd, reg1, reg0, test->op2),
88 ASM_STW(reg1, stk, 8),
89 ASM_LWZ(reg1, stk, 0),
90 ASM_LWZ(reg0, stk, 4),
91 ASM_LWZ(3, stk, 8),
92 ASM_ADDI(1, stk, 16),
93 ASM_LWZ(stk, 1, -4),
94 ASM_BLR,
95 };
96 ulong res;
97 ulong cr;
98
Wolfgang Denk53677ef2008-05-20 16:00:29 +020099 cr = 0;
Wolfgang Denkad5bb452007-03-06 18:08:43 +0100100 cpu_post_exec_21 (code, & cr, & res, test->op1);
101
102 ret = res == test->res && cr == 0 ? 0 : -1;
103
104 if (ret != 0)
105 {
Wolfgang Denk93e14592013-10-04 17:43:24 +0200106 post_log ("Error at threei test %d !\n", i);
Wolfgang Denkad5bb452007-03-06 18:08:43 +0100107 }
108 }
109 }
110
111 if (flag)
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200112 enable_interrupts();
Wolfgang Denkad5bb452007-03-06 18:08:43 +0100113
114 return ret;
115}
116
117#endif