File: plex86.h

package info (click to toggle)
bochs 2.3-2etch1
  • links: PTS
  • area: main
  • in suites: etch
  • size: 14,116 kB
  • ctags: 16,927
  • sloc: cpp: 130,524; ansic: 18,822; sh: 7,922; makefile: 3,836; yacc: 1,056; asm: 463; perl: 381; lex: 280; csh: 3
file content (259 lines) | stat: -rw-r--r-- 6,777 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
/************************************************************************
 * $Id: plex86.h,v 1.7 2004/09/11 15:39:53 vruppert Exp $
 ************************************************************************
 *
 *  plex86: run multiple x86 operating systems concurrently
 *  Copyright (C) 1999-2003  Kevin P. Lawton
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License as published by the Free Software Foundation; either
 *  version 2 of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 */

#ifndef __PLEX86_H__
#define __PLEX86_H__

#include "config.h"
#include "descriptor.h"




typedef struct {
  selector_t   sel;
  descriptor_t des;
  unsigned     valid;
  } __attribute__ ((packed)) guest_sreg_t;

#define SRegES    0
#define SRegCS    1
#define SRegSS    2
#define SRegDS    3
#define SRegFS    4
#define SRegGS    5


typedef union {
  Bit32u raw;
  struct {
    Bit32u pe:1;
    Bit32u mp:1;
    Bit32u em:1;
    Bit32u ts:1;
    Bit32u et:1;
    Bit32u ne:1;
    Bit32u R15_6:10;
    Bit32u wp:1;
    Bit32u R17:1;
    Bit32u am:1;
    Bit32u R28_19:10;
    Bit32u nw:1;
    Bit32u cd:1;
    Bit32u pg:1;
    } __attribute__ ((packed)) fields;
  } __attribute__ ((packed)) cr0_t;

typedef union {
  Bit32u raw;
  struct {
    Bit32u vme:1;
    Bit32u pvi:1;
    Bit32u tsd:1;
    Bit32u de:1;
    Bit32u pse:1;
    Bit32u pae:1;
    Bit32u mce:1;
    Bit32u pge:1;
    Bit32u pce:1;
    Bit32u reserved:23;
    } __attribute__ ((packed)) fields;
  } __attribute__ ((packed)) cr4_t;

typedef struct {
  Bit32u vendorDWord0;
  Bit32u vendorDWord1;
  Bit32u vendorDWord2;
  union {
    Bit32u raw;
    struct {
      Bit32u stepping:4;
      Bit32u model:4;
      Bit32u family:4;
      Bit32u procType:2;
      Bit32u Reserved31_14:18;
      } __attribute__ ((packed)) fields;
    } __attribute__ ((packed)) procSignature;
  union {
    Bit32u raw;
    struct {
      Bit32u fpu:1;
      Bit32u vme:1;
      Bit32u de:1;
      Bit32u pse:1;
      Bit32u tsc:1;
      Bit32u msr:1;
      Bit32u pae:1;
      Bit32u mce:1;
      Bit32u cx8:1;
      Bit32u apic:1;
      Bit32u Reserved10:1;
      Bit32u sep:1;
      Bit32u mtrr:1;
      Bit32u pge:1;
      Bit32u mca:1;
      Bit32u cmov:1;
      Bit32u pat:1;
      Bit32u pse36:1;
      Bit32u Reserved22_18:5;
      Bit32u mmx:1;
      Bit32u fxsr:1;
      Bit32u Reserved31_25:7;
      } __attribute__ ((packed)) fields;
    } __attribute__ ((packed)) featureFlags;
  } __attribute__ ((packed)) cpuid_info_t;

typedef struct {
  Bit32u edi;
  Bit32u esi;
  Bit32u ebp;
  Bit32u esp;
  Bit32u ebx;
  Bit32u edx;
  Bit32u ecx;
  Bit32u eax;

  Bit32u eflags;
  Bit32u eip;
  guest_sreg_t sreg[6];
  guest_sreg_t ldtr;
  guest_sreg_t tr;
  gdt_info_t gdtr;
  gdt_info_t idtr;
  Bit32u dr0, dr1, dr2, dr3, dr6, dr7;
  Bit32u tr3, tr4, tr5, tr6, tr7;
  cr0_t cr0;
  Bit32u cr1, cr2, cr3;
  cr4_t cr4;
  unsigned a20Enable;
  } __attribute__ ((packed)) guest_cpu_t;






/*
 *  ioctl() names.
 */

#if defined(__linux__) || defined(__NetBSD__) || defined(__NetBSD_kernel__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
#ifdef __linux__
#include <asm/ioctl.h>
#else
#include <sys/ioccom.h>
#endif
#define PLEX86_RESET        _IO('k', 3)
#define PLEX86_TEARDOWN     _IO('k', 4)
#define PLEX86_EXECUTE      _IO('k', 5)
#define PLEX86_CPUID        _IO('k', 6)
#define PLEX86_REGISTER_MEMORY _IO('k', 7)
#else
#define PLEX86_RESET        0x6b03
#define PLEX86_TEARDOWN     0x6b04
#define PLEX86_EXECUTE      0x6b05
#define PLEX86_CPUID        0x6b06
#define PLEX86_REGISTER_MEMORY 0x6b07
#endif

/* Reasons why plex86 could not execute the guest context in the VM. */
#define Plex86NoExecute_Method    1
#define Plex86NoExecute_CR0       2
#define Plex86NoExecute_CR4       3
#define Plex86NoExecute_CS        4
#define Plex86NoExecute_A20       5
#define Plex86NoExecute_Selector  6
#define Plex86NoExecute_DPL       7
#define Plex86NoExecute_EFlags    8
#define Plex86NoExecute_Panic     9
#define Plex86NoExecute_VMState  10


/* Requests that the VM monitor makes to host-kernel space or
 * host-user space.
 */
#define MonReqNone              0
#define MonReqFlushPrintBuf     1
#define MonReqRedirect          4 /* Only to host-kernel. */
#define MonReqRemapMonitor      5
#define MonReqGuestFault        6
#define MonReqPinUserPage       7
#define MonReqPanic             8

#define VMStateFDOpened               0x001
#define VMStateMemAllocated           0x002
#define VMStateGuestCPUID             0x004
#define VMStateRegisteredPhyMem       0x008
#define VMStateRegisteredPrintBuffer  0x010
#define VMStateRegisteredGuestCPU     0x020
#define VMStateInitMonitor            0x040
#define VMStateMapMonitor             0x080
#define VMStatePanic                  0x100

  /* State where the VM/monitor is ready to execute. */
#define VMStateReady (VMStateFDOpened | \
                      VMStateMemAllocated | \
                      VMStateGuestCPUID | \
                      VMStateRegisteredPhyMem | \
                      VMStateRegisteredPrintBuffer | \
                      VMStateRegisteredGuestCPU | \
                      VMStateInitMonitor | \
                      VMStateMapMonitor)

  /* State where all user-space memory constructs are registered with
   * the plex86 kernel module.
   */
#define VMStateRegisteredAll \
                     (VMStateRegisteredPhyMem | \
                      VMStateRegisteredPrintBuffer | \
                      VMStateRegisteredGuestCPU)

typedef struct {
  unsigned state;
  unsigned request;
  unsigned guestFaultNo;
  } plex86MonitorState_t;

typedef struct {
#define Plex86ExecuteMethodNative       10
#define Plex86ExecuteMethodBreakpoint   11
  unsigned executeMethod;

  /* User space --> Monitor space. */
  Bit64u               cyclesRequested;
  unsigned             instructionsRequested;

  /* Monitor space --> User space. */
  Bit64u               cyclesExecuted;
  unsigned             instructionsExecuted;
  plex86MonitorState_t monitorState;
  } plex86IoctlExecute_t;

typedef struct {
  unsigned nMegs;
  Bit32u   guestPhyMemVector;

  Bit32u   logBufferWindow;
  Bit32u   guestCPUWindow;
  } plex86IoctlRegisterMem_t;

#endif  /* #ifndef __PLEX86_H__ */