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