archdep.c revision b5b48cc1a59a2d6962c84c49b474efdc7f303fbb
/*
* 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
*/
/*
* Copyright 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
#pragma ident "%Z%%M% %I% %E% SMI"
#include <sys/privregs.h>
#include <sys/asm_linkage.h>
#include <sys/bootconf.h>
#include <sys/archsystm.h>
#include <sys/sysmacros.h>
#include <sys/x86_archext.h>
#include <sys/auxv_386.h>
#include <sys/machbrand.h>
extern const struct fnsave_state x87_initial;
extern const struct fxsave_state sse_initial;
/*
* Map an fnsave-formatted save area into an fxsave-formatted save area.
*
* Most fields are the same width, content and semantics. However
* the tag word is compressed.
*/
static void
{
/*
* copy element by element (because of holes)
*/
for (i = 0; i < 8; i++)
/*
* synthesize compressed tag bits
*/
#if defined(__amd64)
#else
#endif
}
/*
* Map from an fxsave-format save area to an fnsave-format save area.
*/
static void
{
/*
* copy element by element (because of holes)
*/
for (i = 0; i < 8; i++)
/*
* synthesize uncompressed tag bits
*/
if ((tagbits & 1) == 0) {
continue;
}
/*
* (tags refer to *physical* registers)
*/
continue; /* valid fp number */
else
}
#if defined(__amd64)
#else
#endif
}
/*
* Map from an fpregset_t into an fxsave-format save area
*/
static void
{
#if defined(__amd64)
#else
#endif
/*
* avoid useless #gp exceptions - mask reserved bits
*/
}
/*
* Map from an fxsave-format save area into a fpregset_t
*/
static void
{
#if defined(__amd64)
#else
#endif
}
#if defined(_SYSCALL32_IMPL)
static void
{
/*
* avoid useless #gp exceptions - mask reserved bits
*/
}
static void
{
}
static void
{
}
static void
{
}
#endif
/*
* Set floating-point registers from a native fpregset_t.
*/
void
{
/*
* FPU context is still active, release the
* ownership.
*/
}
#if !defined(__amd64)
#endif
#if !defined(__amd64)
} else
#endif
} else {
/*
* If we are trying to change the FPU state of a thread which
* hasn't yet initialized floating point, store the state in
* the pcb and indicate that the state is valid. When the
* thread enables floating point, it will use this state instead
* of the default state.
*/
#if !defined(__amd64)
#endif
#if !defined(__amd64)
} else
#endif
}
}
/*
* Get floating-point registers into a native fpregset_t.
*/
void
{
/*
* If we have FPU hw and the thread's pcb doesn't have
* a valid FPU state then get the state from the hw.
*/
}
/*
* There are 3 possible cases we have to be aware of here:
*
* 1. FPU is enabled. FPU state is stored in the current LWP.
*
* 2. FPU is not enabled, and there have been no intervening /proc
* modifications. Return initial FPU state.
*
* 3. FPU is not enabled, but a /proc consumer has modified FPU state.
* FPU state is stored in the current LWP.
*/
/*
* Cases 1 and 3.
*/
#if !defined(__amd64)
#endif
#if !defined(__amd64)
} else
#endif
} else {
/*
* Case 2.
*/
#if !defined(__amd64)
#endif
#if !defined(__amd64)
} else
#endif
}
}
#if defined(_SYSCALL32_IMPL)
/*
* Set floating-point registers from an fpregset32_t.
*/
void
{
}
/*
* Get floating-point registers into an fpregset32_t.
*/
void
{
}
#endif /* _SYSCALL32_IMPL */
/*
* Return the general registers
*/
void
{
#if defined(__amd64)
if (thisthread)
} else {
}
if (thisthread)
#else
#endif
}
#if defined(_SYSCALL32_IMPL)
void
{
if (thisthread)
} else {
}
if (thisthread)
}
void
{
/*
* A valid fpregs is only copied in if uc.uc_flags has UC_FPU set
* otherwise there is no guarantee that anything in fpregs is valid.
*/
}
#endif /* _SYSCALL32_IMPL */
/*
* Return the user-level PC.
* If in a system call, return the address of the syscall trap.
*/
{
return (upc);
/*
* We might've gotten here from sysenter (0xf 0x34),
* syscall (0xf 0x5) or lcall (0x9a 0 0 0 0 0x27 0).
*
* Go peek at the binary to figure it out..
*/
return (upc - 2);
return (upc - 7);
}
/*
* Protect segment registers from non-user privilege levels and GDT selectors
* other than USER_CS, USER_DS and lwp FS and GS values. If the segment
* TI bit is set to point into the LDT and that the RPL is set to 3.
*
* Since struct regs stores each 16-bit segment register as a 32-bit greg_t, we
* also explicitly zero the top 16 bits since they may be coming from the
* user's address space via setcontext(2) or /proc.
*/
/*ARGSUSED*/
static greg_t
{
switch (sr &= 0xffff) {
#if defined(__amd64)
/*
* If lwp attempts to switch data model then force their
* code selector to be null selector.
*/
case U32CS_SEL:
if (datamodel == DATAMODEL_NATIVE)
return (0);
else
return (sr);
case UCS_SEL:
if (datamodel == DATAMODEL_ILP32)
return (0);
case UCS_SEL:
#endif
/*FALLTHROUGH*/
case UDS_SEL:
case LWPFS_SEL:
case LWPGS_SEL:
case 0:
return (sr);
default:
break;
}
/*
* Allow this process's brand to do any necessary segment register
* manipulation.
*/
/*
* Force it into the LDT in ring 3 for 32-bit processes, which by
* default do not have an LDT, so that any attempt to use an invalid
* selector will reference the (non-existant) LDT, and cause a #gp fault
* for the process.
*
* 64-bit processes get the null gdt selector since they
* are not allowed to have a private LDT.
*/
#if defined(__amd64)
#endif
}
/*
* Set general registers.
*/
void
{
#if defined(__amd64)
if (datamodel == DATAMODEL_NATIVE) {
if (thisthread)
(void) save_syscall_args(); /* copy the args */
/*
* Setting %cs or %ss to anything else is quietly but
* quite definitely forbidden!
*/
if (thisthread)
/*
* values directly, but only if they're using the segment
* selectors that allow that semantic.
*
* (32-bit processes must use lwp_set_private().)
*/
/*
* Ensure that we go out via update_sregs
*/
if (thisthread)
#if defined(_SYSCALL32_IMPL)
} else {
/*
* The kernel uses %cs to determine if it is dealing with
* another part of the kernel or with a userland application.
* Specifically, it tests the privilege bits. For this reason,
* we must prevent user apps from ending up with a NULL selector
* in %cs. Instead, we'll use index 0 into the GDT but with the
* privilege bits set to usermode.
*/
if (thisthread)
/*
*/
/*
* Ensure that we go out via update_sregs
*/
if (thisthread)
#endif
}
/*
* Only certain bits of the flags register can be modified.
*/
/*
* Only certain bits of the flags register can be modified.
*/
/*
* Copy saved registers from user stack.
*/
#endif /* __i386 */
}
/*
* Determine whether eip is likely to have an interrupt frame
* on the stack. We do this by comparing the address to the
* range of addresses spanned by several well-known routines.
*/
extern void _interrupt();
extern void _allsyscalls();
extern void _cmntrap();
extern void fakesoftint();
extern size_t _interrupt_size;
extern size_t _allsyscalls_size;
extern size_t _cmntrap_size;
extern size_t _fakesoftint_size;
/*
* Get a pc-only stacktrace. Used for kmem_alloc() buffer ownership tracking.
* Returns MIN(current stack depth, pcstack_limit).
*/
int
{
int depth = 0;
int on_intr;
else
while (depth < pcstack_limit) {
if (on_intr) {
/*
* Hop from interrupt stack to thread stack.
*/
on_intr = 0;
continue;
}
break;
}
}
return (depth);
}
/*
* The following ELF header fields are defined as processor-specific
* in the V8 ABI:
*
* e_ident[EI_DATA] encoding of the processor-specific
* data in the object file
* e_machine processor identification
* e_flags processor-specific flags associated
* with the file
*/
/*
* The value of at_flags reflects a platform's cpu module support.
* at_flags is used to check for allowing a binary to execute and
* is passed as the value of the AT_FLAGS auxiliary vector.
*/
int at_flags = 0;
/*
* Check the processor-specific fields of an ELF header.
*
* returns 1 if the fields are valid, 0 otherwise
*/
/*ARGSUSED2*/
int
unsigned char e_data,
{
if (e_data != ELFDATA2LSB)
return (0);
#if defined(__amd64)
return (1);
#endif
}
#if defined(_SYSCALL32_IMPL)
#endif
/*
* Gather information about the processor and place it into auxv_hwcap
* so that it can be exported to the linker via the aux vector.
*
* We use this seemingly complicated mechanism so that we can ensure
* cannot discover for itself.
*/
void
bind_hwcap(void)
{
#if defined(__amd64)
/*
* On AMD processors, sysenter just doesn't work at all
* when the kernel is in long mode. On IA-32e processors
* it does, but there's no real point in all the alternate
* mechanism when syscall works on both.
*
* Besides, the kernel's sysenter handler is expecting a
* 32-bit lwp ...
*/
auxv_hwcap &= ~AV_386_SEP;
#else
/*
*/
auxv_hwcap |= AV_386_AHF;
#endif
if (auxv_hwcap_include || auxv_hwcap_exclude)
#if defined(_SYSCALL32_IMPL)
#if defined(__amd64)
/*
* If this is an amd64 architecture machine from Intel, then
* syscall -doesn't- work in compatibility mode, only sysenter does.
*
* Sigh.
*/
if (!cpuid_syscall32_insn(NULL))
/*
*/
#endif
#endif
}
/*
* sync_icache() - this is called
* this is a nop.
*/
/* ARGSUSED */
void
{
/* Do nothing for now */
}
/*ARGSUSED*/
void
{
/* Not implemented for this platform */
}
int
__ipltospl(int ipl)
{
}
/*
* The panic code invokes panic_saveregs() to record the contents of a
* regs structure into the specified panic_data structure for debuggers.
*/
void
{
#if defined(__amd64)
#endif /* __i386 */
}
#if !defined(__amd64)
/*
* Given a return address (%eip), determine the likely number of arguments
* that were pushed on the stack prior to its execution. We do this by
* expecting that a typical call sequence consists of pushing arguments on
* the stack, executing a call instruction, and then performing an add
* on %esp to restore it to the value prior to pushing the arguments for
* the call. We attempt to detect such an add, and divide the addend
* by the size of a word to determine the number of pushed arguments.
*
* If we do not find such an add, we punt and return TR_ARG_MAX. It is not
* possible to reliably determine if a function took no arguments (i.e. was
* void) because assembler routines do not reliably perform an add on %esp
* immediately upon returning (eg. _sys_call()), so returning TR_ARG_MAX is
* safer than returning 0.
*/
static ulong_t
{
ulong_t n;
enum {
};
return (TR_ARG_MAX);
switch (ins[0]) {
case M_ADD_IMM32:
break;
case M_ADD_IMM8:
n = ins[2];
break;
default:
return (TR_ARG_MAX);
}
n /= sizeof (long);
return (MIN(n, TR_ARG_MAX));
}
#endif /* !__amd64 */
/*
* Print a stack backtrace using the specified frame pointer. We delay two
* seconds before continuing, unless this is the panic traceback. Note
* that the frame for the starting stack pointer value is omitted because
* the corresponding %eip is not known.
*/
#if defined(__amd64)
void
{
if (!panicstr)
goto out;
/*
* XX64 Until port is complete tolerate 8-byte aligned
* frame pointers but flag with a warning so they can
* be fixed.
*/
printf(" >> warning! 8-byte"
" aligned %%fp = %p\n", (void *)fp);
} else {
" >> mis-aligned %%fp = %p\n", (void *)fp);
break;
}
}
args[0] = '\0';
} else {
printf("%016lx %lx (%s)\n",
}
}
out:
if (!panicstr) {
printf("end of traceback\n");
}
}
void
{
/*
* args[] holds TR_ARG_MAX hex long args, plus ", " or '\0'.
*/
int on_intr;
char *sym;
if (!panicstr)
/*
* If we are panicking, all high-level interrupt information in
* CPU was overwritten. panic_cpu has the correct values.
*/
kpreempt_disable(); /* prevent migration */
else
goto out;
long *argv;
if (on_intr) {
/*
* Hop from interrupt stack to thread stack.
*/
on_intr = 0;
continue;
}
break; /* we're outside of the expected range */
}
break;
}
args[0] = '\0';
p = args;
}
} else {
printf("%08lx %lx (%s)\n",
}
}
out:
if (!panicstr) {
printf("end of traceback\n");
}
}
#endif /* __i386 */
/*
* Generate a stack backtrace from a saved register set.
*/
void
{
}
void
{
}
gethrtime_waitfree(void)
{
return (dtrace_gethrtime());
}
gethrtime(void)
{
return (gethrtimef());
}
gethrtime_unscaled(void)
{
return (gethrtimeunscaledf());
}
void
{
}
void
{
}
#if defined(__amd64)
/*
* Part of the implementation of hres_tick(); this routine is
* easier in C than assembler .. called with the hres_lock held.
*
* XX64 Many of these timekeeping variables need to be extern'ed in a header
*/
#include <sys/machlock.h>
extern int one_sec;
extern int max_hres_adj;
void
__adj_hrestime(void)
{
long long adj;
if (hrestime_adj == 0)
adj = 0;
else if (hrestime_adj > 0) {
if (hrestime_adj < max_hres_adj)
adj = hrestime_adj;
else
adj = max_hres_adj;
} else {
if (hrestime_adj < -max_hres_adj)
adj = -max_hres_adj;
else
adj = hrestime_adj;
}
one_sec++;
}
}
#endif
/*
* Wrapper functions to maintain backwards compability
*/
int
{
}
int
{
}