andi.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. * Logic instructions: andi., andis.
  11. *
  12. * The test contains a pre-built table of instructions, operands and
  13. * expected results. For each table entry, the test will cyclically use
  14. * different sets of operand registers and result registers.
  15. */
  16. #include <post.h>
  17. #include "cpu_asm.h"
  18. #if CONFIG_POST & CONFIG_SYS_POST_CPU
  19. extern void cpu_post_exec_21 (ulong *code, ulong *cr, ulong *res, ulong op);
  20. extern ulong cpu_post_makecr (long v);
  21. static struct cpu_post_andi_s
  22. {
  23. ulong cmd;
  24. ulong op1;
  25. ushort op2;
  26. ulong res;
  27. } cpu_post_andi_table[] =
  28. {
  29. {
  30. OP_ANDI_,
  31. 0x80008000,
  32. 0xffff,
  33. 0x00008000
  34. },
  35. {
  36. OP_ANDIS_,
  37. 0x80008000,
  38. 0xffff,
  39. 0x80000000
  40. },
  41. };
  42. static unsigned int cpu_post_andi_size = ARRAY_SIZE(cpu_post_andi_table);
  43. int cpu_post_test_andi (void)
  44. {
  45. int ret = 0;
  46. unsigned int i, reg;
  47. int flag = disable_interrupts();
  48. for (i = 0; i < cpu_post_andi_size && ret == 0; i++)
  49. {
  50. struct cpu_post_andi_s *test = cpu_post_andi_table + i;
  51. for (reg = 0; reg < 32 && ret == 0; reg++)
  52. {
  53. unsigned int reg0 = (reg + 0) % 32;
  54. unsigned int reg1 = (reg + 1) % 32;
  55. unsigned int stk = reg < 16 ? 31 : 15;
  56. unsigned long codecr[] =
  57. {
  58. ASM_STW(stk, 1, -4),
  59. ASM_ADDI(stk, 1, -16),
  60. ASM_STW(3, stk, 8),
  61. ASM_STW(reg0, stk, 4),
  62. ASM_STW(reg1, stk, 0),
  63. ASM_LWZ(reg0, stk, 8),
  64. ASM_11IX(test->cmd, reg1, reg0, test->op2),
  65. ASM_STW(reg1, stk, 8),
  66. ASM_LWZ(reg1, stk, 0),
  67. ASM_LWZ(reg0, stk, 4),
  68. ASM_LWZ(3, stk, 8),
  69. ASM_ADDI(1, stk, 16),
  70. ASM_LWZ(stk, 1, -4),
  71. ASM_BLR,
  72. };
  73. ulong res;
  74. ulong cr;
  75. cpu_post_exec_21 (codecr, & cr, & res, test->op1);
  76. ret = res == test->res &&
  77. (cr & 0xe0000000) == cpu_post_makecr (res) ? 0 : -1;
  78. if (ret != 0)
  79. {
  80. post_log ("Error at andi test %d !\n", i);
  81. }
  82. }
  83. }
  84. if (flag)
  85. enable_interrupts();
  86. return ret;
  87. }
  88. #endif