asm.S 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /*
  2. Entry point of all programs (_start).
  3. It initializes DWARF call frame information, the stack pointer, the
  4. frame pointer (needed for closures to work in start_rust) and the global
  5. pointer. Then it calls _start_rust.
  6. */
  7. .section .init, "ax"
  8. .global _start
  9. _start:
  10. .cfi_startproc
  11. .cfi_undefined ra
  12. csrw mie, 0
  13. csrw mip, 0
  14. li x1, 0
  15. li x2, 0
  16. li x3, 0
  17. li x4, 0
  18. li x5, 0
  19. li x6, 0
  20. li x7, 0
  21. li x8, 0
  22. li x9, 0
  23. li x10,0
  24. li x11,0
  25. li x12,0
  26. li x13,0
  27. li x14,0
  28. li x15,0
  29. li x16,0
  30. li x17,0
  31. li x18,0
  32. li x19,0
  33. li x20,0
  34. li x21,0
  35. li x22,0
  36. li x23,0
  37. li x24,0
  38. li x25,0
  39. li x26,0
  40. li x27,0
  41. li x28,0
  42. li x29,0
  43. li x30,0
  44. li x31,0
  45. .option push
  46. .option norelax
  47. la gp, __global_pointer$
  48. .option pop
  49. // Check hart id
  50. csrr a2, mhartid
  51. lui t0, %hi(_max_hart_id)
  52. add t0, t0, %lo(_max_hart_id)
  53. bgtu a2, t0, abort
  54. // Allocate stacks
  55. la sp, _stack_start
  56. lui t0, %hi(_hart_stack_size)
  57. add t0, t0, %lo(_hart_stack_size)
  58. mul t0, a2, t0
  59. sub sp, sp, t0
  60. // Set frame pointer
  61. add s0, sp, zero
  62. // Set trap handler
  63. la t0, _start_trap
  64. csrw mtvec, t0
  65. // Park non-zero harts
  66. bnez a2, abort
  67. jal zero, _start_rust
  68. .cfi_endproc
  69. /*
  70. Trap entry point (_start_trap)
  71. Saves caller saved registers ra, t0..6, a0..7, calls _start_trap_rust,
  72. restores caller saved registers and then returns.
  73. */
  74. .section .trap, "ax"
  75. .global _start_trap
  76. _start_trap:
  77. addi sp, sp, -16*4
  78. sw ra, 0*4(sp)
  79. sw t0, 1*4(sp)
  80. sw t1, 2*4(sp)
  81. sw t2, 3*4(sp)
  82. sw t3, 4*4(sp)
  83. sw t4, 5*4(sp)
  84. sw t5, 6*4(sp)
  85. sw t6, 7*4(sp)
  86. sw a0, 8*4(sp)
  87. sw a1, 9*4(sp)
  88. sw a2, 10*4(sp)
  89. sw a3, 11*4(sp)
  90. sw a4, 12*4(sp)
  91. sw a5, 13*4(sp)
  92. sw a6, 14*4(sp)
  93. sw a7, 15*4(sp)
  94. jal ra, _start_trap_rust
  95. lw ra, 0*4(sp)
  96. lw t0, 1*4(sp)
  97. lw t1, 2*4(sp)
  98. lw t2, 3*4(sp)
  99. lw t3, 4*4(sp)
  100. lw t4, 5*4(sp)
  101. lw t5, 6*4(sp)
  102. lw t6, 7*4(sp)
  103. lw a0, 8*4(sp)
  104. lw a1, 9*4(sp)
  105. lw a2, 10*4(sp)
  106. lw a3, 11*4(sp)
  107. lw a4, 12*4(sp)
  108. lw a5, 13*4(sp)
  109. lw a6, 14*4(sp)
  110. lw a7, 15*4(sp)
  111. addi sp, sp, 16*4
  112. mret
  113. /* Make sure there is an abort when linking */
  114. .section .init
  115. .globl abort
  116. abort:
  117. j abort