Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Wolfgang Denk | b38e0df | 2007-03-06 18:08:43 +0100 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2002 |
| 4 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
Wolfgang Denk | b38e0df | 2007-03-06 18:08:43 +0100 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
| 8 | |
| 9 | /* |
| 10 | * CPU test |
| 11 | * Ternary instructions instr rA,rS,rB |
| 12 | * |
| 13 | * Logic instructions: or, orc, xor, nand, nor, eqv |
| 14 | * Shift instructions: slw, srw, sraw |
| 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 Denk | b38e0df | 2007-03-06 18:08:43 +0100 | [diff] [blame] | 21 | #include <post.h> |
| 22 | #include "cpu_asm.h" |
| 23 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 24 | #if CONFIG_POST & CONFIG_SYS_POST_CPU |
Wolfgang Denk | b38e0df | 2007-03-06 18:08:43 +0100 | [diff] [blame] | 25 | |
| 26 | extern void cpu_post_exec_22 (ulong *code, ulong *cr, ulong *res, ulong op1, |
| 27 | ulong op2); |
| 28 | extern ulong cpu_post_makecr (long v); |
| 29 | |
| 30 | static struct cpu_post_threex_s |
| 31 | { |
| 32 | ulong cmd; |
| 33 | ulong op1; |
| 34 | ulong op2; |
| 35 | ulong res; |
| 36 | } cpu_post_threex_table[] = |
| 37 | { |
| 38 | { |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 39 | OP_OR, |
Wolfgang Denk | b38e0df | 2007-03-06 18:08:43 +0100 | [diff] [blame] | 40 | 0x1234, |
| 41 | 0x5678, |
| 42 | 0x1234 | 0x5678 |
| 43 | }, |
| 44 | { |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 45 | OP_ORC, |
Wolfgang Denk | b38e0df | 2007-03-06 18:08:43 +0100 | [diff] [blame] | 46 | 0x1234, |
| 47 | 0x5678, |
| 48 | 0x1234 | ~0x5678 |
| 49 | }, |
| 50 | { |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 51 | OP_XOR, |
Wolfgang Denk | b38e0df | 2007-03-06 18:08:43 +0100 | [diff] [blame] | 52 | 0x1234, |
| 53 | 0x5678, |
| 54 | 0x1234 ^ 0x5678 |
| 55 | }, |
| 56 | { |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 57 | OP_NAND, |
Wolfgang Denk | b38e0df | 2007-03-06 18:08:43 +0100 | [diff] [blame] | 58 | 0x1234, |
| 59 | 0x5678, |
| 60 | ~(0x1234 & 0x5678) |
| 61 | }, |
| 62 | { |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 63 | OP_NOR, |
Wolfgang Denk | b38e0df | 2007-03-06 18:08:43 +0100 | [diff] [blame] | 64 | 0x1234, |
| 65 | 0x5678, |
| 66 | ~(0x1234 | 0x5678) |
| 67 | }, |
| 68 | { |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 69 | OP_EQV, |
Wolfgang Denk | b38e0df | 2007-03-06 18:08:43 +0100 | [diff] [blame] | 70 | 0x1234, |
| 71 | 0x5678, |
| 72 | ~(0x1234 ^ 0x5678) |
| 73 | }, |
| 74 | { |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 75 | OP_SLW, |
Wolfgang Denk | b38e0df | 2007-03-06 18:08:43 +0100 | [diff] [blame] | 76 | 0x80, |
| 77 | 16, |
| 78 | 0x800000 |
| 79 | }, |
| 80 | { |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 81 | OP_SLW, |
Wolfgang Denk | b38e0df | 2007-03-06 18:08:43 +0100 | [diff] [blame] | 82 | 0x80, |
| 83 | 32, |
| 84 | 0 |
| 85 | }, |
| 86 | { |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 87 | OP_SRW, |
Wolfgang Denk | b38e0df | 2007-03-06 18:08:43 +0100 | [diff] [blame] | 88 | 0x800000, |
| 89 | 16, |
| 90 | 0x80 |
| 91 | }, |
| 92 | { |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 93 | OP_SRW, |
Wolfgang Denk | b38e0df | 2007-03-06 18:08:43 +0100 | [diff] [blame] | 94 | 0x800000, |
| 95 | 32, |
| 96 | 0 |
| 97 | }, |
| 98 | { |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 99 | OP_SRAW, |
Wolfgang Denk | b38e0df | 2007-03-06 18:08:43 +0100 | [diff] [blame] | 100 | 0x80000000, |
| 101 | 3, |
| 102 | 0xf0000000 |
| 103 | }, |
| 104 | { |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 105 | OP_SRAW, |
Wolfgang Denk | b38e0df | 2007-03-06 18:08:43 +0100 | [diff] [blame] | 106 | 0x8000, |
| 107 | 3, |
| 108 | 0x1000 |
| 109 | }, |
| 110 | }; |
Mike Frysinger | 83a687b | 2011-05-10 07:28:35 +0000 | [diff] [blame] | 111 | static unsigned int cpu_post_threex_size = ARRAY_SIZE(cpu_post_threex_table); |
Wolfgang Denk | b38e0df | 2007-03-06 18:08:43 +0100 | [diff] [blame] | 112 | |
| 113 | int cpu_post_test_threex (void) |
| 114 | { |
| 115 | int ret = 0; |
| 116 | unsigned int i, reg; |
| 117 | int flag = disable_interrupts(); |
| 118 | |
| 119 | for (i = 0; i < cpu_post_threex_size && ret == 0; i++) |
| 120 | { |
| 121 | struct cpu_post_threex_s *test = cpu_post_threex_table + i; |
| 122 | |
| 123 | for (reg = 0; reg < 32 && ret == 0; reg++) |
| 124 | { |
| 125 | unsigned int reg0 = (reg + 0) % 32; |
| 126 | unsigned int reg1 = (reg + 1) % 32; |
| 127 | unsigned int reg2 = (reg + 2) % 32; |
| 128 | unsigned int stk = reg < 16 ? 31 : 15; |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 129 | unsigned long code[] = |
Wolfgang Denk | b38e0df | 2007-03-06 18:08:43 +0100 | [diff] [blame] | 130 | { |
| 131 | ASM_STW(stk, 1, -4), |
| 132 | ASM_ADDI(stk, 1, -24), |
| 133 | ASM_STW(3, stk, 12), |
| 134 | ASM_STW(4, stk, 16), |
| 135 | ASM_STW(reg0, stk, 8), |
| 136 | ASM_STW(reg1, stk, 4), |
| 137 | ASM_STW(reg2, stk, 0), |
| 138 | ASM_LWZ(reg1, stk, 12), |
| 139 | ASM_LWZ(reg0, stk, 16), |
| 140 | ASM_12X(test->cmd, reg2, reg1, reg0), |
| 141 | ASM_STW(reg2, stk, 12), |
| 142 | ASM_LWZ(reg2, stk, 0), |
| 143 | ASM_LWZ(reg1, stk, 4), |
| 144 | ASM_LWZ(reg0, stk, 8), |
| 145 | ASM_LWZ(3, stk, 12), |
| 146 | ASM_ADDI(1, stk, 24), |
| 147 | ASM_LWZ(stk, 1, -4), |
| 148 | ASM_BLR, |
| 149 | }; |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 150 | unsigned long codecr[] = |
Wolfgang Denk | b38e0df | 2007-03-06 18:08:43 +0100 | [diff] [blame] | 151 | { |
| 152 | ASM_STW(stk, 1, -4), |
| 153 | ASM_ADDI(stk, 1, -24), |
| 154 | ASM_STW(3, stk, 12), |
| 155 | ASM_STW(4, stk, 16), |
| 156 | ASM_STW(reg0, stk, 8), |
| 157 | ASM_STW(reg1, stk, 4), |
| 158 | ASM_STW(reg2, stk, 0), |
| 159 | ASM_LWZ(reg1, stk, 12), |
| 160 | ASM_LWZ(reg0, stk, 16), |
| 161 | ASM_12X(test->cmd, reg2, reg1, reg0) | BIT_C, |
| 162 | ASM_STW(reg2, stk, 12), |
| 163 | ASM_LWZ(reg2, stk, 0), |
| 164 | ASM_LWZ(reg1, stk, 4), |
| 165 | ASM_LWZ(reg0, stk, 8), |
| 166 | ASM_LWZ(3, stk, 12), |
| 167 | ASM_ADDI(1, stk, 24), |
| 168 | ASM_LWZ(stk, 1, -4), |
| 169 | ASM_BLR, |
| 170 | }; |
| 171 | ulong res; |
| 172 | ulong cr; |
| 173 | |
| 174 | if (ret == 0) |
| 175 | { |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 176 | cr = 0; |
| 177 | cpu_post_exec_22 (code, & cr, & res, test->op1, test->op2); |
Wolfgang Denk | b38e0df | 2007-03-06 18:08:43 +0100 | [diff] [blame] | 178 | |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 179 | ret = res == test->res && cr == 0 ? 0 : -1; |
Wolfgang Denk | b38e0df | 2007-03-06 18:08:43 +0100 | [diff] [blame] | 180 | |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 181 | if (ret != 0) |
| 182 | { |
Wolfgang Denk | ec7fbf5 | 2013-10-04 17:43:24 +0200 | [diff] [blame] | 183 | post_log ("Error at threex test %d !\n", i); |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 184 | } |
Wolfgang Denk | b38e0df | 2007-03-06 18:08:43 +0100 | [diff] [blame] | 185 | } |
| 186 | |
| 187 | if (ret == 0) |
| 188 | { |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 189 | cpu_post_exec_22 (codecr, & cr, & res, test->op1, test->op2); |
Wolfgang Denk | b38e0df | 2007-03-06 18:08:43 +0100 | [diff] [blame] | 190 | |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 191 | ret = res == test->res && |
Wolfgang Denk | b38e0df | 2007-03-06 18:08:43 +0100 | [diff] [blame] | 192 | (cr & 0xe0000000) == cpu_post_makecr (res) ? 0 : -1; |
| 193 | |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 194 | if (ret != 0) |
| 195 | { |
Wolfgang Denk | ec7fbf5 | 2013-10-04 17:43:24 +0200 | [diff] [blame] | 196 | post_log ("Error at threex test %d !\n", i); |
| 197 | } |
Wolfgang Denk | b38e0df | 2007-03-06 18:08:43 +0100 | [diff] [blame] | 198 | } |
| 199 | } |
| 200 | } |
| 201 | |
| 202 | if (flag) |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 203 | enable_interrupts(); |
Wolfgang Denk | b38e0df | 2007-03-06 18:08:43 +0100 | [diff] [blame] | 204 | |
| 205 | return ret; |
| 206 | } |
| 207 | |
| 208 | #endif |