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 | |
Rusty Russell | 93a2cdf | 2013-04-22 14:10:38 +0930 | [diff] [blame] | 14 | /* Page for Switcher text itself, then two pages per cpu */ |
| 15 | #define TOTAL_SWITCHER_PAGES (1 + 2 * nr_cpu_ids) |
Jes Sorensen | 625efab | 2007-10-22 11:03:28 +1000 | [diff] [blame] | 16 | |
Rusty Russell | 406a590b | 2013-04-22 14:10:37 +0930 | [diff] [blame] | 17 | /* Where we map the Switcher, in both Host and Guest. */ |
| 18 | extern unsigned long switcher_addr; |
Jes Sorensen | 625efab | 2007-10-22 11:03:28 +1000 | [diff] [blame] | 19 | |
| 20 | /* Found in switcher.S */ |
| 21 | extern unsigned long default_idt_entries[]; |
| 22 | |
Rusty Russell | 2f921b5 | 2015-03-24 11:51:39 +1030 | [diff] [blame] | 23 | /* Declarations for definitions in arch/x86/lguest/head_32.S */ |
| 24 | extern char lguest_noirq_iret[]; |
Harvey Harrison | cbc3497 | 2008-02-13 13:14:35 -0800 | [diff] [blame] | 25 | extern const char lgstart_cli[], lgend_cli[]; |
Harvey Harrison | cbc3497 | 2008-02-13 13:14:35 -0800 | [diff] [blame] | 26 | extern const char lgstart_pushf[], lgend_pushf[]; |
Harvey Harrison | cbc3497 | 2008-02-13 13:14:35 -0800 | [diff] [blame] | 27 | |
| 28 | extern void lguest_iret(void); |
| 29 | extern void lguest_init(void); |
| 30 | |
Joe Perches | fb444c7 | 2008-03-23 01:02:37 -0700 | [diff] [blame] | 31 | struct lguest_regs { |
Jes Sorensen | 625efab | 2007-10-22 11:03:28 +1000 | [diff] [blame] | 32 | /* Manually saved part. */ |
Jes Sorensen | 4614a3a | 2007-10-22 11:03:29 +1000 | [diff] [blame] | 33 | unsigned long eax, ebx, ecx, edx; |
Jes Sorensen | 625efab | 2007-10-22 11:03:28 +1000 | [diff] [blame] | 34 | unsigned long esi, edi, ebp; |
| 35 | unsigned long gs; |
Jes Sorensen | 625efab | 2007-10-22 11:03:28 +1000 | [diff] [blame] | 36 | unsigned long fs, ds, es; |
| 37 | unsigned long trapnum, errcode; |
| 38 | /* Trap pushed part */ |
| 39 | unsigned long eip; |
| 40 | unsigned long cs; |
| 41 | unsigned long eflags; |
| 42 | unsigned long esp; |
| 43 | unsigned long ss; |
| 44 | }; |
| 45 | |
| 46 | /* This is a guest-specific page (mapped ro) into the guest. */ |
Joe Perches | fb444c7 | 2008-03-23 01:02:37 -0700 | [diff] [blame] | 47 | struct lguest_ro_state { |
Jes Sorensen | 625efab | 2007-10-22 11:03:28 +1000 | [diff] [blame] | 48 | /* Host information we need to restore when we switch back. */ |
| 49 | u32 host_cr3; |
Glauber de Oliveira Costa | 6b68f01 | 2008-01-30 13:31:12 +0100 | [diff] [blame] | 50 | struct desc_ptr host_idt_desc; |
| 51 | struct desc_ptr host_gdt_desc; |
Jes Sorensen | 625efab | 2007-10-22 11:03:28 +1000 | [diff] [blame] | 52 | u32 host_sp; |
| 53 | |
| 54 | /* Fields which are used when guest is running. */ |
Glauber de Oliveira Costa | 6b68f01 | 2008-01-30 13:31:12 +0100 | [diff] [blame] | 55 | struct desc_ptr guest_idt_desc; |
| 56 | struct desc_ptr guest_gdt_desc; |
Glauber de Oliveira Costa | ca241c7 | 2008-01-30 13:31:31 +0100 | [diff] [blame] | 57 | struct x86_hw_tss guest_tss; |
Jes Sorensen | 625efab | 2007-10-22 11:03:28 +1000 | [diff] [blame] | 58 | struct desc_struct guest_idt[IDT_ENTRIES]; |
| 59 | struct desc_struct guest_gdt[GDT_ENTRIES]; |
| 60 | }; |
| 61 | |
Joe Perches | fb444c7 | 2008-03-23 01:02:37 -0700 | [diff] [blame] | 62 | struct lg_cpu_arch { |
Jes Sorensen | 625efab | 2007-10-22 11:03:28 +1000 | [diff] [blame] | 63 | /* The GDT entries copied into lguest_ro_state when running. */ |
| 64 | struct desc_struct gdt[GDT_ENTRIES]; |
| 65 | |
| 66 | /* The IDT entries: some copied into lguest_ro_state when running. */ |
| 67 | struct desc_struct idt[IDT_ENTRIES]; |
| 68 | |
| 69 | /* The address of the last guest-visible pagefault (ie. cr2). */ |
| 70 | unsigned long last_pagefault; |
| 71 | }; |
| 72 | |
| 73 | static inline void lguest_set_ts(void) |
| 74 | { |
| 75 | u32 cr0; |
| 76 | |
| 77 | cr0 = read_cr0(); |
| 78 | if (!(cr0 & 8)) |
Joe Perches | fb444c7 | 2008-03-23 01:02:37 -0700 | [diff] [blame] | 79 | write_cr0(cr0 | 8); |
Jes Sorensen | 625efab | 2007-10-22 11:03:28 +1000 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | /* Full 4G segment descriptors, suitable for CS and DS. */ |
Akinobu Mita | 1e5de18 | 2009-07-19 00:12:20 +0900 | [diff] [blame] | 83 | #define FULL_EXEC_SEGMENT \ |
| 84 | ((struct desc_struct)GDT_ENTRY_INIT(0xc09b, 0, 0xfffff)) |
| 85 | #define FULL_SEGMENT ((struct desc_struct)GDT_ENTRY_INIT(0xc093, 0, 0xfffff)) |
Jes Sorensen | 625efab | 2007-10-22 11:03:28 +1000 | [diff] [blame] | 86 | |
| 87 | #endif /* __ASSEMBLY__ */ |
| 88 | |
H. Peter Anvin | 1965aae | 2008-10-22 22:26:29 -0700 | [diff] [blame] | 89 | #endif /* _ASM_X86_LGUEST_H */ |