ecctest.c 3.7 KB

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