17c478bd9Sstevel@tonic-gate/*
27c478bd9Sstevel@tonic-gate *  GRUB  --  GRand Unified Bootloader
37c478bd9Sstevel@tonic-gate *  Copyright (C) 2000 Free Software Foundation, Inc.
47c478bd9Sstevel@tonic-gate *
57c478bd9Sstevel@tonic-gate *  This program is free software; you can redistribute it and/or modify
67c478bd9Sstevel@tonic-gate *  it under the terms of the GNU General Public License as published by
77c478bd9Sstevel@tonic-gate *  the Free Software Foundation; either version 2 of the License, or
87c478bd9Sstevel@tonic-gate *  (at your option) any later version.
97c478bd9Sstevel@tonic-gate *
107c478bd9Sstevel@tonic-gate *  This program is distributed in the hope that it will be useful,
117c478bd9Sstevel@tonic-gate *  but WITHOUT ANY WARRANTY; without even the implied warranty of
127c478bd9Sstevel@tonic-gate *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
137c478bd9Sstevel@tonic-gate *  GNU General Public License for more details.
147c478bd9Sstevel@tonic-gate *
157c478bd9Sstevel@tonic-gate *  You should have received a copy of the GNU General Public License
167c478bd9Sstevel@tonic-gate *  along with this program; if not, write to the Free Software
177c478bd9Sstevel@tonic-gate *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
187c478bd9Sstevel@tonic-gate */
197c478bd9Sstevel@tonic-gate
207c478bd9Sstevel@tonic-gate/* This is stolen from libc/x86/setjmp.S in the OSKit */
217c478bd9Sstevel@tonic-gate/*
227c478bd9Sstevel@tonic-gate * Mach Operating System
237c478bd9Sstevel@tonic-gate * Copyright (c) 1991,1990,1989 Carnegie Mellon University
247c478bd9Sstevel@tonic-gate * All Rights Reserved.
257c478bd9Sstevel@tonic-gate *
267c478bd9Sstevel@tonic-gate * Permission to use, copy, modify and distribute this software and its
277c478bd9Sstevel@tonic-gate * documentation is hereby granted, provided that both the copyright
287c478bd9Sstevel@tonic-gate * notice and this permission notice appear in all copies of the
297c478bd9Sstevel@tonic-gate * software, derivative works or modified versions, and any portions
307c478bd9Sstevel@tonic-gate * thereof, and that both notices appear in supporting documentation.
317c478bd9Sstevel@tonic-gate *
327c478bd9Sstevel@tonic-gate * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
337c478bd9Sstevel@tonic-gate * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
347c478bd9Sstevel@tonic-gate * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
357c478bd9Sstevel@tonic-gate *
367c478bd9Sstevel@tonic-gate * Carnegie Mellon requests users of this software to return to
377c478bd9Sstevel@tonic-gate *
387c478bd9Sstevel@tonic-gate *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
397c478bd9Sstevel@tonic-gate *  School of Computer Science
407c478bd9Sstevel@tonic-gate *  Carnegie Mellon University
417c478bd9Sstevel@tonic-gate *  Pittsburgh PA 15213-3890
427c478bd9Sstevel@tonic-gate *
437c478bd9Sstevel@tonic-gate * any improvements or extensions that they make and grant Carnegie Mellon
447c478bd9Sstevel@tonic-gate * the rights to redistribute these changes.
457c478bd9Sstevel@tonic-gate */
467c478bd9Sstevel@tonic-gate/*
477c478bd9Sstevel@tonic-gate * C library -- _setjmp, _longjmp
487c478bd9Sstevel@tonic-gate *
497c478bd9Sstevel@tonic-gate *      _longjmp(a,v)
507c478bd9Sstevel@tonic-gate * will generate a "return(v)" from
517c478bd9Sstevel@tonic-gate * the last call to
527c478bd9Sstevel@tonic-gate *      _setjmp(a)
537c478bd9Sstevel@tonic-gate * by restoring registers from the stack,
547c478bd9Sstevel@tonic-gate * The previous signal state is NOT restored.
557c478bd9Sstevel@tonic-gate *
567c478bd9Sstevel@tonic-gate */
577c478bd9Sstevel@tonic-gate
587c478bd9Sstevel@tonic-gateENTRY(grub_setjmp)
597c478bd9Sstevel@tonic-gate	movl	4(%esp), %ecx		/* fetch buffer */
607c478bd9Sstevel@tonic-gate	movl	%ebx, 0(%ecx)
617c478bd9Sstevel@tonic-gate	movl	%esi, 4(%ecx)
627c478bd9Sstevel@tonic-gate	movl	%edi, 8(%ecx)
637c478bd9Sstevel@tonic-gate	movl	%ebp, 12(%ecx)		/* save frame pointer of caller */
647c478bd9Sstevel@tonic-gate	popl	%edx
657c478bd9Sstevel@tonic-gate	movl	%esp, 16(%ecx)		/* save stack pointer of caller */
667c478bd9Sstevel@tonic-gate	movl	%edx, 20(%ecx)		/* save pc of caller */
677c478bd9Sstevel@tonic-gate	xorl	%eax, %eax
687c478bd9Sstevel@tonic-gate        jmp     *%edx
697c478bd9Sstevel@tonic-gate
707c478bd9Sstevel@tonic-gateENTRY(grub_longjmp)
717c478bd9Sstevel@tonic-gate	movl	8(%esp), %eax		/* return(v) */
727c478bd9Sstevel@tonic-gate	movl	4(%esp), %ecx		/* fetch buffer */
737c478bd9Sstevel@tonic-gate	movl	0(%ecx), %ebx
747c478bd9Sstevel@tonic-gate	movl	4(%ecx), %esi
757c478bd9Sstevel@tonic-gate	movl	8(%ecx), %edi
767c478bd9Sstevel@tonic-gate	movl	12(%ecx), %ebp
777c478bd9Sstevel@tonic-gate	movl	16(%ecx), %esp
787c478bd9Sstevel@tonic-gate	orl	%eax, %eax
797c478bd9Sstevel@tonic-gate	jnz	0f
807c478bd9Sstevel@tonic-gate	incl	%eax
817c478bd9Sstevel@tonic-gate0:	jmp	*20(%ecx)		/* done, return.... */
82