H. Peter Anvin | 1965aae | 2008-10-22 22:26:29 -0700 | [diff] [blame] | 1 | #ifndef _ASM_X86_LGUEST_H |
| 2 | #define _ASM_X86_LGUEST_H |
Jes Sorensen | 625efab | 2007-10-22 11:03:28 +1000 | [diff] [blame] | 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 */ |
Mike Travis | 9628937 | 2008-12-31 18:08:46 -0800 | [diff] [blame] | 18 | #define TOTAL_SWITCHER_PAGES (SHARED_SWITCHER_PAGES + 2 * nr_cpu_ids) |
Jes Sorensen | 625efab | 2007-10-22 11:03:28 +1000 | [diff] [blame] | 19 | |
Rusty Russell | 2e04ef7 | 2009-07-30 16:03:45 -0600 | [diff] [blame] | 20 | /* We map at -4M (-2M for PAE) for ease of mapping (one PTE page). */ |
Matias Zabaljauregui | acdd0b6 | 2009-06-12 22:27:07 -0600 | [diff] [blame] | 21 | #ifdef CONFIG_X86_PAE |
| 22 | #define SWITCHER_ADDR 0xFFE00000 |
| 23 | #else |
Jes Sorensen | 625efab | 2007-10-22 11:03:28 +1000 | [diff] [blame] | 24 | #define SWITCHER_ADDR 0xFFC00000 |
Matias Zabaljauregui | acdd0b6 | 2009-06-12 22:27:07 -0600 | [diff] [blame] | 25 | #endif |
Jes Sorensen | 625efab | 2007-10-22 11:03:28 +1000 | [diff] [blame] | 26 | |
| 27 | /* Found in switcher.S */ |
| 28 | extern unsigned long default_idt_entries[]; |
| 29 | |
Harvey Harrison | cbc3497 | 2008-02-13 13:14:35 -0800 | [diff] [blame] | 30 | /* Declarations for definitions in lguest_guest.S */ |
| 31 | extern char lguest_noirq_start[], lguest_noirq_end[]; |
| 32 | extern const char lgstart_cli[], lgend_cli[]; |
| 33 | extern const char lgstart_sti[], lgend_sti[]; |
| 34 | extern const char lgstart_popf[], lgend_popf[]; |
| 35 | extern const char lgstart_pushf[], lgend_pushf[]; |
| 36 | extern const char lgstart_iret[], lgend_iret[]; |
| 37 | |
| 38 | extern void lguest_iret(void); |
| 39 | extern void lguest_init(void); |
| 40 | |
Joe Perches | fb444c7 | 2008-03-23 01:02:37 -0700 | [diff] [blame] | 41 | struct lguest_regs { |
Jes Sorensen | 625efab | 2007-10-22 11:03:28 +1000 | [diff] [blame] | 42 | /* Manually saved part. */ |
Jes Sorensen | 4614a3a | 2007-10-22 11:03:29 +1000 | [diff] [blame] | 43 | unsigned long eax, ebx, ecx, edx; |
Jes Sorensen | 625efab | 2007-10-22 11:03:28 +1000 | [diff] [blame] | 44 | unsigned long esi, edi, ebp; |
| 45 | unsigned long gs; |
Jes Sorensen | 625efab | 2007-10-22 11:03:28 +1000 | [diff] [blame] | 46 | unsigned long fs, ds, es; |
| 47 | unsigned long trapnum, errcode; |
| 48 | /* Trap pushed part */ |
| 49 | unsigned long eip; |
| 50 | unsigned long cs; |
| 51 | unsigned long eflags; |
| 52 | unsigned long esp; |
| 53 | unsigned long ss; |
| 54 | }; |
| 55 | |
| 56 | /* This is a guest-specific page (mapped ro) into the guest. */ |
Joe Perches | fb444c7 | 2008-03-23 01:02:37 -0700 | [diff] [blame] | 57 | struct lguest_ro_state { |
Jes Sorensen | 625efab | 2007-10-22 11:03:28 +1000 | [diff] [blame] | 58 | /* Host information we need to restore when we switch back. */ |
| 59 | u32 host_cr3; |
Glauber de Oliveira Costa | 6b68f01 | 2008-01-30 13:31:12 +0100 | [diff] [blame] | 60 | struct desc_ptr host_idt_desc; |
| 61 | struct desc_ptr host_gdt_desc; |
Jes Sorensen | 625efab | 2007-10-22 11:03:28 +1000 | [diff] [blame] | 62 | u32 host_sp; |
| 63 | |
| 64 | /* Fields which are used when guest is running. */ |
Glauber de Oliveira Costa | 6b68f01 | 2008-01-30 13:31:12 +0100 | [diff] [blame] | 65 | struct desc_ptr guest_idt_desc; |
| 66 | struct desc_ptr guest_gdt_desc; |
Glauber de Oliveira Costa | ca241c7 | 2008-01-30 13:31:31 +0100 | [diff] [blame] | 67 | struct x86_hw_tss guest_tss; |
Jes Sorensen | 625efab | 2007-10-22 11:03:28 +1000 | [diff] [blame] | 68 | struct desc_struct guest_idt[IDT_ENTRIES]; |
| 69 | struct desc_struct guest_gdt[GDT_ENTRIES]; |
| 70 | }; |
| 71 | |
Joe Perches | fb444c7 | 2008-03-23 01:02:37 -0700 | [diff] [blame] | 72 | struct lg_cpu_arch { |
Jes Sorensen | 625efab | 2007-10-22 11:03:28 +1000 | [diff] [blame] | 73 | /* The GDT entries copied into lguest_ro_state when running. */ |
| 74 | struct desc_struct gdt[GDT_ENTRIES]; |
| 75 | |
| 76 | /* The IDT entries: some copied into lguest_ro_state when running. */ |
| 77 | struct desc_struct idt[IDT_ENTRIES]; |
| 78 | |
| 79 | /* The address of the last guest-visible pagefault (ie. cr2). */ |
| 80 | unsigned long last_pagefault; |
| 81 | }; |
| 82 | |
| 83 | static inline void lguest_set_ts(void) |
| 84 | { |
| 85 | u32 cr0; |
| 86 | |
| 87 | cr0 = read_cr0(); |
| 88 | if (!(cr0 & 8)) |
Joe Perches | fb444c7 | 2008-03-23 01:02:37 -0700 | [diff] [blame] | 89 | write_cr0(cr0 | 8); |
Jes Sorensen | 625efab | 2007-10-22 11:03:28 +1000 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | /* Full 4G segment descriptors, suitable for CS and DS. */ |
Akinobu Mita | 1e5de18 | 2009-07-19 00:12:20 +0900 | [diff] [blame] | 93 | #define FULL_EXEC_SEGMENT \ |
| 94 | ((struct desc_struct)GDT_ENTRY_INIT(0xc09b, 0, 0xfffff)) |
| 95 | #define FULL_SEGMENT ((struct desc_struct)GDT_ENTRY_INIT(0xc093, 0, 0xfffff)) |
Jes Sorensen | 625efab | 2007-10-22 11:03:28 +1000 | [diff] [blame] | 96 | |
| 97 | #endif /* __ASSEMBLY__ */ |
| 98 | |
H. Peter Anvin | 1965aae | 2008-10-22 22:26:29 -0700 | [diff] [blame] | 99 | #endif /* _ASM_X86_LGUEST_H */ |