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 56812Sraf * Common Development and Distribution License (the "License"). 66812Sraf * 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 */ 216812Sraf 226812Sraf/* 23*11426SRoger.Faulkner@Sun.COM * Copyright 2010 Sun Microsystems, Inc. All rights reserved. 246812Sraf * Use is subject to license terms. 256812Sraf */ 266812Sraf 270Sstevel@tonic-gate/* Copyright (c) 1988 AT&T */ 280Sstevel@tonic-gate/* All Rights Reserved */ 290Sstevel@tonic-gate 307298SMark.J.Nelson@Sun.COM .file "setjmp.s" 310Sstevel@tonic-gate 320Sstevel@tonic-gate#include <sys/asm_linkage.h> 330Sstevel@tonic-gate 340Sstevel@tonic-gate ANSI_PRAGMA_WEAK(setjmp,function) 350Sstevel@tonic-gate ANSI_PRAGMA_WEAK(longjmp,function) 360Sstevel@tonic-gate 37*11426SRoger.Faulkner@Sun.COM#include <../assym.h> 380Sstevel@tonic-gate#include <sys/trap.h> 390Sstevel@tonic-gate 400Sstevel@tonic-gateJB_FLAGS = (0*4) ! offsets in jmpbuf (see siglonglmp.c) 410Sstevel@tonic-gateJB_SP = (1*4) ! words 5 through 11 are unused! 420Sstevel@tonic-gateJB_PC = (2*4) 430Sstevel@tonic-gateJB_FP = (3*4) 440Sstevel@tonic-gateJB_I7 = (4*4) 450Sstevel@tonic-gate 460Sstevel@tonic-gate/* 47*11426SRoger.Faulkner@Sun.COM * Flag telling longjmp to set curthread->ul_siglink to NULL. 48*11426SRoger.Faulkner@Sun.COM */ 49*11426SRoger.Faulkner@Sun.COMJB_CLEARLINK = 0x10 50*11426SRoger.Faulkner@Sun.COM 51*11426SRoger.Faulkner@Sun.COM/* 520Sstevel@tonic-gate * setjmp(buf_ptr) 530Sstevel@tonic-gate * buf_ptr points to a twelve word array (jmp_buf) 540Sstevel@tonic-gate */ 550Sstevel@tonic-gate ENTRY(setjmp) 56*11426SRoger.Faulkner@Sun.COM clr %o2 57*11426SRoger.Faulkner@Sun.COM ld [%g7 + UL_SIGLINK], %o1 ! are we in a signal context? 58*11426SRoger.Faulkner@Sun.COM tst %o1 59*11426SRoger.Faulkner@Sun.COM be,a,pt %icc, 1f 60*11426SRoger.Faulkner@Sun.COM mov JB_CLEARLINK, %o2 ! no, tell longjmp to clear ul_siglink 61*11426SRoger.Faulkner@Sun.COM1: st %o2, [%o0 + JB_FLAGS] 620Sstevel@tonic-gate st %sp, [%o0 + JB_SP] ! save caller's sp 63*11426SRoger.Faulkner@Sun.COM add %o7, 8, %o1 ! compute return pc 640Sstevel@tonic-gate st %o1, [%o0 + JB_PC] ! save pc 650Sstevel@tonic-gate st %fp, [%o0 + JB_FP] ! save fp 660Sstevel@tonic-gate st %i7, [%o0 + JB_I7] ! save %i7 670Sstevel@tonic-gate retl 680Sstevel@tonic-gate clr %o0 ! return (0) 690Sstevel@tonic-gate 700Sstevel@tonic-gate SET_SIZE(setjmp) 710Sstevel@tonic-gate 720Sstevel@tonic-gate/* 730Sstevel@tonic-gate * longjmp(buf_ptr, val) 740Sstevel@tonic-gate * buf_ptr points to a jmpbuf which has been initialized by setjmp. 750Sstevel@tonic-gate * val is the value we wish to return to setjmp's caller 760Sstevel@tonic-gate * 770Sstevel@tonic-gate * We flush the register file to the stack by doing a kernel call. 780Sstevel@tonic-gate * This is necessary to ensure that the registers we want to 790Sstevel@tonic-gate * pick up are stored on the stack, and that subsequent restores 800Sstevel@tonic-gate * will function correctly. 810Sstevel@tonic-gate * 820Sstevel@tonic-gate * sp, fp, and %i7, the caller's return address, are all restored 830Sstevel@tonic-gate * to the values they had at the time of the call to setjmp(). All 840Sstevel@tonic-gate * other locals, ins and outs are set to potentially random values 850Sstevel@tonic-gate * (as per the man page). This is sufficient to permit the correct 860Sstevel@tonic-gate * operation of normal code. 870Sstevel@tonic-gate * 880Sstevel@tonic-gate * Actually, the above description is not quite correct. If the routine 890Sstevel@tonic-gate * that called setjmp() has not altered the sp value of their frame we 900Sstevel@tonic-gate * will restore the remaining locals and ins to the values these 910Sstevel@tonic-gate * registers had in the this frame at the time of the call to longjmp() 920Sstevel@tonic-gate * (not setjmp()!). This is intended to help compilers, typically not 930Sstevel@tonic-gate * C compilers, that have some registers assigned to fixed purposes, 940Sstevel@tonic-gate * and that only alter the values of these registers on function entry 950Sstevel@tonic-gate * and exit. 960Sstevel@tonic-gate * 970Sstevel@tonic-gate * Since a C routine could call setjmp() followed by alloca() and thus 980Sstevel@tonic-gate * alter the sp this feature will typically not be helpful for a C 990Sstevel@tonic-gate * compiler. 1000Sstevel@tonic-gate * 1010Sstevel@tonic-gate * Note also that because the caller of a routine compiled "flat" (without 1020Sstevel@tonic-gate * register windows) assumes that their ins and locals are preserved, 1030Sstevel@tonic-gate * routines that call setjmp() must not be flat. 1040Sstevel@tonic-gate */ 1050Sstevel@tonic-gate ENTRY(longjmp) 1060Sstevel@tonic-gate ta ST_FLUSH_WINDOWS ! flush all reg windows to the stack. 1070Sstevel@tonic-gate ld [%o0 + JB_SP], %o2 ! sp in %o2 until safe to puke there 1080Sstevel@tonic-gate ldd [%o2 + (0*8)], %l0 ! restore locals and ins if we can 1090Sstevel@tonic-gate ldd [%o2 + (1*8)], %l2 1100Sstevel@tonic-gate ldd [%o2 + (2*8)], %l4 1110Sstevel@tonic-gate ldd [%o2 + (3*8)], %l6 1120Sstevel@tonic-gate ldd [%o2 + (4*8)], %i0 1130Sstevel@tonic-gate ldd [%o2 + (5*8)], %i2 1140Sstevel@tonic-gate ldd [%o2 + (6*8)], %i4 1150Sstevel@tonic-gate ld [%o0 + JB_FP], %fp ! restore fp 1160Sstevel@tonic-gate mov %o2, %sp ! restore sp 117*11426SRoger.Faulkner@Sun.COM ld [%o0 + JB_FLAGS], %o2 118*11426SRoger.Faulkner@Sun.COM btst JB_CLEARLINK, %o2 ! test JB_CLEARLINK flag 119*11426SRoger.Faulkner@Sun.COM bne,a,pt %icc, 1f 120*11426SRoger.Faulkner@Sun.COM clr [%g7 + UL_SIGLINK] ! if set, clear ul_siglink 121*11426SRoger.Faulkner@Sun.COM1: 1220Sstevel@tonic-gate ld [%o0 + JB_I7], %i7 ! restore %i7 1230Sstevel@tonic-gate ld [%o0 + JB_PC], %o3 ! get new return pc 1240Sstevel@tonic-gate tst %o1 ! is return value 0? 1250Sstevel@tonic-gate bnz 1f ! no - leave it alone 1260Sstevel@tonic-gate sub %o3, 8, %o7 ! normalize return (for adb) (dly slot) 1270Sstevel@tonic-gate mov 1, %o1 ! yes - set it to one 1280Sstevel@tonic-gate1: 1290Sstevel@tonic-gate retl 1300Sstevel@tonic-gate mov %o1, %o0 ! return (val) 1310Sstevel@tonic-gate 1320Sstevel@tonic-gate SET_SIZE(longjmp) 133