load.c 4.1 KB

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