string.c 1.6 KB

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