mipscfg.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. * File : mipscfg.c
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2010, RT-Thread Development Team
  5. *
  6. * The license and distribution terms for this file may be
  7. * found in the file LICENSE in this distribution or at
  8. * http://www.rt-thread.org/license/LICENSE
  9. *
  10. * Change Logs:
  11. * Date Author Notes
  12. * 2010-05-27 swkyer first version
  13. */
  14. #include <rtthread.h>
  15. #include "../common/mipsregs.h"
  16. #include "../common/mipscfg.h"
  17. mips32_core_cfg_t g_mips_core =
  18. {
  19. 16, /* icache_line_size */
  20. 256, /* icache_lines_per_way */
  21. 4, /* icache_ways */
  22. 16, /* dcache_line_size */
  23. 256, /* dcache_lines_per_way */
  24. 4, /* dcache_ways */
  25. 16, /* max_tlb_entries */
  26. };
  27. static rt_uint16_t m_pow(rt_uint16_t b, rt_uint16_t n)
  28. {
  29. rt_uint16_t rets = 1;
  30. while (n--)
  31. rets *= b;
  32. return rets;
  33. }
  34. static rt_uint16_t m_log2(rt_uint16_t b)
  35. {
  36. rt_uint16_t rets = 0;
  37. while (b != 1)
  38. {
  39. b /= 2;
  40. rets++;
  41. }
  42. return rets;
  43. }
  44. /**
  45. * read core attribute
  46. */
  47. void mips32_cfg_init(void)
  48. {
  49. rt_uint16_t val;
  50. rt_uint32_t cp0_config1;
  51. cp0_config1 = read_c0_config();
  52. if (cp0_config1 & 0x80000000)
  53. {
  54. cp0_config1 = read_c0_config1();
  55. val = (cp0_config1 & (7<<22))>>22;
  56. g_mips_core.icache_lines_per_way = 64 * m_pow(2, val);
  57. val = (cp0_config1 & (7<<19))>>19;
  58. g_mips_core.icache_line_size = 2 * m_pow(2, val);
  59. val = (cp0_config1 & (7<<16))>>16;
  60. g_mips_core.icache_ways = val + 1;
  61. val = (cp0_config1 & (7<<13))>>13;
  62. g_mips_core.dcache_lines_per_way = 64 * m_pow(2, val);
  63. val = (cp0_config1 & (7<<10))>>10;
  64. g_mips_core.dcache_line_size = 2 * m_pow(2, val);
  65. val = (cp0_config1 & (7<<7))>>7;
  66. g_mips_core.dcache_ways = val + 1;
  67. val = (cp0_config1 & (0x3F<<25))>>25;
  68. g_mips_core.max_tlb_entries = val + 1;
  69. }
  70. }