Back to home page

Quest Cross Reference

 
 

    


Warning, cross-references for /kernel/include/vm/vmx.h need to be fixed.

0001 /*                    The Quest Operating System
0002  *  Copyright (C) 2005-2010  Richard West, Boston University
0003  *
0004  *  This program is free software: you can redistribute it and/or modify
0005  *  it under the terms of the GNU General Public License as published by
0006  *  the Free Software Foundation, either version 3 of the License, or
0007  *  (at your option) any later version.
0008  *
0009  *  This program is distributed in the hope that it will be useful,
0010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
0011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0012  *  GNU General Public License for more details.
0013  *
0014  *  You should have received a copy of the GNU General Public License
0015  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
0016  */
0017 
0018 #ifndef _VMX_H_
0019 #define _VMX_H_
0020 #include "types.h"
0021 #include "vmx-defs.h"
0022 #include "smp/spinlock.h"
0023 
0024 typedef struct
0025 {
0026   /* Order based on PUSHA/POPA */
0027   uint32 edi, esi, ebp, esp, ebx, edx, ecx, eax;
0028 } gp_registers;
0029 
0030 typedef struct
0031 {
0032   uint32 vmcs_frame, current_cpu;
0033   void *guest_stack;
0034   gp_registers guest_regs;
0035   uint32 launched, loaded, realmode;
0036 } virtual_machine;
0037 
0038 #define VM_REG(n) ((((uint32 *) (&vm->guest_regs)))[7 - (n)])
0039 static char *gp_register_names[] = {
0040    "edi", "esi", "ebp", "esp", "ebx", "edx", "ecx", "eax"
0041 };
0042 #define VM_REG_NAME(n) (gp_register_names[7 - n])
0043 
0044 void vmx_detect (void);
0045 void vmx_global_init (void);
0046 void vmx_processor_init (void);
0047 int vmx_create_VM (virtual_machine *);
0048 int vmx_create_pmode_VM (virtual_machine *, u32, u32);
0049 int vmx_destroy_VM (virtual_machine *);
0050 int vmx_load_VM (virtual_machine *);
0051 int vmx_unload_VM (virtual_machine *);
0052 int vmx_enter_pmode_VM (virtual_machine *);
0053 int vmx_start_VM (virtual_machine *);
0054 
0055 static inline int
0056 vmx_get_error (void)
0057 {
0058   uint32 flags;
0059   asm volatile ("pushfl\n"
0060                 "pop %0"
0061                 :"=r" (flags));
0062   if (flags & (1<<0))
0063     return -1;
0064   if (flags & (1<<6))
0065     return 1;
0066   return 0;
0067 }
0068 
0069 static inline void
0070 vmxon (uint32 frame)
0071 {
0072   uint64 frame64 = (uint64)frame & 0xFFFFFFFF;
0073   asm volatile ("vmxon %0"::"m" (frame64):"flags");
0074 }
0075 
0076 static inline void
0077 vmclear (uint32 frame)
0078 {
0079   uint64 frame64 = (uint64)frame & 0xFFFFFFFF;
0080   asm volatile ("vmclear %0"::"m" (frame64):"flags");
0081 }
0082 
0083 static inline void
0084 vmptrld (uint32 frame)
0085 {
0086   uint64 frame64 = (uint64)frame & 0xFFFFFFFF;
0087   asm volatile ("vmptrld %0"::"m" (frame64):"flags");
0088 }
0089 
0090 static inline uint32
0091 vmptrst (void)
0092 {
0093   uint64 frame64;
0094   asm volatile ("vmptrst %0":"=m" (frame64));
0095   return (uint32) frame64;
0096 }
0097 
0098 static inline uint32
0099 vmread (uint32 encoding)
0100 {
0101   uint32 value;
0102   asm volatile ("vmread %1, %0":"=r" (value):"r" (encoding):"flags");
0103   return value;
0104 }
0105 
0106 static inline void
0107 vmwrite (uint32 val, uint32 encoding)
0108 {
0109   asm volatile ("vmwrite %0, %1"::"r" (val), "r" (encoding):"flags");
0110 }
0111 
0112 static inline void
0113 vmwrite64 (uint64 val, uint32 encoding)
0114 {
0115   uint32 lo = (uint32) val, hi = (uint32) (val >> 32);
0116   asm volatile ("vmwrite %0, %1"::"r" (lo), "r" (encoding):"flags");
0117   asm volatile ("vmwrite %0, %1"::"r" (hi), "r" (encoding+1):"flags");
0118 }
0119 
0120 #define CLOBBERS "cc","memory","%eax","%ebx","%ecx","%edx","%esi","%edi","%esp"
0121 
0122 static inline void
0123 vmlaunch (void)
0124 {
0125   asm volatile ("vmlaunch":::CLOBBERS);
0126 }
0127 
0128 static inline void
0129 vmresume (void)
0130 {
0131   asm volatile ("vmresume":::CLOBBERS);
0132 }
0133 
0134 #undef CLOBBERS
0135 
0136 static inline void
0137 vmxoff (void)
0138 {
0139   asm volatile ("vmxoff");
0140 }
0141 
0142 
0143 #endif
0144 
0145 /*
0146  * Local Variables:
0147  * indent-tabs-mode: nil
0148  * mode: C
0149  * c-file-style: "gnu"
0150  * c-basic-offset: 2
0151  * End:
0152  */
0153 
0154 /* vi: set et sw=2 sts=2: */