mipscfg.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * Copyright (c) 2006-2021, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2020-07-28 lizhirui first version
  9. */
  10. #include <rtthread.h>
  11. #include <mips.h>
  12. mips32_core_cfg_t g_mips_core =
  13. {
  14. 64, /* icache_line_size */
  15. 128, /* icache_lines_per_way */
  16. 4, /* icache_ways */
  17. 32768,
  18. 64, /* dcache_line_size */
  19. 128, /* dcache_lines_per_way */
  20. 4, /* dcache_ways */
  21. 32768,
  22. 64, /* max_tlb_entries */
  23. };
  24. static rt_uint16_t m_pow(rt_uint16_t b, rt_uint16_t n)
  25. {
  26. rt_uint16_t rets = 1;
  27. while (n--)
  28. rets *= b;
  29. return rets;
  30. }
  31. static rt_uint16_t m_log2(rt_uint16_t b)
  32. {
  33. rt_uint16_t rets = 0;
  34. while (b != 1)
  35. {
  36. b /= 2;
  37. rets++;
  38. }
  39. return rets;
  40. }
  41. /**
  42. * read core attribute
  43. */
  44. void mips32_cfg_init(void)
  45. {
  46. rt_uint16_t val;
  47. rt_uint32_t cp0_config1;
  48. cp0_config1 = read_c0_config();
  49. if (cp0_config1 & 0x80000000)
  50. {
  51. cp0_config1 = read_c0_config1();
  52. val = (cp0_config1 & (7<<22))>>22;
  53. g_mips_core.icache_lines_per_way = 64 * m_pow(2, val);
  54. val = (cp0_config1 & (7<<19))>>19;
  55. g_mips_core.icache_line_size = 2 * m_pow(2, val);
  56. val = (cp0_config1 & (7<<16))>>16;
  57. g_mips_core.icache_ways = val + 1;
  58. val = (cp0_config1 & (7<<13))>>13;
  59. g_mips_core.dcache_lines_per_way = 64 * m_pow(2, val);
  60. val = (cp0_config1 & (7<<10))>>10;
  61. g_mips_core.dcache_line_size = 2 * m_pow(2, val);
  62. val = (cp0_config1 & (7<<7))>>7;
  63. g_mips_core.dcache_ways = val + 1;
  64. val = (cp0_config1 & (0x3F<<25))>>25;
  65. g_mips_core.max_tlb_entries = val + 1;
  66. }
  67. }