store.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. /*
  2. * (C) Copyright 2002
  3. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  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. #include <common.h>
  24. /*
  25. * CPU test
  26. * Store instructions: stb(x)(u), sth(x)(u), stw(x)(u)
  27. *
  28. * All operations are performed on a 16-byte array. The array
  29. * is 4-byte aligned. The base register points to offset 8.
  30. * The immediate offset (index register) ranges in [-8 ... +7].
  31. * The test cases are composed so that they do not
  32. * cause alignment exceptions.
  33. * The test contains a pre-built table describing all test cases.
  34. * The table entry contains:
  35. * the instruction opcode, the value of the index register and
  36. * the value of the source register. After executing the
  37. * instruction, the test verifies the contents of the array
  38. * and the value of the base register (it must change for "store
  39. * with update" instructions).
  40. */
  41. #ifdef CONFIG_POST
  42. #include <post.h>
  43. #include "cpu_asm.h"
  44. #if CONFIG_POST & CFG_POST_CPU
  45. extern void cpu_post_exec_12w (ulong *code, ulong *op1, ulong op2, ulong op3);
  46. extern void cpu_post_exec_11w (ulong *code, ulong *op1, ulong op2);
  47. static struct cpu_post_store_s
  48. {
  49. ulong cmd;
  50. uint width;
  51. int update;
  52. int index;
  53. ulong offset;
  54. ulong value;
  55. } cpu_post_store_table[] =
  56. {
  57. {
  58. OP_STW,
  59. 4,
  60. 0,
  61. 0,
  62. -4,
  63. 0xff00ff00
  64. },
  65. {
  66. OP_STH,
  67. 2,
  68. 0,
  69. 0,
  70. -2,
  71. 0xff00
  72. },
  73. {
  74. OP_STB,
  75. 1,
  76. 0,
  77. 0,
  78. -1,
  79. 0xff
  80. },
  81. {
  82. OP_STWU,
  83. 4,
  84. 1,
  85. 0,
  86. -4,
  87. 0xff00ff00
  88. },
  89. {
  90. OP_STHU,
  91. 2,
  92. 1,
  93. 0,
  94. -2,
  95. 0xff00
  96. },
  97. {
  98. OP_STBU,
  99. 1,
  100. 1,
  101. 0,
  102. -1,
  103. 0xff
  104. },
  105. {
  106. OP_STWX,
  107. 4,
  108. 0,
  109. 1,
  110. -4,
  111. 0xff00ff00
  112. },
  113. {
  114. OP_STHX,
  115. 2,
  116. 0,
  117. 1,
  118. -2,
  119. 0xff00
  120. },
  121. {
  122. OP_STBX,
  123. 1,
  124. 0,
  125. 1,
  126. -1,
  127. 0xff
  128. },
  129. {
  130. OP_STWUX,
  131. 4,
  132. 1,
  133. 1,
  134. -4,
  135. 0xff00ff00
  136. },
  137. {
  138. OP_STHUX,
  139. 2,
  140. 1,
  141. 1,
  142. -2,
  143. 0xff00
  144. },
  145. {
  146. OP_STBUX,
  147. 1,
  148. 1,
  149. 1,
  150. -1,
  151. 0xff
  152. },
  153. };
  154. static unsigned int cpu_post_store_size =
  155. sizeof (cpu_post_store_table) / sizeof (struct cpu_post_store_s);
  156. int cpu_post_test_store (void)
  157. {
  158. int ret = 0;
  159. unsigned int i;
  160. for (i = 0; i < cpu_post_store_size && ret == 0; i++)
  161. {
  162. struct cpu_post_store_s *test = cpu_post_store_table + i;
  163. uchar data[16] =
  164. { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
  165. ulong base0 = (ulong) (data + 8);
  166. ulong base = base0;
  167. if (test->index)
  168. {
  169. ulong code[] =
  170. {
  171. ASM_12(test->cmd, 5, 3, 4),
  172. ASM_BLR,
  173. };
  174. cpu_post_exec_12w (code, &base, test->offset, test->value);
  175. }
  176. else
  177. {
  178. ulong code[] =
  179. {
  180. ASM_11I(test->cmd, 4, 3, test->offset),
  181. ASM_BLR,
  182. };
  183. cpu_post_exec_11w (code, &base, test->value);
  184. }
  185. if (ret == 0)
  186. {
  187. if (test->update)
  188. ret = base == base0 + test->offset ? 0 : -1;
  189. else
  190. ret = base == base0 ? 0 : -1;
  191. }
  192. if (ret == 0)
  193. {
  194. switch (test->width)
  195. {
  196. case 1:
  197. ret = *(uchar *)(base0 + test->offset) == test->value ?
  198. 0 : -1;
  199. break;
  200. case 2:
  201. ret = *(ushort *)(base0 + test->offset) == test->value ?
  202. 0 : -1;
  203. break;
  204. case 4:
  205. ret = *(ulong *)(base0 + test->offset) == test->value ?
  206. 0 : -1;
  207. break;
  208. }
  209. }
  210. if (ret != 0)
  211. {
  212. post_log ("Error at store test %d !\n", i);
  213. }
  214. }
  215. return ret;
  216. }
  217. #endif
  218. #endif