1/*
2** Copyright (c) 2011, Intel Corporation
3**
4** This software is licensed under the terms of the GNU General Public
5** License version 2, as published by the Free Software Foundation, and
6** may be copied, distributed, and modified under those terms.
7**
8** This program is distributed in the hope that it will be useful,
9** but WITHOUT ANY WARRANTY; without even the implied warranty of
10** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11** GNU General Public License for more details.
12*/
13
14#ifndef _HAX_I386_H
15#define _HAX_I386_H
16
17#include "android/utils/debug.h"
18#include "hax.h"
19
20#ifdef CONFIG_DARWIN
21typedef int hax_fd;
22#endif
23
24#ifdef CONFIG_WIN32
25typedef HANDLE hax_fd;
26#endif
27
28extern struct hax_state hax_global;
29struct hax_vcpu_state
30{
31    hax_fd fd;
32    int vcpu_id;
33    int emulation_state;
34    struct hax_tunnel *tunnel;
35    unsigned char *iobuf;
36};
37
38struct hax_state
39{
40    hax_fd fd; /* the global hax device interface */
41    uint32_t version;
42    struct hax_vm *vm;
43    uint64_t mem_quota;
44};
45
46#define HAX_MAX_VCPU 0x10
47#define MAX_VM_ID 0x40
48#define MAX_VCPU_ID 0x40
49
50struct hax_vm
51{
52    hax_fd fd;
53    int id;
54    struct hax_vcpu_state *vcpus[HAX_MAX_VCPU];
55};
56
57/* Functions exported to host specific mode */
58hax_fd hax_vcpu_get_fd(CPUState *env);
59int valid_hax_tunnel_size(uint16_t size);
60
61/* Host specific functions */
62int hax_mod_version(struct hax_state *hax, struct hax_module_version *version);
63int hax_inject_interrupt(CPUState *env, int vector);
64struct hax_vm *hax_vm_create(struct hax_state *hax);
65int hax_vcpu_run(struct hax_vcpu_state *vcpu);
66int hax_vcpu_create(int id);
67int hax_sync_vcpu_state(CPUState *env, struct vcpu_state_t *state, int set);
68int hax_sync_msr(CPUState *env, struct hax_msr_data *msrs, int set);
69int hax_sync_fpu(CPUState *env, struct fx_layout *fl, int set);
70int hax_vm_destroy(struct hax_vm *vm);
71int hax_capability(struct hax_state *hax, struct hax_capabilityinfo *cap);
72int hax_notify_qemu_version(hax_fd vm_fd, struct hax_qemu_version *qversion);
73
74/* Common host function */
75int hax_host_create_vm(struct hax_state *hax, int *vm_id);
76hax_fd hax_host_open_vm(struct hax_state *hax, int vm_id);
77int hax_host_create_vcpu(hax_fd vm_fd, int vcpuid);
78hax_fd hax_host_open_vcpu(int vmid, int vcpuid);
79int hax_host_setup_vcpu_channel(struct hax_vcpu_state *vcpu);
80hax_fd hax_mod_open(void);
81
82
83#ifdef CONFIG_DARWIN
84#include "target-i386/hax-darwin.h"
85#endif
86
87#ifdef CONFIG_WIN32
88#include "target-i386/hax-windows.h"
89#endif
90
91#include "target-i386/hax-interface.h"
92
93#endif
94