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 | * Load/store string instructions: lswi, stswi, lswx, stswx |
| 13 | * |
| 14 | * Several consecutive bytes from a source memory buffer are loaded |
| 15 | * left to right into GPRs. After that, the bytes are stored |
| 16 | * from the GPRs into a target memory buffer. The contents |
| 17 | * of the source and target buffers are then compared. |
| 18 | */ |
| 19 | |
Wolfgang Denk | b38e0df | 2007-03-06 18:08:43 +0100 | [diff] [blame] | 20 | #include <post.h> |
| 21 | #include "cpu_asm.h" |
| 22 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 23 | #if CONFIG_POST & CONFIG_SYS_POST_CPU |
Wolfgang Denk | b38e0df | 2007-03-06 18:08:43 +0100 | [diff] [blame] | 24 | |
| 25 | extern void cpu_post_exec_02 (ulong *code, ulong op1, ulong op2); |
| 26 | extern void cpu_post_exec_04 (ulong *code, ulong op1, ulong op2, ulong op3, |
| 27 | ulong op4); |
| 28 | |
| 29 | #include <bedbug/regs.h> |
| 30 | int cpu_post_test_string (void) |
| 31 | { |
| 32 | int ret = 0; |
| 33 | unsigned int i; |
Stefan Roese | 3762825 | 2008-08-06 14:05:38 +0200 | [diff] [blame] | 34 | int flag = disable_interrupts(); |
Wolfgang Denk | b38e0df | 2007-03-06 18:08:43 +0100 | [diff] [blame] | 35 | |
| 36 | if (ret == 0) |
| 37 | { |
| 38 | char src [31], dst [31]; |
| 39 | |
| 40 | ulong code[] = |
| 41 | { |
| 42 | ASM_LSWI(5, 3, 31), |
| 43 | ASM_STSWI(5, 4, 31), |
| 44 | ASM_BLR, |
| 45 | }; |
| 46 | |
| 47 | for (i = 0; i < sizeof(src); i ++) |
| 48 | { |
| 49 | src[i] = (char) i; |
| 50 | dst[i] = 0; |
| 51 | } |
| 52 | |
| 53 | cpu_post_exec_02(code, (ulong)src, (ulong)dst); |
| 54 | |
| 55 | ret = memcmp(src, dst, sizeof(dst)) == 0 ? 0 : -1; |
| 56 | } |
| 57 | |
| 58 | if (ret == 0) |
| 59 | { |
| 60 | char src [95], dst [95]; |
| 61 | |
| 62 | ulong code[] = |
| 63 | { |
| 64 | ASM_LSWX(8, 3, 5), |
| 65 | ASM_STSWX(8, 4, 5), |
| 66 | ASM_BLR, |
| 67 | }; |
| 68 | |
| 69 | for (i = 0; i < sizeof(src); i ++) |
| 70 | { |
| 71 | src[i] = (char) i; |
| 72 | dst[i] = 0; |
| 73 | } |
| 74 | |
| 75 | cpu_post_exec_04(code, (ulong)src, (ulong)dst, 0, sizeof(src)); |
| 76 | |
| 77 | ret = memcmp(src, dst, sizeof(dst)) == 0 ? 0 : -1; |
| 78 | } |
| 79 | |
| 80 | if (ret != 0) |
| 81 | { |
| 82 | post_log ("Error at string test !\n"); |
| 83 | } |
| 84 | |
Stefan Roese | 3762825 | 2008-08-06 14:05:38 +0200 | [diff] [blame] | 85 | if (flag) |
| 86 | enable_interrupts(); |
| 87 | |
Wolfgang Denk | b38e0df | 2007-03-06 18:08:43 +0100 | [diff] [blame] | 88 | return ret; |
| 89 | } |
| 90 | |
| 91 | #endif |