load.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  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 = ARRAY_SIZE(cpu_post_load_table);
  169. int cpu_post_test_load (void)
  170. {
  171. int ret = 0;
  172. unsigned int i;
  173. int flag = disable_interrupts();
  174. for (i = 0; i < cpu_post_load_size && ret == 0; i++)
  175. {
  176. struct cpu_post_load_s *test = cpu_post_load_table + i;
  177. uchar data[16] =
  178. { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
  179. ulong base0 = (ulong) (data + 8);
  180. ulong base = base0;
  181. ulong value;
  182. if (test->index)
  183. {
  184. ulong code[] =
  185. {
  186. ASM_12(test->cmd, 5, 3, 4),
  187. ASM_BLR,
  188. };
  189. cpu_post_exec_22w (code, &base, test->offset, &value);
  190. }
  191. else
  192. {
  193. ulong code[] =
  194. {
  195. ASM_11I(test->cmd, 4, 3, test->offset),
  196. ASM_BLR,
  197. };
  198. cpu_post_exec_21w (code, &base, &value);
  199. }
  200. if (ret == 0)
  201. {
  202. if (test->update)
  203. ret = base == base0 + test->offset ? 0 : -1;
  204. else
  205. ret = base == base0 ? 0 : -1;
  206. }
  207. if (ret == 0)
  208. {
  209. switch (test->width)
  210. {
  211. case 1:
  212. ret = *(uchar *)(base0 + test->offset) == value ?
  213. 0 : -1;
  214. break;
  215. case 2:
  216. ret = *(ushort *)(base0 + test->offset) == value ?
  217. 0 : -1;
  218. break;
  219. case 3:
  220. ret = *(short *)(base0 + test->offset) == value ?
  221. 0 : -1;
  222. break;
  223. case 4:
  224. ret = *(ulong *)(base0 + test->offset) == value ?
  225. 0 : -1;
  226. break;
  227. }
  228. }
  229. if (ret != 0)
  230. {
  231. post_log ("Error at load test %d !\n", i);
  232. }
  233. }
  234. if (flag)
  235. enable_interrupts();
  236. return ret;
  237. }
  238. #endif