lguest.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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 eax, ebx, ecx, edx;
  23. unsigned long esi, edi, ebp;
  24. unsigned long gs;
  25. unsigned long fs, ds, es;
  26. unsigned long trapnum, errcode;
  27. /* Trap pushed part */
  28. unsigned long eip;
  29. unsigned long cs;
  30. unsigned long eflags;
  31. unsigned long esp;
  32. unsigned long ss;
  33. };
  34. /* This is a guest-specific page (mapped ro) into the guest. */
  35. struct lguest_ro_state
  36. {
  37. /* Host information we need to restore when we switch back. */
  38. u32 host_cr3;
  39. struct Xgt_desc_struct host_idt_desc;
  40. struct Xgt_desc_struct host_gdt_desc;
  41. u32 host_sp;
  42. /* Fields which are used when guest is running. */
  43. struct Xgt_desc_struct guest_idt_desc;
  44. struct Xgt_desc_struct guest_gdt_desc;
  45. struct i386_hw_tss guest_tss;
  46. struct desc_struct guest_idt[IDT_ENTRIES];
  47. struct desc_struct guest_gdt[GDT_ENTRIES];
  48. };
  49. struct lguest_arch
  50. {
  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 ((struct desc_struct){0x0000ffff, 0x00cf9b00})
  67. #define FULL_SEGMENT ((struct desc_struct){0x0000ffff, 0x00cf9300})
  68. #endif /* __ASSEMBLY__ */
  69. #endif