blob: 9b17571e9bc35f3aaf68c4eb451ae4fa384578d7 [file] [log] [blame]
Jes Sorensen625efab2007-10-22 11:03:28 +10001#ifndef _X86_LGUEST_H
2#define _X86_LGUEST_H
3
4#define GDT_ENTRY_LGUEST_CS 10
5#define GDT_ENTRY_LGUEST_DS 11
6#define LGUEST_CS (GDT_ENTRY_LGUEST_CS * 8)
7#define LGUEST_DS (GDT_ENTRY_LGUEST_DS * 8)
8
9#ifndef __ASSEMBLY__
10#include <asm/desc.h>
11
12#define GUEST_PL 1
13
14/* Every guest maps the core switcher code. */
15#define SHARED_SWITCHER_PAGES \
16 DIV_ROUND_UP(end_switcher_text - start_switcher_text, PAGE_SIZE)
17/* Pages for switcher itself, then two pages per cpu */
18#define TOTAL_SWITCHER_PAGES (SHARED_SWITCHER_PAGES + 2 * NR_CPUS)
19
20/* We map at -4M for ease of mapping into the guest (one PTE page). */
21#define SWITCHER_ADDR 0xFFC00000
22
23/* Found in switcher.S */
24extern unsigned long default_idt_entries[];
25
Harvey Harrisoncbc34972008-02-13 13:14:35 -080026/* Declarations for definitions in lguest_guest.S */
27extern char lguest_noirq_start[], lguest_noirq_end[];
28extern const char lgstart_cli[], lgend_cli[];
29extern const char lgstart_sti[], lgend_sti[];
30extern const char lgstart_popf[], lgend_popf[];
31extern const char lgstart_pushf[], lgend_pushf[];
32extern const char lgstart_iret[], lgend_iret[];
33
34extern void lguest_iret(void);
35extern void lguest_init(void);
36
Jes Sorensen625efab2007-10-22 11:03:28 +100037struct lguest_regs
38{
39 /* Manually saved part. */
Jes Sorensen4614a3a2007-10-22 11:03:29 +100040 unsigned long eax, ebx, ecx, edx;
Jes Sorensen625efab2007-10-22 11:03:28 +100041 unsigned long esi, edi, ebp;
42 unsigned long gs;
Jes Sorensen625efab2007-10-22 11:03:28 +100043 unsigned long fs, ds, es;
44 unsigned long trapnum, errcode;
45 /* Trap pushed part */
46 unsigned long eip;
47 unsigned long cs;
48 unsigned long eflags;
49 unsigned long esp;
50 unsigned long ss;
51};
52
53/* This is a guest-specific page (mapped ro) into the guest. */
54struct lguest_ro_state
55{
56 /* Host information we need to restore when we switch back. */
57 u32 host_cr3;
Glauber de Oliveira Costa6b68f012008-01-30 13:31:12 +010058 struct desc_ptr host_idt_desc;
59 struct desc_ptr host_gdt_desc;
Jes Sorensen625efab2007-10-22 11:03:28 +100060 u32 host_sp;
61
62 /* Fields which are used when guest is running. */
Glauber de Oliveira Costa6b68f012008-01-30 13:31:12 +010063 struct desc_ptr guest_idt_desc;
64 struct desc_ptr guest_gdt_desc;
Glauber de Oliveira Costaca241c72008-01-30 13:31:31 +010065 struct x86_hw_tss guest_tss;
Jes Sorensen625efab2007-10-22 11:03:28 +100066 struct desc_struct guest_idt[IDT_ENTRIES];
67 struct desc_struct guest_gdt[GDT_ENTRIES];
68};
69
Glauber de Oliveira Costafc708b32008-01-07 11:05:33 -020070struct lg_cpu_arch
Jes Sorensen625efab2007-10-22 11:03:28 +100071{
72 /* The GDT entries copied into lguest_ro_state when running. */
73 struct desc_struct gdt[GDT_ENTRIES];
74
75 /* The IDT entries: some copied into lguest_ro_state when running. */
76 struct desc_struct idt[IDT_ENTRIES];
77
78 /* The address of the last guest-visible pagefault (ie. cr2). */
79 unsigned long last_pagefault;
80};
81
82static inline void lguest_set_ts(void)
83{
84 u32 cr0;
85
86 cr0 = read_cr0();
87 if (!(cr0 & 8))
88 write_cr0(cr0|8);
89}
90
91/* Full 4G segment descriptors, suitable for CS and DS. */
Glauber de Oliveira Costa6842ef02008-01-30 13:31:11 +010092#define FULL_EXEC_SEGMENT ((struct desc_struct){ { {0x0000ffff, 0x00cf9b00} } })
93#define FULL_SEGMENT ((struct desc_struct){ { {0x0000ffff, 0x00cf9300} } })
Jes Sorensen625efab2007-10-22 11:03:28 +100094
95#endif /* __ASSEMBLY__ */
96
97#endif