three.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  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. * Ternary instructions instr rD,rA,rB
  27. *
  28. * Arithmetic instructions: add, addc, adde, subf, subfc, subfe,
  29. * mullw, mulhw, mulhwu, divw, divwu
  30. *
  31. * The test contains a pre-built table of instructions, operands and
  32. * expected results. For each table entry, the test will cyclically use
  33. * different sets of operand registers and result registers.
  34. */
  35. #ifdef CONFIG_POST
  36. #include <post.h>
  37. #include "cpu_asm.h"
  38. #if CONFIG_POST & CFG_POST_CPU
  39. extern void cpu_post_exec_22 (ulong *code, ulong *cr, ulong *res, ulong op1,
  40. ulong op2);
  41. extern ulong cpu_post_makecr (long v);
  42. static struct cpu_post_three_s
  43. {
  44. ulong cmd;
  45. ulong op1;
  46. ulong op2;
  47. ulong res;
  48. } cpu_post_three_table[] =
  49. {
  50. {
  51. OP_ADD,
  52. 100,
  53. 200,
  54. 300
  55. },
  56. {
  57. OP_ADD,
  58. 100,
  59. -200,
  60. -100
  61. },
  62. {
  63. OP_ADDC,
  64. 100,
  65. 200,
  66. 300
  67. },
  68. {
  69. OP_ADDC,
  70. 100,
  71. -200,
  72. -100
  73. },
  74. {
  75. OP_ADDE,
  76. 100,
  77. 200,
  78. 300
  79. },
  80. {
  81. OP_ADDE,
  82. 100,
  83. -200,
  84. -100
  85. },
  86. {
  87. OP_SUBF,
  88. 100,
  89. 200,
  90. 100
  91. },
  92. {
  93. OP_SUBF,
  94. 300,
  95. 200,
  96. -100
  97. },
  98. {
  99. OP_SUBFC,
  100. 100,
  101. 200,
  102. 100
  103. },
  104. {
  105. OP_SUBFC,
  106. 300,
  107. 200,
  108. -100
  109. },
  110. {
  111. OP_SUBFE,
  112. 100,
  113. 200,
  114. 200 + ~100
  115. },
  116. {
  117. OP_SUBFE,
  118. 300,
  119. 200,
  120. 200 + ~300
  121. },
  122. {
  123. OP_MULLW,
  124. 200,
  125. 300,
  126. 200 * 300
  127. },
  128. {
  129. OP_MULHW,
  130. 0x10000000,
  131. 0x10000000,
  132. 0x1000000
  133. },
  134. {
  135. OP_MULHWU,
  136. 0x80000000,
  137. 0x80000000,
  138. 0x40000000
  139. },
  140. {
  141. OP_DIVW,
  142. -20,
  143. 5,
  144. -4
  145. },
  146. {
  147. OP_DIVWU,
  148. 0x8000,
  149. 0x200,
  150. 0x40
  151. },
  152. };
  153. static unsigned int cpu_post_three_size =
  154. sizeof (cpu_post_three_table) / sizeof (struct cpu_post_three_s);
  155. int cpu_post_test_three (void)
  156. {
  157. int ret = 0;
  158. unsigned int i, reg;
  159. int flag = disable_interrupts();
  160. for (i = 0; i < cpu_post_three_size && ret == 0; i++)
  161. {
  162. struct cpu_post_three_s *test = cpu_post_three_table + i;
  163. for (reg = 0; reg < 32 && ret == 0; reg++)
  164. {
  165. unsigned int reg0 = (reg + 0) % 32;
  166. unsigned int reg1 = (reg + 1) % 32;
  167. unsigned int reg2 = (reg + 2) % 32;
  168. unsigned int stk = reg < 16 ? 31 : 15;
  169. unsigned long code[] =
  170. {
  171. ASM_STW(stk, 1, -4),
  172. ASM_ADDI(stk, 1, -24),
  173. ASM_STW(3, stk, 12),
  174. ASM_STW(4, stk, 16),
  175. ASM_STW(reg0, stk, 8),
  176. ASM_STW(reg1, stk, 4),
  177. ASM_STW(reg2, stk, 0),
  178. ASM_LWZ(reg1, stk, 12),
  179. ASM_LWZ(reg0, stk, 16),
  180. ASM_12(test->cmd, reg2, reg1, reg0),
  181. ASM_STW(reg2, stk, 12),
  182. ASM_LWZ(reg2, stk, 0),
  183. ASM_LWZ(reg1, stk, 4),
  184. ASM_LWZ(reg0, stk, 8),
  185. ASM_LWZ(3, stk, 12),
  186. ASM_ADDI(1, stk, 24),
  187. ASM_LWZ(stk, 1, -4),
  188. ASM_BLR,
  189. };
  190. unsigned long codecr[] =
  191. {
  192. ASM_STW(stk, 1, -4),
  193. ASM_ADDI(stk, 1, -24),
  194. ASM_STW(3, stk, 12),
  195. ASM_STW(4, stk, 16),
  196. ASM_STW(reg0, stk, 8),
  197. ASM_STW(reg1, stk, 4),
  198. ASM_STW(reg2, stk, 0),
  199. ASM_LWZ(reg1, stk, 12),
  200. ASM_LWZ(reg0, stk, 16),
  201. ASM_12(test->cmd, reg2, reg1, reg0) | BIT_C,
  202. ASM_STW(reg2, stk, 12),
  203. ASM_LWZ(reg2, stk, 0),
  204. ASM_LWZ(reg1, stk, 4),
  205. ASM_LWZ(reg0, stk, 8),
  206. ASM_LWZ(3, stk, 12),
  207. ASM_ADDI(1, stk, 24),
  208. ASM_LWZ(stk, 1, -4),
  209. ASM_BLR,
  210. };
  211. ulong res;
  212. ulong cr;
  213. if (ret == 0)
  214. {
  215. cr = 0;
  216. cpu_post_exec_22 (code, & cr, & res, test->op1, test->op2);
  217. ret = res == test->res && cr == 0 ? 0 : -1;
  218. if (ret != 0)
  219. {
  220. post_log ("Error at three test %d !\n", i);
  221. }
  222. }
  223. if (ret == 0)
  224. {
  225. cpu_post_exec_22 (codecr, & cr, & res, test->op1, test->op2);
  226. ret = res == test->res &&
  227. (cr & 0xe0000000) == cpu_post_makecr (res) ? 0 : -1;
  228. if (ret != 0)
  229. {
  230. post_log ("Error at three test %d !\n", i);
  231. }
  232. }
  233. }
  234. }
  235. if (flag)
  236. enable_interrupts();
  237. return ret;
  238. }
  239. #endif
  240. #endif