xref: /onnv-gate/usr/src/lib/libc/sparc/gen/getctxt.c (revision 6812:febeba71273d)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
56515Sraf  * Common Development and Distribution License (the "License").
66515Sraf  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
211016Sraf 
226515Sraf /*
236515Sraf  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
246515Sraf  * Use is subject to license terms.
256515Sraf  */
266515Sraf 
270Sstevel@tonic-gate /*	Copyright (c) 1988 AT&T	*/
280Sstevel@tonic-gate /*	  All Rights Reserved  	*/
290Sstevel@tonic-gate 
300Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
310Sstevel@tonic-gate 
32*6812Sraf #pragma weak _getcontext = getcontext
330Sstevel@tonic-gate 
34*6812Sraf #include "lint.h"
351016Sraf #include "thr_uberdata.h"
360Sstevel@tonic-gate #include <ucontext.h>
370Sstevel@tonic-gate #include <sys/types.h>
380Sstevel@tonic-gate 
390Sstevel@tonic-gate int
getcontext(ucontext_t * ucp)400Sstevel@tonic-gate getcontext(ucontext_t *ucp)
410Sstevel@tonic-gate {
420Sstevel@tonic-gate 	greg_t *reg;
430Sstevel@tonic-gate 
440Sstevel@tonic-gate 	ucp->uc_flags = UC_ALL;
456515Sraf 	if (__getcontext(ucp))
460Sstevel@tonic-gate 		return (-1);
470Sstevel@tonic-gate 
480Sstevel@tonic-gate 	/*
490Sstevel@tonic-gate 	 * Note that %o1 and %g1 are modified by the system call
500Sstevel@tonic-gate 	 * routine. ABI calling conventions specify that the caller
510Sstevel@tonic-gate 	 * cannot depend upon %o0 through %o5 nor %g1, so no effort is
520Sstevel@tonic-gate 	 * made to maintain these registers. %o0 is forced to reflect
530Sstevel@tonic-gate 	 * an affirmative return code.
540Sstevel@tonic-gate 	 */
550Sstevel@tonic-gate 	reg = ucp->uc_mcontext.gregs;
560Sstevel@tonic-gate 	reg[REG_SP] = getfp();
570Sstevel@tonic-gate 	reg[REG_O7] = caller();
580Sstevel@tonic-gate 	reg[REG_PC] = reg[REG_O7] + 8;
590Sstevel@tonic-gate 	reg[REG_nPC] = reg[REG_PC] + 4;
600Sstevel@tonic-gate 	reg[REG_O0] = 0;
610Sstevel@tonic-gate 
620Sstevel@tonic-gate 	return (0);
630Sstevel@tonic-gate }
64