lguest.h 2.2 KB

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