1181834Sroberto/* SPDX-License-Identifier: MIT */
2181834Sroberto/*
3181834Sroberto * Copyright (c) 2015, Roger Pau Monne <roger.pau@citrix.com>
4181834Sroberto */
5181834Sroberto
6181834Sroberto#ifndef __XEN_PUBLIC_HVM_HVM_VCPU_H__
7181834Sroberto#define __XEN_PUBLIC_HVM_HVM_VCPU_H__
8181834Sroberto
9181834Sroberto#include "../xen.h"
10181834Sroberto
11181834Srobertostruct vcpu_hvm_x86_32 {
12181834Sroberto    uint32_t eax;
13181834Sroberto    uint32_t ecx;
14181834Sroberto    uint32_t edx;
15181834Sroberto    uint32_t ebx;
16181834Sroberto    uint32_t esp;
17181834Sroberto    uint32_t ebp;
18181834Sroberto    uint32_t esi;
19181834Sroberto    uint32_t edi;
20181834Sroberto    uint32_t eip;
21181834Sroberto    uint32_t eflags;
22181834Sroberto
23181834Sroberto    uint32_t cr0;
24181834Sroberto    uint32_t cr3;
25181834Sroberto    uint32_t cr4;
26181834Sroberto
27181834Sroberto    uint32_t pad1;
28181834Sroberto
29181834Sroberto    /*
30181834Sroberto     * EFER should only be used to set the NXE bit (if required)
31181834Sroberto     * when starting a vCPU in 32bit mode with paging enabled or
32181834Sroberto     * to set the LME/LMA bits in order to start the vCPU in
33181834Sroberto     * compatibility mode.
34181834Sroberto     */
35181834Sroberto    uint64_t efer;
36181834Sroberto
37181834Sroberto    uint32_t cs_base;
38181834Sroberto    uint32_t ds_base;
39181834Sroberto    uint32_t ss_base;
40181834Sroberto    uint32_t es_base;
41181834Sroberto    uint32_t tr_base;
42181834Sroberto    uint32_t cs_limit;
43181834Sroberto    uint32_t ds_limit;
44181834Sroberto    uint32_t ss_limit;
45181834Sroberto    uint32_t es_limit;
46181834Sroberto    uint32_t tr_limit;
47181834Sroberto    uint16_t cs_ar;
48181834Sroberto    uint16_t ds_ar;
49181834Sroberto    uint16_t ss_ar;
50181834Sroberto    uint16_t es_ar;
51181834Sroberto    uint16_t tr_ar;
52181834Sroberto
53181834Sroberto    uint16_t pad2[3];
54181834Sroberto};
55181834Sroberto
56181834Sroberto/*
57181834Sroberto * The layout of the _ar fields of the segment registers is the
58181834Sroberto * following:
59181834Sroberto *
60181834Sroberto * Bits   [0,3]: type (bits 40-43).
61181834Sroberto * Bit        4: s    (descriptor type, bit 44).
62181834Sroberto * Bit    [5,6]: dpl  (descriptor privilege level, bits 45-46).
63181834Sroberto * Bit        7: p    (segment-present, bit 47).
64181834Sroberto * Bit        8: avl  (available for system software, bit 52).
65181834Sroberto * Bit        9: l    (64-bit code segment, bit 53).
66181834Sroberto * Bit       10: db   (meaning depends on the segment, bit 54).
67181834Sroberto * Bit       11: g    (granularity, bit 55)
68181834Sroberto * Bits [12,15]: unused, must be blank.
69181834Sroberto *
70181834Sroberto * A more complete description of the meaning of this fields can be
71181834Sroberto * obtained from the Intel SDM, Volume 3, section 3.4.5.
72181834Sroberto */
73181834Sroberto
74181834Srobertostruct vcpu_hvm_x86_64 {
75181834Sroberto    uint64_t rax;
76181834Sroberto    uint64_t rcx;
77181834Sroberto    uint64_t rdx;
78181834Sroberto    uint64_t rbx;
79181834Sroberto    uint64_t rsp;
80181834Sroberto    uint64_t rbp;
81181834Sroberto    uint64_t rsi;
82181834Sroberto    uint64_t rdi;
83181834Sroberto    uint64_t rip;
84181834Sroberto    uint64_t rflags;
85181834Sroberto
86181834Sroberto    uint64_t cr0;
87181834Sroberto    uint64_t cr3;
88181834Sroberto    uint64_t cr4;
89181834Sroberto    uint64_t efer;
90181834Sroberto
91181834Sroberto    /*
92181834Sroberto     * Using VCPU_HVM_MODE_64B implies that the vCPU is launched
93181834Sroberto     * directly in long mode, so the cached parts of the segment
94181834Sroberto     * registers get set to match that environment.
95181834Sroberto     *
96181834Sroberto     * If the user wants to launch the vCPU in compatibility mode
97181834Sroberto     * the 32-bit structure should be used instead.
98181834Sroberto     */
99181834Sroberto};
100181834Sroberto
101181834Srobertostruct vcpu_hvm_context {
102181834Sroberto#define VCPU_HVM_MODE_32B 0  /* 32bit fields of the structure will be used. */
103181834Sroberto#define VCPU_HVM_MODE_64B 1  /* 64bit fields of the structure will be used. */
104181834Sroberto    uint32_t mode;
105181834Sroberto
106181834Sroberto    uint32_t pad;
107181834Sroberto
108181834Sroberto    /* CPU registers. */
109181834Sroberto    union {
110181834Sroberto        struct vcpu_hvm_x86_32 x86_32;
111181834Sroberto        struct vcpu_hvm_x86_64 x86_64;
112181834Sroberto    } cpu_regs;
113181834Sroberto};
114181834Srobertotypedef struct vcpu_hvm_context vcpu_hvm_context_t;
115181834Sroberto
116181834Sroberto#endif /* __XEN_PUBLIC_HVM_HVM_VCPU_H__ */
117181834Sroberto