1/**
2 * \file
3 * \brief Functions used in the rigorous checks that are performed (optionally)
4 *  before launching and/or resuming a VM-guest.
5 */
6
7/*
8 * Copyright (c) 2014, University of Washington.
9 * All rights reserved.
10 *
11 * This file is distributed under the terms in the attached LICENSE file.
12 * If you do not find this file, copies can be found by writing to:
13 * ETH Zurich D-INFK, CAB F.78, Universitaetstr. 6, CH-8092 Zurich.
14 * Attn: Systems Group.
15 */
16
17#ifndef VMX_CHECKS_H
18#define VMX_CHECKS_H
19
20#define INTR_TYPE_EXT_INTR 0
21#define INTR_TYPE_NMI 2
22#define INTR_TYPE_HW_EXCEP 3
23#define INTR_TYPE_SW_INTR 4
24#define INTR_TYPE_PRIV_SW_EXCEP 5
25#define INTR_TYPE_SW_EXCEP 6
26#define INTR_TYPE_OTHER 7
27
28#define ACCESS_UNUSABLE (1 << 16)
29#define SEL_TI (1 << 2)
30#define SEL_RPL (0x3)
31#define SEG_TYPE_ACCESSED (1 << 0)
32#define SEG_TYPE_READABLE (1 << 1)
33#define SEG_TYPE_CODE_SEGMENT (1 << 3)
34
35static inline int seg_reg_usable(int access_rights)
36{
37    return !(access_rights & ACCESS_UNUSABLE);
38}
39
40static inline int seg_access_type(uint64_t access_rights)
41{
42    return ((access_rights >> 0) & 0xF);
43}
44
45static inline int seg_access_s(uint64_t access_rights)
46{
47    return ((access_rights >> 4) & 0x1);
48}
49
50static inline int seg_access_dpl(uint64_t access_rights)
51{
52    return ((access_rights >> 5) & 0x3);
53}
54
55static inline int seg_access_p(uint64_t access_rights)
56{
57    return ((access_rights >> 7) & 0x1);
58}
59
60static inline int seg_access_l(uint64_t access_rights)
61{
62    return ((access_rights >> 13) & 0x1);
63}
64
65static inline int seg_access_db(uint64_t access_rights)
66{
67    return ((access_rights >> 14) & 0x1);
68}
69
70static inline int seg_access_g(uint64_t access_rights)
71{
72    return ((access_rights >> 15) & 0x1);
73}
74
75static inline int ept_type(uint64_t eptp)
76{
77    return ((eptp >> 0) & 0x7);
78}
79
80static inline int ept_page_walk_length(uint64_t eptp)
81{
82    return ((eptp >> 3) & 0x7);
83}
84
85static inline int ept_accessed_dirty_enable(uint64_t eptp)
86{
87    return ((eptp >> 6) & 0x1);
88}
89
90void check_guest_state_area(void);
91void check_host_state_area(void);
92void check_vmx_controls(void);
93
94#endif // VMX_CHECKS_H
95