startup_gcc.S 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /*
  2. * Copyright (c) 2006-2018, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2018/10/01 Bernard The first version
  9. * 2018/12/27 Jesven Add SMP support
  10. * 2020/6/12 Xim Port to QEMU and remove SMP support
  11. * 2024-06-30 Shell Support of kernel remapping
  12. */
  13. #include <encoding.h>
  14. #include <cpuport.h>
  15. .data
  16. .global boot_hartid /* global varible rt_boot_hartid in .data section */
  17. boot_hartid:
  18. .word 0xdeadbeef
  19. .global _start
  20. .section ".start", "ax"
  21. _start:
  22. j 1f
  23. .word 0xdeadbeef
  24. .align 3
  25. .global g_wake_up
  26. g_wake_up:
  27. .dword 1
  28. .dword 0
  29. 1:
  30. /* save hartid */
  31. la t0, boot_hartid /* global varible rt_boot_hartid */
  32. mv t1, a0 /* get hartid in S-mode frome a0 register */
  33. sw t1, (t0) /* store t1 register low 4 bits in memory address which is stored in t0 */
  34. /* clear Interrupt Registers */
  35. csrw sie, 0
  36. csrw sip, 0
  37. /* set Trap Vector Base Address Register */
  38. la t0, trap_entry
  39. csrw stvec, t0
  40. li x1, 0
  41. li x2, 0
  42. li x3, 0
  43. li x4, 0
  44. li x5, 0
  45. li x6, 0
  46. li x7, 0
  47. li x8, 0
  48. li x9, 0
  49. li x10,0
  50. li x11,0
  51. li x12,0
  52. li x13,0
  53. li x14,0
  54. li x15,0
  55. li x16,0
  56. li x17,0
  57. li x18,0
  58. li x19,0
  59. li x20,0
  60. li x21,0
  61. li x22,0
  62. li x23,0
  63. li x24,0
  64. li x25,0
  65. li x26,0
  66. li x27,0
  67. li x28,0
  68. li x29,0
  69. li x30,0
  70. li x31,0
  71. /* set to disable FPU */
  72. li t0, SSTATUS_FS + SSTATUS_VS
  73. csrc sstatus, t0
  74. li t0, SSTATUS_SUM
  75. csrs sstatus, t0
  76. .option push
  77. .option norelax
  78. la gp, __global_pointer$
  79. .option pop
  80. /* removed SMP support here */
  81. la sp, __stack_start__
  82. li t0, __STACKSIZE__
  83. add sp, sp, t0
  84. /**
  85. * sscratch is always zero on kernel mode
  86. */
  87. csrw sscratch, zero
  88. call init_bss
  89. #ifdef ARCH_MM_MMU
  90. call rt_hw_mem_setup_early
  91. call rt_kmem_pvoff
  92. /* a0 := pvoff */
  93. beq a0, zero, 1f
  94. /* relocate pc */
  95. la x1, _after_pc_relocation
  96. sub x1, x1, a0
  97. ret
  98. _after_pc_relocation:
  99. /* relocate gp */
  100. sub gp, gp, a0
  101. /* relocate context: sp */
  102. la sp, __stack_start__
  103. li t0, __STACKSIZE__
  104. add sp, sp, t0
  105. /* reset s0-fp */
  106. mv s0, zero
  107. /* relocate stvec */
  108. la t0, trap_entry
  109. csrw stvec, t0
  110. 1:
  111. #endif
  112. call sbi_init
  113. call primary_cpu_entry
  114. _never_return_here:
  115. j .
  116. .global _start_link_addr
  117. _start_link_addr:
  118. .dword __text_start