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 | * Integer compare instructions: cmpw, cmplw |
| 12 | * |
| 13 | * To verify these instructions the test runs them with |
| 14 | * different combinations of operands, reads the condition |
| 15 | * register value and compares it with the expected one. |
| 16 | * The test contains a pre-built table |
| 17 | * containing the description of each test case: the instruction, |
| 18 | * the values of the operands, the condition field to save |
| 19 | * the result in and the expected result. |
| 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_12 (ulong *code, ulong *res, ulong op1, ulong op2); |
| 28 | |
| 29 | static struct cpu_post_cmp_s |
| 30 | { |
| 31 | ulong cmd; |
| 32 | ulong op1; |
| 33 | ulong op2; |
| 34 | ulong cr; |
| 35 | ulong res; |
| 36 | } cpu_post_cmp_table[] = |
| 37 | { |
| 38 | { |
| 39 | OP_CMPW, |
| 40 | 123, |
| 41 | 123, |
| 42 | 2, |
| 43 | 0x02 |
| 44 | }, |
| 45 | { |
| 46 | OP_CMPW, |
| 47 | 123, |
| 48 | 133, |
| 49 | 3, |
| 50 | 0x08 |
| 51 | }, |
| 52 | { |
| 53 | OP_CMPW, |
| 54 | 123, |
| 55 | -133, |
| 56 | 4, |
| 57 | 0x04 |
| 58 | }, |
| 59 | { |
| 60 | OP_CMPLW, |
| 61 | 123, |
| 62 | 123, |
| 63 | 2, |
| 64 | 0x02 |
| 65 | }, |
| 66 | { |
| 67 | OP_CMPLW, |
| 68 | 123, |
| 69 | -133, |
| 70 | 3, |
| 71 | 0x08 |
| 72 | }, |
| 73 | { |
| 74 | OP_CMPLW, |
| 75 | 123, |
| 76 | 113, |
| 77 | 4, |
| 78 | 0x04 |
| 79 | }, |
| 80 | }; |
Mike Frysinger | 83a687b | 2011-05-10 07:28:35 +0000 | [diff] [blame] | 81 | static unsigned int cpu_post_cmp_size = ARRAY_SIZE(cpu_post_cmp_table); |
Wolfgang Denk | b38e0df | 2007-03-06 18:08:43 +0100 | [diff] [blame] | 82 | |
| 83 | int cpu_post_test_cmp (void) |
| 84 | { |
| 85 | int ret = 0; |
| 86 | unsigned int i; |
Stefan Roese | 3762825 | 2008-08-06 14:05:38 +0200 | [diff] [blame] | 87 | int flag = disable_interrupts(); |
Wolfgang Denk | b38e0df | 2007-03-06 18:08:43 +0100 | [diff] [blame] | 88 | |
| 89 | for (i = 0; i < cpu_post_cmp_size && ret == 0; i++) |
| 90 | { |
| 91 | struct cpu_post_cmp_s *test = cpu_post_cmp_table + i; |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 92 | unsigned long code[] = |
Wolfgang Denk | b38e0df | 2007-03-06 18:08:43 +0100 | [diff] [blame] | 93 | { |
| 94 | ASM_2C(test->cmd, test->cr, 3, 4), |
| 95 | ASM_MFCR(3), |
| 96 | ASM_BLR |
| 97 | }; |
| 98 | ulong res; |
| 99 | |
| 100 | cpu_post_exec_12 (code, & res, test->op1, test->op2); |
| 101 | |
| 102 | ret = ((res >> (28 - 4 * test->cr)) & 0xe) == test->res ? 0 : -1; |
| 103 | |
| 104 | if (ret != 0) |
| 105 | { |
| 106 | post_log ("Error at cmp test %d !\n", i); |
| 107 | } |
| 108 | } |
| 109 | |
Stefan Roese | 3762825 | 2008-08-06 14:05:38 +0200 | [diff] [blame] | 110 | if (flag) |
| 111 | enable_interrupts(); |
| 112 | |
Wolfgang Denk | b38e0df | 2007-03-06 18:08:43 +0100 | [diff] [blame] | 113 | return ret; |
| 114 | } |
| 115 | |
| 116 | #endif |