OpenSDE Packages Database (without history before r20070)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

268 lines
8.6 KiB

  1. # --- SDE-COPYRIGHT-NOTE-BEGIN ---
  2. # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
  3. #
  4. # Filename: package/.../qemu/qvm86.kqemu130.patch
  5. # Copyright (C) 2006 The OpenSDE Project
  6. #
  7. # More information can be found in the files COPYING and README.
  8. #
  9. # This patch file is dual-licensed. It is available under the license the
  10. # patched project is licensed under, as long as it is an OpenSource license
  11. # as defined at http://www.opensource.org/ (e.g. BSD, X11) or under the terms
  12. # of the GNU General Public License as published by the Free Software
  13. # Foundation; either version 2 of the License, or (at your option) any later
  14. # version.
  15. # --- SDE-COPYRIGHT-NOTE-END ---
  16. by Jim C. Brown <jma5@umd.edu>
  17. http://lists.gnu.org/archive/html/qvm86-devel/2006-02/msg00000.html
  18. diff -ur qvm86.orig/kqemu.h qvm86/kqemu.h
  19. --- ./qvm86.orig/kqemu.h Thu Jul 28 12:22:55 2005
  20. +++ ./qvm86/kqemu.h Tue Feb 14 20:45:43 2006
  21. @@ -1,11 +1,7 @@
  22. #ifndef KQEMU_H
  23. #define KQEMU_H
  24. -#ifdef _WIN32
  25. -#define KQEMU_VERSION 0x010101
  26. -#else
  27. -#define KQEMU_VERSION 0x010000
  28. -#endif
  29. +#define KQEMU_VERSION 0x010300
  30. struct kqemu_segment_cache {
  31. uint32_t selector;
  32. @@ -15,9 +11,13 @@
  33. };
  34. struct kqemu_cpu_state {
  35. - uint32_t regs[8];
  36. - uint32_t eip;
  37. - uint32_t eflags;
  38. +#ifdef __x86_64__
  39. + unsigned long regs[16];
  40. +#else
  41. + unsigned long regs[8];
  42. +#endif
  43. + unsigned long eip;
  44. + unsigned long eflags;
  45. uint32_t dummy0, dummy1, dumm2, dummy3, dummy4;
  46. @@ -27,31 +27,48 @@
  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. - uint32_t cr0;
  50. - uint32_t dumm5;
  51. - uint32_t cr2;
  52. - uint32_t cr3;
  53. - uint32_t cr4;
  54. + unsigned long cr0;
  55. + unsigned long dumm5;
  56. + unsigned long cr2;
  57. + unsigned long cr3;
  58. + unsigned long cr4;
  59. uint32_t a20_mask;
  60. - uint32_t dr0;
  61. - uint32_t dr1;
  62. - uint32_t dr2;
  63. - uint32_t dr3;
  64. - uint32_t dr6;
  65. - uint32_t dr7;
  66. + uint32_t sysenter_cs;
  67. + uint32_t sysenter_esp;
  68. + uint32_t sysenter_eip;
  69. + uint64_t efer __attribute__((aligned(8)));
  70. + uint64_t star;
  71. +#ifdef __x86_64__
  72. + unsigned long lstar;
  73. + unsigned long cstar;
  74. + unsigned long fmask;
  75. + unsigned long kernelgsbase;
  76. +#endif
  77. + uint64_t tsc_offset;
  78. +
  79. + unsigned long dr0;
  80. + unsigned long dr1;
  81. + unsigned long dr2;
  82. + unsigned long dr3;
  83. + unsigned long dr6;
  84. + unsigned long dr7;
  85. - int cpl; /* currently only 3 */
  86. + uint8_t cpl; /* currently only 3 */
  87. + uint8_t user_only;
  88. uint32_t error_code; /* error_code when exiting with an exception */
  89. - uint32_t next_eip; /* next eip value when exiting with an interrupt */
  90. + unsigned long next_eip; /* next eip value when exiting with an interrupt */
  91. unsigned int nb_pages_to_flush; /* number of pages to flush,
  92. - KQEMU_FLUSH_ALL means full flush */
  93. + KQEMU_FLUSH_ALL means full flush */
  94. #define KQEMU_MAX_PAGES_TO_FLUSH 512
  95. #define KQEMU_FLUSH_ALL (KQEMU_MAX_PAGES_TO_FLUSH + 1)
  96. -#ifdef _WIN32
  97. - uint32_t retval;
  98. -#endif
  99. + long retval;
  100. + unsigned int nb_ram_pages_to_update;
  101. + unsigned int nb_modified_ram_pages;
  102. +#define KQEMU_MAX_RAM_PAGES_TO_UPDATE 512
  103. +#define KQEMU_RAM_PAGES_UPDATE_ALL (KQEMU_MAX_RAM_PAGES_TO_UPDATE + 1)
  104. +#define KQEMU_MAX_MODIFIED_RAM_PAGES 512
  105. };
  106. struct kqemu_init {
  107. @@ -60,23 +77,28 @@
  108. uint8_t *ram_dirty; /* must be page aligned */
  109. uint32_t **phys_to_ram_map; /* must be page aligned */
  110. unsigned long *pages_to_flush; /* must be page aligned */
  111. + unsigned long *ram_pages_to_update; /* must be page aligned */
  112. + unsigned long *modified_ram_pages; /* must be page aligned */
  113. };
  114. #define KQEMU_RET_ABORT (-1)
  115. #define KQEMU_RET_EXCEPTION 0x0000 /* 8 low order bit are the exception */
  116. #define KQEMU_RET_INT 0x0100 /* 8 low order bit are the interrupt */
  117. #define KQEMU_RET_SOFTMMU 0x0200 /* emulation needed (I/O or
  118. - unsupported INSN) */
  119. + unsupported INSN) */
  120. #define KQEMU_RET_INTR 0x0201 /* interrupted by a signal */
  121. +#define KQEMU_RET_SYSCALL 0x0300 /* syscall insn */
  122. #ifdef _WIN32
  123. #define KQEMU_EXEC CTL_CODE(FILE_DEVICE_UNKNOWN, 1, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS)
  124. #define KQEMU_INIT CTL_CODE(FILE_DEVICE_UNKNOWN, 2, METHOD_BUFFERED, FILE_WRITE_ACCESS)
  125. #define KQEMU_GET_VERSION CTL_CODE(FILE_DEVICE_UNKNOWN, 3, METHOD_BUFFERED, FILE_READ_ACCESS)
  126. +#define KQEMU_MODIFY_RAM_PAGES CTL_CODE(FILE_DEVICE_UNKNOWN, 4, METHOD_BUFFERED, FILE_WRITE_ACCESS)
  127. #else
  128. #define KQEMU_EXEC _IOWR('q', 1, struct kqemu_cpu_state)
  129. #define KQEMU_INIT _IOW('q', 2, struct kqemu_init)
  130. #define KQEMU_GET_VERSION _IOR('q', 3, int)
  131. +#define KQEMU_MODIFY_RAM_PAGES _IOW('q', 4, int)
  132. #endif
  133. #endif /* KQEMU_H */
  134. diff -ur qvm86.orig/qvm86-host.c qvm86/qvm86-host.c
  135. --- ./qvm86.orig/qvm86-host.c Tue Aug 23 20:14:20 2005
  136. +++ ./qvm86/qvm86-host.c Tue Feb 14 20:57:01 2006
  137. @@ -1209,9 +1209,19 @@
  138. printk ("eax:%08x, ebx:%08x, ecx:%08x, edx:%08x\n", hostenv->regs[0], hostenv->regs[3], hostenv->regs[1], hostenv->regs[2]);
  139. printk ("esi:%08x, edi:%08x, ebp:%08x, esp:%08x\n", hostenv->regs[6], hostenv->regs[7], hostenv->regs[5], hostenv->regs[4]);
  140. }
  141. + /* Awwwww......................... bullshit */
  142. + if (hostenv->cpl == 0)
  143. + {
  144. + hostenv->retval = KQEMU_RET_SOFTMMU;
  145. + return KQEMU_RET_SOFTMMU;
  146. + }
  147. +
  148. /* We currently assume paging is enabled. */
  149. if ((hostenv->cr0 & 0x80000000) == 0)
  150. + {
  151. + hostenv->retval = KQEMU_RET_SOFTMMU;
  152. return KQEMU_RET_SOFTMMU;
  153. + }
  154. if (qs->guest_cr3 != hostenv->cr3)
  155. {
  156. @@ -1252,11 +1262,15 @@
  157. qvm86_clear_gdt_entries (qs, hostenv);
  158. if (i == 0x20)
  159. + {
  160. + hostenv->retval = KQEMU_RET_SOFTMMU;
  161. return KQEMU_RET_SOFTMMU;
  162. + }
  163. else
  164. {
  165. hostenv->error_code = i & 0xf;
  166. hostenv->cr2 = hostenv->segs[1].base + hostenv->eip;
  167. + hostenv->retval = KQEMU_RET_EXCEPTION + 14;
  168. return KQEMU_RET_EXCEPTION + 14;
  169. }
  170. }
  171. @@ -1308,7 +1322,10 @@
  172. /* Bail out if something went wrong. */
  173. if (qs->die)
  174. + {
  175. + hostenv->retval = KQEMU_RET_ABORT;
  176. return KQEMU_RET_ABORT;
  177. + }
  178. profile_timer(0);
  179. /* Setup monitor state. */
  180. @@ -1365,6 +1382,7 @@
  181. if (next_offset)
  182. hostenv->next_eip = hostenv->eip + next_offset;
  183. + hostenv->retval = retval; /* for some reason kqemu.c requires this */
  184. return retval;
  185. }
  186. @@ -1580,6 +1598,8 @@
  187. qs->l1_phys_map = (uint32_t *) init->phys_to_ram_map;
  188. qs->phys_ram_dirty = init->ram_dirty;
  189. qs->pages_to_flush = init->pages_to_flush;
  190. + qs->ram_pages_to_update = init->ram_pages_to_update;
  191. + qs->modified_ram_pages = init->modified_ram_pages;
  192. qvm86_init_shadow (qs);
  193. qvm86_init_monitor_stack (qs);
  194. qvm86_create_monitor_gdt (qs);
  195. Only in qvm86: qvm86-host.o
  196. diff -ur qvm86.orig/qvm86-linux.c qvm86/qvm86-linux.c
  197. --- ./qvm86.orig/qvm86-linux.c Thu Jul 28 12:22:55 2005
  198. +++ ./qvm86/qvm86-linux.c Tue Feb 14 20:14:15 2006
  199. @@ -129,6 +129,7 @@
  200. int ret;
  201. struct page *page;
  202. + down_read(&current->mm->mmap_sem);
  203. ret = get_user_pages(current,
  204. current->mm,
  205. (unsigned long) useraddr,
  206. @@ -138,6 +139,7 @@
  207. &page,
  208. NULL /* struct vm_area_struct *[] */
  209. );
  210. + up_read(&current->mm->mmap_sem);
  211. /* TODO: error handling. */
  212. if (ret != 1)
  213. printk (KERN_ERR "qvm86: host_map_user failed\n");
  214. @@ -231,6 +233,17 @@
  215. case KQEMU_GET_VERSION:
  216. if (put_user(KQEMU_VERSION, (int *)arg) < 0)
  217. ret = -EFAULT;
  218. + break;
  219. +
  220. +// called by kqemu_modify_pages()
  221. +// modified_ram_pages are the pages that qemu had changed (by writing to) and hence are dirty
  222. +// for userspace (which we run directly) we could care less.
  223. +// kqemu probabaly only needs this for -kernel-kqemu - pages in ring 0 which
  224. +// contain code and are written to will need to be updated with the binary
  225. +// translator. Since we don't do kernel mode (yet) we can safely ignore this.
  226. +// Paul Brook: any ETA on real -kernel-kqemu support?
  227. +
  228. + case KQEMU_MODIFY_RAM_PAGES:
  229. break;
  230. default:
  231. Only in qvm86: qvm86-linux.o
  232. diff -ur qvm86.orig/qvm86.h qvm86/qvm86.h
  233. --- ./qvm86.orig/qvm86.h Thu Jul 28 12:22:55 2005
  234. +++ ./qvm86/qvm86.h Tue Feb 14 20:47:32 2006
  235. @@ -217,6 +217,10 @@
  236. /* Emulator dirty memory flags. */
  237. uint8_t *phys_ram_dirty;
  238. unsigned long *pages_to_flush;
  239. + /* What does this do??? */
  240. + unsigned long *ram_pages_to_update;
  241. + /* This isn't used, its needed for -kernel-kqemu only (not implemented yet) */
  242. + unsigned long *modified_ram_pages;
  243. /* Satus of mapped-in host pages. */
  244. qvm86_mapped_page *host_physmem_map;