2N/A/*
2N/A * CDDL HEADER START
2N/A *
2N/A * The contents of this file are subject to the terms of the
2N/A * Common Development and Distribution License (the "License").
2N/A * You may not use this file except in compliance with the License.
2N/A *
2N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2N/A * or http://www.opensolaris.org/os/licensing.
2N/A * See the License for the specific language governing permissions
2N/A * and limitations under the License.
2N/A *
2N/A * When distributing Covered Code, include this CDDL HEADER in each
2N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2N/A * If applicable, add the following below this CDDL HEADER, with the
2N/A * fields enclosed by brackets "[]" replaced with your own identifying
2N/A * information: Portions Copyright [yyyy] [name of copyright owner]
2N/A *
2N/A * CDDL HEADER END
2N/A */
2N/A
2N/A/*
2N/A * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
2N/A * Use is subject to license terms.
2N/A */
2N/A
2N/A/* Copyright (c) 1988 AT&T */
2N/A/* All Rights Reserved */
2N/A
2N/A .file "setjmp.s"
2N/A
2N/A#include <sys/asm_linkage.h>
2N/A
2N/A ANSI_PRAGMA_WEAK(setjmp,function)
2N/A ANSI_PRAGMA_WEAK(longjmp,function)
2N/A
2N/A#include <../assym.h>
2N/A#include <sys/trap.h>
2N/A
2N/AJB_FLAGS = (0*4) ! offsets in jmpbuf (see siglonglmp.c)
2N/AJB_SP = (1*4) ! words 5 through 11 are unused!
2N/AJB_PC = (2*4)
2N/AJB_FP = (3*4)
2N/AJB_I7 = (4*4)
2N/A
2N/A/*
2N/A * Flag telling longjmp to set curthread->ul_siglink to NULL.
2N/A */
2N/AJB_CLEARLINK = 0x10
2N/A
2N/A/*
2N/A * setjmp(buf_ptr)
2N/A * buf_ptr points to a twelve word array (jmp_buf)
2N/A */
2N/A ENTRY(setjmp)
2N/A clr %o2
2N/A ld [%g7 + UL_SIGLINK], %o1 ! are we in a signal context?
2N/A tst %o1
2N/A be,a,pt %icc, 1f
2N/A mov JB_CLEARLINK, %o2 ! no, tell longjmp to clear ul_siglink
2N/A1: st %o2, [%o0 + JB_FLAGS]
2N/A st %sp, [%o0 + JB_SP] ! save caller's sp
2N/A add %o7, 8, %o1 ! compute return pc
2N/A st %o1, [%o0 + JB_PC] ! save pc
2N/A st %fp, [%o0 + JB_FP] ! save fp
2N/A st %i7, [%o0 + JB_I7] ! save %i7
2N/A retl
2N/A clr %o0 ! return (0)
2N/A
2N/A SET_SIZE(setjmp)
2N/A
2N/A/*
2N/A * longjmp(buf_ptr, val)
2N/A * buf_ptr points to a jmpbuf which has been initialized by setjmp.
2N/A * val is the value we wish to return to setjmp's caller
2N/A *
2N/A * We flush the register file to the stack by doing a kernel call.
2N/A * This is necessary to ensure that the registers we want to
2N/A * pick up are stored on the stack, and that subsequent restores
2N/A * will function correctly.
2N/A *
2N/A * sp, fp, and %i7, the caller's return address, are all restored
2N/A * to the values they had at the time of the call to setjmp(). All
2N/A * other locals, ins and outs are set to potentially random values
2N/A * (as per the man page). This is sufficient to permit the correct
2N/A * operation of normal code.
2N/A *
2N/A * Actually, the above description is not quite correct. If the routine
2N/A * that called setjmp() has not altered the sp value of their frame we
2N/A * will restore the remaining locals and ins to the values these
2N/A * registers had in the this frame at the time of the call to longjmp()
2N/A * (not setjmp()!). This is intended to help compilers, typically not
2N/A * C compilers, that have some registers assigned to fixed purposes,
2N/A * and that only alter the values of these registers on function entry
2N/A * and exit.
2N/A *
2N/A * Since a C routine could call setjmp() followed by alloca() and thus
2N/A * alter the sp this feature will typically not be helpful for a C
2N/A * compiler.
2N/A *
2N/A * Note also that because the caller of a routine compiled "flat" (without
2N/A * register windows) assumes that their ins and locals are preserved,
2N/A * routines that call setjmp() must not be flat.
2N/A */
2N/A ENTRY(longjmp)
2N/A ta ST_FLUSH_WINDOWS ! flush all reg windows to the stack.
2N/A ld [%o0 + JB_SP], %o2 ! sp in %o2 until safe to puke there
2N/A ldd [%o2 + (0*8)], %l0 ! restore locals and ins if we can
2N/A ldd [%o2 + (1*8)], %l2
2N/A ldd [%o2 + (2*8)], %l4
2N/A ldd [%o2 + (3*8)], %l6
2N/A ldd [%o2 + (4*8)], %i0
2N/A ldd [%o2 + (5*8)], %i2
2N/A ldd [%o2 + (6*8)], %i4
2N/A ld [%o0 + JB_FP], %fp ! restore fp
2N/A mov %o2, %sp ! restore sp
2N/A ld [%o0 + JB_FLAGS], %o2
2N/A btst JB_CLEARLINK, %o2 ! test JB_CLEARLINK flag
2N/A bne,a,pt %icc, 1f
2N/A clr [%g7 + UL_SIGLINK] ! if set, clear ul_siglink
2N/A1:
2N/A ld [%o0 + JB_I7], %i7 ! restore %i7
2N/A ld [%o0 + JB_PC], %o3 ! get new return pc
2N/A tst %o1 ! is return value 0?
2N/A bnz 1f ! no - leave it alone
2N/A sub %o3, 8, %o7 ! normalize return (for adb) (dly slot)
2N/A mov 1, %o1 ! yes - set it to one
2N/A1:
2N/A retl
2N/A mov %o1, %o0 ! return (val)
2N/A
2N/A SET_SIZE(longjmp)