ecctest.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /*
  2. * (C) Copyright 2001
  3. *
  4. * See file CREDITS for list of people who contributed to this
  5. * project.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License as
  9. * published by the Free Software Foundation; either version 2 of
  10. * the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  20. * MA 02111-1307 USA
  21. */
  22. #ifdef ECC_TEST
  23. static inline void ecc_off (void)
  24. {
  25. *(volatile int *) (INTERNAL_REG_BASE_ADDR + 0x4b4) &= ~0x00200000;
  26. }
  27. static inline void ecc_on (void)
  28. {
  29. *(volatile int *) (INTERNAL_REG_BASE_ADDR + 0x4b4) |= 0x00200000;
  30. }
  31. static int putshex (const char *buf, int len)
  32. {
  33. int i;
  34. for (i = 0; i < len; i++) {
  35. printf ("%02x", buf[i]);
  36. }
  37. return 0;
  38. }
  39. static int char_memcpy (void *d, const void *s, int len)
  40. {
  41. int i;
  42. char *cd = d;
  43. const char *cs = s;
  44. for (i = 0; i < len; i++) {
  45. *(cd++) = *(cs++);
  46. }
  47. return 0;
  48. }
  49. static int memory_test (char *buf)
  50. {
  51. const char src[][16] = {
  52. {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  53. {0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
  54. 0x01, 0x01, 0x01, 0x01, 0x01, 0x01},
  55. {0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02,
  56. 0x02, 0x02, 0x02, 0x02, 0x02, 0x02},
  57. {0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
  58. 0x04, 0x04, 0x04, 0x04, 0x04, 0x04},
  59. {0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08,
  60. 0x08, 0x08, 0x08, 0x08, 0x08, 0x08},
  61. {0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10,
  62. 0x10, 0x10, 0x10, 0x10, 0x10, 0x10},
  63. {0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  64. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20},
  65. {0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
  66. 0x40, 0x40, 0x40, 0x40, 0x40, 0x40},
  67. {0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
  68. 0x80, 0x80, 0x80, 0x80, 0x80, 0x80},
  69. {0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
  70. 0x55, 0x55, 0x55, 0x55, 0x55, 0x55},
  71. {0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
  72. 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa},
  73. {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  74. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}
  75. };
  76. const int foo[] = { 0 };
  77. int i, j, a;
  78. printf ("\ntest @ %d %p\n", foo[0], buf);
  79. for (i = 0; i < 12; i++) {
  80. for (a = 0; a < 8; a++) {
  81. const char *s = src[i] + a;
  82. int align = (unsigned) (s) & 0x7;
  83. /* ecc_off(); */
  84. memcpy (buf, s, 8);
  85. /* ecc_on(); */
  86. putshex (s, 8);
  87. if (memcmp (buf, s, 8)) {
  88. putc ('\n');
  89. putshex (buf, 8);
  90. printf (" [FAIL] (%p) align=%d\n", s, align);
  91. for (j = 0; j < 8; j++) {
  92. s[j] == buf[j] ? puts (" ") :
  93. printf ("%02x",
  94. (s[j]) ^ (buf[j]));
  95. }
  96. putc ('\n');
  97. } else {
  98. printf (" [PASS] (%p) align=%d\n", s, align);
  99. }
  100. /* ecc_off(); */
  101. char_memcpy (buf, s, 8);
  102. /* ecc_on(); */
  103. putshex (s, 8);
  104. if (memcmp (buf, s, 8)) {
  105. putc ('\n');
  106. putshex (buf, 8);
  107. printf (" [FAIL] (%p) align=%d\n", s, align);
  108. for (j = 0; j < 8; j++) {
  109. s[j] == buf[j] ? puts (" ") :
  110. printf ("%02x",
  111. (s[j]) ^ (buf[j]));
  112. }
  113. putc ('\n');
  114. } else {
  115. printf (" [PASS] (%p) align=%d\n", s, align);
  116. }
  117. }
  118. }
  119. return 0;
  120. }
  121. #endif