expression_with_stack_riscv_asm.S 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. stack pointer for riscv should always be 16 byte aligned */
  24. addi sp,sp,-16
  25. sw t0, 0(sp)
  26. sw t1, 4(sp)
  27. /* call the subroutine */
  28. jalr a0, 0
  29. /* gets the ra and stack pointer saved previously */
  30. lw t0, 0(sp)
  31. lw t1, 4(sp)
  32. addi sp, sp, 16
  33. /* restore both ra and real stack pointer of current task */
  34. mv ra, t1
  35. mv sp, t0
  36. ret