board.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*
  2. * Copyright (c) 2006-2025 RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2025-01-22 ZhangJing first version
  9. */
  10. #include <rthw.h>
  11. #include <rtthread.h>
  12. #include <rtdevice.h>
  13. #include "board.h"
  14. #include "tick.h"
  15. #include "drv_uart.h"
  16. #include "sbi.h"
  17. #include "riscv.h"
  18. #include "plic.h"
  19. #ifdef RT_USING_SMART
  20. #include <mmu.h>
  21. #include "page.h"
  22. #include "lwp_arch.h"
  23. rt_region_t init_page_region = {(rt_size_t)RT_HW_PAGE_START, (rt_size_t)RT_HW_PAGE_END};
  24. extern size_t MMUTable[];
  25. struct mem_desc platform_mem_desc[] =
  26. {
  27. {KERNEL_VADDR_START, (rt_size_t)RT_HW_PAGE_END - 1, (rt_size_t)ARCH_MAP_FAILED, NORMAL_MEM},
  28. };
  29. #define NUM_MEM_DESC (sizeof(platform_mem_desc) / sizeof(platform_mem_desc[0]))
  30. #endif
  31. void primary_cpu_entry(void)
  32. {
  33. /* disable global interrupt */
  34. rt_hw_interrupt_disable();
  35. entry();
  36. }
  37. /*initialize the bss section*/
  38. void init_bss(void)
  39. {
  40. unsigned int *dst;
  41. dst = &__bss_start;
  42. while (dst < &__bss_end)
  43. {
  44. *dst++ = 0;
  45. }
  46. }
  47. #define IOREMAP_SIZE (1ul << 30)
  48. #ifndef ARCH_REMAP_KERNEL
  49. #define IOREMAP_VEND USER_VADDR_START
  50. #else
  51. #define IOREMAP_VEND 0ul
  52. #endif
  53. /*set the plic base*/
  54. void set_plic_base(void)
  55. {
  56. plic_base = PLIC_BASE_ADDR;
  57. return;
  58. }
  59. void rt_hw_board_init(void)
  60. {
  61. #if defined(RT_USING_SMART)
  62. /* init data structure */
  63. rt_hw_mmu_map_init(&rt_kernel_space, (void *)(IOREMAP_VEND - IOREMAP_SIZE), IOREMAP_SIZE, (rt_size_t *)MMUTable, PV_OFFSET);
  64. /* init page allocator */
  65. rt_page_init(init_page_region);
  66. /* setup region, and enable MMU */
  67. rt_hw_mmu_setup(&rt_kernel_space, platform_mem_desc, NUM_MEM_DESC);
  68. #endif
  69. /* initialize memory system */
  70. #ifdef RT_USING_HEAP
  71. rt_system_heap_init(RT_HW_HEAP_BEGIN, RT_HW_HEAP_END);
  72. #endif
  73. /*set the plic base*/
  74. set_plic_base();
  75. /* initalize interrupt */
  76. rt_hw_interrupt_init();
  77. /* init rtthread hardware */
  78. rt_hw_tick_init();
  79. #ifdef RT_USING_SERIAL
  80. rt_hw_uart_init();
  81. #endif
  82. #ifdef RT_USING_CONSOLE
  83. /* set console device */
  84. rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
  85. #endif /* RT_USING_CONSOLE */
  86. #ifdef RT_USING_COMPONENTS_INIT
  87. rt_components_board_init();
  88. #endif
  89. #ifdef RT_USING_HEAP
  90. rt_kprintf("heap: [0x%08x - 0x%08x]\n", (rt_ubase_t)RT_HW_HEAP_BEGIN, (rt_ubase_t)RT_HW_HEAP_END);
  91. #endif /* RT_USING_HEAP */
  92. }
  93. void rt_hw_cpu_reset(void)
  94. {
  95. sbi_shutdown();
  96. while (1)
  97. ;
  98. }
  99. MSH_CMD_EXPORT_ALIAS(rt_hw_cpu_reset, reboot, reset machine);