setjmp_ia32.S 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * GRUB -- GRand Unified Bootloader
  3. * Copyright (C) 2000 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. /* This is stolen from libc/x86/setjmp.S in the OSKit */
  19. /*
  20. * Mach Operating System
  21. * Copyright (c) 1991,1990,1989 Carnegie Mellon University
  22. * All Rights Reserved.
  23. *
  24. * Permission to use, copy, modify and distribute this software and its
  25. * documentation is hereby granted, provided that both the copyright
  26. * notice and this permission notice appear in all copies of the
  27. * software, derivative works or modified versions, and any portions
  28. * thereof, and that both notices appear in supporting documentation.
  29. *
  30. * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
  31. * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
  32. * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
  33. *
  34. * Carnegie Mellon requests users of this software to return to
  35. *
  36. * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
  37. * School of Computer Science
  38. * Carnegie Mellon University
  39. * Pittsburgh PA 15213-3890
  40. *
  41. * any improvements or extensions that they make and grant Carnegie Mellon
  42. * the rights to redistribute these changes.
  43. */
  44. /*
  45. * C library -- _setjmp, _longjmp
  46. *
  47. * _longjmp(a,v)
  48. * will generate a "return(v)" from
  49. * the last call to
  50. * _setjmp(a)
  51. * by restoring registers from the stack,
  52. * The previous signal state is NOT restored.
  53. *
  54. */
  55. #define EXT_C(sym) sym
  56. #define FUNCTION(x) .globl EXT_C(x) ; .type EXT_C(x), @function ; EXT_C(x):
  57. .file "setjmp.S"
  58. .text
  59. FUNCTION(setjmp)
  60. movl 4(%esp), %ecx /* fetch buffer */
  61. movl %ebx, 0(%ecx)
  62. movl %esi, 4(%ecx)
  63. movl %edi, 8(%ecx)
  64. movl %ebp, 12(%ecx) /* save frame pointer of caller */
  65. popl %edx
  66. movl %esp, 16(%ecx) /* save stack pointer of caller */
  67. movl %edx, 20(%ecx) /* save pc of caller */
  68. xorl %eax, %eax
  69. jmp *%edx
  70. FUNCTION(longjmp)
  71. movl 8(%esp), %eax /* return(v) */
  72. movl 4(%esp), %ecx /* fetch buffer */
  73. movl 0(%ecx), %ebx
  74. movl 4(%ecx), %esi
  75. movl 8(%ecx), %edi
  76. movl 12(%ecx), %ebp
  77. movl 16(%ecx), %esp
  78. orl %eax, %eax
  79. jnz 0f
  80. incl %eax
  81. 0: jmp *20(%ecx) /* done, return.... */