cpu.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /*
  2. * (C) Copyright 2011, Stefan Kristiansson <stefan.kristiansson@saunalahti.fi>
  3. * (C) Copyright 2011, Julius Baxter <julius@opencores.org>
  4. *
  5. * SPDX-License-Identifier: GPL-2.0+
  6. */
  7. #include <common.h>
  8. #include <asm/system.h>
  9. #include <asm/openrisc_exc.h>
  10. static volatile int illegal_instruction;
  11. static void illegal_instruction_handler(void)
  12. {
  13. ulong *epcr = (ulong *)mfspr(SPR_EPCR_BASE);
  14. /* skip over the illegal instruction */
  15. mtspr(SPR_EPCR_BASE, (ulong)(++epcr));
  16. illegal_instruction = 1;
  17. }
  18. static void checkinstructions(void)
  19. {
  20. ulong ra = 1, rb = 1, rc;
  21. exception_install_handler(EXC_ILLEGAL_INSTR,
  22. illegal_instruction_handler);
  23. illegal_instruction = 0;
  24. asm volatile("l.mul %0,%1,%2" : "=r" (rc) : "r" (ra), "r" (rb));
  25. printf(" Hardware multiplier: %s\n",
  26. illegal_instruction ? "no" : "yes");
  27. illegal_instruction = 0;
  28. asm volatile("l.div %0,%1,%2" : "=r" (rc) : "r" (ra), "r" (rb));
  29. printf(" Hardware divider: %s\n",
  30. illegal_instruction ? "no" : "yes");
  31. exception_free_handler(EXC_ILLEGAL_INSTR);
  32. }
  33. int checkcpu(void)
  34. {
  35. ulong upr = mfspr(SPR_UPR);
  36. ulong vr = mfspr(SPR_VR);
  37. ulong iccfgr = mfspr(SPR_ICCFGR);
  38. ulong dccfgr = mfspr(SPR_DCCFGR);
  39. ulong immucfgr = mfspr(SPR_IMMUCFGR);
  40. ulong dmmucfgr = mfspr(SPR_DMMUCFGR);
  41. ulong cpucfgr = mfspr(SPR_CPUCFGR);
  42. uint ver = (vr & SPR_VR_VER) >> 24;
  43. uint rev = vr & SPR_VR_REV;
  44. uint block_size;
  45. uint ways;
  46. uint sets;
  47. printf("CPU: OpenRISC-%x00 (rev %d) @ %d MHz\n",
  48. ver, rev, (CONFIG_SYS_CLK_FREQ / 1000000));
  49. if (upr & SPR_UPR_DCP) {
  50. block_size = (dccfgr & SPR_DCCFGR_CBS) ? 32 : 16;
  51. ways = 1 << (dccfgr & SPR_DCCFGR_NCW);
  52. printf(" D-Cache: %d bytes, %d bytes/line, %d way(s)\n",
  53. checkdcache(), block_size, ways);
  54. } else {
  55. printf(" D-Cache: no\n");
  56. }
  57. if (upr & SPR_UPR_ICP) {
  58. block_size = (iccfgr & SPR_ICCFGR_CBS) ? 32 : 16;
  59. ways = 1 << (iccfgr & SPR_ICCFGR_NCW);
  60. printf(" I-Cache: %d bytes, %d bytes/line, %d way(s)\n",
  61. checkicache(), block_size, ways);
  62. } else {
  63. printf(" I-Cache: no\n");
  64. }
  65. if (upr & SPR_UPR_DMP) {
  66. sets = 1 << ((dmmucfgr & SPR_DMMUCFGR_NTS) >> 2);
  67. ways = (dmmucfgr & SPR_DMMUCFGR_NTW) + 1;
  68. printf(" DMMU: %d sets, %d way(s)\n",
  69. sets, ways);
  70. } else {
  71. printf(" DMMU: no\n");
  72. }
  73. if (upr & SPR_UPR_IMP) {
  74. sets = 1 << ((immucfgr & SPR_IMMUCFGR_NTS) >> 2);
  75. ways = (immucfgr & SPR_IMMUCFGR_NTW) + 1;
  76. printf(" IMMU: %d sets, %d way(s)\n",
  77. sets, ways);
  78. } else {
  79. printf(" IMMU: no\n");
  80. }
  81. printf(" MAC unit: %s\n",
  82. (upr & SPR_UPR_MP) ? "yes" : "no");
  83. printf(" Debug unit: %s\n",
  84. (upr & SPR_UPR_DUP) ? "yes" : "no");
  85. printf(" Performance counters: %s\n",
  86. (upr & SPR_UPR_PCUP) ? "yes" : "no");
  87. printf(" Power management: %s\n",
  88. (upr & SPR_UPR_PMP) ? "yes" : "no");
  89. printf(" Interrupt controller: %s\n",
  90. (upr & SPR_UPR_PICP) ? "yes" : "no");
  91. printf(" Timer: %s\n",
  92. (upr & SPR_UPR_TTP) ? "yes" : "no");
  93. printf(" Custom unit(s): %s\n",
  94. (upr & SPR_UPR_CUP) ? "yes" : "no");
  95. printf(" Supported instructions:\n");
  96. printf(" ORBIS32: %s\n",
  97. (cpucfgr & SPR_CPUCFGR_OB32S) ? "yes" : "no");
  98. printf(" ORBIS64: %s\n",
  99. (cpucfgr & SPR_CPUCFGR_OB64S) ? "yes" : "no");
  100. printf(" ORFPX32: %s\n",
  101. (cpucfgr & SPR_CPUCFGR_OF32S) ? "yes" : "no");
  102. printf(" ORFPX64: %s\n",
  103. (cpucfgr & SPR_CPUCFGR_OF64S) ? "yes" : "no");
  104. checkinstructions();
  105. return 0;
  106. }
  107. int cleanup_before_linux(void)
  108. {
  109. disable_interrupts();
  110. return 0;
  111. }
  112. extern void __reset(void);
  113. int do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  114. {
  115. disable_interrupts();
  116. /* Code the jump to __reset here as the compiler is prone to
  117. emitting a bad jump instruction if the function is in flash */
  118. __asm__("l.movhi r1,hi(__reset); \
  119. l.ori r1,r1,lo(__reset); \
  120. l.jr r1");
  121. /* not reached, __reset does not return */
  122. return 0;
  123. }