paravirt_patch_32.c 2.1 KB

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