syscall_gcc.S 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*
  2. * Copyright (c) 2006-2022, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2019-10-25 tyx first version
  9. */
  10. .cpu cortex-m4
  11. .syntax unified
  12. .thumb
  13. .text
  14. /*
  15. * int tzcall(int id, rt_ubase_t arg0, rt_ubase_t arg1, rt_ubase_t arg2);
  16. */
  17. .global tzcall
  18. .type tzcall, %function
  19. tzcall:
  20. SVC 1 /* call SVC 1 */
  21. BX LR
  22. tzcall_entry:
  23. PUSH {R1, R4, LR}
  24. MOV R4, R1 /* copy thread SP to R4 */
  25. LDMFD R4!, {r0 - r3} /* pop user stack, get input arg0, arg1, arg2 */
  26. STMFD R4!, {r0 - r3} /* push stack, user stack recovery */
  27. BL rt_secure_svc_handle /* call fun */
  28. POP {R1, R4, LR}
  29. STR R0, [R1] /* update return value */
  30. BX LR /* return to thread */
  31. syscall_entry:
  32. BX LR /* return to user app */
  33. .global SVC_Handler
  34. .type SVC_Handler, %function
  35. SVC_Handler:
  36. /* get SP, save to R1 */
  37. MRS R1, MSP /* get fault context from handler. */
  38. TST LR, #0x04 /* if(!EXC_RETURN[2]) */
  39. BEQ get_sp_done
  40. MRS R1, PSP /* get fault context from thread. */
  41. get_sp_done:
  42. /* get svc index */
  43. LDR R0, [R1, #24]
  44. LDRB R0, [R0, #-2]
  45. /* if svc == 0, do system call */
  46. CMP R0, #0x0
  47. BEQ syscall_entry
  48. /* if svc == 1, do TrustZone call */
  49. CMP R0, #0x1
  50. BEQ tzcall_entry