17c478bd9Sstevel@tonic-gate/* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 57257d1b4Sraf * Common Development and Distribution License (the "License"). 67257d1b4Sraf * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 217257d1b4Sraf 227c478bd9Sstevel@tonic-gate/* 23*3de0cfbbSRoger A. Faulkner * Copyright 2010 Sun Microsystems, Inc. All rights reserved. 247c478bd9Sstevel@tonic-gate * Use is subject to license terms. 257c478bd9Sstevel@tonic-gate */ 267c478bd9Sstevel@tonic-gate 279a70fc3bSMark J. Nelson .file "setjmp.s" 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate/* 307c478bd9Sstevel@tonic-gate * longjmp(env, val) 317c478bd9Sstevel@tonic-gate * will generate a "return(val)" from 327c478bd9Sstevel@tonic-gate * the last call to 337c478bd9Sstevel@tonic-gate * setjmp(env) 347c478bd9Sstevel@tonic-gate * by restoring registers rip rsp rbp rbx r12 r13 r14 r15 from 'env' 357c478bd9Sstevel@tonic-gate * and doing a return. 367c478bd9Sstevel@tonic-gate */ 377c478bd9Sstevel@tonic-gate 387c478bd9Sstevel@tonic-gate/* 397c478bd9Sstevel@tonic-gate * entry reg offset 407c478bd9Sstevel@tonic-gate * env[0] = %rbx 0 register variables 417c478bd9Sstevel@tonic-gate * env[1] = %r12 8 427c478bd9Sstevel@tonic-gate * env[2] = %r13 16 437c478bd9Sstevel@tonic-gate * env[3] = %r14 24 447c478bd9Sstevel@tonic-gate * env[4] = %r15 32 457c478bd9Sstevel@tonic-gate * env[5] = %rbp 40 stack frame 467c478bd9Sstevel@tonic-gate * env[6] = %rsp 48 477c478bd9Sstevel@tonic-gate * env[7] = %rip 56 487c478bd9Sstevel@tonic-gate */ 497c478bd9Sstevel@tonic-gate 507c478bd9Sstevel@tonic-gate#include <sys/asm_linkage.h> 51*3de0cfbbSRoger A. Faulkner#include <../assym.h> 527c478bd9Sstevel@tonic-gate 537c478bd9Sstevel@tonic-gate ANSI_PRAGMA_WEAK(setjmp,function) 547c478bd9Sstevel@tonic-gate ANSI_PRAGMA_WEAK(longjmp,function) 557c478bd9Sstevel@tonic-gate 567c478bd9Sstevel@tonic-gate ENTRY(setjmp) 577c478bd9Sstevel@tonic-gate movq %rbx, 0(%rdi) 587c478bd9Sstevel@tonic-gate movq %r12, 8(%rdi) 597c478bd9Sstevel@tonic-gate movq %r13, 16(%rdi) 607c478bd9Sstevel@tonic-gate movq %r14, 24(%rdi) 617c478bd9Sstevel@tonic-gate movq %r15, 32(%rdi) 627c478bd9Sstevel@tonic-gate movq %rbp, 40(%rdi) 637c478bd9Sstevel@tonic-gate popq %rdx /* return address */ 647c478bd9Sstevel@tonic-gate movq %rsp, 48(%rdi) 657c478bd9Sstevel@tonic-gate movq %rdx, 56(%rdi) 66*3de0cfbbSRoger A. Faulkner 67*3de0cfbbSRoger A. Faulkner movq %fs:UL_SIGLINK, %rax 68*3de0cfbbSRoger A. Faulkner xorq %rcx, %rcx 69*3de0cfbbSRoger A. Faulkner testq %rax, %rax /* are we in a signal handler? */ 70*3de0cfbbSRoger A. Faulkner jnz 1f 71*3de0cfbbSRoger A. Faulkner incq %rcx /* no, tell longjmp to clear ul_siglink */ 72*3de0cfbbSRoger A. Faulkner1: orq %rcx, 48(%rdi) /* low-order 1-bit flag in the saved %rsp */ 73*3de0cfbbSRoger A. Faulkner 747c478bd9Sstevel@tonic-gate xorl %eax, %eax /* return 0 */ 757c478bd9Sstevel@tonic-gate jmp *%rdx 767c478bd9Sstevel@tonic-gate SET_SIZE(setjmp) 777c478bd9Sstevel@tonic-gate 787c478bd9Sstevel@tonic-gate ENTRY(longjmp) 797c478bd9Sstevel@tonic-gate movq 0(%rdi), %rbx 807c478bd9Sstevel@tonic-gate movq 8(%rdi), %r12 817c478bd9Sstevel@tonic-gate movq 16(%rdi), %r13 827c478bd9Sstevel@tonic-gate movq 24(%rdi), %r14 837c478bd9Sstevel@tonic-gate movq 32(%rdi), %r15 847c478bd9Sstevel@tonic-gate movq 40(%rdi), %rbp 85*3de0cfbbSRoger A. Faulkner 86*3de0cfbbSRoger A. Faulkner movq 48(%rdi), %rax /* test low-order bit in the saved %rsp */ 87*3de0cfbbSRoger A. Faulkner testq $1, %rax 88*3de0cfbbSRoger A. Faulkner jz 1f 89*3de0cfbbSRoger A. Faulkner xorq %rcx, %rcx /* if set, clear ul_siglink */ 90*3de0cfbbSRoger A. Faulkner movq %rcx, %fs:UL_SIGLINK 91*3de0cfbbSRoger A. Faulkner subq $1, %rax /* clear the flag bit */ 92*3de0cfbbSRoger A. Faulkner1: movq %rax, %rsp 93*3de0cfbbSRoger A. Faulkner 947c478bd9Sstevel@tonic-gate movl %esi, %eax 957c478bd9Sstevel@tonic-gate test %eax, %eax /* if val != 0 */ 967c478bd9Sstevel@tonic-gate jnz 1f /* return val */ 977c478bd9Sstevel@tonic-gate incl %eax /* else return 1 */ 987c478bd9Sstevel@tonic-gate1: 997c478bd9Sstevel@tonic-gate movq 56(%rdi), %rdx /* return to caller of setjmp */ 1007c478bd9Sstevel@tonic-gate jmp *%rdx 1017c478bd9Sstevel@tonic-gate SET_SIZE(longjmp) 102