store.c 3.2 KB

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