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