lguest.h 2.6 KB

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