1
0

mipscfg.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. * 2010-05-27 swkyer first version
  9. */
  10. #include <rtthread.h>
  11. #include <mips.h>
  12. mips32_core_cfg_t g_mips_core =
  13. {
  14. 16, /* icache_line_size */
  15. 256, /* icache_lines_per_way */
  16. 4, /* icache_ways */
  17. 16, /* dcache_line_size */
  18. 256, /* dcache_lines_per_way */
  19. 4, /* dcache_ways */
  20. 16, /* max_tlb_entries */
  21. };
  22. static rt_uint16_t m_pow(rt_uint16_t b, rt_uint16_t n)
  23. {
  24. rt_uint16_t rets = 1;
  25. while (n--)
  26. rets *= b;
  27. return rets;
  28. }
  29. static rt_uint16_t m_log2(rt_uint16_t b)
  30. {
  31. rt_uint16_t rets = 0;
  32. while (b != 1)
  33. {
  34. b /= 2;
  35. rets++;
  36. }
  37. return rets;
  38. }
  39. /**
  40. * read core attribute
  41. */
  42. void mips32_cfg_init(void)
  43. {
  44. rt_uint16_t val;
  45. rt_uint32_t cp0_config1;
  46. cp0_config1 = read_c0_config();
  47. if (cp0_config1 & 0x80000000)
  48. {
  49. cp0_config1 = read_c0_config1();
  50. val = (cp0_config1 & (7<<22))>>22;
  51. g_mips_core.icache_lines_per_way = 64 * m_pow(2, val);
  52. val = (cp0_config1 & (7<<19))>>19;
  53. g_mips_core.icache_line_size = 2 * m_pow(2, val);
  54. val = (cp0_config1 & (7<<16))>>16;
  55. g_mips_core.icache_ways = val + 1;
  56. val = (cp0_config1 & (7<<13))>>13;
  57. g_mips_core.dcache_lines_per_way = 64 * m_pow(2, val);
  58. val = (cp0_config1 & (7<<10))>>10;
  59. g_mips_core.dcache_line_size = 2 * m_pow(2, val);
  60. val = (cp0_config1 & (7<<7))>>7;
  61. g_mips_core.dcache_ways = val + 1;
  62. val = (cp0_config1 & (0x3F<<25))>>25;
  63. g_mips_core.max_tlb_entries = val + 1;
  64. }
  65. }