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*8) ! offsets in jmpbuf (see siglongjmp.c) 410Sstevel@tonic-gateJB_SP = (1*8) ! words 5 through 11 are unused! 420Sstevel@tonic-gateJB_PC = (2*8) 430Sstevel@tonic-gateJB_FP = (3*8) 440Sstevel@tonic-gateJB_I7 = (4*8) 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 ldx [%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 %xcc, 1f 60*11426SRoger.Faulkner@Sun.COM mov JB_CLEARLINK, %o2 ! no, tell longjmp to clear ul_siglink 61*11426SRoger.Faulkner@Sun.COM1: stx %o2, [%o0 + JB_FLAGS] 620Sstevel@tonic-gate stx %sp, [%o0 + JB_SP] ! save caller's sp 630Sstevel@tonic-gate add %o7, 8, %o1 ! compute return pc 640Sstevel@tonic-gate stx %o1, [%o0 + JB_PC] ! save pc 650Sstevel@tonic-gate stx %fp, [%o0 + JB_FP] ! save fp 660Sstevel@tonic-gate stx %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 ldx [%o0 + JB_SP], %o2 ! sp in %o2 until safe to puke there 1080Sstevel@tonic-gate ldx [%o2 + STACK_BIAS], %l0 ! restore locals and ins if we can 1090Sstevel@tonic-gate ldx [%o2 + (1*8) + STACK_BIAS], %l1 1100Sstevel@tonic-gate ldx [%o2 + (2*8) + STACK_BIAS], %l2 1110Sstevel@tonic-gate ldx [%o2 + (3*8) + STACK_BIAS], %l3 1120Sstevel@tonic-gate ldx [%o2 + (4*8) + STACK_BIAS], %l4 1130Sstevel@tonic-gate ldx [%o2 + (5*8) + STACK_BIAS], %l5 1140Sstevel@tonic-gate ldx [%o2 + (6*8) + STACK_BIAS], %l6 1150Sstevel@tonic-gate ldx [%o2 + (7*8) + STACK_BIAS], %l7 1160Sstevel@tonic-gate ldx [%o2 + (8*8) + STACK_BIAS], %i0 1170Sstevel@tonic-gate ldx [%o2 + (9*8) + STACK_BIAS], %i1 1180Sstevel@tonic-gate ldx [%o2 + (10*8) + STACK_BIAS], %i2 1190Sstevel@tonic-gate ldx [%o2 + (11*8) + STACK_BIAS], %i3 1200Sstevel@tonic-gate ldx [%o2 + (12*8) + STACK_BIAS], %i4 1210Sstevel@tonic-gate ldx [%o2 + (13*8) + STACK_BIAS], %i5 1220Sstevel@tonic-gate ldx [%o0 + JB_FP], %fp ! restore fp 1230Sstevel@tonic-gate mov %o2, %sp ! restore sp 124*11426SRoger.Faulkner@Sun.COM ldx [%o0 + JB_FLAGS], %o2 125*11426SRoger.Faulkner@Sun.COM btst JB_CLEARLINK, %o2 ! test JB_CLEARLINK flag 126*11426SRoger.Faulkner@Sun.COM bne,a,pt %xcc, 1f 127*11426SRoger.Faulkner@Sun.COM clrx [%g7 + UL_SIGLINK] ! if set, clear ul_siglink 128*11426SRoger.Faulkner@Sun.COM1: 1290Sstevel@tonic-gate ldx [%o0 + JB_I7], %i7 ! restore %i7 1300Sstevel@tonic-gate ldx [%o0 + JB_PC], %o3 ! get new return pc 1310Sstevel@tonic-gate tst %o1 ! is return value 0? 1320Sstevel@tonic-gate bnz 1f ! no - leave it alone 1330Sstevel@tonic-gate sub %o3, 8, %o7 ! normalize return (for adb) (dly slot) 1340Sstevel@tonic-gate mov 1, %o1 ! yes - set it to one 1350Sstevel@tonic-gate1: 1360Sstevel@tonic-gate retl 1370Sstevel@tonic-gate mov %o1, %o0 ! return (val) 1380Sstevel@tonic-gate 1390Sstevel@tonic-gate SET_SIZE(longjmp) 140