threex.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * (C) Copyright 2002
  4. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  5. */
  6. #include <common.h>
  7. /*
  8. * CPU test
  9. * Ternary instructions instr rA,rS,rB
  10. *
  11. * Logic instructions: or, orc, xor, nand, nor, eqv
  12. * Shift instructions: slw, srw, sraw
  13. *
  14. * The test contains a pre-built table of instructions, operands and
  15. * expected results. For each table entry, the test will cyclically use
  16. * different sets of operand registers and result registers.
  17. */
  18. #include <post.h>
  19. #include "cpu_asm.h"
  20. #if CONFIG_POST & CONFIG_SYS_POST_CPU
  21. extern void cpu_post_exec_22 (ulong *code, ulong *cr, ulong *res, ulong op1,
  22. ulong op2);
  23. extern ulong cpu_post_makecr (long v);
  24. static struct cpu_post_threex_s
  25. {
  26. ulong cmd;
  27. ulong op1;
  28. ulong op2;
  29. ulong res;
  30. } cpu_post_threex_table[] =
  31. {
  32. {
  33. OP_OR,
  34. 0x1234,
  35. 0x5678,
  36. 0x1234 | 0x5678
  37. },
  38. {
  39. OP_ORC,
  40. 0x1234,
  41. 0x5678,
  42. 0x1234 | ~0x5678
  43. },
  44. {
  45. OP_XOR,
  46. 0x1234,
  47. 0x5678,
  48. 0x1234 ^ 0x5678
  49. },
  50. {
  51. OP_NAND,
  52. 0x1234,
  53. 0x5678,
  54. ~(0x1234 & 0x5678)
  55. },
  56. {
  57. OP_NOR,
  58. 0x1234,
  59. 0x5678,
  60. ~(0x1234 | 0x5678)
  61. },
  62. {
  63. OP_EQV,
  64. 0x1234,
  65. 0x5678,
  66. ~(0x1234 ^ 0x5678)
  67. },
  68. {
  69. OP_SLW,
  70. 0x80,
  71. 16,
  72. 0x800000
  73. },
  74. {
  75. OP_SLW,
  76. 0x80,
  77. 32,
  78. 0
  79. },
  80. {
  81. OP_SRW,
  82. 0x800000,
  83. 16,
  84. 0x80
  85. },
  86. {
  87. OP_SRW,
  88. 0x800000,
  89. 32,
  90. 0
  91. },
  92. {
  93. OP_SRAW,
  94. 0x80000000,
  95. 3,
  96. 0xf0000000
  97. },
  98. {
  99. OP_SRAW,
  100. 0x8000,
  101. 3,
  102. 0x1000
  103. },
  104. };
  105. static unsigned int cpu_post_threex_size = ARRAY_SIZE(cpu_post_threex_table);
  106. int cpu_post_test_threex (void)
  107. {
  108. int ret = 0;
  109. unsigned int i, reg;
  110. int flag = disable_interrupts();
  111. for (i = 0; i < cpu_post_threex_size && ret == 0; i++)
  112. {
  113. struct cpu_post_threex_s *test = cpu_post_threex_table + i;
  114. for (reg = 0; reg < 32 && ret == 0; reg++)
  115. {
  116. unsigned int reg0 = (reg + 0) % 32;
  117. unsigned int reg1 = (reg + 1) % 32;
  118. unsigned int reg2 = (reg + 2) % 32;
  119. unsigned int stk = reg < 16 ? 31 : 15;
  120. unsigned long code[] =
  121. {
  122. ASM_STW(stk, 1, -4),
  123. ASM_ADDI(stk, 1, -24),
  124. ASM_STW(3, stk, 12),
  125. ASM_STW(4, stk, 16),
  126. ASM_STW(reg0, stk, 8),
  127. ASM_STW(reg1, stk, 4),
  128. ASM_STW(reg2, stk, 0),
  129. ASM_LWZ(reg1, stk, 12),
  130. ASM_LWZ(reg0, stk, 16),
  131. ASM_12X(test->cmd, reg2, reg1, reg0),
  132. ASM_STW(reg2, stk, 12),
  133. ASM_LWZ(reg2, stk, 0),
  134. ASM_LWZ(reg1, stk, 4),
  135. ASM_LWZ(reg0, stk, 8),
  136. ASM_LWZ(3, stk, 12),
  137. ASM_ADDI(1, stk, 24),
  138. ASM_LWZ(stk, 1, -4),
  139. ASM_BLR,
  140. };
  141. unsigned long codecr[] =
  142. {
  143. ASM_STW(stk, 1, -4),
  144. ASM_ADDI(stk, 1, -24),
  145. ASM_STW(3, stk, 12),
  146. ASM_STW(4, stk, 16),
  147. ASM_STW(reg0, stk, 8),
  148. ASM_STW(reg1, stk, 4),
  149. ASM_STW(reg2, stk, 0),
  150. ASM_LWZ(reg1, stk, 12),
  151. ASM_LWZ(reg0, stk, 16),
  152. ASM_12X(test->cmd, reg2, reg1, reg0) | BIT_C,
  153. ASM_STW(reg2, stk, 12),
  154. ASM_LWZ(reg2, stk, 0),
  155. ASM_LWZ(reg1, stk, 4),
  156. ASM_LWZ(reg0, stk, 8),
  157. ASM_LWZ(3, stk, 12),
  158. ASM_ADDI(1, stk, 24),
  159. ASM_LWZ(stk, 1, -4),
  160. ASM_BLR,
  161. };
  162. ulong res;
  163. ulong cr;
  164. if (ret == 0)
  165. {
  166. cr = 0;
  167. cpu_post_exec_22 (code, & cr, & res, test->op1, test->op2);
  168. ret = res == test->res && cr == 0 ? 0 : -1;
  169. if (ret != 0)
  170. {
  171. post_log ("Error at threex test %d !\n", i);
  172. }
  173. }
  174. if (ret == 0)
  175. {
  176. cpu_post_exec_22 (codecr, & cr, & res, test->op1, test->op2);
  177. ret = res == test->res &&
  178. (cr & 0xe0000000) == cpu_post_makecr (res) ? 0 : -1;
  179. if (ret != 0)
  180. {
  181. post_log ("Error at threex test %d !\n", i);
  182. }
  183. }
  184. }
  185. }
  186. if (flag)
  187. enable_interrupts();
  188. return ret;
  189. }
  190. #endif