expression_with_stack_riscv_asm.S 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // Copyright 2015-2020 Espressif Systems (Shanghai) PTE LTD
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. // http://www.apache.org/licenses/LICENSE-2.0
  7. //
  8. // Unless required by applicable law or agreed to in writing, software
  9. // distributed under the License is distributed on an "AS IS" BASIS,
  10. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. // See the License for the specific language governing permissions and
  12. // limitations under the License.
  13. .section .text
  14. .global esp_shared_stack_invoke_function
  15. .type esp_shared_stack_invoke_function, @function
  16. esp_shared_stack_invoke_function:
  17. /* save current stack and return address */
  18. mv t0, sp
  19. mv t1, ra
  20. /* Set shared stack as new stack pointer */
  21. mv sp, a1
  22. /* store the ra and previous stack pointer in a safe place */
  23. addi sp,sp,-4
  24. sw t0, 0(sp)
  25. sw t1, 4(sp)
  26. /* call the subroutine */
  27. jalr a0, 0
  28. /* gets the ra and stack pointer saved previously */
  29. lw t0, 0(sp)
  30. lw t1, 4(sp)
  31. addi sp, sp, 4
  32. /* restore both ra and real stack pointer of current task */
  33. mv ra, t1
  34. mv sp, t0
  35. ret