lguest.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. #ifndef _ASM_X86_LGUEST_H
  2. #define _ASM_X86_LGUEST_H
  3. #define GDT_ENTRY_LGUEST_CS 10
  4. #define GDT_ENTRY_LGUEST_DS 11
  5. #define LGUEST_CS (GDT_ENTRY_LGUEST_CS * 8)
  6. #define LGUEST_DS (GDT_ENTRY_LGUEST_DS * 8)
  7. #ifndef __ASSEMBLY__
  8. #include <asm/desc.h>
  9. #define GUEST_PL 1
  10. /* Every guest maps the core switcher code. */
  11. #define SHARED_SWITCHER_PAGES \
  12. DIV_ROUND_UP(end_switcher_text - start_switcher_text, PAGE_SIZE)
  13. /* Pages for switcher itself, then two pages per cpu */
  14. #define TOTAL_SWITCHER_PAGES (SHARED_SWITCHER_PAGES + 2 * nr_cpu_ids)
  15. /* We map at -4M (-2M for PAE) for ease of mapping (one PTE page). */
  16. #ifdef CONFIG_X86_PAE
  17. #define SWITCHER_ADDR 0xFFE00000
  18. #else
  19. #define SWITCHER_ADDR 0xFFC00000
  20. #endif
  21. /* Found in switcher.S */
  22. extern unsigned long default_idt_entries[];
  23. /* Declarations for definitions in lguest_guest.S */
  24. extern char lguest_noirq_start[], lguest_noirq_end[];
  25. extern const char lgstart_cli[], lgend_cli[];
  26. extern const char lgstart_sti[], lgend_sti[];
  27. extern const char lgstart_popf[], lgend_popf[];
  28. extern const char lgstart_pushf[], lgend_pushf[];
  29. extern const char lgstart_iret[], lgend_iret[];
  30. extern void lguest_iret(void);
  31. extern void lguest_init(void);
  32. struct lguest_regs {
  33. /* Manually saved part. */
  34. unsigned long eax, ebx, ecx, edx;
  35. unsigned long esi, edi, ebp;
  36. unsigned long gs;
  37. unsigned long fs, ds, es;
  38. unsigned long trapnum, errcode;
  39. /* Trap pushed part */
  40. unsigned long eip;
  41. unsigned long cs;
  42. unsigned long eflags;
  43. unsigned long esp;
  44. unsigned long ss;
  45. };
  46. /* This is a guest-specific page (mapped ro) into the guest. */
  47. struct lguest_ro_state {
  48. /* Host information we need to restore when we switch back. */
  49. u32 host_cr3;
  50. struct desc_ptr host_idt_desc;
  51. struct desc_ptr host_gdt_desc;
  52. u32 host_sp;
  53. /* Fields which are used when guest is running. */
  54. struct desc_ptr guest_idt_desc;
  55. struct desc_ptr guest_gdt_desc;
  56. struct x86_hw_tss guest_tss;
  57. struct desc_struct guest_idt[IDT_ENTRIES];
  58. struct desc_struct guest_gdt[GDT_ENTRIES];
  59. };
  60. struct lg_cpu_arch {
  61. /* The GDT entries copied into lguest_ro_state when running. */
  62. struct desc_struct gdt[GDT_ENTRIES];
  63. /* The IDT entries: some copied into lguest_ro_state when running. */
  64. struct desc_struct idt[IDT_ENTRIES];
  65. /* The address of the last guest-visible pagefault (ie. cr2). */
  66. unsigned long last_pagefault;
  67. };
  68. static inline void lguest_set_ts(void)
  69. {
  70. u32 cr0;
  71. cr0 = read_cr0();
  72. if (!(cr0 & 8))
  73. write_cr0(cr0 | 8);
  74. }
  75. /* Full 4G segment descriptors, suitable for CS and DS. */
  76. #define FULL_EXEC_SEGMENT \
  77. ((struct desc_struct)GDT_ENTRY_INIT(0xc09b, 0, 0xfffff))
  78. #define FULL_SEGMENT ((struct desc_struct)GDT_ENTRY_INIT(0xc093, 0, 0xfffff))
  79. #endif /* __ASSEMBLY__ */
  80. #endif /* _ASM_X86_LGUEST_H */