reset.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. * Copyright (c) 2022 HPMicro
  3. * SPDX-License-Identifier: BSD-3-Clause
  4. */
  5. #include <stdint.h>
  6. #include "hpm_common.h"
  7. #include "hpm_soc.h"
  8. #include "hpm_l1c_drv.h"
  9. #include "hpm_interrupt.h"
  10. extern void system_init(void);
  11. __attribute__((weak)) void _clean_up(void)
  12. {
  13. /* clean up plic, it will help while debugging */
  14. disable_irq_from_intc();
  15. intc_m_set_threshold(0);
  16. for (uint32_t irq = 0; irq < 128; irq++) {
  17. intc_m_complete_irq(irq);
  18. }
  19. /* clear any bits left in plic enable register */
  20. for (uint32_t i = 0; i < 4; i++) {
  21. *(volatile uint32_t *)(HPM_PLIC_BASE + HPM_PLIC_ENABLE_OFFSET + (i << 2)) = 0;
  22. }
  23. }
  24. __attribute__((weak)) void c_startup(void)
  25. {
  26. uint32_t i, size;
  27. #if defined(FLASH_XIP) || defined(FLASH_UF2)
  28. extern uint8_t __vector_ram_start__[], __vector_ram_end__[], __vector_load_addr__[];
  29. size = __vector_ram_end__ - __vector_ram_start__;
  30. for (i = 0; i < size; i++) {
  31. *(__vector_ram_start__ + i) = *(__vector_load_addr__ + i);
  32. }
  33. #endif
  34. extern uint8_t __etext[];
  35. extern uint8_t __bss_start__[], __bss_end__[];
  36. extern uint8_t __data_start__[], __data_end__[];
  37. extern uint8_t __noncacheable_bss_start__[], __noncacheable_bss_end__[];
  38. extern uint8_t __ramfunc_start__[], __ramfunc_end__[];
  39. extern uint8_t __noncacheable_init_start__[], __noncacheable_init_end__[];
  40. /* bss section */
  41. size = __bss_end__ - __bss_start__;
  42. for (i = 0; i < size; i++) {
  43. *(__bss_start__ + i) = 0;
  44. }
  45. /* noncacheable bss section */
  46. size = __noncacheable_bss_end__ - __noncacheable_bss_start__;
  47. for (i = 0; i < size; i++) {
  48. *(__noncacheable_bss_start__ + i) = 0;
  49. }
  50. /* data section LMA: etext */
  51. size = __data_end__ - __data_start__;
  52. for (i = 0; i < size; i++) {
  53. *(__data_start__ + i) = *(__etext + i);
  54. }
  55. /* ramfunc section LMA: etext + data length */
  56. size = __ramfunc_end__ - __ramfunc_start__;
  57. for (i = 0; i < size; i++) {
  58. *(__ramfunc_start__ + i) = *(__etext + (__data_end__ - __data_start__) + i);
  59. }
  60. /* noncacheable init section LMA: etext + data length + ramfunc legnth */
  61. size = __noncacheable_init_end__ - __noncacheable_init_start__;
  62. for (i = 0; i < size; i++) {
  63. *(__noncacheable_init_start__ + i) = *(__etext + (__data_end__ - __data_start__) + (__ramfunc_end__ - __ramfunc_start__) + i);
  64. }
  65. }
  66. __attribute__((weak)) int main(void)
  67. {
  68. while (1) {
  69. ;
  70. }
  71. }
  72. __attribute__((weak)) void reset_handler(void)
  73. {
  74. l1c_dc_disable();
  75. l1c_dc_invalidate_all();
  76. /* Call platform specific hardware initialization */
  77. system_init();
  78. /* Entry function */
  79. main();
  80. }
  81. /*
  82. * When compiling C++ code with static objects, the compiler inserts
  83. * a call to __cxa_atexit() with __dso_handle as one of the arguments.
  84. * The dummy versions of these symbols should be provided.
  85. */
  86. __attribute__((weak)) void __cxa_atexit(void (*arg1)(void *), void *arg2, void *arg3)
  87. {
  88. }
  89. #if !defined(__SEGGER_RTL_VERSION) || defined(__riscv_xandes)
  90. void *__dso_handle = (void *) &__dso_handle;
  91. #endif
  92. __attribute__((weak)) void _init(void)
  93. {
  94. }