setjmp.S 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. * Copyright (c) 2018-2019, Arm Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <asm_macros.S>
  7. #include <assert_macros.S>
  8. #include <setjmp.h>
  9. .globl setjmp
  10. .globl longjmp
  11. /*
  12. * int setjmp(jmp_buf env);
  13. */
  14. func setjmp
  15. mov x7, sp
  16. stp x19, x20, [x0, #JMP_CTX_X19]
  17. stp x21, x22, [x0, #JMP_CTX_X21]
  18. stp x23, x24, [x0, #JMP_CTX_X23]
  19. stp x25, x26, [x0, #JMP_CTX_X25]
  20. stp x27, x28, [x0, #JMP_CTX_X27]
  21. stp x29, x30, [x0, #JMP_CTX_X29]
  22. stp x7, xzr, [x0, #JMP_CTX_SP]
  23. mov x0, #0
  24. ret
  25. endfunc setjmp
  26. /*
  27. * void longjmp(jmp_buf env, int val);
  28. */
  29. func longjmp
  30. ldp x7, xzr, [x0, #JMP_CTX_SP]
  31. #if ENABLE_ASSERTIONS
  32. /*
  33. * Since we're unwinding the stack, assert that the stack being reset to
  34. * is shallower.
  35. */
  36. mov x19, sp
  37. cmp x7, x19
  38. ASM_ASSERT(ge)
  39. #endif
  40. ldp x19, x20, [x0, #JMP_CTX_X19]
  41. ldp x21, x22, [x0, #JMP_CTX_X21]
  42. ldp x23, x24, [x0, #JMP_CTX_X23]
  43. ldp x25, x26, [x0, #JMP_CTX_X25]
  44. ldp x27, x28, [x0, #JMP_CTX_X27]
  45. ldp x29, x30, [x0, #JMP_CTX_X29]
  46. mov sp, x7
  47. ands x0, x1, x1 /* Move val to x0 and set flags */
  48. cinc x0, x0, eq /* If val is 0, return 1 */
  49. ret
  50. endfunc longjmp