blob: 74edebd010aba1420052120c3c9de01fa8b51e46 [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
Rusty Russell93a2cdf2013-04-22 14:10:38 +093014/* Page for Switcher text itself, then two pages per cpu */
15#define TOTAL_SWITCHER_PAGES (1 + 2 * nr_cpu_ids)
Jes Sorensen625efab2007-10-22 11:03:28 +100016
Rusty Russell2e04ef72009-07-30 16:03:45 -060017/* We map at -4M (-2M for PAE) for ease of mapping (one PTE page). */
Matias Zabaljaureguiacdd0b62009-06-12 22:27:07 -060018#ifdef CONFIG_X86_PAE
19#define SWITCHER_ADDR 0xFFE00000
20#else
Jes Sorensen625efab2007-10-22 11:03:28 +100021#define SWITCHER_ADDR 0xFFC00000
Matias Zabaljaureguiacdd0b62009-06-12 22:27:07 -060022#endif
Rusty Russell406a590b2013-04-22 14:10:37 +093023/* Where we map the Switcher, in both Host and Guest. */
24extern unsigned long switcher_addr;
Jes Sorensen625efab2007-10-22 11:03:28 +100025
26/* Found in switcher.S */
27extern unsigned long default_idt_entries[];
28
Harvey Harrisoncbc34972008-02-13 13:14:35 -080029/* Declarations for definitions in lguest_guest.S */
30extern char lguest_noirq_start[], lguest_noirq_end[];
31extern const char lgstart_cli[], lgend_cli[];
32extern const char lgstart_sti[], lgend_sti[];
33extern const char lgstart_popf[], lgend_popf[];
34extern const char lgstart_pushf[], lgend_pushf[];
35extern const char lgstart_iret[], lgend_iret[];
36
37extern void lguest_iret(void);
38extern void lguest_init(void);
39
Joe Perchesfb444c72008-03-23 01:02:37 -070040struct lguest_regs {
Jes Sorensen625efab2007-10-22 11:03:28 +100041 /* Manually saved part. */
Jes Sorensen4614a3a2007-10-22 11:03:29 +100042 unsigned long eax, ebx, ecx, edx;
Jes Sorensen625efab2007-10-22 11:03:28 +100043 unsigned long esi, edi, ebp;
44 unsigned long gs;
Jes Sorensen625efab2007-10-22 11:03:28 +100045 unsigned long fs, ds, es;
46 unsigned long trapnum, errcode;
47 /* Trap pushed part */
48 unsigned long eip;
49 unsigned long cs;
50 unsigned long eflags;
51 unsigned long esp;
52 unsigned long ss;
53};
54
55/* This is a guest-specific page (mapped ro) into the guest. */
Joe Perchesfb444c72008-03-23 01:02:37 -070056struct lguest_ro_state {
Jes Sorensen625efab2007-10-22 11:03:28 +100057 /* Host information we need to restore when we switch back. */
58 u32 host_cr3;
Glauber de Oliveira Costa6b68f012008-01-30 13:31:12 +010059 struct desc_ptr host_idt_desc;
60 struct desc_ptr host_gdt_desc;
Jes Sorensen625efab2007-10-22 11:03:28 +100061 u32 host_sp;
62
63 /* Fields which are used when guest is running. */
Glauber de Oliveira Costa6b68f012008-01-30 13:31:12 +010064 struct desc_ptr guest_idt_desc;
65 struct desc_ptr guest_gdt_desc;
Glauber de Oliveira Costaca241c72008-01-30 13:31:31 +010066 struct x86_hw_tss guest_tss;
Jes Sorensen625efab2007-10-22 11:03:28 +100067 struct desc_struct guest_idt[IDT_ENTRIES];
68 struct desc_struct guest_gdt[GDT_ENTRIES];
69};
70
Joe Perchesfb444c72008-03-23 01:02:37 -070071struct lg_cpu_arch {
Jes Sorensen625efab2007-10-22 11:03:28 +100072 /* 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))
Joe Perchesfb444c72008-03-23 01:02:37 -070088 write_cr0(cr0 | 8);
Jes Sorensen625efab2007-10-22 11:03:28 +100089}
90
91/* Full 4G segment descriptors, suitable for CS and DS. */
Akinobu Mita1e5de182009-07-19 00:12:20 +090092#define FULL_EXEC_SEGMENT \
93 ((struct desc_struct)GDT_ENTRY_INIT(0xc09b, 0, 0xfffff))
94#define FULL_SEGMENT ((struct desc_struct)GDT_ENTRY_INIT(0xc093, 0, 0xfffff))
Jes Sorensen625efab2007-10-22 11:03:28 +100095
96#endif /* __ASSEMBLY__ */
97
H. Peter Anvin1965aae2008-10-22 22:26:29 -070098#endif /* _ASM_X86_LGUEST_H */