string.c 1.6 KB

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