lguest.h 2.3 KB

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