fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER START
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The contents of this file are subject to the terms of the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Common Development and Distribution License (the "License").
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * You may not use this file except in compliance with the License.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * or http://www.opensolaris.org/os/licensing.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * See the License for the specific language governing permissions
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and limitations under the License.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * When distributing Covered Code, include this CDDL HEADER in each
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If applicable, add the following below this CDDL HEADER, with the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * fields enclosed by brackets "[]" replaced with your own identifying
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * information: Portions Copyright [yyyy] [name of copyright owner]
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER END
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Use is subject to license terms.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#if defined(lint) || defined(DS_DDICT)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/types.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/param.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#else
fd65ca2882506123b77fd24431c8f6fbfdb37ce5John Forte#include "assym.h" /* Determine value of CPU_THREAD */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/asm_linkage.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DS_DDICT
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define uint8_t uchar_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Special support routines that can't be done with C
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * x86 variant
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * uint8_t nsc_ldstub(uint8_t *cp)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Store 0xFF at the specified location, and return its previous content.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#if defined(lint) || defined(DS_DDICT)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteuint8_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortensc_ldstub(uint8_t *cp)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint8_t rv;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rv = *cp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *cp = 0xFF;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (rv);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ENTRY(nsc_ldstub)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#if defined(__amd64)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte movl $0xff,%eax
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lock
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte xchgb %al, (%rdi) /* rdi = lock addr */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#elif defined(__i386)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte movl 4(%esp), %ecx /* ecx = lock addr */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte movl $0xff, %eax /* eax = 0xff */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lock
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte xchgb %al, (%ecx) /* atomic swap eax <-> *ecx */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#error "port this routine"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SET_SIZE(nsc_ldstub)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * nsc_membar_stld(void)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * On SPARC this is a C callable interface to SPARC asm membar instruction.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * For x86 we brute force it with a #LOCK instruction.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#if defined(lint) || defined(DS_DDICT)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortensc_membar_stld(void)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ENTRY(nsc_membar_stld)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#if defined(__amd64)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mfence
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#elif defined(__i386)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lock
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte xorl $0, (%esp)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#error "port this routine"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SET_SIZE(nsc_membar_stld)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif /* lint || DS_DDICT */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * if a() calls b() calls nsc_caller(),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * nsc_caller() returns return address in a().
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#if defined(lint) || defined(DS_DDICT)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortecaddr_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortensc_caller(void)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ENTRY(nsc_caller)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#if defined(__amd64)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte movq 8(%rbp), %rax /* b()'s return pc, in a() */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#elif defined(__i386)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte movl 4(%ebp), %eax /* b()'s return pc, in a() */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#error "port this routine"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SET_SIZE(nsc_caller)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif /* lint || DS_DDICT */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * if a() calls nsc_callee(), nsc_callee() returns the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * return address in a();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#if defined(lint) || defined(DS_DDICT)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortecaddr_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortensc_callee(void)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ENTRY(nsc_callee)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#if defined(__amd64)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte movq (%rsp), %rax /* callee()'s return pc, in a() */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#elif defined(__i386)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte movl (%esp), %eax /* callee()'s return pc, in a() */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#error "port this routine"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SET_SIZE(nsc_callee)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif /* lint || DS_DDICT */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * nsc_threadp(void)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * C callable interface to get the current thread pointer.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#if defined(lint) || defined(DS_DDICT)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortensc_threadp(void)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ENTRY(nsc_threadp)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#if defined(__amd64)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte movq %gs:CPU_THREAD, %rax
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#elif defined(__i386)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte movl %gs:CPU_THREAD,%eax
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#error "port this routine"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SET_SIZE(nsc_threadp)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif /* lint || DS_DDICT */