cmpi.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. * Integer compare instructions: cmpwi, cmplwi
  10. *
  11. * To verify these instructions the test runs them with
  12. * different combinations of operands, reads the condition
  13. * register value and compares it with the expected one.
  14. * The test contains a pre-built table
  15. * containing the description of each test case: the instruction,
  16. * the values of the operands, the condition field to save
  17. * the result in and the expected result.
  18. */
  19. #include <post.h>
  20. #include "cpu_asm.h"
  21. #if CONFIG_POST & CONFIG_SYS_POST_CPU
  22. extern void cpu_post_exec_11 (ulong *code, ulong *res, ulong op1);
  23. static struct cpu_post_cmpi_s
  24. {
  25. ulong cmd;
  26. ulong op1;
  27. ushort op2;
  28. ulong cr;
  29. ulong res;
  30. } cpu_post_cmpi_table[] =
  31. {
  32. {
  33. OP_CMPWI,
  34. 123,
  35. 123,
  36. 2,
  37. 0x02
  38. },
  39. {
  40. OP_CMPWI,
  41. 123,
  42. 133,
  43. 3,
  44. 0x08
  45. },
  46. {
  47. OP_CMPWI,
  48. 123,
  49. -133,
  50. 4,
  51. 0x04
  52. },
  53. {
  54. OP_CMPLWI,
  55. 123,
  56. 123,
  57. 2,
  58. 0x02
  59. },
  60. {
  61. OP_CMPLWI,
  62. 123,
  63. -133,
  64. 3,
  65. 0x08
  66. },
  67. {
  68. OP_CMPLWI,
  69. 123,
  70. 113,
  71. 4,
  72. 0x04
  73. },
  74. };
  75. static unsigned int cpu_post_cmpi_size = ARRAY_SIZE(cpu_post_cmpi_table);
  76. int cpu_post_test_cmpi (void)
  77. {
  78. int ret = 0;
  79. unsigned int i;
  80. int flag = disable_interrupts();
  81. for (i = 0; i < cpu_post_cmpi_size && ret == 0; i++)
  82. {
  83. struct cpu_post_cmpi_s *test = cpu_post_cmpi_table + i;
  84. unsigned long code[] =
  85. {
  86. ASM_1IC(test->cmd, test->cr, 3, test->op2),
  87. ASM_MFCR(3),
  88. ASM_BLR
  89. };
  90. ulong res;
  91. cpu_post_exec_11 (code, & res, test->op1);
  92. ret = ((res >> (28 - 4 * test->cr)) & 0xe) == test->res ? 0 : -1;
  93. if (ret != 0)
  94. {
  95. post_log ("Error at cmpi test %d !\n", i);
  96. }
  97. }
  98. if (flag)
  99. enable_interrupts();
  100. return ret;
  101. }
  102. #endif