2013-08-23 00:37:26 +00:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 2013, Anish Gupta (akgupt3@gmail.com)
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice unmodified, this list of conditions, and the following
|
|
|
|
* disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
#include <machine/asmacros.h>
|
|
|
|
|
2014-10-20 02:57:30 +00:00
|
|
|
#include "svm_assym.h"
|
2013-08-23 00:37:26 +00:00
|
|
|
|
|
|
|
/*
|
2014-09-27 02:04:58 +00:00
|
|
|
* Be friendly to DTrace FBT's prologue/epilogue pattern matching.
|
|
|
|
*
|
|
|
|
* They are also responsible for saving/restoring the host %rbp across VMRUN.
|
2013-08-23 00:37:26 +00:00
|
|
|
*/
|
2014-09-27 02:04:58 +00:00
|
|
|
#define VENTER push %rbp ; mov %rsp,%rbp
|
|
|
|
#define VLEAVE pop %rbp
|
2013-08-23 00:37:26 +00:00
|
|
|
|
|
|
|
/*
|
2014-09-27 02:04:58 +00:00
|
|
|
* svm_launch(uint64_t vmcb, struct svm_regctx *gctx)
|
|
|
|
* %rdi: physical address of VMCB
|
|
|
|
* %rsi: pointer to guest context
|
2013-08-23 00:37:26 +00:00
|
|
|
*/
|
|
|
|
ENTRY(svm_launch)
|
2014-09-27 02:04:58 +00:00
|
|
|
VENTER
|
2013-08-23 00:37:26 +00:00
|
|
|
|
|
|
|
/*
|
2014-09-27 02:04:58 +00:00
|
|
|
* Host register state saved across a VMRUN.
|
|
|
|
*
|
|
|
|
* All "callee saved registers" except:
|
|
|
|
* %rsp: because it is preserved by the processor across VMRUN.
|
|
|
|
* %rbp: because it is saved/restored by the function prologue/epilogue.
|
2013-08-23 00:37:26 +00:00
|
|
|
*/
|
2014-09-27 02:04:58 +00:00
|
|
|
push %rbx
|
|
|
|
push %r12
|
|
|
|
push %r13
|
|
|
|
push %r14
|
|
|
|
push %r15
|
|
|
|
|
|
|
|
/* Save the physical address of the VMCB in %rax */
|
2013-08-23 00:37:26 +00:00
|
|
|
movq %rdi, %rax
|
|
|
|
|
2014-09-27 02:04:58 +00:00
|
|
|
push %rsi /* push guest context pointer on the stack */
|
2013-08-23 00:37:26 +00:00
|
|
|
|
2014-09-27 02:04:58 +00:00
|
|
|
/*
|
|
|
|
* Restore guest state.
|
|
|
|
*/
|
|
|
|
movq SCTX_R8(%rsi), %r8
|
|
|
|
movq SCTX_R9(%rsi), %r9
|
|
|
|
movq SCTX_R10(%rsi), %r10
|
|
|
|
movq SCTX_R11(%rsi), %r11
|
|
|
|
movq SCTX_R12(%rsi), %r12
|
|
|
|
movq SCTX_R13(%rsi), %r13
|
|
|
|
movq SCTX_R14(%rsi), %r14
|
|
|
|
movq SCTX_R15(%rsi), %r15
|
|
|
|
movq SCTX_RBP(%rsi), %rbp
|
|
|
|
movq SCTX_RBX(%rsi), %rbx
|
|
|
|
movq SCTX_RCX(%rsi), %rcx
|
|
|
|
movq SCTX_RDX(%rsi), %rdx
|
|
|
|
movq SCTX_RDI(%rsi), %rdi
|
|
|
|
movq SCTX_RSI(%rsi), %rsi /* %rsi must be restored last */
|
2013-08-23 00:37:26 +00:00
|
|
|
|
2014-09-27 02:04:58 +00:00
|
|
|
vmload %rax
|
2013-08-23 00:37:26 +00:00
|
|
|
vmrun %rax
|
|
|
|
vmsave %rax
|
|
|
|
|
2014-09-27 02:04:58 +00:00
|
|
|
pop %rax /* pop guest context pointer from the stack */
|
2013-08-23 00:37:26 +00:00
|
|
|
|
2014-09-27 02:04:58 +00:00
|
|
|
/*
|
|
|
|
* Save guest state.
|
|
|
|
*/
|
|
|
|
movq %r8, SCTX_R8(%rax)
|
|
|
|
movq %r9, SCTX_R9(%rax)
|
|
|
|
movq %r10, SCTX_R10(%rax)
|
|
|
|
movq %r11, SCTX_R11(%rax)
|
|
|
|
movq %r12, SCTX_R12(%rax)
|
|
|
|
movq %r13, SCTX_R13(%rax)
|
|
|
|
movq %r14, SCTX_R14(%rax)
|
|
|
|
movq %r15, SCTX_R15(%rax)
|
|
|
|
movq %rbp, SCTX_RBP(%rax)
|
|
|
|
movq %rbx, SCTX_RBX(%rax)
|
|
|
|
movq %rcx, SCTX_RCX(%rax)
|
|
|
|
movq %rdx, SCTX_RDX(%rax)
|
|
|
|
movq %rdi, SCTX_RDI(%rax)
|
|
|
|
movq %rsi, SCTX_RSI(%rax)
|
|
|
|
|
|
|
|
/* Restore host state */
|
|
|
|
pop %r15
|
|
|
|
pop %r14
|
|
|
|
pop %r13
|
|
|
|
pop %r12
|
|
|
|
pop %rbx
|
|
|
|
|
|
|
|
VLEAVE
|
2013-08-23 00:37:26 +00:00
|
|
|
ret
|
|
|
|
END(svm_launch)
|