board.c 2.7 KB

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