setjmp.S 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. * GRUB -- GRand Unified Bootloader
  3. * Copyright (C) 2003,2007 Free Software Foundation, Inc.
  4. *
  5. * GRUB 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 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * GRUB 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 GRUB. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #include <grub/symbol.h>
  19. #include <grub/dl.h>
  20. .file "setjmp.S"
  21. GRUB_MOD_LICENSE "GPLv3+"
  22. .text
  23. /*
  24. * jmp_buf:
  25. * rbx rsp rbp r12 r13 r14 r15 rip
  26. * 0 8 16 24 32 40 48 56
  27. */
  28. /*
  29. * int grub_setjmp (grub_jmp_buf env)
  30. */
  31. FUNCTION(grub_setjmp)
  32. pop %rsi /* Return address, and adjust the stack */
  33. xorq %rax, %rax
  34. movq %rbx, 0(%rdi) /* RBX */
  35. movq %rsp, 8(%rdi) /* RSP */
  36. push %rsi
  37. movq %rbp, 16(%rdi) /* RBP */
  38. movq %r12, 24(%rdi) /* R12 */
  39. movq %r13, 32(%rdi) /* R13 */
  40. movq %r14, 40(%rdi) /* R14 */
  41. movq %r15, 48(%rdi) /* R15 */
  42. movq %rsi, 56(%rdi) /* RSI */
  43. ret
  44. /*
  45. * int grub_longjmp (grub_jmp_buf env, int val)
  46. */
  47. FUNCTION(grub_longjmp)
  48. movl %esi, %eax
  49. orl %eax, %eax
  50. jnz 1f
  51. incl %eax
  52. 1:
  53. movq (%rdi), %rbx
  54. movq 8(%rdi), %rsp
  55. movq 16(%rdi), %rbp
  56. movq 24(%rdi), %r12
  57. movq 32(%rdi), %r13
  58. movq 40(%rdi), %r14
  59. movq 48(%rdi), %r15
  60. jmp *56(%rdi)