load.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  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. * Load instructions: lbz(x)(u), lhz(x)(u), lha(x)(u), lwz(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 array contents, the value of the index
  19. * register and the expected value of the destination register.
  20. * After executing the instruction, the test verifies the
  21. * value of the destination register and the value of the base
  22. * register (it must change for "load 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_22w (ulong *code, ulong *op1, ulong op2, ulong *op3);
  28. extern void cpu_post_exec_21w (ulong *code, ulong *op1, ulong *op2);
  29. static struct cpu_post_load_s
  30. {
  31. ulong cmd;
  32. uint width;
  33. int update;
  34. int index;
  35. ulong offset;
  36. } cpu_post_load_table[] =
  37. {
  38. {
  39. OP_LWZ,
  40. 4,
  41. 0,
  42. 0,
  43. 4
  44. },
  45. {
  46. OP_LHA,
  47. 3,
  48. 0,
  49. 0,
  50. 2
  51. },
  52. {
  53. OP_LHZ,
  54. 2,
  55. 0,
  56. 0,
  57. 2
  58. },
  59. {
  60. OP_LBZ,
  61. 1,
  62. 0,
  63. 0,
  64. 1
  65. },
  66. {
  67. OP_LWZU,
  68. 4,
  69. 1,
  70. 0,
  71. 4
  72. },
  73. {
  74. OP_LHAU,
  75. 3,
  76. 1,
  77. 0,
  78. 2
  79. },
  80. {
  81. OP_LHZU,
  82. 2,
  83. 1,
  84. 0,
  85. 2
  86. },
  87. {
  88. OP_LBZU,
  89. 1,
  90. 1,
  91. 0,
  92. 1
  93. },
  94. {
  95. OP_LWZX,
  96. 4,
  97. 0,
  98. 1,
  99. 4
  100. },
  101. {
  102. OP_LHAX,
  103. 3,
  104. 0,
  105. 1,
  106. 2
  107. },
  108. {
  109. OP_LHZX,
  110. 2,
  111. 0,
  112. 1,
  113. 2
  114. },
  115. {
  116. OP_LBZX,
  117. 1,
  118. 0,
  119. 1,
  120. 1
  121. },
  122. {
  123. OP_LWZUX,
  124. 4,
  125. 1,
  126. 1,
  127. 4
  128. },
  129. {
  130. OP_LHAUX,
  131. 3,
  132. 1,
  133. 1,
  134. 2
  135. },
  136. {
  137. OP_LHZUX,
  138. 2,
  139. 1,
  140. 1,
  141. 2
  142. },
  143. {
  144. OP_LBZUX,
  145. 1,
  146. 1,
  147. 1,
  148. 1
  149. },
  150. };
  151. static unsigned int cpu_post_load_size = ARRAY_SIZE(cpu_post_load_table);
  152. int cpu_post_test_load (void)
  153. {
  154. int ret = 0;
  155. unsigned int i;
  156. int flag = disable_interrupts();
  157. for (i = 0; i < cpu_post_load_size && ret == 0; i++)
  158. {
  159. struct cpu_post_load_s *test = cpu_post_load_table + i;
  160. uchar data[16] =
  161. { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
  162. ulong base0 = (ulong) (data + 8);
  163. ulong base = base0;
  164. ulong value;
  165. if (test->index)
  166. {
  167. ulong code[] =
  168. {
  169. ASM_12(test->cmd, 5, 3, 4),
  170. ASM_BLR,
  171. };
  172. cpu_post_exec_22w (code, &base, test->offset, &value);
  173. }
  174. else
  175. {
  176. ulong code[] =
  177. {
  178. ASM_11I(test->cmd, 4, 3, test->offset),
  179. ASM_BLR,
  180. };
  181. cpu_post_exec_21w (code, &base, &value);
  182. }
  183. if (ret == 0)
  184. {
  185. if (test->update)
  186. ret = base == base0 + test->offset ? 0 : -1;
  187. else
  188. ret = base == base0 ? 0 : -1;
  189. }
  190. if (ret == 0)
  191. {
  192. switch (test->width)
  193. {
  194. case 1:
  195. ret = *(uchar *)(base0 + test->offset) == value ?
  196. 0 : -1;
  197. break;
  198. case 2:
  199. ret = *(ushort *)(base0 + test->offset) == value ?
  200. 0 : -1;
  201. break;
  202. case 3:
  203. ret = *(short *)(base0 + test->offset) == value ?
  204. 0 : -1;
  205. break;
  206. case 4:
  207. ret = *(ulong *)(base0 + test->offset) == value ?
  208. 0 : -1;
  209. break;
  210. }
  211. }
  212. if (ret != 0)
  213. {
  214. post_log ("Error at load test %d !\n", i);
  215. }
  216. }
  217. if (flag)
  218. enable_interrupts();
  219. return ret;
  220. }
  221. #endif