OSDN Git Service

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