syscall_iar.S 1.7 KB

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