rlwnm.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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: rlwnm
  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_rlwnm_s
  22. {
  23. ulong cmd;
  24. ulong op1;
  25. ulong op2;
  26. uchar mb;
  27. uchar me;
  28. ulong res;
  29. } cpu_post_rlwnm_table[] =
  30. {
  31. {
  32. OP_RLWNM,
  33. 0xffff0000,
  34. 24,
  35. 16,
  36. 23,
  37. 0x0000ff00
  38. },
  39. };
  40. static unsigned int cpu_post_rlwnm_size = ARRAY_SIZE(cpu_post_rlwnm_table);
  41. int cpu_post_test_rlwnm (void)
  42. {
  43. int ret = 0;
  44. unsigned int i, reg;
  45. int flag = disable_interrupts();
  46. for (i = 0; i < cpu_post_rlwnm_size && ret == 0; i++)
  47. {
  48. struct cpu_post_rlwnm_s *test = cpu_post_rlwnm_table + i;
  49. for (reg = 0; reg < 32 && ret == 0; reg++)
  50. {
  51. unsigned int reg0 = (reg + 0) % 32;
  52. unsigned int reg1 = (reg + 1) % 32;
  53. unsigned int reg2 = (reg + 2) % 32;
  54. unsigned int stk = reg < 16 ? 31 : 15;
  55. unsigned long code[] =
  56. {
  57. ASM_STW(stk, 1, -4),
  58. ASM_ADDI(stk, 1, -24),
  59. ASM_STW(3, stk, 12),
  60. ASM_STW(4, stk, 16),
  61. ASM_STW(reg0, stk, 8),
  62. ASM_STW(reg1, stk, 4),
  63. ASM_STW(reg2, stk, 0),
  64. ASM_LWZ(reg1, stk, 12),
  65. ASM_LWZ(reg0, stk, 16),
  66. ASM_122(test->cmd, reg2, reg1, reg0, test->mb, test->me),
  67. ASM_STW(reg2, stk, 12),
  68. ASM_LWZ(reg2, stk, 0),
  69. ASM_LWZ(reg1, stk, 4),
  70. ASM_LWZ(reg0, stk, 8),
  71. ASM_LWZ(3, stk, 12),
  72. ASM_ADDI(1, stk, 24),
  73. ASM_LWZ(stk, 1, -4),
  74. ASM_BLR,
  75. };
  76. unsigned long codecr[] =
  77. {
  78. ASM_STW(stk, 1, -4),
  79. ASM_ADDI(stk, 1, -24),
  80. ASM_STW(3, stk, 12),
  81. ASM_STW(4, stk, 16),
  82. ASM_STW(reg0, stk, 8),
  83. ASM_STW(reg1, stk, 4),
  84. ASM_STW(reg2, stk, 0),
  85. ASM_LWZ(reg1, stk, 12),
  86. ASM_LWZ(reg0, stk, 16),
  87. ASM_122(test->cmd, reg2, reg1, reg0, test->mb, test->me) |
  88. BIT_C,
  89. ASM_STW(reg2, stk, 12),
  90. ASM_LWZ(reg2, stk, 0),
  91. ASM_LWZ(reg1, stk, 4),
  92. ASM_LWZ(reg0, stk, 8),
  93. ASM_LWZ(3, stk, 12),
  94. ASM_ADDI(1, stk, 24),
  95. ASM_LWZ(stk, 1, -4),
  96. ASM_BLR,
  97. };
  98. ulong res;
  99. ulong cr;
  100. if (ret == 0)
  101. {
  102. cr = 0;
  103. cpu_post_exec_22 (code, & cr, & res, test->op1, test->op2);
  104. ret = res == test->res && cr == 0 ? 0 : -1;
  105. if (ret != 0)
  106. {
  107. post_log ("Error at rlwnm test %d !\n", i);
  108. }
  109. }
  110. if (ret == 0)
  111. {
  112. cpu_post_exec_22 (codecr, & cr, & res, test->op1, test->op2);
  113. ret = res == test->res &&
  114. (cr & 0xe0000000) == cpu_post_makecr (res) ? 0 : -1;
  115. if (ret != 0)
  116. {
  117. post_log ("Error at rlwnm test %d !\n", i);
  118. }
  119. }
  120. }
  121. }
  122. if (flag)
  123. enable_interrupts();
  124. return ret;
  125. }
  126. #endif