store.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  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. #include <post.h>
  42. #include "cpu_asm.h"
  43. #if CONFIG_POST & CONFIG_SYS_POST_CPU
  44. extern void cpu_post_exec_12w (ulong *code, ulong *op1, ulong op2, ulong op3);
  45. extern void cpu_post_exec_11w (ulong *code, ulong *op1, ulong op2);
  46. static struct cpu_post_store_s
  47. {
  48. ulong cmd;
  49. uint width;
  50. int update;
  51. int index;
  52. ulong offset;
  53. ulong value;
  54. } cpu_post_store_table[] =
  55. {
  56. {
  57. OP_STW,
  58. 4,
  59. 0,
  60. 0,
  61. -4,
  62. 0xff00ff00
  63. },
  64. {
  65. OP_STH,
  66. 2,
  67. 0,
  68. 0,
  69. -2,
  70. 0xff00
  71. },
  72. {
  73. OP_STB,
  74. 1,
  75. 0,
  76. 0,
  77. -1,
  78. 0xff
  79. },
  80. {
  81. OP_STWU,
  82. 4,
  83. 1,
  84. 0,
  85. -4,
  86. 0xff00ff00
  87. },
  88. {
  89. OP_STHU,
  90. 2,
  91. 1,
  92. 0,
  93. -2,
  94. 0xff00
  95. },
  96. {
  97. OP_STBU,
  98. 1,
  99. 1,
  100. 0,
  101. -1,
  102. 0xff
  103. },
  104. {
  105. OP_STWX,
  106. 4,
  107. 0,
  108. 1,
  109. -4,
  110. 0xff00ff00
  111. },
  112. {
  113. OP_STHX,
  114. 2,
  115. 0,
  116. 1,
  117. -2,
  118. 0xff00
  119. },
  120. {
  121. OP_STBX,
  122. 1,
  123. 0,
  124. 1,
  125. -1,
  126. 0xff
  127. },
  128. {
  129. OP_STWUX,
  130. 4,
  131. 1,
  132. 1,
  133. -4,
  134. 0xff00ff00
  135. },
  136. {
  137. OP_STHUX,
  138. 2,
  139. 1,
  140. 1,
  141. -2,
  142. 0xff00
  143. },
  144. {
  145. OP_STBUX,
  146. 1,
  147. 1,
  148. 1,
  149. -1,
  150. 0xff
  151. },
  152. };
  153. static unsigned int cpu_post_store_size =
  154. sizeof (cpu_post_store_table) / sizeof (struct cpu_post_store_s);
  155. int cpu_post_test_store (void)
  156. {
  157. int ret = 0;
  158. unsigned int i;
  159. int flag = disable_interrupts();
  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. if (flag)
  216. enable_interrupts();
  217. return ret;
  218. }
  219. #endif