Home | History | Annotate | Line # | Download | only in x86
nvmm_x86.h revision 1.14
      1  1.14  maxv /*	$NetBSD: nvmm_x86.h,v 1.14 2019/05/01 09:20:21 maxv Exp $	*/
      2   1.1  maxv 
      3   1.1  maxv /*
      4   1.1  maxv  * Copyright (c) 2018 The NetBSD Foundation, Inc.
      5   1.1  maxv  * All rights reserved.
      6   1.1  maxv  *
      7   1.1  maxv  * This code is derived from software contributed to The NetBSD Foundation
      8   1.1  maxv  * by Maxime Villard.
      9   1.1  maxv  *
     10   1.1  maxv  * Redistribution and use in source and binary forms, with or without
     11   1.1  maxv  * modification, are permitted provided that the following conditions
     12   1.1  maxv  * are met:
     13   1.1  maxv  * 1. Redistributions of source code must retain the above copyright
     14   1.1  maxv  *    notice, this list of conditions and the following disclaimer.
     15   1.1  maxv  * 2. Redistributions in binary form must reproduce the above copyright
     16   1.1  maxv  *    notice, this list of conditions and the following disclaimer in the
     17   1.1  maxv  *    documentation and/or other materials provided with the distribution.
     18   1.1  maxv  *
     19   1.1  maxv  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20   1.1  maxv  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21   1.1  maxv  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22   1.1  maxv  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23   1.1  maxv  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24   1.1  maxv  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25   1.1  maxv  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26   1.1  maxv  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27   1.1  maxv  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28   1.1  maxv  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29   1.1  maxv  * POSSIBILITY OF SUCH DAMAGE.
     30   1.1  maxv  */
     31   1.1  maxv 
     32   1.1  maxv #ifndef _NVMM_X86_H_
     33   1.1  maxv #define _NVMM_X86_H_
     34   1.1  maxv 
     35  1.12  maxv /* --------------------------------------------------------------------- */
     36  1.12  maxv 
     37  1.12  maxv #ifndef ASM_NVMM
     38  1.12  maxv 
     39  1.12  maxv struct nvmm_exit_memory {
     40  1.12  maxv 	int prot;
     41  1.12  maxv 	gpaddr_t gpa;
     42  1.12  maxv 	uint8_t inst_len;
     43  1.12  maxv 	uint8_t inst_bytes[15];
     44  1.12  maxv };
     45  1.12  maxv 
     46  1.12  maxv enum nvmm_exit_io_type {
     47  1.12  maxv 	NVMM_EXIT_IO_IN,
     48  1.12  maxv 	NVMM_EXIT_IO_OUT
     49  1.12  maxv };
     50  1.12  maxv 
     51  1.12  maxv struct nvmm_exit_io {
     52  1.12  maxv 	enum nvmm_exit_io_type type;
     53  1.12  maxv 	uint16_t port;
     54  1.12  maxv 	int seg;
     55  1.12  maxv 	uint8_t address_size;
     56  1.12  maxv 	uint8_t operand_size;
     57  1.12  maxv 	bool rep;
     58  1.12  maxv 	bool str;
     59  1.12  maxv 	uint64_t npc;
     60  1.12  maxv };
     61  1.12  maxv 
     62  1.12  maxv enum nvmm_exit_msr_type {
     63  1.12  maxv 	NVMM_EXIT_MSR_RDMSR,
     64  1.12  maxv 	NVMM_EXIT_MSR_WRMSR
     65  1.12  maxv };
     66  1.12  maxv 
     67  1.12  maxv struct nvmm_exit_msr {
     68  1.12  maxv 	enum nvmm_exit_msr_type type;
     69  1.12  maxv 	uint64_t msr;
     70  1.12  maxv 	uint64_t val;
     71  1.12  maxv 	uint64_t npc;
     72  1.12  maxv };
     73  1.12  maxv 
     74  1.12  maxv struct nvmm_exit_insn {
     75  1.12  maxv 	uint64_t npc;
     76  1.12  maxv };
     77  1.12  maxv 
     78  1.12  maxv struct nvmm_exit_invalid {
     79  1.12  maxv 	uint64_t hwcode;
     80  1.12  maxv };
     81  1.12  maxv 
     82  1.12  maxv union nvmm_exit_md {
     83  1.12  maxv 	struct nvmm_exit_memory mem;
     84  1.12  maxv 	struct nvmm_exit_io io;
     85  1.12  maxv 	struct nvmm_exit_msr msr;
     86  1.12  maxv 	struct nvmm_exit_insn insn;
     87  1.12  maxv 	struct nvmm_exit_invalid inv;
     88  1.12  maxv };
     89  1.12  maxv 
     90  1.12  maxv #define NVMM_EXIT_MONITOR	0x0000000000001000ULL
     91  1.12  maxv #define NVMM_EXIT_MWAIT		0x0000000000001001ULL
     92  1.12  maxv #define NVMM_EXIT_MWAIT_COND	0x0000000000001002ULL
     93  1.12  maxv 
     94  1.12  maxv struct nvmm_cap_md {
     95  1.12  maxv 	uint64_t xcr0_mask;
     96  1.12  maxv 	uint64_t mxcsr_mask;
     97  1.12  maxv 	uint64_t conf_cpuid_maxops;
     98  1.12  maxv 	uint64_t rsvd[5];
     99  1.12  maxv };
    100  1.12  maxv 
    101  1.12  maxv #endif
    102  1.12  maxv 
    103  1.12  maxv /* --------------------------------------------------------------------- */
    104  1.12  maxv 
    105   1.1  maxv /* Segments. */
    106   1.7  maxv #define NVMM_X64_SEG_ES			0
    107   1.7  maxv #define NVMM_X64_SEG_CS			1
    108   1.7  maxv #define NVMM_X64_SEG_SS			2
    109   1.7  maxv #define NVMM_X64_SEG_DS			3
    110   1.7  maxv #define NVMM_X64_SEG_FS			4
    111   1.7  maxv #define NVMM_X64_SEG_GS			5
    112   1.1  maxv #define NVMM_X64_SEG_GDT		6
    113   1.1  maxv #define NVMM_X64_SEG_IDT		7
    114   1.1  maxv #define NVMM_X64_SEG_LDT		8
    115   1.1  maxv #define NVMM_X64_SEG_TR			9
    116   1.1  maxv #define NVMM_X64_NSEG			10
    117   1.1  maxv 
    118   1.1  maxv /* General Purpose Registers. */
    119   1.1  maxv #define NVMM_X64_GPR_RAX		0
    120   1.4  maxv #define NVMM_X64_GPR_RCX		1
    121   1.4  maxv #define NVMM_X64_GPR_RDX		2
    122   1.4  maxv #define NVMM_X64_GPR_RBX		3
    123   1.4  maxv #define NVMM_X64_GPR_RSP		4
    124   1.4  maxv #define NVMM_X64_GPR_RBP		5
    125   1.4  maxv #define NVMM_X64_GPR_RSI		6
    126   1.4  maxv #define NVMM_X64_GPR_RDI		7
    127   1.4  maxv #define NVMM_X64_GPR_R8			8
    128   1.4  maxv #define NVMM_X64_GPR_R9			9
    129   1.4  maxv #define NVMM_X64_GPR_R10		10
    130   1.4  maxv #define NVMM_X64_GPR_R11		11
    131   1.4  maxv #define NVMM_X64_GPR_R12		12
    132   1.4  maxv #define NVMM_X64_GPR_R13		13
    133   1.4  maxv #define NVMM_X64_GPR_R14		14
    134   1.4  maxv #define NVMM_X64_GPR_R15		15
    135   1.1  maxv #define NVMM_X64_GPR_RIP		16
    136   1.1  maxv #define NVMM_X64_GPR_RFLAGS		17
    137   1.1  maxv #define NVMM_X64_NGPR			18
    138   1.1  maxv 
    139   1.1  maxv /* Control Registers. */
    140   1.1  maxv #define NVMM_X64_CR_CR0			0
    141   1.1  maxv #define NVMM_X64_CR_CR2			1
    142   1.1  maxv #define NVMM_X64_CR_CR3			2
    143   1.1  maxv #define NVMM_X64_CR_CR4			3
    144   1.1  maxv #define NVMM_X64_CR_CR8			4
    145   1.1  maxv #define NVMM_X64_CR_XCR0		5
    146   1.1  maxv #define NVMM_X64_NCR			6
    147   1.1  maxv 
    148   1.1  maxv /* Debug Registers. */
    149   1.1  maxv #define NVMM_X64_DR_DR0			0
    150   1.1  maxv #define NVMM_X64_DR_DR1			1
    151   1.1  maxv #define NVMM_X64_DR_DR2			2
    152   1.1  maxv #define NVMM_X64_DR_DR3			3
    153   1.1  maxv #define NVMM_X64_DR_DR6			4
    154   1.1  maxv #define NVMM_X64_DR_DR7			5
    155   1.1  maxv #define NVMM_X64_NDR			6
    156   1.1  maxv 
    157   1.1  maxv /* MSRs. */
    158   1.1  maxv #define NVMM_X64_MSR_EFER		0
    159   1.1  maxv #define NVMM_X64_MSR_STAR		1
    160   1.1  maxv #define NVMM_X64_MSR_LSTAR		2
    161   1.1  maxv #define NVMM_X64_MSR_CSTAR		3
    162   1.1  maxv #define NVMM_X64_MSR_SFMASK		4
    163   1.1  maxv #define NVMM_X64_MSR_KERNELGSBASE	5
    164   1.1  maxv #define NVMM_X64_MSR_SYSENTER_CS	6
    165   1.1  maxv #define NVMM_X64_MSR_SYSENTER_ESP	7
    166   1.1  maxv #define NVMM_X64_MSR_SYSENTER_EIP	8
    167   1.1  maxv #define NVMM_X64_MSR_PAT		9
    168   1.9  maxv #define NVMM_X64_MSR_TSC		10
    169   1.9  maxv #define NVMM_X64_NMSR			11
    170   1.1  maxv 
    171   1.1  maxv #ifndef ASM_NVMM
    172   1.1  maxv 
    173   1.1  maxv #include <sys/types.h>
    174   1.1  maxv #include <x86/cpu_extended_state.h>
    175   1.1  maxv 
    176   1.1  maxv struct nvmm_x64_state_seg {
    177   1.7  maxv 	uint16_t selector;
    178   1.1  maxv 	struct {		/* hidden */
    179   1.7  maxv 		uint16_t type:4;
    180   1.7  maxv 		uint16_t s:1;
    181   1.7  maxv 		uint16_t dpl:2;
    182   1.7  maxv 		uint16_t p:1;
    183   1.7  maxv 		uint16_t avl:1;
    184   1.7  maxv 		uint16_t l:1;
    185   1.7  maxv 		uint16_t def:1;
    186   1.7  maxv 		uint16_t g:1;
    187   1.7  maxv 		uint16_t rsvd:4;
    188   1.1  maxv 	} attrib;
    189   1.7  maxv 	uint32_t limit;		/* hidden */
    190   1.1  maxv 	uint64_t base;		/* hidden */
    191   1.1  maxv };
    192   1.1  maxv 
    193  1.11  maxv struct nvmm_x64_state_intr {
    194  1.11  maxv 	uint64_t int_shadow:1;
    195  1.11  maxv 	uint64_t int_window_exiting:1;
    196  1.11  maxv 	uint64_t nmi_window_exiting:1;
    197  1.11  maxv 	uint64_t evt_pending:1;
    198  1.11  maxv 	uint64_t rsvd:60;
    199  1.11  maxv };
    200  1.11  maxv 
    201   1.1  maxv /* VM exit state indexes. */
    202   1.3  maxv #define NVMM_X64_EXITSTATE_CR8			0
    203   1.3  maxv #define NVMM_X64_EXITSTATE_RFLAGS		1
    204   1.3  maxv #define NVMM_X64_EXITSTATE_INT_SHADOW		2
    205   1.3  maxv #define NVMM_X64_EXITSTATE_INT_WINDOW_EXIT	3
    206   1.3  maxv #define NVMM_X64_EXITSTATE_NMI_WINDOW_EXIT	4
    207  1.11  maxv #define NVMM_X64_EXITSTATE_EVT_PENDING		5
    208   1.1  maxv 
    209   1.1  maxv /* Flags. */
    210   1.1  maxv #define NVMM_X64_STATE_SEGS	0x01
    211   1.1  maxv #define NVMM_X64_STATE_GPRS	0x02
    212   1.1  maxv #define NVMM_X64_STATE_CRS	0x04
    213   1.1  maxv #define NVMM_X64_STATE_DRS	0x08
    214   1.1  maxv #define NVMM_X64_STATE_MSRS	0x10
    215  1.11  maxv #define NVMM_X64_STATE_INTR	0x20
    216   1.1  maxv #define NVMM_X64_STATE_FPU	0x40
    217   1.1  maxv #define NVMM_X64_STATE_ALL	\
    218   1.1  maxv 	(NVMM_X64_STATE_SEGS | NVMM_X64_STATE_GPRS | NVMM_X64_STATE_CRS | \
    219  1.11  maxv 	 NVMM_X64_STATE_DRS | NVMM_X64_STATE_MSRS | NVMM_X64_STATE_INTR | \
    220   1.1  maxv 	 NVMM_X64_STATE_FPU)
    221   1.1  maxv 
    222   1.1  maxv struct nvmm_x64_state {
    223   1.1  maxv 	struct nvmm_x64_state_seg segs[NVMM_X64_NSEG];
    224   1.1  maxv 	uint64_t gprs[NVMM_X64_NGPR];
    225   1.1  maxv 	uint64_t crs[NVMM_X64_NCR];
    226   1.1  maxv 	uint64_t drs[NVMM_X64_NDR];
    227   1.1  maxv 	uint64_t msrs[NVMM_X64_NMSR];
    228  1.11  maxv 	struct nvmm_x64_state_intr intr;
    229   1.1  maxv 	struct fxsave fpu;
    230   1.1  maxv };
    231   1.1  maxv 
    232  1.14  maxv #define nvmm_vcpu_state nvmm_x64_state
    233  1.14  maxv 
    234   1.1  maxv #define NVMM_X86_CONF_CPUID	0
    235   1.1  maxv #define NVMM_X86_NCONF		1
    236   1.1  maxv 
    237   1.1  maxv struct nvmm_x86_conf_cpuid {
    238   1.1  maxv 	uint32_t leaf;
    239   1.1  maxv 	struct {
    240   1.1  maxv 		uint32_t eax;
    241   1.1  maxv 		uint32_t ebx;
    242   1.1  maxv 		uint32_t ecx;
    243   1.1  maxv 		uint32_t edx;
    244   1.1  maxv 	} set;
    245   1.1  maxv 	struct {
    246   1.1  maxv 		uint32_t eax;
    247   1.1  maxv 		uint32_t ebx;
    248   1.1  maxv 		uint32_t ecx;
    249   1.1  maxv 		uint32_t edx;
    250   1.1  maxv 	} del;
    251   1.1  maxv };
    252   1.1  maxv 
    253   1.6  maxv #ifdef _KERNEL
    254   1.8  maxv struct nvmm_x86_cpuid_mask {
    255   1.8  maxv 	uint32_t eax;
    256   1.8  maxv 	uint32_t ebx;
    257   1.8  maxv 	uint32_t ecx;
    258   1.8  maxv 	uint32_t edx;
    259   1.8  maxv };
    260   1.6  maxv extern const struct nvmm_x64_state nvmm_x86_reset_state;
    261   1.8  maxv extern const struct nvmm_x86_cpuid_mask nvmm_cpuid_00000001;
    262   1.8  maxv extern const struct nvmm_x86_cpuid_mask nvmm_cpuid_00000007;
    263   1.8  maxv extern const struct nvmm_x86_cpuid_mask nvmm_cpuid_80000001;
    264  1.10  maxv bool nvmm_x86_pat_validate(uint64_t);
    265   1.6  maxv #endif
    266   1.6  maxv 
    267   1.1  maxv #endif /* ASM_NVMM */
    268   1.1  maxv 
    269   1.1  maxv #endif /* _NVMM_X86_H_ */
    270