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> |
Simon Glass | 8f3f761 | 2019-11-14 12:57:42 -0700 | [diff] [blame] | 8 | #include <irq_func.h> |
Wolfgang Denk | b38e0df | 2007-03-06 18:08:43 +0100 | [diff] [blame] | 9 | |
| 10 | /* |
| 11 | * CPU test |
| 12 | * Binary instructions instr rA,rS |
| 13 | * |
| 14 | * Logic instructions: cntlzw |
| 15 | * Arithmetic instructions: extsb, extsh |
| 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_21 (ulong *code, ulong *cr, ulong *res, ulong op1); |
| 28 | extern ulong cpu_post_makecr (long v); |
| 29 | |
| 30 | static struct cpu_post_twox_s |
| 31 | { |
| 32 | ulong cmd; |
| 33 | ulong op; |
| 34 | ulong res; |
| 35 | } cpu_post_twox_table[] = |
| 36 | { |
| 37 | { |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 38 | OP_EXTSB, |
Wolfgang Denk | b38e0df | 2007-03-06 18:08:43 +0100 | [diff] [blame] | 39 | 3, |
| 40 | 3 |
| 41 | }, |
| 42 | { |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 43 | OP_EXTSB, |
Wolfgang Denk | b38e0df | 2007-03-06 18:08:43 +0100 | [diff] [blame] | 44 | 0xff, |
| 45 | -1 |
| 46 | }, |
| 47 | { |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 48 | OP_EXTSH, |
Wolfgang Denk | b38e0df | 2007-03-06 18:08:43 +0100 | [diff] [blame] | 49 | 3, |
| 50 | 3 |
| 51 | }, |
| 52 | { |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 53 | OP_EXTSH, |
Wolfgang Denk | b38e0df | 2007-03-06 18:08:43 +0100 | [diff] [blame] | 54 | 0xff, |
| 55 | 0xff |
| 56 | }, |
| 57 | { |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 58 | OP_EXTSH, |
Wolfgang Denk | b38e0df | 2007-03-06 18:08:43 +0100 | [diff] [blame] | 59 | 0xffff, |
| 60 | -1 |
| 61 | }, |
| 62 | { |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 63 | OP_CNTLZW, |
Wolfgang Denk | b38e0df | 2007-03-06 18:08:43 +0100 | [diff] [blame] | 64 | 0x000fffff, |
| 65 | 12 |
| 66 | }, |
| 67 | }; |
Mike Frysinger | 83a687b | 2011-05-10 07:28:35 +0000 | [diff] [blame] | 68 | static unsigned int cpu_post_twox_size = ARRAY_SIZE(cpu_post_twox_table); |
Wolfgang Denk | b38e0df | 2007-03-06 18:08:43 +0100 | [diff] [blame] | 69 | |
| 70 | int cpu_post_test_twox (void) |
| 71 | { |
| 72 | int ret = 0; |
| 73 | unsigned int i, reg; |
| 74 | int flag = disable_interrupts(); |
| 75 | |
| 76 | for (i = 0; i < cpu_post_twox_size && ret == 0; i++) |
| 77 | { |
| 78 | struct cpu_post_twox_s *test = cpu_post_twox_table + i; |
| 79 | |
| 80 | for (reg = 0; reg < 32 && ret == 0; reg++) |
| 81 | { |
| 82 | unsigned int reg0 = (reg + 0) % 32; |
| 83 | unsigned int reg1 = (reg + 1) % 32; |
| 84 | unsigned int stk = reg < 16 ? 31 : 15; |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 85 | unsigned long code[] = |
Wolfgang Denk | b38e0df | 2007-03-06 18:08:43 +0100 | [diff] [blame] | 86 | { |
| 87 | ASM_STW(stk, 1, -4), |
| 88 | ASM_ADDI(stk, 1, -16), |
| 89 | ASM_STW(3, stk, 8), |
| 90 | ASM_STW(reg0, stk, 4), |
| 91 | ASM_STW(reg1, stk, 0), |
| 92 | ASM_LWZ(reg0, stk, 8), |
| 93 | ASM_11X(test->cmd, reg1, reg0), |
| 94 | ASM_STW(reg1, stk, 8), |
| 95 | ASM_LWZ(reg1, stk, 0), |
| 96 | ASM_LWZ(reg0, stk, 4), |
| 97 | ASM_LWZ(3, stk, 8), |
| 98 | ASM_ADDI(1, stk, 16), |
| 99 | ASM_LWZ(stk, 1, -4), |
| 100 | ASM_BLR, |
| 101 | }; |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 102 | unsigned long codecr[] = |
Wolfgang Denk | b38e0df | 2007-03-06 18:08:43 +0100 | [diff] [blame] | 103 | { |
| 104 | ASM_STW(stk, 1, -4), |
| 105 | ASM_ADDI(stk, 1, -16), |
| 106 | ASM_STW(3, stk, 8), |
| 107 | ASM_STW(reg0, stk, 4), |
| 108 | ASM_STW(reg1, stk, 0), |
| 109 | ASM_LWZ(reg0, stk, 8), |
| 110 | ASM_11X(test->cmd, reg1, reg0) | BIT_C, |
| 111 | ASM_STW(reg1, stk, 8), |
| 112 | ASM_LWZ(reg1, stk, 0), |
| 113 | ASM_LWZ(reg0, stk, 4), |
| 114 | ASM_LWZ(3, stk, 8), |
| 115 | ASM_ADDI(1, stk, 16), |
| 116 | ASM_LWZ(stk, 1, -4), |
| 117 | ASM_BLR, |
| 118 | }; |
| 119 | ulong res; |
| 120 | ulong cr; |
| 121 | |
| 122 | if (ret == 0) |
| 123 | { |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 124 | cr = 0; |
| 125 | cpu_post_exec_21 (code, & cr, & res, test->op); |
Wolfgang Denk | b38e0df | 2007-03-06 18:08:43 +0100 | [diff] [blame] | 126 | |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 127 | ret = res == test->res && cr == 0 ? 0 : -1; |
Wolfgang Denk | b38e0df | 2007-03-06 18:08:43 +0100 | [diff] [blame] | 128 | |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 129 | if (ret != 0) |
| 130 | { |
Wolfgang Denk | ec7fbf5 | 2013-10-04 17:43:24 +0200 | [diff] [blame] | 131 | post_log ("Error at twox test %d !\n", i); |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 132 | } |
Wolfgang Denk | b38e0df | 2007-03-06 18:08:43 +0100 | [diff] [blame] | 133 | } |
| 134 | |
| 135 | if (ret == 0) |
| 136 | { |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 137 | cpu_post_exec_21 (codecr, & cr, & res, test->op); |
Wolfgang Denk | b38e0df | 2007-03-06 18:08:43 +0100 | [diff] [blame] | 138 | |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 139 | ret = res == test->res && |
Wolfgang Denk | b38e0df | 2007-03-06 18:08:43 +0100 | [diff] [blame] | 140 | (cr & 0xe0000000) == cpu_post_makecr (res) ? 0 : -1; |
| 141 | |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 142 | if (ret != 0) |
| 143 | { |
Wolfgang Denk | ec7fbf5 | 2013-10-04 17:43:24 +0200 | [diff] [blame] | 144 | post_log ("Error at twox test %d !\n", i); |
| 145 | } |
Wolfgang Denk | b38e0df | 2007-03-06 18:08:43 +0100 | [diff] [blame] | 146 | } |
| 147 | } |
| 148 | } |
| 149 | |
| 150 | if (flag) |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 151 | enable_interrupts(); |
Wolfgang Denk | b38e0df | 2007-03-06 18:08:43 +0100 | [diff] [blame] | 152 | |
| 153 | return ret; |
| 154 | } |
| 155 | |
| 156 | #endif |