1*5d9d9091SRichard Lowe/* 2*5d9d9091SRichard Lowe * CDDL HEADER START 3*5d9d9091SRichard Lowe * 4*5d9d9091SRichard Lowe * The contents of this file are subject to the terms of the 5*5d9d9091SRichard Lowe * Common Development and Distribution License (the "License"). 6*5d9d9091SRichard Lowe * You may not use this file except in compliance with the License. 7*5d9d9091SRichard Lowe * 8*5d9d9091SRichard Lowe * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9*5d9d9091SRichard Lowe * or http://www.opensolaris.org/os/licensing. 10*5d9d9091SRichard Lowe * See the License for the specific language governing permissions 11*5d9d9091SRichard Lowe * and limitations under the License. 12*5d9d9091SRichard Lowe * 13*5d9d9091SRichard Lowe * When distributing Covered Code, include this CDDL HEADER in each 14*5d9d9091SRichard Lowe * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15*5d9d9091SRichard Lowe * If applicable, add the following below this CDDL HEADER, with the 16*5d9d9091SRichard Lowe * fields enclosed by brackets "[]" replaced with your own identifying 17*5d9d9091SRichard Lowe * information: Portions Copyright [yyyy] [name of copyright owner] 18*5d9d9091SRichard Lowe * 19*5d9d9091SRichard Lowe * CDDL HEADER END 20*5d9d9091SRichard Lowe */ 21*5d9d9091SRichard Lowe 22*5d9d9091SRichard Lowe/* 23*5d9d9091SRichard Lowe * Copyright 2010 Sun Microsystems, Inc. All rights reserved. 24*5d9d9091SRichard Lowe * Use is subject to license terms. 25*5d9d9091SRichard Lowe */ 26*5d9d9091SRichard Lowe 27*5d9d9091SRichard Lowe .file "setjmp.s" 28*5d9d9091SRichard Lowe 29*5d9d9091SRichard Lowe/* 30*5d9d9091SRichard Lowe * longjmp(env, val) 31*5d9d9091SRichard Lowe * will generate a "return(val)" from 32*5d9d9091SRichard Lowe * the last call to 33*5d9d9091SRichard Lowe * setjmp(env) 34*5d9d9091SRichard Lowe * by restoring registers rip rsp rbp rbx r12 r13 r14 r15 from 'env' 35*5d9d9091SRichard Lowe * and doing a return. 36*5d9d9091SRichard Lowe */ 37*5d9d9091SRichard Lowe 38*5d9d9091SRichard Lowe/* 39*5d9d9091SRichard Lowe * entry reg offset 40*5d9d9091SRichard Lowe * env[0] = %rbx 0 register variables 41*5d9d9091SRichard Lowe * env[1] = %r12 8 42*5d9d9091SRichard Lowe * env[2] = %r13 16 43*5d9d9091SRichard Lowe * env[3] = %r14 24 44*5d9d9091SRichard Lowe * env[4] = %r15 32 45*5d9d9091SRichard Lowe * env[5] = %rbp 40 stack frame 46*5d9d9091SRichard Lowe * env[6] = %rsp 48 47*5d9d9091SRichard Lowe * env[7] = %rip 56 48*5d9d9091SRichard Lowe */ 49*5d9d9091SRichard Lowe 50*5d9d9091SRichard Lowe#include <sys/asm_linkage.h> 51*5d9d9091SRichard Lowe#include <../assym.h> 52*5d9d9091SRichard Lowe 53*5d9d9091SRichard Lowe ANSI_PRAGMA_WEAK(setjmp,function) 54*5d9d9091SRichard Lowe ANSI_PRAGMA_WEAK(longjmp,function) 55*5d9d9091SRichard Lowe 56*5d9d9091SRichard Lowe ENTRY(setjmp) 57*5d9d9091SRichard Lowe movq %rbx, 0(%rdi) 58*5d9d9091SRichard Lowe movq %r12, 8(%rdi) 59*5d9d9091SRichard Lowe movq %r13, 16(%rdi) 60*5d9d9091SRichard Lowe movq %r14, 24(%rdi) 61*5d9d9091SRichard Lowe movq %r15, 32(%rdi) 62*5d9d9091SRichard Lowe movq %rbp, 40(%rdi) 63*5d9d9091SRichard Lowe popq %rdx /* return address */ 64*5d9d9091SRichard Lowe movq %rsp, 48(%rdi) 65*5d9d9091SRichard Lowe movq %rdx, 56(%rdi) 66*5d9d9091SRichard Lowe 67*5d9d9091SRichard Lowe movq %fs:UL_SIGLINK, %rax 68*5d9d9091SRichard Lowe xorq %rcx, %rcx 69*5d9d9091SRichard Lowe testq %rax, %rax /* are we in a signal handler? */ 70*5d9d9091SRichard Lowe jnz 1f 71*5d9d9091SRichard Lowe incq %rcx /* no, tell longjmp to clear ul_siglink */ 72*5d9d9091SRichard Lowe1: orq %rcx, 48(%rdi) /* low-order 1-bit flag in the saved %rsp */ 73*5d9d9091SRichard Lowe 74*5d9d9091SRichard Lowe xorl %eax, %eax /* return 0 */ 75*5d9d9091SRichard Lowe jmp *%rdx 76*5d9d9091SRichard Lowe SET_SIZE(setjmp) 77*5d9d9091SRichard Lowe 78*5d9d9091SRichard Lowe ENTRY(longjmp) 79*5d9d9091SRichard Lowe movq 0(%rdi), %rbx 80*5d9d9091SRichard Lowe movq 8(%rdi), %r12 81*5d9d9091SRichard Lowe movq 16(%rdi), %r13 82*5d9d9091SRichard Lowe movq 24(%rdi), %r14 83*5d9d9091SRichard Lowe movq 32(%rdi), %r15 84*5d9d9091SRichard Lowe movq 40(%rdi), %rbp 85*5d9d9091SRichard Lowe 86*5d9d9091SRichard Lowe movq 48(%rdi), %rax /* test low-order bit in the saved %rsp */ 87*5d9d9091SRichard Lowe testq $1, %rax 88*5d9d9091SRichard Lowe jz 1f 89*5d9d9091SRichard Lowe xorq %rcx, %rcx /* if set, clear ul_siglink */ 90*5d9d9091SRichard Lowe movq %rcx, %fs:UL_SIGLINK 91*5d9d9091SRichard Lowe subq $1, %rax /* clear the flag bit */ 92*5d9d9091SRichard Lowe1: movq %rax, %rsp 93*5d9d9091SRichard Lowe 94*5d9d9091SRichard Lowe movl %esi, %eax 95*5d9d9091SRichard Lowe test %eax, %eax /* if val != 0 */ 96*5d9d9091SRichard Lowe jnz 1f /* return val */ 97*5d9d9091SRichard Lowe incl %eax /* else return 1 */ 98*5d9d9091SRichard Lowe1: 99*5d9d9091SRichard Lowe movq 56(%rdi), %rdx /* return to caller of setjmp */ 100*5d9d9091SRichard Lowe jmp *%rdx 101*5d9d9091SRichard Lowe SET_SIZE(longjmp) 102