rlwimi.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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. * Shift instructions: rlwimi
  10. *
  11. * The test contains a pre-built table of instructions, operands and
  12. * expected results. For each table entry, the test will cyclically use
  13. * different sets of operand registers and result registers.
  14. */
  15. #include <post.h>
  16. #include "cpu_asm.h"
  17. #if CONFIG_POST & CONFIG_SYS_POST_CPU
  18. extern void cpu_post_exec_22 (ulong *code, ulong *cr, ulong *res, ulong op1,
  19. ulong op2);
  20. extern ulong cpu_post_makecr (long v);
  21. static struct cpu_post_rlwimi_s
  22. {
  23. ulong cmd;
  24. ulong op0;
  25. ulong op1;
  26. uchar op2;
  27. uchar mb;
  28. uchar me;
  29. ulong res;
  30. } cpu_post_rlwimi_table[] =
  31. {
  32. {
  33. OP_RLWIMI,
  34. 0xff00ffff,
  35. 0x0000aa00,
  36. 8,
  37. 8,
  38. 15,
  39. 0xffaaffff
  40. },
  41. };
  42. static unsigned int cpu_post_rlwimi_size = ARRAY_SIZE(cpu_post_rlwimi_table);
  43. int cpu_post_test_rlwimi (void)
  44. {
  45. int ret = 0;
  46. unsigned int i, reg;
  47. int flag = disable_interrupts();
  48. for (i = 0; i < cpu_post_rlwimi_size && ret == 0; i++)
  49. {
  50. struct cpu_post_rlwimi_s *test = cpu_post_rlwimi_table + i;
  51. for (reg = 0; reg < 32 && ret == 0; reg++)
  52. {
  53. unsigned int reg0 = (reg + 0) % 32;
  54. unsigned int reg1 = (reg + 1) % 32;
  55. unsigned int stk = reg < 16 ? 31 : 15;
  56. unsigned long code[] =
  57. {
  58. ASM_STW(stk, 1, -4),
  59. ASM_ADDI(stk, 1, -20),
  60. ASM_STW(3, stk, 8),
  61. ASM_STW(4, stk, 12),
  62. ASM_STW(reg0, stk, 4),
  63. ASM_STW(reg1, stk, 0),
  64. ASM_LWZ(reg1, stk, 8),
  65. ASM_LWZ(reg0, stk, 12),
  66. ASM_113(test->cmd, reg1, reg0, test->op2, test->mb, test->me),
  67. ASM_STW(reg1, stk, 8),
  68. ASM_LWZ(reg1, stk, 0),
  69. ASM_LWZ(reg0, stk, 4),
  70. ASM_LWZ(3, stk, 8),
  71. ASM_ADDI(1, stk, 20),
  72. ASM_LWZ(stk, 1, -4),
  73. ASM_BLR,
  74. };
  75. unsigned long codecr[] =
  76. {
  77. ASM_STW(stk, 1, -4),
  78. ASM_ADDI(stk, 1, -20),
  79. ASM_STW(3, stk, 8),
  80. ASM_STW(4, stk, 12),
  81. ASM_STW(reg0, stk, 4),
  82. ASM_STW(reg1, stk, 0),
  83. ASM_LWZ(reg1, stk, 8),
  84. ASM_LWZ(reg0, stk, 12),
  85. ASM_113(test->cmd, reg1, reg0, test->op2, test->mb, test->me) |
  86. BIT_C,
  87. ASM_STW(reg1, stk, 8),
  88. ASM_LWZ(reg1, stk, 0),
  89. ASM_LWZ(reg0, stk, 4),
  90. ASM_LWZ(3, stk, 8),
  91. ASM_ADDI(1, stk, 20),
  92. ASM_LWZ(stk, 1, -4),
  93. ASM_BLR,
  94. };
  95. ulong res;
  96. ulong cr;
  97. if (ret == 0)
  98. {
  99. cr = 0;
  100. cpu_post_exec_22 (code, & cr, & res, test->op0, test->op1);
  101. ret = res == test->res && cr == 0 ? 0 : -1;
  102. if (ret != 0)
  103. {
  104. post_log ("Error at rlwimi test %d !\n", i);
  105. }
  106. }
  107. if (ret == 0)
  108. {
  109. cpu_post_exec_22 (codecr, & cr, & res, test->op0, test->op1);
  110. ret = res == test->res &&
  111. (cr & 0xe0000000) == cpu_post_makecr (res) ? 0 : -1;
  112. if (ret != 0)
  113. {
  114. post_log ("Error at rlwimi test %d !\n", i);
  115. }
  116. }
  117. }
  118. }
  119. if (flag)
  120. enable_interrupts();
  121. return ret;
  122. }
  123. #endif