paravirt_patch_32.c 1.9 KB

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