cmpi.c 1.8 KB

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