syscall_iar.S 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. ;/*
  2. ; * Copyright (c) 2006-2018, 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. ;/*
  11. ; * @addtogroup cortex-m33
  12. ; */
  13. SECTION .text:CODE(2)
  14. THUMB
  15. REQUIRE8
  16. PRESERVE8
  17. ;/*
  18. ; * int tzcall(int id, rt_ubase_t arg0, rt_ubase_t arg1, rt_ubase_t arg2);
  19. ; */
  20. .global tzcall
  21. .type tzcall, %function
  22. tzcall:
  23. SVC 1 ;/* call SVC 1 */
  24. BX LR
  25. tzcall_entry:
  26. PUSH {R1, R4, LR}
  27. MOV R4, R1 ;/* copy thread SP to R4 */
  28. LDMFD R4!, {r0 - r3} ;/* pop user stack, get input arg0, arg1, arg2 */
  29. STMFD R4!, {r0 - r3} ;/* push stack, user stack recovery */
  30. BL rt_secure_svc_handle ;/* call fun */
  31. POP {R1, R4, LR}
  32. STR R0, [R1] ;/* update return value */
  33. BX LR ;/* return to thread */
  34. syscall_entry:
  35. BX LR ;/* return to user app */
  36. .global SVC_Handler
  37. .type SVC_Handler, %function
  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