threex.c 4.3 KB

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