lguest.h 2.7 KB
Newer Older
H
H. Peter Anvin 已提交
1 2
#ifndef _ASM_X86_LGUEST_H
#define _ASM_X86_LGUEST_H
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17

#define GDT_ENTRY_LGUEST_CS	10
#define GDT_ENTRY_LGUEST_DS	11
#define LGUEST_CS		(GDT_ENTRY_LGUEST_CS * 8)
#define LGUEST_DS		(GDT_ENTRY_LGUEST_DS * 8)

#ifndef __ASSEMBLY__
#include <asm/desc.h>

#define GUEST_PL 1

/* Every guest maps the core switcher code. */
#define SHARED_SWITCHER_PAGES \
	DIV_ROUND_UP(end_switcher_text - start_switcher_text, PAGE_SIZE)
/* Pages for switcher itself, then two pages per cpu */
18
#define TOTAL_SWITCHER_PAGES (SHARED_SWITCHER_PAGES + 2 * nr_cpu_ids)
19

M
Matias Zabaljauregui 已提交
20 21 22 23 24
/* We map at -4M (-2M when PAE is activated) for ease of mapping
 * into the guest (one PTE page). */
#ifdef CONFIG_X86_PAE
#define SWITCHER_ADDR 0xFFE00000
#else
25
#define SWITCHER_ADDR 0xFFC00000
M
Matias Zabaljauregui 已提交
26
#endif
27 28 29 30

/* Found in switcher.S */
extern unsigned long default_idt_entries[];

31 32 33 34 35 36 37 38 39 40 41
/* Declarations for definitions in lguest_guest.S */
extern char lguest_noirq_start[], lguest_noirq_end[];
extern const char lgstart_cli[], lgend_cli[];
extern const char lgstart_sti[], lgend_sti[];
extern const char lgstart_popf[], lgend_popf[];
extern const char lgstart_pushf[], lgend_pushf[];
extern const char lgstart_iret[], lgend_iret[];

extern void lguest_iret(void);
extern void lguest_init(void);

42
struct lguest_regs {
43
	/* Manually saved part. */
44
	unsigned long eax, ebx, ecx, edx;
45 46 47 48 49 50 51 52 53 54 55 56 57
	unsigned long esi, edi, ebp;
	unsigned long gs;
	unsigned long fs, ds, es;
	unsigned long trapnum, errcode;
	/* Trap pushed part */
	unsigned long eip;
	unsigned long cs;
	unsigned long eflags;
	unsigned long esp;
	unsigned long ss;
};

/* This is a guest-specific page (mapped ro) into the guest. */
58
struct lguest_ro_state {
59 60
	/* Host information we need to restore when we switch back. */
	u32 host_cr3;
61 62
	struct desc_ptr host_idt_desc;
	struct desc_ptr host_gdt_desc;
63 64 65
	u32 host_sp;

	/* Fields which are used when guest is running. */
66 67
	struct desc_ptr guest_idt_desc;
	struct desc_ptr guest_gdt_desc;
68
	struct x86_hw_tss guest_tss;
69 70 71 72
	struct desc_struct guest_idt[IDT_ENTRIES];
	struct desc_struct guest_gdt[GDT_ENTRIES];
};

73
struct lg_cpu_arch {
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
	/* The GDT entries copied into lguest_ro_state when running. */
	struct desc_struct gdt[GDT_ENTRIES];

	/* The IDT entries: some copied into lguest_ro_state when running. */
	struct desc_struct idt[IDT_ENTRIES];

	/* The address of the last guest-visible pagefault (ie. cr2). */
	unsigned long last_pagefault;
};

static inline void lguest_set_ts(void)
{
	u32 cr0;

	cr0 = read_cr0();
	if (!(cr0 & 8))
90
		write_cr0(cr0 | 8);
91 92 93
}

/* Full 4G segment descriptors, suitable for CS and DS. */
94 95
#define FULL_EXEC_SEGMENT ((struct desc_struct){ { {0x0000ffff, 0x00cf9b00} } })
#define FULL_SEGMENT ((struct desc_struct){ { {0x0000ffff, 0x00cf9300} } })
96 97 98

#endif /* __ASSEMBLY__ */

H
H. Peter Anvin 已提交
99
#endif /* _ASM_X86_LGUEST_H */