rlwinm.c 2.7 KB

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