/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
*/
/*
* This is an assembly file that gets #include-ed into the brand-specific
* assembly files (e.g. sn1_brand_asm.s) for Solaris-derived brands.
* We can't make these into functions since in the trap context there's
* no easy place to save the extra parameters that would be required, so
* each brand module needs its own copy of this code. We #include this and
* use brand-specific #defines to replace the XXX_brand_... definitions.
*/
#ifdef lint
void
{
}
void
{
}
#else /* !lint */
#include <sys/asm_linkage.h>
#include <sys/machthread.h>
#include <sys/privregs.h>
#include "assym.h"
#ifdef _ASM /* The remainder of this file is only for assembly files */
#if defined(sun4v)
/*
* The GLOBALS_RESTORE macro can only be one instruction since it's
* used in a delay slot.
*/
#else /* !sun4v */
/*
* The GLOBALS_RESTORE macro can only be one instruction since it's
* used in a delay slot.
*/
#endif /* !sun4v */
/*
* Input parameters:
* %g1: return point
* %g2: pointer to our cpu structure
*/
/*
* If the trapping thread has the address mask bit clear, then it's
* a 64-bit process, and has no business calling 32-bit syscalls.
*/
nop;
nop;
/*
* Input parameters:
* %g1: return point
* %g2: pointer to our cpu structure
*/
/*
* If the trapping thread has the address mask bit set, then it's
* a 32-bit process, and has no business calling 64-bit syscalls.
*/
nop;
nop;
/*
* Input parameters:
* %g1: return point
* %g2: pointer to our cpu structure
*
* Note that we're free to use any %g? registers as long as
* we are are executing with alternate globals. If we're
* executing with user globals we need to backup any registers
* that we want to use so that we can restore them when we're
* done.
*
* Save some locals in the CPU tmp area to give us a little
* room to work.
*/
#if defined(sun4v)
/*
* On sun4v save our input parameters (which are stored in the
* alternate globals) since we'll need to switch between alternate
* globals and normal globals, and on sun4v the alternate globals
* are not preserved across these types of switches.
*/
#endif /* sun4v */
/*
* Switch from the alternate to user globals to grab the syscall
* number.
*/
/*
* If the system call number is >= 1024, then it is a native
* syscall that doesn't need emulation.
*/
/*
* This is a native syscall, probably from the emulation library.
* Subtract 1024 from the syscall number and let it go through.
*/
/* switch back to alternate globals */
/*
* If the system call number is 0 (SYS_syscall), then this might be
* an indirect syscall, in which case the actual syscall number
* would be stored in %o0, in which case we need to redo the
* the whole >= 1024 check.
*/
nop; /* if not, goto the emulation check */
/*
* Indirect syscalls are only supported for 32 bit processes so
* consult the tstate address mask again.
*/
/* switch back to alternate globals */
/*
* The caller is 32 bit and this an indirect system call.
*/
/*
* This is native indirect syscall, probably from the emulation
* library. Subtract 1024 from the syscall number and let it go
* through.
*/
/* switch back to alternate globals */
/*
* Check to see if we want to interpose on this system call. If
* not, we jump back into the normal syscall path and pretend
* nothing happened. %l1 contains the syscall we're invoking.
*/
nop;
/*
* Find the address of the userspace handler.
* cpu->cpu_thread->t_procp->p_brand_data->spd_handler.
*/
#if defined(sun4v)
/* restore the alternate global registers after incrementing %gl */
#endif /* sun4v */
nop;
/*
* Make sure this isn't an agent lwp. We can't do syscall
* interposition for system calls made by a agent lwp. See
* the block comments in the top of the brand emulation library
* for more information.
*/
nop;
/*
* Now the magic happens. Grab the trap return address and then
* reset it to point to the user space handler. When we execute
* the 'done' instruction, we will jump into our handler instead of
* the user's code. We also stick the old return address in %g5,
* so we can return to the proper instruction in the user's code.
* Note: we also pass back the base address of the syscall
* emulation table. This is a performance hack to avoid having to
* look it up on every call.
*/
/* Update the address we're going to return to */
#if defined(sun4v)
#else /* !sun4v */
#endif /* !sun4v */
/*
* Restore registers before returning.
*
* Note that %g2 should be loaded with the CPU struct addr and
* %g1 should be loaded the address we're going to return to.
*/
#if defined(sun4v)
/* restore the alternate global registers after incrementing %gl */
#endif /* sun4v */
nop;
#endif /* _ASM */
#endif /* !lint */