lguest.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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 for ease of mapping into the guest (one PTE page). */
  16. #define SWITCHER_ADDR 0xFFC00000
  17. /* Found in switcher.S */
  18. extern unsigned long default_idt_entries[];
  19. /* Declarations for definitions in lguest_guest.S */
  20. extern char lguest_noirq_start[], lguest_noirq_end[];
  21. extern const char lgstart_cli[], lgend_cli[];
  22. extern const char lgstart_sti[], lgend_sti[];
  23. extern const char lgstart_popf[], lgend_popf[];
  24. extern const char lgstart_pushf[], lgend_pushf[];
  25. extern const char lgstart_iret[], lgend_iret[];
  26. extern void lguest_iret(void);
  27. extern void lguest_init(void);
  28. struct lguest_regs {
  29. /* Manually saved part. */
  30. unsigned long eax, ebx, ecx, edx;
  31. unsigned long esi, edi, ebp;
  32. unsigned long gs;
  33. unsigned long fs, ds, es;
  34. unsigned long trapnum, errcode;
  35. /* Trap pushed part */
  36. unsigned long eip;
  37. unsigned long cs;
  38. unsigned long eflags;
  39. unsigned long esp;
  40. unsigned long ss;
  41. };
  42. /* This is a guest-specific page (mapped ro) into the guest. */
  43. struct lguest_ro_state {
  44. /* Host information we need to restore when we switch back. */
  45. u32 host_cr3;
  46. struct desc_ptr host_idt_desc;
  47. struct desc_ptr host_gdt_desc;
  48. u32 host_sp;
  49. /* Fields which are used when guest is running. */
  50. struct desc_ptr guest_idt_desc;
  51. struct desc_ptr guest_gdt_desc;
  52. struct x86_hw_tss guest_tss;
  53. struct desc_struct guest_idt[IDT_ENTRIES];
  54. struct desc_struct guest_gdt[GDT_ENTRIES];
  55. };
  56. struct lg_cpu_arch {
  57. /* The GDT entries copied into lguest_ro_state when running. */
  58. struct desc_struct gdt[GDT_ENTRIES];
  59. /* The IDT entries: some copied into lguest_ro_state when running. */
  60. struct desc_struct idt[IDT_ENTRIES];
  61. /* The address of the last guest-visible pagefault (ie. cr2). */
  62. unsigned long last_pagefault;
  63. };
  64. static inline void lguest_set_ts(void)
  65. {
  66. u32 cr0;
  67. cr0 = read_cr0();
  68. if (!(cr0 & 8))
  69. write_cr0(cr0 | 8);
  70. }
  71. /* Full 4G segment descriptors, suitable for CS and DS. */
  72. #define FULL_EXEC_SEGMENT ((struct desc_struct){ { {0x0000ffff, 0x00cf9b00} } })
  73. #define FULL_SEGMENT ((struct desc_struct){ { {0x0000ffff, 0x00cf9300} } })
  74. #endif /* __ASSEMBLY__ */
  75. #endif /* _ASM_X86_LGUEST_H */