/*
* 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.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <sys/asm_linkage.h>
#include <sys/hypervisor.h>
#include <sys/privregs.h>
#include <sys/segments.h>
#include <sys/traptrace.h>
#include <sys/x86_archext.h>
#include <sys/asm_misc.h>
#if !defined(__lint)
#include "assym.h"
#endif
#if defined(__lint)
void
xen_failsafe_callback(void)
{}
void
xen_callback(void)
{}
#else /* __lint */
/*
* The stack frame for events is exactly that of an x86 hardware
* interrupt.
*
* The stack frame for a failsafe callback is augmented with saved
* values for segment registers:
*
* i386
* %ds, %es, %fs, %gs, %eip, %cs, %eflags [, %oldesp, %oldss ]
*
* On amd64 the stack frame for events is exactly that of an hardware
* interrupt with the addition of rcx and r11.
*
* The stack frame for a failsafe callback is augmented with saved
* values for segment registers:
*
* amd64
* %rcx, %r11, %ds, %es, %fs, %gs, %rip, %cs, %rflags,
* [, %oldrsp, %oldss ]
*
* The hypervisor does this to allow the guest OS to handle returns
* to processes which have bad segment registers.
*
*
* We will construct a fully fledged 'struct regs' and call trap
* with a #gp fault.
*/
#if defined(__amd64)
/*
* The saved values of rcx and r11 are on the top of the stack.
* pop them and let INTR_PUSH save them. We drop ds, es, fs and
* gs since the hypervisor will have already loaded these for us.
* If any were bad and faulted the hypervisor would have loaded
* them with the null selctor.
*/
XPV_TRAP_POP /* rcx, r11 */
/*
* XXPV
* If the current segregs are provided for us on the stack by
* the hypervisor then we should simply move them into their proper
* location in the regs struct?
*/
/*
* XXPV
* It would be nice to somehow figure out which selector caused
* #gp fault.
*/
pushq $0 /* dummy error */
/*
* We're here because HYPERVISOR_IRET to userland failed due to a
* bad %cs value. Rewrite %cs, %ss and %rip on the stack so trap
* will know to handle this with kern_gpfault and kill the currently
* running process.
*/
/*
* drop ds, es, fs and gs
*/
pushl $0 /* dummy error (see comment for 64-bit) */
INTGATE_INIT_KERNEL_FLAGS /* (set kernel flag values) */
/*
* The fact were here is because HYPERVISOR_IRET to userland
* failed due to a bad %cs value. Rewrite %cs, %ss and %eip
* on the stack so trap will know to handle this with
* kern_gpfault and kill the currently running process.
*/
pushl $0
#endif /* __i386 */
#if defined(__amd64)
pushq $0 /* dummy error */
INTGATE_INIT_KERNEL_FLAGS /* (set kernel flag values) */
/*NOTREACHED*/
pushl $0 /* dummy error */
INTGATE_INIT_KERNEL_FLAGS /* (set kernel flag values) */
/*NOTREACHED*/
#endif /* __i386 */
#endif /* __lint */