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 rD,rA,rB |
| 12 | * |
| 13 | * Arithmetic instructions: add, addc, adde, subf, subfc, subfe, |
| 14 | * mullw, mulhw, mulhwu, divw, divwu |
| 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_three_s |
| 31 | { |
| 32 | ulong cmd; |
| 33 | ulong op1; |
| 34 | ulong op2; |
| 35 | ulong res; |
| 36 | } cpu_post_three_table[] = |
| 37 | { |
| 38 | { |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 39 | OP_ADD, |
Wolfgang Denk | b38e0df | 2007-03-06 18:08:43 +0100 | [diff] [blame] | 40 | 100, |
| 41 | 200, |
| 42 | 300 |
| 43 | }, |
| 44 | { |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 45 | OP_ADD, |
Wolfgang Denk | b38e0df | 2007-03-06 18:08:43 +0100 | [diff] [blame] | 46 | 100, |
| 47 | -200, |
| 48 | -100 |
| 49 | }, |
| 50 | { |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 51 | OP_ADDC, |
Wolfgang Denk | b38e0df | 2007-03-06 18:08:43 +0100 | [diff] [blame] | 52 | 100, |
| 53 | 200, |
| 54 | 300 |
| 55 | }, |
| 56 | { |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 57 | OP_ADDC, |
Wolfgang Denk | b38e0df | 2007-03-06 18:08:43 +0100 | [diff] [blame] | 58 | 100, |
| 59 | -200, |
| 60 | -100 |
| 61 | }, |
| 62 | { |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 63 | OP_ADDE, |
Wolfgang Denk | b38e0df | 2007-03-06 18:08:43 +0100 | [diff] [blame] | 64 | 100, |
| 65 | 200, |
| 66 | 300 |
| 67 | }, |
| 68 | { |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 69 | OP_ADDE, |
Wolfgang Denk | b38e0df | 2007-03-06 18:08:43 +0100 | [diff] [blame] | 70 | 100, |
| 71 | -200, |
| 72 | -100 |
| 73 | }, |
| 74 | { |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 75 | OP_SUBF, |
Wolfgang Denk | b38e0df | 2007-03-06 18:08:43 +0100 | [diff] [blame] | 76 | 100, |
| 77 | 200, |
| 78 | 100 |
| 79 | }, |
| 80 | { |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 81 | OP_SUBF, |
Wolfgang Denk | b38e0df | 2007-03-06 18:08:43 +0100 | [diff] [blame] | 82 | 300, |
| 83 | 200, |
| 84 | -100 |
| 85 | }, |
| 86 | { |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 87 | OP_SUBFC, |
Wolfgang Denk | b38e0df | 2007-03-06 18:08:43 +0100 | [diff] [blame] | 88 | 100, |
| 89 | 200, |
| 90 | 100 |
| 91 | }, |
| 92 | { |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 93 | OP_SUBFC, |
Wolfgang Denk | b38e0df | 2007-03-06 18:08:43 +0100 | [diff] [blame] | 94 | 300, |
| 95 | 200, |
| 96 | -100 |
| 97 | }, |
| 98 | { |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 99 | OP_SUBFE, |
Wolfgang Denk | b38e0df | 2007-03-06 18:08:43 +0100 | [diff] [blame] | 100 | 100, |
| 101 | 200, |
| 102 | 200 + ~100 |
| 103 | }, |
| 104 | { |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 105 | OP_SUBFE, |
Wolfgang Denk | b38e0df | 2007-03-06 18:08:43 +0100 | [diff] [blame] | 106 | 300, |
| 107 | 200, |
| 108 | 200 + ~300 |
| 109 | }, |
| 110 | { |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 111 | OP_MULLW, |
Wolfgang Denk | b38e0df | 2007-03-06 18:08:43 +0100 | [diff] [blame] | 112 | 200, |
| 113 | 300, |
| 114 | 200 * 300 |
| 115 | }, |
| 116 | { |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 117 | OP_MULHW, |
Wolfgang Denk | b38e0df | 2007-03-06 18:08:43 +0100 | [diff] [blame] | 118 | 0x10000000, |
| 119 | 0x10000000, |
| 120 | 0x1000000 |
| 121 | }, |
| 122 | { |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 123 | OP_MULHWU, |
Wolfgang Denk | b38e0df | 2007-03-06 18:08:43 +0100 | [diff] [blame] | 124 | 0x80000000, |
| 125 | 0x80000000, |
| 126 | 0x40000000 |
| 127 | }, |
| 128 | { |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 129 | OP_DIVW, |
Wolfgang Denk | b38e0df | 2007-03-06 18:08:43 +0100 | [diff] [blame] | 130 | -20, |
| 131 | 5, |
| 132 | -4 |
| 133 | }, |
| 134 | { |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 135 | OP_DIVWU, |
Wolfgang Denk | b38e0df | 2007-03-06 18:08:43 +0100 | [diff] [blame] | 136 | 0x8000, |
| 137 | 0x200, |
| 138 | 0x40 |
| 139 | }, |
| 140 | }; |
Mike Frysinger | 83a687b | 2011-05-10 07:28:35 +0000 | [diff] [blame] | 141 | static unsigned int cpu_post_three_size = ARRAY_SIZE(cpu_post_three_table); |
Wolfgang Denk | b38e0df | 2007-03-06 18:08:43 +0100 | [diff] [blame] | 142 | |
| 143 | int cpu_post_test_three (void) |
| 144 | { |
| 145 | int ret = 0; |
| 146 | unsigned int i, reg; |
| 147 | int flag = disable_interrupts(); |
| 148 | |
| 149 | for (i = 0; i < cpu_post_three_size && ret == 0; i++) |
| 150 | { |
| 151 | struct cpu_post_three_s *test = cpu_post_three_table + i; |
| 152 | |
| 153 | for (reg = 0; reg < 32 && ret == 0; reg++) |
| 154 | { |
| 155 | unsigned int reg0 = (reg + 0) % 32; |
| 156 | unsigned int reg1 = (reg + 1) % 32; |
| 157 | unsigned int reg2 = (reg + 2) % 32; |
| 158 | unsigned int stk = reg < 16 ? 31 : 15; |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 159 | unsigned long code[] = |
Wolfgang Denk | b38e0df | 2007-03-06 18:08:43 +0100 | [diff] [blame] | 160 | { |
| 161 | ASM_STW(stk, 1, -4), |
| 162 | ASM_ADDI(stk, 1, -24), |
| 163 | ASM_STW(3, stk, 12), |
| 164 | ASM_STW(4, stk, 16), |
| 165 | ASM_STW(reg0, stk, 8), |
| 166 | ASM_STW(reg1, stk, 4), |
| 167 | ASM_STW(reg2, stk, 0), |
| 168 | ASM_LWZ(reg1, stk, 12), |
| 169 | ASM_LWZ(reg0, stk, 16), |
| 170 | ASM_12(test->cmd, reg2, reg1, reg0), |
| 171 | ASM_STW(reg2, stk, 12), |
| 172 | ASM_LWZ(reg2, stk, 0), |
| 173 | ASM_LWZ(reg1, stk, 4), |
| 174 | ASM_LWZ(reg0, stk, 8), |
| 175 | ASM_LWZ(3, stk, 12), |
| 176 | ASM_ADDI(1, stk, 24), |
| 177 | ASM_LWZ(stk, 1, -4), |
| 178 | ASM_BLR, |
| 179 | }; |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 180 | unsigned long codecr[] = |
Wolfgang Denk | b38e0df | 2007-03-06 18:08:43 +0100 | [diff] [blame] | 181 | { |
| 182 | ASM_STW(stk, 1, -4), |
| 183 | ASM_ADDI(stk, 1, -24), |
| 184 | ASM_STW(3, stk, 12), |
| 185 | ASM_STW(4, stk, 16), |
| 186 | ASM_STW(reg0, stk, 8), |
| 187 | ASM_STW(reg1, stk, 4), |
| 188 | ASM_STW(reg2, stk, 0), |
| 189 | ASM_LWZ(reg1, stk, 12), |
| 190 | ASM_LWZ(reg0, stk, 16), |
| 191 | ASM_12(test->cmd, reg2, reg1, reg0) | BIT_C, |
| 192 | ASM_STW(reg2, stk, 12), |
| 193 | ASM_LWZ(reg2, stk, 0), |
| 194 | ASM_LWZ(reg1, stk, 4), |
| 195 | ASM_LWZ(reg0, stk, 8), |
| 196 | ASM_LWZ(3, stk, 12), |
| 197 | ASM_ADDI(1, stk, 24), |
| 198 | ASM_LWZ(stk, 1, -4), |
| 199 | ASM_BLR, |
| 200 | }; |
| 201 | ulong res; |
| 202 | ulong cr; |
| 203 | |
| 204 | if (ret == 0) |
| 205 | { |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 206 | cr = 0; |
| 207 | cpu_post_exec_22 (code, & cr, & res, test->op1, test->op2); |
Wolfgang Denk | b38e0df | 2007-03-06 18:08:43 +0100 | [diff] [blame] | 208 | |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 209 | ret = res == test->res && cr == 0 ? 0 : -1; |
Wolfgang Denk | b38e0df | 2007-03-06 18:08:43 +0100 | [diff] [blame] | 210 | |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 211 | if (ret != 0) |
| 212 | { |
Wolfgang Denk | ec7fbf5 | 2013-10-04 17:43:24 +0200 | [diff] [blame] | 213 | post_log ("Error at three test %d !\n", i); |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 214 | } |
Wolfgang Denk | b38e0df | 2007-03-06 18:08:43 +0100 | [diff] [blame] | 215 | } |
| 216 | |
| 217 | if (ret == 0) |
| 218 | { |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 219 | cpu_post_exec_22 (codecr, & cr, & res, test->op1, test->op2); |
Wolfgang Denk | b38e0df | 2007-03-06 18:08:43 +0100 | [diff] [blame] | 220 | |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 221 | ret = res == test->res && |
Wolfgang Denk | b38e0df | 2007-03-06 18:08:43 +0100 | [diff] [blame] | 222 | (cr & 0xe0000000) == cpu_post_makecr (res) ? 0 : -1; |
| 223 | |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 224 | if (ret != 0) |
| 225 | { |
Wolfgang Denk | ec7fbf5 | 2013-10-04 17:43:24 +0200 | [diff] [blame] | 226 | post_log ("Error at three test %d !\n", i); |
| 227 | } |
Wolfgang Denk | b38e0df | 2007-03-06 18:08:43 +0100 | [diff] [blame] | 228 | } |
| 229 | } |
| 230 | } |
| 231 | |
| 232 | if (flag) |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 233 | enable_interrupts(); |
Wolfgang Denk | b38e0df | 2007-03-06 18:08:43 +0100 | [diff] [blame] | 234 | |
| 235 | return ret; |
| 236 | } |
| 237 | |
| 238 | #endif |