paravirt_patch_32.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #include <asm/paravirt.h>
  2. DEF_NATIVE(pv_irq_ops, irq_disable, "cli");
  3. DEF_NATIVE(pv_irq_ops, irq_enable, "sti");
  4. DEF_NATIVE(pv_irq_ops, restore_fl, "push %eax; popf");
  5. DEF_NATIVE(pv_irq_ops, save_fl, "pushf; pop %eax");
  6. DEF_NATIVE(pv_cpu_ops, iret, "iret");
  7. DEF_NATIVE(pv_cpu_ops, irq_enable_sysexit, "sti; sysexit");
  8. DEF_NATIVE(pv_mmu_ops, read_cr2, "mov %cr2, %eax");
  9. DEF_NATIVE(pv_mmu_ops, write_cr3, "mov %eax, %cr3");
  10. DEF_NATIVE(pv_mmu_ops, read_cr3, "mov %cr3, %eax");
  11. DEF_NATIVE(pv_cpu_ops, clts, "clts");
  12. DEF_NATIVE(pv_cpu_ops, read_tsc, "rdtsc");
  13. #if defined(CONFIG_PARAVIRT_SPINLOCKS) && defined(CONFIG_QUEUED_SPINLOCKS)
  14. DEF_NATIVE(pv_lock_ops, queued_spin_unlock, "movb $0, (%eax)");
  15. #endif
  16. unsigned paravirt_patch_ident_32(void *insnbuf, unsigned len)
  17. {
  18. /* arg in %eax, return in %eax */
  19. return 0;
  20. }
  21. unsigned paravirt_patch_ident_64(void *insnbuf, unsigned len)
  22. {
  23. /* arg in %edx:%eax, return in %edx:%eax */
  24. return 0;
  25. }
  26. extern bool pv_is_native_spin_unlock(void);
  27. unsigned native_patch(u8 type, u16 clobbers, void *ibuf,
  28. unsigned long addr, unsigned len)
  29. {
  30. const unsigned char *start, *end;
  31. unsigned ret;
  32. #define PATCH_SITE(ops, x) \
  33. case PARAVIRT_PATCH(ops.x): \
  34. start = start_##ops##_##x; \
  35. end = end_##ops##_##x; \
  36. goto patch_site
  37. switch (type) {
  38. PATCH_SITE(pv_irq_ops, irq_disable);
  39. PATCH_SITE(pv_irq_ops, irq_enable);
  40. PATCH_SITE(pv_irq_ops, restore_fl);
  41. PATCH_SITE(pv_irq_ops, save_fl);
  42. PATCH_SITE(pv_cpu_ops, iret);
  43. PATCH_SITE(pv_cpu_ops, irq_enable_sysexit);
  44. PATCH_SITE(pv_mmu_ops, read_cr2);
  45. PATCH_SITE(pv_mmu_ops, read_cr3);
  46. PATCH_SITE(pv_mmu_ops, write_cr3);
  47. PATCH_SITE(pv_cpu_ops, clts);
  48. PATCH_SITE(pv_cpu_ops, read_tsc);
  49. #if defined(CONFIG_PARAVIRT_SPINLOCKS) && defined(CONFIG_QUEUED_SPINLOCKS)
  50. case PARAVIRT_PATCH(pv_lock_ops.queued_spin_unlock):
  51. if (pv_is_native_spin_unlock()) {
  52. start = start_pv_lock_ops_queued_spin_unlock;
  53. end = end_pv_lock_ops_queued_spin_unlock;
  54. goto patch_site;
  55. }
  56. #endif
  57. default:
  58. ret = paravirt_patch_default(type, clobbers, ibuf, addr, len);
  59. break;
  60. patch_site:
  61. ret = paravirt_patch_insns(ibuf, len, start, end);
  62. break;
  63. }
  64. #undef PATCH_SITE
  65. return ret;
  66. }