srawi.c 2.6 KB

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