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