threex.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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 rA,rS,rB
  27. *
  28. * Logic instructions: or, orc, xor, nand, nor, eqv
  29. * Shift instructions: slw, srw, sraw
  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_threex_s
  43. {
  44. ulong cmd;
  45. ulong op1;
  46. ulong op2;
  47. ulong res;
  48. } cpu_post_threex_table[] =
  49. {
  50. {
  51. OP_OR,
  52. 0x1234,
  53. 0x5678,
  54. 0x1234 | 0x5678
  55. },
  56. {
  57. OP_ORC,
  58. 0x1234,
  59. 0x5678,
  60. 0x1234 | ~0x5678
  61. },
  62. {
  63. OP_XOR,
  64. 0x1234,
  65. 0x5678,
  66. 0x1234 ^ 0x5678
  67. },
  68. {
  69. OP_NAND,
  70. 0x1234,
  71. 0x5678,
  72. ~(0x1234 & 0x5678)
  73. },
  74. {
  75. OP_NOR,
  76. 0x1234,
  77. 0x5678,
  78. ~(0x1234 | 0x5678)
  79. },
  80. {
  81. OP_EQV,
  82. 0x1234,
  83. 0x5678,
  84. ~(0x1234 ^ 0x5678)
  85. },
  86. {
  87. OP_SLW,
  88. 0x80,
  89. 16,
  90. 0x800000
  91. },
  92. {
  93. OP_SLW,
  94. 0x80,
  95. 32,
  96. 0
  97. },
  98. {
  99. OP_SRW,
  100. 0x800000,
  101. 16,
  102. 0x80
  103. },
  104. {
  105. OP_SRW,
  106. 0x800000,
  107. 32,
  108. 0
  109. },
  110. {
  111. OP_SRAW,
  112. 0x80000000,
  113. 3,
  114. 0xf0000000
  115. },
  116. {
  117. OP_SRAW,
  118. 0x8000,
  119. 3,
  120. 0x1000
  121. },
  122. };
  123. static unsigned int cpu_post_threex_size =
  124. sizeof (cpu_post_threex_table) / sizeof (struct cpu_post_threex_s);
  125. int cpu_post_test_threex (void)
  126. {
  127. int ret = 0;
  128. unsigned int i, reg;
  129. int flag = disable_interrupts();
  130. for (i = 0; i < cpu_post_threex_size && ret == 0; i++)
  131. {
  132. struct cpu_post_threex_s *test = cpu_post_threex_table + i;
  133. for (reg = 0; reg < 32 && ret == 0; reg++)
  134. {
  135. unsigned int reg0 = (reg + 0) % 32;
  136. unsigned int reg1 = (reg + 1) % 32;
  137. unsigned int reg2 = (reg + 2) % 32;
  138. unsigned int stk = reg < 16 ? 31 : 15;
  139. unsigned long code[] =
  140. {
  141. ASM_STW(stk, 1, -4),
  142. ASM_ADDI(stk, 1, -24),
  143. ASM_STW(3, stk, 12),
  144. ASM_STW(4, stk, 16),
  145. ASM_STW(reg0, stk, 8),
  146. ASM_STW(reg1, stk, 4),
  147. ASM_STW(reg2, stk, 0),
  148. ASM_LWZ(reg1, stk, 12),
  149. ASM_LWZ(reg0, stk, 16),
  150. ASM_12X(test->cmd, reg2, reg1, reg0),
  151. ASM_STW(reg2, stk, 12),
  152. ASM_LWZ(reg2, stk, 0),
  153. ASM_LWZ(reg1, stk, 4),
  154. ASM_LWZ(reg0, stk, 8),
  155. ASM_LWZ(3, stk, 12),
  156. ASM_ADDI(1, stk, 24),
  157. ASM_LWZ(stk, 1, -4),
  158. ASM_BLR,
  159. };
  160. unsigned long codecr[] =
  161. {
  162. ASM_STW(stk, 1, -4),
  163. ASM_ADDI(stk, 1, -24),
  164. ASM_STW(3, stk, 12),
  165. ASM_STW(4, stk, 16),
  166. ASM_STW(reg0, stk, 8),
  167. ASM_STW(reg1, stk, 4),
  168. ASM_STW(reg2, stk, 0),
  169. ASM_LWZ(reg1, stk, 12),
  170. ASM_LWZ(reg0, stk, 16),
  171. ASM_12X(test->cmd, reg2, reg1, reg0) | BIT_C,
  172. ASM_STW(reg2, stk, 12),
  173. ASM_LWZ(reg2, stk, 0),
  174. ASM_LWZ(reg1, stk, 4),
  175. ASM_LWZ(reg0, stk, 8),
  176. ASM_LWZ(3, stk, 12),
  177. ASM_ADDI(1, stk, 24),
  178. ASM_LWZ(stk, 1, -4),
  179. ASM_BLR,
  180. };
  181. ulong res;
  182. ulong cr;
  183. if (ret == 0)
  184. {
  185. cr = 0;
  186. cpu_post_exec_22 (code, & cr, & res, test->op1, test->op2);
  187. ret = res == test->res && cr == 0 ? 0 : -1;
  188. if (ret != 0)
  189. {
  190. post_log ("Error at threex test %d !\n", i);
  191. }
  192. }
  193. if (ret == 0)
  194. {
  195. cpu_post_exec_22 (codecr, & cr, & res, test->op1, test->op2);
  196. ret = res == test->res &&
  197. (cr & 0xe0000000) == cpu_post_makecr (res) ? 0 : -1;
  198. if (ret != 0)
  199. {
  200. post_log ("Error at threex test %d !\n", i);
  201. }
  202. }
  203. }
  204. }
  205. if (flag)
  206. enable_interrupts();
  207. return ret;
  208. }
  209. #endif
  210. #endif