1/**
2 * \file
3 */
4
5/*
6 * Copyright (c) 2014, University of Washington.
7 * All rights reserved.
8 *
9 * This file is distributed under the terms in the attached LICENSE file.
10 * If you do not find this file, copies can be found by writing to:
11 * ETH Zurich D-INFK, CAB F.78, Universitaetstrasse 6, CH-8092 Zurich.
12 * Attn: Systems Group.
13 */
14
15#ifndef INTEL_VMX_H
16#define INTEL_VMX_H
17
18#include <stdint.h>
19#include <barrelfish_kpi/vmx_controls.h>
20#include <barrelfish_kpi/vmx_encodings.h>
21#include <barrelfish_kpi/vmx_exit_reasons.h>
22
23// Number of MSRs that are stored/loaded for the guest on VM-exit/VM-entry
24#define VMX_MSR_COUNT 5
25
26// Size of the guest MSR store/load area
27#define VMX_MSR_AREA_SIZE (VMX_MSR_COUNT * 16)
28
29#define VMX_EXIT_REASON_SWINT 57
30#define RFLAGS_CF (1UL << 0)
31#define RFLAGS_IF (1UL << 9)
32#define CR0_PE (1UL << 0)
33#define CR0_PG (1UL << 31)
34#define CR4_PAE (1UL << 5)
35#define EFER_LMA (1UL << 10)
36#define ACCESS_RIGHTS_LONG_MODE (1UL << 13)
37
38/**
39 * \brief Convenience macro to write real-mode segmentation registers
40 *
41 * Write the selector, base and limit to a selector reg according to real-mode
42 * segmentation rules to the VMCS.
43 */
44
45#define VMCS_WRITE_SEGREG_REALMODE(dcb_cap,reg,selector)		                                \
46do {									                                \
47    errval_t err_val = invoke_dispatcher_vmwrite(dcb_cap, VMX_GUEST_ ##reg## _SEL, (selector));         \
48    err_val += invoke_dispatcher_vmwrite(dcb_cap, VMX_GUEST_ ##reg## _BASE, (selector) << 4);           \
49    err_val += invoke_dispatcher_vmwrite(dcb_cap, VMX_GUEST_ ##reg## _LIM, ((selector) << 4) + 0xffff); \
50    assert(err_is_ok(err_val));                                                                         \
51} while (0)
52
53#endif // INTEL_VMX_H
54