paravirt_patch_32.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. unsigned native_patch(u8 type, u16 clobbers, void *ibuf,
  14. unsigned long addr, unsigned len)
  15. {
  16. const unsigned char *start, *end;
  17. unsigned ret;
  18. #define PATCH_SITE(ops, x) \
  19. case PARAVIRT_PATCH(ops.x): \
  20. start = start_##ops##_##x; \
  21. end = end_##ops##_##x; \
  22. goto patch_site
  23. switch (type) {
  24. PATCH_SITE(pv_irq_ops, irq_disable);
  25. PATCH_SITE(pv_irq_ops, irq_enable);
  26. PATCH_SITE(pv_irq_ops, restore_fl);
  27. PATCH_SITE(pv_irq_ops, save_fl);
  28. PATCH_SITE(pv_cpu_ops, iret);
  29. PATCH_SITE(pv_cpu_ops, irq_enable_sysexit);
  30. PATCH_SITE(pv_mmu_ops, read_cr2);
  31. PATCH_SITE(pv_mmu_ops, read_cr3);
  32. PATCH_SITE(pv_mmu_ops, write_cr3);
  33. PATCH_SITE(pv_cpu_ops, clts);
  34. PATCH_SITE(pv_cpu_ops, read_tsc);
  35. patch_site:
  36. ret = paravirt_patch_insns(ibuf, len, start, end);
  37. break;
  38. default:
  39. ret = paravirt_patch_default(type, clobbers, ibuf, addr, len);
  40. break;
  41. }
  42. #undef PATCH_SITE
  43. return ret;
  44. }