board.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. /* respect to boot loader, must be 0xFFFFFFC000200000 */
  20. RT_STATIC_ASSERT(kmem_region, KERNEL_VADDR_START == 0xFFFFFFC000200000);
  21. rt_region_t init_page_region = {(rt_size_t)RT_HW_PAGE_START, (rt_size_t)RT_HW_PAGE_END};
  22. extern size_t MMUTable[];
  23. struct mem_desc platform_mem_desc[] = {
  24. {KERNEL_VADDR_START, (rt_size_t)RT_HW_PAGE_END - 1, (rt_size_t)ARCH_MAP_FAILED, NORMAL_MEM},
  25. };
  26. #define NUM_MEM_DESC (sizeof(platform_mem_desc) / sizeof(platform_mem_desc[0]))
  27. #endif /* RT_USING_SMART */
  28. void init_bss(void)
  29. {
  30. unsigned int *dst;
  31. dst = &__bss_start;
  32. while ((rt_ubase_t)dst < (rt_ubase_t)&__bss_end)
  33. {
  34. *dst++ = 0;
  35. }
  36. }
  37. static void __rt_assert_handler(const char *ex_string, const char *func, rt_size_t line)
  38. {
  39. rt_kprintf("(%s) assertion failed at function:%s, line number:%d \n", ex_string, func, line);
  40. asm volatile("ebreak" ::
  41. : "memory");
  42. }
  43. void primary_cpu_entry(void)
  44. {
  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_REMAP_KERNEL
  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%p - 0x%p]\n", (rt_ubase_t)RT_HW_HEAP_BEGIN, (rt_ubase_t)RT_HW_HEAP_END);
  86. #endif /* RT_USING_HEAP */
  87. }