setjmp_x86_64.S 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /*
  2. * GRUB -- GRand Unified Bootloader
  3. * Copyright (C) 2003 Free Software Foundation, Inc.
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #define EXT_C(sym) sym
  19. #define FUNCTION(x) .globl EXT_C(x) ; .type EXT_C(x), @function ; EXT_C(x):
  20. .file "setjmp.S"
  21. .text
  22. /*
  23. * int setjmp (jmp_buf env)
  24. */
  25. FUNCTION(setjmp)
  26. pop %rsi /* Return address, and adjust the stack */
  27. xor %rax, %rax
  28. movq %rbx, 0(%rdi) /* RBX */
  29. movq %rsp, 8(%rdi) /* RSP */
  30. push %rsi
  31. movq %rbp, 16(%rdi) /* RBP */
  32. movq %r12, 24(%rdi) /* R12 */
  33. movq %r13, 32(%rdi) /* R13 */
  34. movq %r14, 40(%rdi) /* R14 */
  35. movq %r15, 48(%rdi) /* R15 */
  36. movq %rsi, 56(%rdi) /* RSI */
  37. ret
  38. /*
  39. * int longjmp (jmp_buf env, int val)
  40. */
  41. FUNCTION(longjmp)
  42. movl %esi, %eax
  43. movq (%rdi), %rbx
  44. movq 8(%rdi), %rsp
  45. movq 16(%rdi), %rbp
  46. movq 24(%rdi), %r12
  47. movq 32(%rdi), %r13
  48. movq 40(%rdi), %r14
  49. movq 48(%rdi), %r15
  50. jmp *56(%rdi)