blob: 313389cd50d2a3dfe1285152b2d43645e40f7636 [file] [log] [blame]
H. Peter Anvin1965aae2008-10-22 22:26:29 -07001#ifndef _ASM_X86_LGUEST_H
2#define _ASM_X86_LGUEST_H
Jes Sorensen625efab2007-10-22 11:03:28 +10003
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 */
Mike Travis96289372008-12-31 18:08:46 -080018#define TOTAL_SWITCHER_PAGES (SHARED_SWITCHER_PAGES + 2 * nr_cpu_ids)
Jes Sorensen625efab2007-10-22 11:03:28 +100019
Matias Zabaljaureguiacdd0b62009-06-12 22:27:07 -060020/* We map at -4M (-2M when PAE is activated) for ease of mapping
21 * into the guest (one PTE page). */
22#ifdef CONFIG_X86_PAE
23#define SWITCHER_ADDR 0xFFE00000
24#else
Jes Sorensen625efab2007-10-22 11:03:28 +100025#define SWITCHER_ADDR 0xFFC00000
Matias Zabaljaureguiacdd0b62009-06-12 22:27:07 -060026#endif
Jes Sorensen625efab2007-10-22 11:03:28 +100027
28/* Found in switcher.S */
29extern unsigned long default_idt_entries[];
30
Harvey Harrisoncbc34972008-02-13 13:14:35 -080031/* Declarations for definitions in lguest_guest.S */
32extern char lguest_noirq_start[], lguest_noirq_end[];
33extern const char lgstart_cli[], lgend_cli[];
34extern const char lgstart_sti[], lgend_sti[];
35extern const char lgstart_popf[], lgend_popf[];
36extern const char lgstart_pushf[], lgend_pushf[];
37extern const char lgstart_iret[], lgend_iret[];
38
39extern void lguest_iret(void);
40extern void lguest_init(void);
41
Joe Perchesfb444c72008-03-23 01:02:37 -070042struct lguest_regs {
Jes Sorensen625efab2007-10-22 11:03:28 +100043 /* Manually saved part. */
Jes Sorensen4614a3a2007-10-22 11:03:29 +100044 unsigned long eax, ebx, ecx, edx;
Jes Sorensen625efab2007-10-22 11:03:28 +100045 unsigned long esi, edi, ebp;
46 unsigned long gs;
Jes Sorensen625efab2007-10-22 11:03:28 +100047 unsigned long fs, ds, es;
48 unsigned long trapnum, errcode;
49 /* Trap pushed part */
50 unsigned long eip;
51 unsigned long cs;
52 unsigned long eflags;
53 unsigned long esp;
54 unsigned long ss;
55};
56
57/* This is a guest-specific page (mapped ro) into the guest. */
Joe Perchesfb444c72008-03-23 01:02:37 -070058struct lguest_ro_state {
Jes Sorensen625efab2007-10-22 11:03:28 +100059 /* Host information we need to restore when we switch back. */
60 u32 host_cr3;
Glauber de Oliveira Costa6b68f012008-01-30 13:31:12 +010061 struct desc_ptr host_idt_desc;
62 struct desc_ptr host_gdt_desc;
Jes Sorensen625efab2007-10-22 11:03:28 +100063 u32 host_sp;
64
65 /* Fields which are used when guest is running. */
Glauber de Oliveira Costa6b68f012008-01-30 13:31:12 +010066 struct desc_ptr guest_idt_desc;
67 struct desc_ptr guest_gdt_desc;
Glauber de Oliveira Costaca241c72008-01-30 13:31:31 +010068 struct x86_hw_tss guest_tss;
Jes Sorensen625efab2007-10-22 11:03:28 +100069 struct desc_struct guest_idt[IDT_ENTRIES];
70 struct desc_struct guest_gdt[GDT_ENTRIES];
71};
72
Joe Perchesfb444c72008-03-23 01:02:37 -070073struct lg_cpu_arch {
Jes Sorensen625efab2007-10-22 11:03:28 +100074 /* The GDT entries copied into lguest_ro_state when running. */
75 struct desc_struct gdt[GDT_ENTRIES];
76
77 /* The IDT entries: some copied into lguest_ro_state when running. */
78 struct desc_struct idt[IDT_ENTRIES];
79
80 /* The address of the last guest-visible pagefault (ie. cr2). */
81 unsigned long last_pagefault;
82};
83
84static inline void lguest_set_ts(void)
85{
86 u32 cr0;
87
88 cr0 = read_cr0();
89 if (!(cr0 & 8))
Joe Perchesfb444c72008-03-23 01:02:37 -070090 write_cr0(cr0 | 8);
Jes Sorensen625efab2007-10-22 11:03:28 +100091}
92
93/* Full 4G segment descriptors, suitable for CS and DS. */
Glauber de Oliveira Costa6842ef02008-01-30 13:31:11 +010094#define FULL_EXEC_SEGMENT ((struct desc_struct){ { {0x0000ffff, 0x00cf9b00} } })
95#define FULL_SEGMENT ((struct desc_struct){ { {0x0000ffff, 0x00cf9300} } })
Jes Sorensen625efab2007-10-22 11:03:28 +100096
97#endif /* __ASSEMBLY__ */
98
H. Peter Anvin1965aae2008-10-22 22:26:29 -070099#endif /* _ASM_X86_LGUEST_H */