board.c 2.2 KB

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