lguest.h 2.4 KB

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