board.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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 "tick.h"
  15. #include "drv_uart.h"
  16. #include "encoding.h"
  17. #include "stack.h"
  18. #include "sbi.h"
  19. #include "riscv.h"
  20. #include "plic.h"
  21. #include "stack.h"
  22. #ifdef RT_USING_USERSPACE
  23. #include "riscv_mmu.h"
  24. #include "mmu.h"
  25. #include "page.h"
  26. #include "lwp_arch.h"
  27. rt_region_t init_page_region = {(rt_size_t)RT_HW_PAGE_START, (rt_size_t)RT_HW_PAGE_END};
  28. rt_mmu_info mmu_info;
  29. extern size_t MMUTable[];
  30. struct mem_desc platform_mem_desc[] = {
  31. {KERNEL_VADDR_START, KERNEL_VADDR_START + 0x10000000 - 1, KERNEL_VADDR_START + PV_OFFSET, NORMAL_MEM},
  32. };
  33. #define NUM_MEM_DESC (sizeof(platform_mem_desc) / sizeof(platform_mem_desc[0]))
  34. #endif
  35. void init_bss(void)
  36. {
  37. unsigned int *dst;
  38. dst = &__bss_start;
  39. while (dst < &__bss_end)
  40. {
  41. *dst++ = 0;
  42. }
  43. }
  44. void primary_cpu_entry(void)
  45. {
  46. extern void entry(void);
  47. /* disable global interrupt */
  48. init_bss();
  49. rt_hw_interrupt_disable();
  50. entry();
  51. }
  52. #define IOREMAP_SIZE (1ul << 30)
  53. void rt_hw_board_init(void)
  54. {
  55. #ifdef RT_USING_USERSPACE
  56. rt_page_init(init_page_region);
  57. /* init mmu_info structure */
  58. rt_hw_mmu_map_init(&mmu_info, (void *)(USER_VADDR_START - IOREMAP_SIZE), IOREMAP_SIZE, (rt_size_t *)MMUTable, 0);
  59. // this API is reserved currently since PLIC etc had not been porting completely to MMU version
  60. rt_hw_mmu_kernel_map_init(&mmu_info, 0x00000000UL, 0x80000000);
  61. /* setup region, and enable MMU */
  62. rt_hw_mmu_setup(&mmu_info, platform_mem_desc, NUM_MEM_DESC);
  63. #endif
  64. #ifdef RT_USING_HEAP
  65. /* initialize memory system */
  66. rt_system_heap_init(RT_HW_HEAP_BEGIN, RT_HW_HEAP_END);
  67. #endif
  68. plic_init();
  69. rt_hw_interrupt_init();
  70. rt_hw_uart_init();
  71. #ifdef RT_USING_CONSOLE
  72. /* set console device */
  73. rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
  74. #endif /* RT_USING_CONSOLE */
  75. rt_hw_tick_init();
  76. #ifdef RT_USING_COMPONENTS_INIT
  77. rt_components_board_init();
  78. #endif
  79. #ifdef RT_USING_HEAP
  80. rt_kprintf("heap: [0x%08x - 0x%08x]\n", (rt_ubase_t)RT_HW_HEAP_BEGIN, (rt_ubase_t)RT_HW_HEAP_END);
  81. #endif /* RT_USING_HEAP */
  82. }
  83. void rt_hw_cpu_reset(void)
  84. {
  85. sbi_shutdown();
  86. while (1)
  87. ;
  88. }
  89. MSH_CMD_EXPORT_ALIAS(rt_hw_cpu_reset, reboot, reset machine);