syscall_rvds.S 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. AREA |.text|, CODE, READONLY, ALIGN=2
  11. THUMB
  12. REQUIRE8
  13. PRESERVE8
  14. IMPORT rt_secure_svc_handle
  15. ;/*
  16. ; * int tzcall(int id, rt_ubase_t arg0, rt_ubase_t arg1, rt_ubase_t arg2);
  17. ; */
  18. tzcall PROC
  19. EXPORT tzcall
  20. SVC 1 ;call SVC 1
  21. BX LR
  22. ENDP
  23. tzcall_entry PROC
  24. PUSH {R1, R4, LR}
  25. MOV R4, R1 ; copy thread SP to R4
  26. LDMFD R4!, {r0 - r3} ; pop user stack, get input arg0, arg1, arg2
  27. STMFD R4!, {r0 - r3} ; push stack, user stack recovery
  28. BL rt_secure_svc_handle ; call fun
  29. POP {R1, R4, LR}
  30. STR R0, [R1] ; update return value
  31. BX LR ; return to thread
  32. ENDP
  33. syscall_entry PROC
  34. BX LR ; return to user app
  35. ENDP
  36. ;/*
  37. ; * void SVC_Handler(void);
  38. ; */
  39. SVC_Handler PROC
  40. EXPORT SVC_Handler
  41. ; get SP, save to R1
  42. MRS R1, MSP ;get fault context from handler
  43. TST LR, #0x04 ;if(!EXC_RETURN[2])
  44. BEQ get_sp_done
  45. MRS R1, PSP ;get fault context from thread
  46. get_sp_done
  47. ; get svc index
  48. LDR R0, [R1, #24]
  49. LDRB R0, [R0, #-2]
  50. ;if svc == 0, do system call
  51. CMP R0, #0x0
  52. BEQ syscall_entry
  53. ;if svc == 1, do TrustZone call
  54. CMP R0, #0x1
  55. BEQ tzcall_entry
  56. ENDP
  57. ALIGN
  58. END