kqemu.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /*
  2. * KQEMU header
  3. *
  4. * Copyright (c) 2004-2008 Fabrice Bellard
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a copy
  7. * of this software and associated documentation files (the "Software"), to deal
  8. * in the Software without restriction, including without limitation the rights
  9. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10. * copies of the Software, and to permit persons to whom the Software is
  11. * furnished to do so, subject to the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be included in
  14. * all copies or substantial portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  19. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  21. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  22. * THE SOFTWARE.
  23. */
  24. #ifndef KQEMU_H
  25. #define KQEMU_H
  26. #if defined(__i386__)
  27. #define KQEMU_PAD32(x) x
  28. #else
  29. #define KQEMU_PAD32(x)
  30. #endif
  31. #define KQEMU_VERSION 0x010400
  32. struct kqemu_segment_cache {
  33. uint16_t selector;
  34. uint16_t padding1;
  35. uint32_t flags;
  36. uint64_t base;
  37. uint32_t limit;
  38. uint32_t padding2;
  39. };
  40. struct kqemu_cpu_state {
  41. uint64_t regs[16];
  42. uint64_t eip;
  43. uint64_t eflags;
  44. struct kqemu_segment_cache segs[6]; /* selector values */
  45. struct kqemu_segment_cache ldt;
  46. struct kqemu_segment_cache tr;
  47. struct kqemu_segment_cache gdt; /* only base and limit are used */
  48. struct kqemu_segment_cache idt; /* only base and limit are used */
  49. uint64_t cr0;
  50. uint64_t cr2;
  51. uint64_t cr3;
  52. uint64_t cr4;
  53. uint64_t a20_mask;
  54. /* sysenter registers */
  55. uint64_t sysenter_cs;
  56. uint64_t sysenter_esp;
  57. uint64_t sysenter_eip;
  58. uint64_t efer;
  59. uint64_t star;
  60. uint64_t lstar;
  61. uint64_t cstar;
  62. uint64_t fmask;
  63. uint64_t kernelgsbase;
  64. uint64_t tsc_offset;
  65. uint64_t dr0;
  66. uint64_t dr1;
  67. uint64_t dr2;
  68. uint64_t dr3;
  69. uint64_t dr6;
  70. uint64_t dr7;
  71. uint8_t cpl;
  72. uint8_t user_only;
  73. uint16_t padding1;
  74. uint32_t error_code; /* error_code when exiting with an exception */
  75. uint64_t next_eip; /* next eip value when exiting with an interrupt */
  76. uint32_t nb_pages_to_flush; /* number of pages to flush,
  77. KQEMU_FLUSH_ALL means full flush */
  78. #define KQEMU_MAX_PAGES_TO_FLUSH 512
  79. #define KQEMU_FLUSH_ALL (KQEMU_MAX_PAGES_TO_FLUSH + 1)
  80. int32_t retval;
  81. /* number of ram_dirty entries to update */
  82. uint32_t nb_ram_pages_to_update;
  83. #define KQEMU_MAX_RAM_PAGES_TO_UPDATE 512
  84. #define KQEMU_RAM_PAGES_UPDATE_ALL (KQEMU_MAX_RAM_PAGES_TO_UPDATE + 1)
  85. #define KQEMU_MAX_MODIFIED_RAM_PAGES 512
  86. uint32_t nb_modified_ram_pages;
  87. };
  88. struct kqemu_init {
  89. uint8_t *ram_base; /* must be page aligned */
  90. KQEMU_PAD32(uint32_t padding1;)
  91. uint64_t ram_size; /* must be multiple of 4 KB */
  92. uint8_t *ram_dirty; /* must be page aligned */
  93. KQEMU_PAD32(uint32_t padding2;)
  94. uint64_t *pages_to_flush; /* must be page aligned */
  95. KQEMU_PAD32(uint32_t padding4;)
  96. uint64_t *ram_pages_to_update; /* must be page aligned */
  97. KQEMU_PAD32(uint32_t padding5;)
  98. uint64_t *modified_ram_pages; /* must be page aligned */
  99. KQEMU_PAD32(uint32_t padding6;)
  100. };
  101. #define KQEMU_IO_MEM_RAM 0
  102. #define KQEMU_IO_MEM_ROM 1
  103. #define KQEMU_IO_MEM_COMM 2 /* kqemu communication page */
  104. #define KQEMU_IO_MEM_UNASSIGNED 3 /* any device: return to application */
  105. struct kqemu_phys_mem {
  106. uint64_t phys_addr; /* physical address range: phys_addr,
  107. phys_addr + size */
  108. uint64_t size;
  109. uint64_t ram_addr; /* corresponding ram address */
  110. uint32_t io_index; /* memory type: see KQEMU_IO_MEM_xxx */
  111. uint32_t padding1;
  112. };
  113. #define KQEMU_RET_ABORT (-1)
  114. #define KQEMU_RET_EXCEPTION 0x0000 /* 8 low order bit are the exception */
  115. #define KQEMU_RET_INT 0x0100 /* 8 low order bit are the interrupt */
  116. #define KQEMU_RET_SOFTMMU 0x0200 /* emulation needed (I/O or
  117. unsupported INSN) */
  118. #define KQEMU_RET_INTR 0x0201 /* interrupted by a signal */
  119. #define KQEMU_RET_SYSCALL 0x0300 /* syscall insn */
  120. #ifdef _WIN32
  121. #define KQEMU_EXEC CTL_CODE(FILE_DEVICE_UNKNOWN, 1, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS)
  122. #define KQEMU_INIT CTL_CODE(FILE_DEVICE_UNKNOWN, 2, METHOD_BUFFERED, FILE_WRITE_ACCESS)
  123. #define KQEMU_GET_VERSION CTL_CODE(FILE_DEVICE_UNKNOWN, 3, METHOD_BUFFERED, FILE_READ_ACCESS)
  124. #define KQEMU_MODIFY_RAM_PAGES CTL_CODE(FILE_DEVICE_UNKNOWN, 4, METHOD_BUFFERED, FILE_WRITE_ACCESS)
  125. #define KQEMU_SET_PHYS_MEM CTL_CODE(FILE_DEVICE_UNKNOWN, 5, METHOD_BUFFERED, FILE_WRITE_ACCESS)
  126. #else
  127. #define KQEMU_EXEC _IOWR('q', 1, struct kqemu_cpu_state)
  128. #define KQEMU_INIT _IOW('q', 2, struct kqemu_init)
  129. #define KQEMU_GET_VERSION _IOR('q', 3, int)
  130. #define KQEMU_MODIFY_RAM_PAGES _IOW('q', 4, int)
  131. #define KQEMU_SET_PHYS_MEM _IOW('q', 5, struct kqemu_phys_mem)
  132. #endif
  133. #endif /* KQEMU_H */