b.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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. * Branch instructions: b, bl, bc
  27. *
  28. * The first 2 instructions (b, bl) are verified by jumping
  29. * to a fixed address and checking whether control was transfered
  30. * to that very point. For the bl instruction the value of the
  31. * link register is checked as well (using mfspr).
  32. * To verify the bc instruction various combinations of the BI/BO
  33. * fields, the CTR and the condition register values are
  34. * checked. The list of such combinations is pre-built and
  35. * linked in U-Boot at build time.
  36. */
  37. #ifdef CONFIG_POST
  38. #include <post.h>
  39. #include "cpu_asm.h"
  40. #if CONFIG_POST & CFG_POST_CPU
  41. extern void cpu_post_exec_11 (ulong *code, ulong *res, ulong op1);
  42. extern void cpu_post_exec_31 (ulong *code, ulong *ctr, ulong *lr, ulong *jump,
  43. ulong cr);
  44. static int cpu_post_test_bc (ulong cmd, ulong bo, ulong bi,
  45. int pjump, int decr, int link, ulong pctr, ulong cr)
  46. {
  47. int ret = 0;
  48. ulong lr = 0;
  49. ulong ctr = pctr;
  50. ulong jump;
  51. unsigned long code[] =
  52. {
  53. ASM_MTCR(6),
  54. ASM_MFLR(6),
  55. ASM_MTCTR(3),
  56. ASM_MTLR(4),
  57. ASM_LI(5, 1),
  58. ASM_3O(cmd, bo, bi, 8),
  59. ASM_LI(5, 0),
  60. ASM_MFCTR(3),
  61. ASM_MFLR(4),
  62. ASM_MTLR(6),
  63. ASM_BLR,
  64. };
  65. cpu_post_exec_31 (code, &ctr, &lr, &jump, cr);
  66. if (ret == 0)
  67. ret = pjump == jump ? 0 : -1;
  68. if (ret == 0)
  69. {
  70. if (decr)
  71. ret = pctr == ctr + 1 ? 0 : -1;
  72. else
  73. ret = pctr == ctr ? 0 : -1;
  74. }
  75. if (ret == 0)
  76. {
  77. if (link)
  78. ret = lr == (ulong) code + 24 ? 0 : -1;
  79. else
  80. ret = lr == 0 ? 0 : -1;
  81. }
  82. return ret;
  83. }
  84. int cpu_post_test_b (void)
  85. {
  86. int ret = 0;
  87. unsigned int i;
  88. if (ret == 0)
  89. {
  90. ulong code[] =
  91. {
  92. ASM_MFLR(4),
  93. ASM_MTLR(3),
  94. ASM_B(4),
  95. ASM_MFLR(3),
  96. ASM_MTLR(4),
  97. ASM_BLR,
  98. };
  99. ulong res;
  100. cpu_post_exec_11 (code, &res, 0);
  101. ret = res == 0 ? 0 : -1;
  102. if (ret != 0)
  103. {
  104. post_log ("Error at b1 test !\n");
  105. }
  106. }
  107. if (ret == 0)
  108. {
  109. ulong code[] =
  110. {
  111. ASM_MFLR(4),
  112. ASM_MTLR(3),
  113. ASM_BL(4),
  114. ASM_MFLR(3),
  115. ASM_MTLR(4),
  116. ASM_BLR,
  117. };
  118. ulong res;
  119. cpu_post_exec_11 (code, &res, 0);
  120. ret = res == (ulong)code + 12 ? 0 : -1;
  121. if (ret != 0)
  122. {
  123. post_log ("Error at b2 test !\n");
  124. }
  125. }
  126. if (ret == 0)
  127. {
  128. ulong cc, cd;
  129. int cond;
  130. ulong ctr;
  131. int link;
  132. i = 0;
  133. for (cc = 0; cc < 4 && ret == 0; cc++)
  134. {
  135. for (cd = 0; cd < 4 && ret == 0; cd++)
  136. {
  137. for (link = 0; link <= 1 && ret == 0; link++)
  138. {
  139. for (cond = 0; cond <= 1 && ret == 0; cond++)
  140. {
  141. for (ctr = 1; ctr <= 2 && ret == 0; ctr++)
  142. {
  143. int decr = cd < 2;
  144. int cr = cond ? 0x80000000 : 0x00000000;
  145. int jumpc = cc >= 2 ||
  146. (cc == 0 && !cond) ||
  147. (cc == 1 && cond);
  148. int jumpd = cd >= 2 ||
  149. (cd == 0 && ctr != 1) ||
  150. (cd == 1 && ctr == 1);
  151. int jump = jumpc && jumpd;
  152. ret = cpu_post_test_bc (link ? OP_BCL : OP_BC,
  153. (cc << 3) + (cd << 1), 0, jump, decr, link,
  154. ctr, cr);
  155. if (ret != 0)
  156. {
  157. post_log ("Error at b3 test %d !\n", i);
  158. }
  159. i++;
  160. }
  161. }
  162. }
  163. }
  164. }
  165. }
  166. return ret;
  167. }
  168. #endif
  169. #endif