cpu.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /*
  2. * (C) Copyright 2011, Stefan Kristiansson <stefan.kristiansson@saunalahti.fi>
  3. * (C) Copyright 2011, Julius Baxter <julius@opencores.org>
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. */
  23. #include <common.h>
  24. #include <asm/system.h>
  25. #include <asm/openrisc_exc.h>
  26. static volatile int illegal_instruction;
  27. static void illegal_instruction_handler(void)
  28. {
  29. ulong *epcr = (ulong *)mfspr(SPR_EPCR_BASE);
  30. /* skip over the illegal instruction */
  31. mtspr(SPR_EPCR_BASE, (ulong)(++epcr));
  32. illegal_instruction = 1;
  33. }
  34. static void checkinstructions(void)
  35. {
  36. ulong ra = 1, rb = 1, rc;
  37. exception_install_handler(EXC_ILLEGAL_INSTR,
  38. illegal_instruction_handler);
  39. illegal_instruction = 0;
  40. asm volatile("l.mul %0,%1,%2" : "=r" (rc) : "r" (ra), "r" (rb));
  41. printf(" Hardware multiplier: %s\n",
  42. illegal_instruction ? "no" : "yes");
  43. illegal_instruction = 0;
  44. asm volatile("l.div %0,%1,%2" : "=r" (rc) : "r" (ra), "r" (rb));
  45. printf(" Hardware divider: %s\n",
  46. illegal_instruction ? "no" : "yes");
  47. exception_free_handler(EXC_ILLEGAL_INSTR);
  48. }
  49. int checkcpu(void)
  50. {
  51. ulong upr = mfspr(SPR_UPR);
  52. ulong vr = mfspr(SPR_VR);
  53. ulong iccfgr = mfspr(SPR_ICCFGR);
  54. ulong dccfgr = mfspr(SPR_DCCFGR);
  55. ulong immucfgr = mfspr(SPR_IMMUCFGR);
  56. ulong dmmucfgr = mfspr(SPR_DMMUCFGR);
  57. ulong cpucfgr = mfspr(SPR_CPUCFGR);
  58. uint ver = (vr & SPR_VR_VER) >> 24;
  59. uint rev = vr & SPR_VR_REV;
  60. uint block_size;
  61. uint ways;
  62. uint sets;
  63. printf("CPU: OpenRISC-%x00 (rev %d) @ %d MHz\n",
  64. ver, rev, (CONFIG_SYS_CLK_FREQ / 1000000));
  65. if (upr & SPR_UPR_DCP) {
  66. block_size = (dccfgr & SPR_DCCFGR_CBS) ? 32 : 16;
  67. ways = 1 << (dccfgr & SPR_DCCFGR_NCW);
  68. printf(" D-Cache: %d bytes, %d bytes/line, %d way(s)\n",
  69. checkdcache(), block_size, ways);
  70. } else {
  71. printf(" D-Cache: no\n");
  72. }
  73. if (upr & SPR_UPR_ICP) {
  74. block_size = (iccfgr & SPR_ICCFGR_CBS) ? 32 : 16;
  75. ways = 1 << (iccfgr & SPR_ICCFGR_NCW);
  76. printf(" I-Cache: %d bytes, %d bytes/line, %d way(s)\n",
  77. checkicache(), block_size, ways);
  78. } else {
  79. printf(" I-Cache: no\n");
  80. }
  81. if (upr & SPR_UPR_DMP) {
  82. sets = 1 << ((dmmucfgr & SPR_DMMUCFGR_NTS) >> 2);
  83. ways = (dmmucfgr & SPR_DMMUCFGR_NTW) + 1;
  84. printf(" DMMU: %d sets, %d way(s)\n",
  85. sets, ways);
  86. } else {
  87. printf(" DMMU: no\n");
  88. }
  89. if (upr & SPR_UPR_IMP) {
  90. sets = 1 << ((immucfgr & SPR_IMMUCFGR_NTS) >> 2);
  91. ways = (immucfgr & SPR_IMMUCFGR_NTW) + 1;
  92. printf(" IMMU: %d sets, %d way(s)\n",
  93. sets, ways);
  94. } else {
  95. printf(" IMMU: no\n");
  96. }
  97. printf(" MAC unit: %s\n",
  98. (upr & SPR_UPR_MP) ? "yes" : "no");
  99. printf(" Debug unit: %s\n",
  100. (upr & SPR_UPR_DUP) ? "yes" : "no");
  101. printf(" Performance counters: %s\n",
  102. (upr & SPR_UPR_PCUP) ? "yes" : "no");
  103. printf(" Power management: %s\n",
  104. (upr & SPR_UPR_PMP) ? "yes" : "no");
  105. printf(" Interrupt controller: %s\n",
  106. (upr & SPR_UPR_PICP) ? "yes" : "no");
  107. printf(" Timer: %s\n",
  108. (upr & SPR_UPR_TTP) ? "yes" : "no");
  109. printf(" Custom unit(s): %s\n",
  110. (upr & SPR_UPR_CUP) ? "yes" : "no");
  111. printf(" Supported instructions:\n");
  112. printf(" ORBIS32: %s\n",
  113. (cpucfgr & SPR_CPUCFGR_OB32S) ? "yes" : "no");
  114. printf(" ORBIS64: %s\n",
  115. (cpucfgr & SPR_CPUCFGR_OB64S) ? "yes" : "no");
  116. printf(" ORFPX32: %s\n",
  117. (cpucfgr & SPR_CPUCFGR_OF32S) ? "yes" : "no");
  118. printf(" ORFPX64: %s\n",
  119. (cpucfgr & SPR_CPUCFGR_OF64S) ? "yes" : "no");
  120. checkinstructions();
  121. return 0;
  122. }
  123. int cleanup_before_linux(void)
  124. {
  125. disable_interrupts();
  126. return 0;
  127. }
  128. extern void __reset(void);
  129. int do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  130. {
  131. disable_interrupts();
  132. /* Code the jump to __reset here as the compiler is prone to
  133. emitting a bad jump instruction if the function is in flash */
  134. __asm__("l.movhi r1,hi(__reset); \
  135. l.ori r1,r1,lo(__reset); \
  136. l.jr r1");
  137. /* not reached, __reset does not return */
  138. return 0;
  139. }