Jes Sorensen | 625efab | 2007-10-22 11:03:28 +1000 | [diff] [blame] | 1 | #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 */ |
| 24 | extern unsigned long default_idt_entries[]; |
| 25 | |
| 26 | struct lguest_regs |
| 27 | { |
| 28 | /* Manually saved part. */ |
Jes Sorensen | 4614a3a | 2007-10-22 11:03:29 +1000 | [diff] [blame] | 29 | unsigned long eax, ebx, ecx, edx; |
Jes Sorensen | 625efab | 2007-10-22 11:03:28 +1000 | [diff] [blame] | 30 | unsigned long esi, edi, ebp; |
| 31 | unsigned long gs; |
Jes Sorensen | 625efab | 2007-10-22 11:03:28 +1000 | [diff] [blame] | 32 | unsigned long fs, ds, es; |
| 33 | unsigned long trapnum, errcode; |
| 34 | /* Trap pushed part */ |
| 35 | unsigned long eip; |
| 36 | unsigned long cs; |
| 37 | unsigned long eflags; |
| 38 | unsigned long esp; |
| 39 | unsigned long ss; |
| 40 | }; |
| 41 | |
| 42 | /* This is a guest-specific page (mapped ro) into the guest. */ |
| 43 | struct lguest_ro_state |
| 44 | { |
| 45 | /* Host information we need to restore when we switch back. */ |
| 46 | u32 host_cr3; |
| 47 | struct Xgt_desc_struct host_idt_desc; |
| 48 | struct Xgt_desc_struct host_gdt_desc; |
| 49 | u32 host_sp; |
| 50 | |
| 51 | /* Fields which are used when guest is running. */ |
| 52 | struct Xgt_desc_struct guest_idt_desc; |
| 53 | struct Xgt_desc_struct guest_gdt_desc; |
| 54 | struct i386_hw_tss guest_tss; |
| 55 | struct desc_struct guest_idt[IDT_ENTRIES]; |
| 56 | struct desc_struct guest_gdt[GDT_ENTRIES]; |
| 57 | }; |
| 58 | |
| 59 | struct lguest_arch |
| 60 | { |
| 61 | /* The GDT entries copied into lguest_ro_state when running. */ |
| 62 | struct desc_struct gdt[GDT_ENTRIES]; |
| 63 | |
| 64 | /* The IDT entries: some copied into lguest_ro_state when running. */ |
| 65 | struct desc_struct idt[IDT_ENTRIES]; |
| 66 | |
| 67 | /* The address of the last guest-visible pagefault (ie. cr2). */ |
| 68 | unsigned long last_pagefault; |
| 69 | }; |
| 70 | |
| 71 | static inline void lguest_set_ts(void) |
| 72 | { |
| 73 | u32 cr0; |
| 74 | |
| 75 | cr0 = read_cr0(); |
| 76 | if (!(cr0 & 8)) |
| 77 | write_cr0(cr0|8); |
| 78 | } |
| 79 | |
| 80 | /* Full 4G segment descriptors, suitable for CS and DS. */ |
| 81 | #define FULL_EXEC_SEGMENT ((struct desc_struct){0x0000ffff, 0x00cf9b00}) |
| 82 | #define FULL_SEGMENT ((struct desc_struct){0x0000ffff, 0x00cf9300}) |
| 83 | |
| 84 | #endif /* __ASSEMBLY__ */ |
| 85 | |
| 86 | #endif |