1 // SPDX-License-Identifier: GPL-2.0-or-later
5 * Copyright (C) 2004 Paul Mackerras <paulus@au.ibm.com>, IBM
7 #include <linux/kernel.h>
8 #include <linux/kprobes.h>
9 #include <linux/ptrace.h>
10 #include <linux/prefetch.h>
11 #include <asm/sstep.h>
12 #include <asm/processor.h>
13 #include <linux/uaccess.h>
14 #include <asm/cpu_has_feature.h>
15 #include <asm/cputable.h>
16 #include <asm/disassemble.h>
19 /* Bits in SRR1 that are copied from MSR */
20 #define MSR_MASK 0xffffffff87c0ffffUL
22 #define MSR_MASK 0x87c0ffff
26 #define XER_SO 0x80000000U
27 #define XER_OV 0x40000000U
28 #define XER_CA 0x20000000U
29 #define XER_OV32 0x00080000U
30 #define XER_CA32 0x00040000U
33 #define VSX_REGISTER_XTP(rd) ((((rd) & 1) << 5) | ((rd) & 0xfe))
38 * Functions in ldstfp.S
40 extern void get_fpr(int rn
, double *p
);
41 extern void put_fpr(int rn
, const double *p
);
42 extern void get_vr(int rn
, __vector128
*p
);
43 extern void put_vr(int rn
, __vector128
*p
);
44 extern void load_vsrn(int vsr
, const void *p
);
45 extern void store_vsrn(int vsr
, void *p
);
46 extern void conv_sp_to_dp(const float *sp
, double *dp
);
47 extern void conv_dp_to_sp(const double *dp
, float *sp
);
54 extern int do_lq(unsigned long ea
, unsigned long *regs
);
55 extern int do_stq(unsigned long ea
, unsigned long val0
, unsigned long val1
);
56 extern int do_lqarx(unsigned long ea
, unsigned long *regs
);
57 extern int do_stqcx(unsigned long ea
, unsigned long val0
, unsigned long val1
,
61 #ifdef __LITTLE_ENDIAN__
70 * Emulate the truncation of 64 bit values in 32-bit mode.
72 static nokprobe_inline
unsigned long truncate_if_32bit(unsigned long msr
,
75 if ((msr
& MSR_64BIT
) == 0)
81 * Determine whether a conditional branch instruction would branch.
83 static nokprobe_inline
int branch_taken(unsigned int instr
,
84 const struct pt_regs
*regs
,
85 struct instruction_op
*op
)
87 unsigned int bo
= (instr
>> 21) & 0x1f;
91 /* decrement counter */
93 if (((bo
>> 1) & 1) ^ (regs
->ctr
== 1))
96 if ((bo
& 0x10) == 0) {
97 /* check bit from CR */
98 bi
= (instr
>> 16) & 0x1f;
99 if (((regs
->ccr
>> (31 - bi
)) & 1) != ((bo
>> 3) & 1))
105 static nokprobe_inline
long address_ok(struct pt_regs
*regs
,
106 unsigned long ea
, int nb
)
108 if (!user_mode(regs
))
110 if (access_ok((void __user
*)ea
, nb
))
112 if (access_ok((void __user
*)ea
, 1))
113 /* Access overlaps the end of the user region */
114 regs
->dar
= TASK_SIZE_MAX
- 1;
121 * Calculate effective address for a D-form instruction
123 static nokprobe_inline
unsigned long dform_ea(unsigned int instr
,
124 const struct pt_regs
*regs
)
129 ra
= (instr
>> 16) & 0x1f;
130 ea
= (signed short) instr
; /* sign-extend */
139 * Calculate effective address for a DS-form instruction
141 static nokprobe_inline
unsigned long dsform_ea(unsigned int instr
,
142 const struct pt_regs
*regs
)
147 ra
= (instr
>> 16) & 0x1f;
148 ea
= (signed short) (instr
& ~3); /* sign-extend */
156 * Calculate effective address for a DQ-form instruction
158 static nokprobe_inline
unsigned long dqform_ea(unsigned int instr
,
159 const struct pt_regs
*regs
)
164 ra
= (instr
>> 16) & 0x1f;
165 ea
= (signed short) (instr
& ~0xf); /* sign-extend */
171 #endif /* __powerpc64 */
174 * Calculate effective address for an X-form instruction
176 static nokprobe_inline
unsigned long xform_ea(unsigned int instr
,
177 const struct pt_regs
*regs
)
182 ra
= (instr
>> 16) & 0x1f;
183 rb
= (instr
>> 11) & 0x1f;
192 * Calculate effective address for a MLS:D-form / 8LS:D-form
193 * prefixed instruction
195 static nokprobe_inline
unsigned long mlsd_8lsd_ea(unsigned int instr
,
197 const struct pt_regs
*regs
)
201 unsigned long ea
, d0
, d1
, d
;
203 prefix_r
= GET_PREFIX_R(instr
);
204 ra
= GET_PREFIX_RA(suffix
);
206 d0
= instr
& 0x3ffff;
207 d1
= suffix
& 0xffff;
211 * sign extend a 34 bit number
213 dd
= (unsigned int)(d
>> 2);
215 ea
= (ea
<< 2) | (d
& 0x3);
219 else if (!prefix_r
&& !ra
)
220 ; /* Leave ea as is */
225 * (prefix_r && ra) is an invalid form. Should already be
226 * checked for by caller!
233 * Return the largest power of 2, not greater than sizeof(unsigned long),
234 * such that x is a multiple of it.
236 static nokprobe_inline
unsigned long max_align(unsigned long x
)
238 x
|= sizeof(unsigned long);
239 return x
& -x
; /* isolates rightmost bit */
242 static nokprobe_inline
unsigned long byterev_2(unsigned long x
)
244 return ((x
>> 8) & 0xff) | ((x
& 0xff) << 8);
247 static nokprobe_inline
unsigned long byterev_4(unsigned long x
)
249 return ((x
>> 24) & 0xff) | ((x
>> 8) & 0xff00) |
250 ((x
& 0xff00) << 8) | ((x
& 0xff) << 24);
254 static nokprobe_inline
unsigned long byterev_8(unsigned long x
)
256 return (byterev_4(x
) << 32) | byterev_4(x
>> 32);
260 static nokprobe_inline
void do_byte_reverse(void *ptr
, int nb
)
264 *(u16
*)ptr
= byterev_2(*(u16
*)ptr
);
267 *(u32
*)ptr
= byterev_4(*(u32
*)ptr
);
271 *(unsigned long *)ptr
= byterev_8(*(unsigned long *)ptr
);
274 unsigned long *up
= (unsigned long *)ptr
;
276 tmp
= byterev_8(up
[0]);
277 up
[0] = byterev_8(up
[1]);
282 unsigned long *up
= (unsigned long *)ptr
;
285 tmp
= byterev_8(up
[0]);
286 up
[0] = byterev_8(up
[3]);
288 tmp
= byterev_8(up
[2]);
289 up
[2] = byterev_8(up
[1]);
300 static __always_inline
int
301 __read_mem_aligned(unsigned long *dest
, unsigned long ea
, int nb
, struct pt_regs
*regs
)
307 unsafe_get_user(x
, (unsigned char __user
*)ea
, Efault
);
310 unsafe_get_user(x
, (unsigned short __user
*)ea
, Efault
);
313 unsafe_get_user(x
, (unsigned int __user
*)ea
, Efault
);
317 unsafe_get_user(x
, (unsigned long __user
*)ea
, Efault
);
329 static nokprobe_inline
int
330 read_mem_aligned(unsigned long *dest
, unsigned long ea
, int nb
, struct pt_regs
*regs
)
334 if (is_kernel_addr(ea
))
335 return __read_mem_aligned(dest
, ea
, nb
, regs
);
337 if (user_read_access_begin((void __user
*)ea
, nb
)) {
338 err
= __read_mem_aligned(dest
, ea
, nb
, regs
);
339 user_read_access_end();
349 * Copy from userspace to a buffer, using the largest possible
350 * aligned accesses, up to sizeof(long).
352 static __always_inline
int __copy_mem_in(u8
*dest
, unsigned long ea
, int nb
, struct pt_regs
*regs
)
356 for (; nb
> 0; nb
-= c
) {
362 unsafe_get_user(*dest
, (u8 __user
*)ea
, Efault
);
365 unsafe_get_user(*(u16
*)dest
, (u16 __user
*)ea
, Efault
);
368 unsafe_get_user(*(u32
*)dest
, (u32 __user
*)ea
, Efault
);
372 unsafe_get_user(*(u64
*)dest
, (u64 __user
*)ea
, Efault
);
386 static nokprobe_inline
int copy_mem_in(u8
*dest
, unsigned long ea
, int nb
, struct pt_regs
*regs
)
390 if (is_kernel_addr(ea
))
391 return __copy_mem_in(dest
, ea
, nb
, regs
);
393 if (user_read_access_begin((void __user
*)ea
, nb
)) {
394 err
= __copy_mem_in(dest
, ea
, nb
, regs
);
395 user_read_access_end();
404 static nokprobe_inline
int read_mem_unaligned(unsigned long *dest
,
405 unsigned long ea
, int nb
,
406 struct pt_regs
*regs
)
410 u8 b
[sizeof(unsigned long)];
416 i
= IS_BE
? sizeof(unsigned long) - nb
: 0;
417 err
= copy_mem_in(&u
.b
[i
], ea
, nb
, regs
);
424 * Read memory at address ea for nb bytes, return 0 for success
425 * or -EFAULT if an error occurred. N.B. nb must be 1, 2, 4 or 8.
426 * If nb < sizeof(long), the result is right-justified on BE systems.
428 static int read_mem(unsigned long *dest
, unsigned long ea
, int nb
,
429 struct pt_regs
*regs
)
431 if (!address_ok(regs
, ea
, nb
))
433 if ((ea
& (nb
- 1)) == 0)
434 return read_mem_aligned(dest
, ea
, nb
, regs
);
435 return read_mem_unaligned(dest
, ea
, nb
, regs
);
437 NOKPROBE_SYMBOL(read_mem
);
439 static __always_inline
int
440 __write_mem_aligned(unsigned long val
, unsigned long ea
, int nb
, struct pt_regs
*regs
)
444 unsafe_put_user(val
, (unsigned char __user
*)ea
, Efault
);
447 unsafe_put_user(val
, (unsigned short __user
*)ea
, Efault
);
450 unsafe_put_user(val
, (unsigned int __user
*)ea
, Efault
);
454 unsafe_put_user(val
, (unsigned long __user
*)ea
, Efault
);
465 static nokprobe_inline
int
466 write_mem_aligned(unsigned long val
, unsigned long ea
, int nb
, struct pt_regs
*regs
)
470 if (is_kernel_addr(ea
))
471 return __write_mem_aligned(val
, ea
, nb
, regs
);
473 if (user_write_access_begin((void __user
*)ea
, nb
)) {
474 err
= __write_mem_aligned(val
, ea
, nb
, regs
);
475 user_write_access_end();
485 * Copy from a buffer to userspace, using the largest possible
486 * aligned accesses, up to sizeof(long).
488 static __always_inline
int __copy_mem_out(u8
*dest
, unsigned long ea
, int nb
, struct pt_regs
*regs
)
492 for (; nb
> 0; nb
-= c
) {
498 unsafe_put_user(*dest
, (u8 __user
*)ea
, Efault
);
501 unsafe_put_user(*(u16
*)dest
, (u16 __user
*)ea
, Efault
);
504 unsafe_put_user(*(u32
*)dest
, (u32 __user
*)ea
, Efault
);
508 unsafe_put_user(*(u64
*)dest
, (u64 __user
*)ea
, Efault
);
522 static nokprobe_inline
int copy_mem_out(u8
*dest
, unsigned long ea
, int nb
, struct pt_regs
*regs
)
526 if (is_kernel_addr(ea
))
527 return __copy_mem_out(dest
, ea
, nb
, regs
);
529 if (user_write_access_begin((void __user
*)ea
, nb
)) {
530 err
= __copy_mem_out(dest
, ea
, nb
, regs
);
531 user_write_access_end();
540 static nokprobe_inline
int write_mem_unaligned(unsigned long val
,
541 unsigned long ea
, int nb
,
542 struct pt_regs
*regs
)
546 u8 b
[sizeof(unsigned long)];
551 i
= IS_BE
? sizeof(unsigned long) - nb
: 0;
552 return copy_mem_out(&u
.b
[i
], ea
, nb
, regs
);
556 * Write memory at address ea for nb bytes, return 0 for success
557 * or -EFAULT if an error occurred. N.B. nb must be 1, 2, 4 or 8.
559 static int write_mem(unsigned long val
, unsigned long ea
, int nb
,
560 struct pt_regs
*regs
)
562 if (!address_ok(regs
, ea
, nb
))
564 if ((ea
& (nb
- 1)) == 0)
565 return write_mem_aligned(val
, ea
, nb
, regs
);
566 return write_mem_unaligned(val
, ea
, nb
, regs
);
568 NOKPROBE_SYMBOL(write_mem
);
570 #ifdef CONFIG_PPC_FPU
572 * These access either the real FP register or the image in the
573 * thread_struct, depending on regs->msr & MSR_FP.
575 static int do_fp_load(struct instruction_op
*op
, unsigned long ea
,
576 struct pt_regs
*regs
, bool cross_endian
)
585 u8 b
[2 * sizeof(double)];
588 nb
= GETSIZE(op
->type
);
591 if (!address_ok(regs
, ea
, nb
))
594 err
= copy_mem_in(u
.b
, ea
, nb
, regs
);
597 if (unlikely(cross_endian
)) {
598 do_byte_reverse(u
.b
, min(nb
, 8));
600 do_byte_reverse(&u
.b
[8], 8);
604 if (op
->type
& FPCONV
)
605 conv_sp_to_dp(&u
.f
, &u
.d
[0]);
606 else if (op
->type
& SIGNEXT
)
611 if (regs
->msr
& MSR_FP
)
612 put_fpr(rn
, &u
.d
[0]);
614 current
->thread
.TS_FPR(rn
) = u
.l
[0];
618 if (regs
->msr
& MSR_FP
)
619 put_fpr(rn
, &u
.d
[1]);
621 current
->thread
.TS_FPR(rn
) = u
.l
[1];
626 NOKPROBE_SYMBOL(do_fp_load
);
628 static int do_fp_store(struct instruction_op
*op
, unsigned long ea
,
629 struct pt_regs
*regs
, bool cross_endian
)
637 u8 b
[2 * sizeof(double)];
640 nb
= GETSIZE(op
->type
);
643 if (!address_ok(regs
, ea
, nb
))
647 if (regs
->msr
& MSR_FP
)
648 get_fpr(rn
, &u
.d
[0]);
650 u
.l
[0] = current
->thread
.TS_FPR(rn
);
652 if (op
->type
& FPCONV
)
653 conv_dp_to_sp(&u
.d
[0], &u
.f
);
659 if (regs
->msr
& MSR_FP
)
660 get_fpr(rn
, &u
.d
[1]);
662 u
.l
[1] = current
->thread
.TS_FPR(rn
);
665 if (unlikely(cross_endian
)) {
666 do_byte_reverse(u
.b
, min(nb
, 8));
668 do_byte_reverse(&u
.b
[8], 8);
670 return copy_mem_out(u
.b
, ea
, nb
, regs
);
672 NOKPROBE_SYMBOL(do_fp_store
);
675 #ifdef CONFIG_ALTIVEC
676 /* For Altivec/VMX, no need to worry about alignment */
677 static nokprobe_inline
int do_vec_load(int rn
, unsigned long ea
,
678 int size
, struct pt_regs
*regs
,
684 u8 b
[sizeof(__vector128
)];
687 if (size
> sizeof(u
))
690 if (!address_ok(regs
, ea
& ~0xfUL
, 16))
692 /* align to multiple of size */
694 err
= copy_mem_in(&u
.b
[ea
& 0xf], ea
, size
, regs
);
697 if (unlikely(cross_endian
))
698 do_byte_reverse(&u
.b
[ea
& 0xf], min_t(size_t, size
, sizeof(u
)));
700 if (regs
->msr
& MSR_VEC
)
703 current
->thread
.vr_state
.vr
[rn
] = u
.v
;
708 static nokprobe_inline
int do_vec_store(int rn
, unsigned long ea
,
709 int size
, struct pt_regs
*regs
,
714 u8 b
[sizeof(__vector128
)];
717 if (size
> sizeof(u
))
720 if (!address_ok(regs
, ea
& ~0xfUL
, 16))
722 /* align to multiple of size */
726 if (regs
->msr
& MSR_VEC
)
729 u
.v
= current
->thread
.vr_state
.vr
[rn
];
731 if (unlikely(cross_endian
))
732 do_byte_reverse(&u
.b
[ea
& 0xf], min_t(size_t, size
, sizeof(u
)));
733 return copy_mem_out(&u
.b
[ea
& 0xf], ea
, size
, regs
);
735 #endif /* CONFIG_ALTIVEC */
738 static nokprobe_inline
int emulate_lq(struct pt_regs
*regs
, unsigned long ea
,
739 int reg
, bool cross_endian
)
743 if (!address_ok(regs
, ea
, 16))
745 /* if aligned, should be atomic */
746 if ((ea
& 0xf) == 0) {
747 err
= do_lq(ea
, ®s
->gpr
[reg
]);
749 err
= read_mem(®s
->gpr
[reg
+ IS_LE
], ea
, 8, regs
);
751 err
= read_mem(®s
->gpr
[reg
+ IS_BE
], ea
+ 8, 8, regs
);
753 if (!err
&& unlikely(cross_endian
))
754 do_byte_reverse(®s
->gpr
[reg
], 16);
758 static nokprobe_inline
int emulate_stq(struct pt_regs
*regs
, unsigned long ea
,
759 int reg
, bool cross_endian
)
762 unsigned long vals
[2];
764 if (!address_ok(regs
, ea
, 16))
766 vals
[0] = regs
->gpr
[reg
];
767 vals
[1] = regs
->gpr
[reg
+ 1];
768 if (unlikely(cross_endian
))
769 do_byte_reverse(vals
, 16);
771 /* if aligned, should be atomic */
773 return do_stq(ea
, vals
[0], vals
[1]);
775 err
= write_mem(vals
[IS_LE
], ea
, 8, regs
);
777 err
= write_mem(vals
[IS_BE
], ea
+ 8, 8, regs
);
780 #endif /* __powerpc64 */
783 static nokprobe_inline
void emulate_vsx_load(struct instruction_op
*op
, union vsx_reg
*reg
,
784 const void *mem
, bool rev
)
788 const unsigned int *wp
;
789 const unsigned short *hp
;
790 const unsigned char *bp
;
792 size
= GETSIZE(op
->type
);
793 reg
->d
[0] = reg
->d
[1] = 0;
795 switch (op
->element_size
) {
799 /* whole vector; lxv[x] or lxvl[l] */
802 memcpy(reg
, mem
, size
);
803 if (IS_LE
&& (op
->vsx_flags
& VSX_LDLEFT
))
806 do_byte_reverse(reg
, size
);
809 /* scalar loads, lxvd2x, lxvdsx */
810 read_size
= (size
>= 8) ? 8 : size
;
811 i
= IS_LE
? 8 : 8 - read_size
;
812 memcpy(®
->b
[i
], mem
, read_size
);
814 do_byte_reverse(®
->b
[i
], 8);
816 if (op
->type
& SIGNEXT
) {
817 /* size == 4 is the only case here */
818 reg
->d
[IS_LE
] = (signed int) reg
->d
[IS_LE
];
819 } else if (op
->vsx_flags
& VSX_FPCONV
) {
821 conv_sp_to_dp(®
->fp
[1 + IS_LE
],
827 unsigned long v
= *(unsigned long *)(mem
+ 8);
828 reg
->d
[IS_BE
] = !rev
? v
: byterev_8(v
);
829 } else if (op
->vsx_flags
& VSX_SPLAT
)
830 reg
->d
[IS_BE
] = reg
->d
[IS_LE
];
836 for (j
= 0; j
< size
/ 4; ++j
) {
837 i
= IS_LE
? 3 - j
: j
;
838 reg
->w
[i
] = !rev
? *wp
++ : byterev_4(*wp
++);
840 if (op
->vsx_flags
& VSX_SPLAT
) {
841 u32 val
= reg
->w
[IS_LE
? 3 : 0];
843 i
= IS_LE
? 3 - j
: j
;
851 for (j
= 0; j
< size
/ 2; ++j
) {
852 i
= IS_LE
? 7 - j
: j
;
853 reg
->h
[i
] = !rev
? *hp
++ : byterev_2(*hp
++);
859 for (j
= 0; j
< size
; ++j
) {
860 i
= IS_LE
? 15 - j
: j
;
867 static nokprobe_inline
void emulate_vsx_store(struct instruction_op
*op
, const union vsx_reg
*reg
,
870 int size
, write_size
;
877 size
= GETSIZE(op
->type
);
879 switch (op
->element_size
) {
885 /* reverse 32 bytes */
886 union vsx_reg buf32
[2];
887 buf32
[0].d
[0] = byterev_8(reg
[1].d
[1]);
888 buf32
[0].d
[1] = byterev_8(reg
[1].d
[0]);
889 buf32
[1].d
[0] = byterev_8(reg
[0].d
[1]);
890 buf32
[1].d
[1] = byterev_8(reg
[0].d
[0]);
891 memcpy(mem
, buf32
, size
);
893 memcpy(mem
, reg
, size
);
897 /* stxv, stxvx, stxvl, stxvll */
900 if (IS_LE
&& (op
->vsx_flags
& VSX_LDLEFT
))
903 /* reverse 16 bytes */
904 buf
.d
[0] = byterev_8(reg
->d
[1]);
905 buf
.d
[1] = byterev_8(reg
->d
[0]);
908 memcpy(mem
, reg
, size
);
911 /* scalar stores, stxvd2x */
912 write_size
= (size
>= 8) ? 8 : size
;
913 i
= IS_LE
? 8 : 8 - write_size
;
914 if (size
< 8 && op
->vsx_flags
& VSX_FPCONV
) {
915 buf
.d
[0] = buf
.d
[1] = 0;
917 conv_dp_to_sp(®
->dp
[IS_LE
], &buf
.fp
[1 + IS_LE
]);
921 memcpy(mem
, ®
->b
[i
], write_size
);
923 memcpy(mem
+ 8, ®
->d
[IS_BE
], 8);
925 do_byte_reverse(mem
, write_size
);
927 do_byte_reverse(mem
+ 8, 8);
933 for (j
= 0; j
< size
/ 4; ++j
) {
934 i
= IS_LE
? 3 - j
: j
;
935 *wp
++ = !rev
? reg
->w
[i
] : byterev_4(reg
->w
[i
]);
941 for (j
= 0; j
< size
/ 2; ++j
) {
942 i
= IS_LE
? 7 - j
: j
;
943 *hp
++ = !rev
? reg
->h
[i
] : byterev_2(reg
->h
[i
]);
949 for (j
= 0; j
< size
; ++j
) {
950 i
= IS_LE
? 15 - j
: j
;
957 static nokprobe_inline
int do_vsx_load(struct instruction_op
*op
,
958 unsigned long ea
, struct pt_regs
*regs
,
962 int i
, j
, nr_vsx_regs
;
964 union vsx_reg buf
[2];
965 int size
= GETSIZE(op
->type
);
967 if (!address_ok(regs
, ea
, size
) || copy_mem_in(mem
, ea
, size
, regs
))
970 nr_vsx_regs
= max(1ul, size
/ sizeof(__vector128
));
971 emulate_vsx_load(op
, buf
, mem
, cross_endian
);
974 /* FP regs + extensions */
975 if (regs
->msr
& MSR_FP
) {
976 for (i
= 0; i
< nr_vsx_regs
; i
++) {
977 j
= IS_LE
? nr_vsx_regs
- i
- 1 : i
;
978 load_vsrn(reg
+ i
, &buf
[j
].v
);
981 for (i
= 0; i
< nr_vsx_regs
; i
++) {
982 j
= IS_LE
? nr_vsx_regs
- i
- 1 : i
;
983 current
->thread
.fp_state
.fpr
[reg
+ i
][0] = buf
[j
].d
[0];
984 current
->thread
.fp_state
.fpr
[reg
+ i
][1] = buf
[j
].d
[1];
988 if (regs
->msr
& MSR_VEC
) {
989 for (i
= 0; i
< nr_vsx_regs
; i
++) {
990 j
= IS_LE
? nr_vsx_regs
- i
- 1 : i
;
991 load_vsrn(reg
+ i
, &buf
[j
].v
);
994 for (i
= 0; i
< nr_vsx_regs
; i
++) {
995 j
= IS_LE
? nr_vsx_regs
- i
- 1 : i
;
996 current
->thread
.vr_state
.vr
[reg
- 32 + i
] = buf
[j
].v
;
1004 static nokprobe_inline
int do_vsx_store(struct instruction_op
*op
,
1005 unsigned long ea
, struct pt_regs
*regs
,
1009 int i
, j
, nr_vsx_regs
;
1011 union vsx_reg buf
[2];
1012 int size
= GETSIZE(op
->type
);
1014 if (!address_ok(regs
, ea
, size
))
1017 nr_vsx_regs
= max(1ul, size
/ sizeof(__vector128
));
1020 /* FP regs + extensions */
1021 if (regs
->msr
& MSR_FP
) {
1022 for (i
= 0; i
< nr_vsx_regs
; i
++) {
1023 j
= IS_LE
? nr_vsx_regs
- i
- 1 : i
;
1024 store_vsrn(reg
+ i
, &buf
[j
].v
);
1027 for (i
= 0; i
< nr_vsx_regs
; i
++) {
1028 j
= IS_LE
? nr_vsx_regs
- i
- 1 : i
;
1029 buf
[j
].d
[0] = current
->thread
.fp_state
.fpr
[reg
+ i
][0];
1030 buf
[j
].d
[1] = current
->thread
.fp_state
.fpr
[reg
+ i
][1];
1034 if (regs
->msr
& MSR_VEC
) {
1035 for (i
= 0; i
< nr_vsx_regs
; i
++) {
1036 j
= IS_LE
? nr_vsx_regs
- i
- 1 : i
;
1037 store_vsrn(reg
+ i
, &buf
[j
].v
);
1040 for (i
= 0; i
< nr_vsx_regs
; i
++) {
1041 j
= IS_LE
? nr_vsx_regs
- i
- 1 : i
;
1042 buf
[j
].v
= current
->thread
.vr_state
.vr
[reg
- 32 + i
];
1047 emulate_vsx_store(op
, buf
, mem
, cross_endian
);
1048 return copy_mem_out(mem
, ea
, size
, regs
);
1050 #endif /* CONFIG_VSX */
1052 static __always_inline
int __emulate_dcbz(unsigned long ea
)
1055 unsigned long size
= l1_dcache_bytes();
1057 for (i
= 0; i
< size
; i
+= sizeof(long))
1058 unsafe_put_user(0, (unsigned long __user
*)(ea
+ i
), Efault
);
1066 int emulate_dcbz(unsigned long ea
, struct pt_regs
*regs
)
1069 unsigned long size
= l1_dcache_bytes();
1071 ea
= truncate_if_32bit(regs
->msr
, ea
);
1073 if (!address_ok(regs
, ea
, size
))
1076 if (is_kernel_addr(ea
)) {
1077 err
= __emulate_dcbz(ea
);
1078 } else if (user_write_access_begin((void __user
*)ea
, size
)) {
1079 err
= __emulate_dcbz(ea
);
1080 user_write_access_end();
1091 NOKPROBE_SYMBOL(emulate_dcbz
);
1093 #define __put_user_asmx(x, addr, err, op, cr) \
1094 __asm__ __volatile__( \
1096 ".machine power8\n" \
1097 "1: " op " %2,0,%3\n" \
1101 ".section .fixup,\"ax\"\n" \
1106 : "=r" (err), "=r" (cr) \
1107 : "r" (x), "r" (addr), "i" (-EFAULT), "0" (err))
1109 #define __get_user_asmx(x, addr, err, op) \
1110 __asm__ __volatile__( \
1112 ".machine power8\n" \
1113 "1: "op" %1,0,%2\n" \
1116 ".section .fixup,\"ax\"\n" \
1121 : "=r" (err), "=r" (x) \
1122 : "r" (addr), "i" (-EFAULT), "0" (err))
1124 #define __cacheop_user_asmx(addr, err, op) \
1125 __asm__ __volatile__( \
1128 ".section .fixup,\"ax\"\n" \
1134 : "r" (addr), "i" (-EFAULT), "0" (err))
1136 static nokprobe_inline
void set_cr0(const struct pt_regs
*regs
,
1137 struct instruction_op
*op
)
1142 op
->ccval
= (regs
->ccr
& 0x0fffffff) | ((regs
->xer
>> 3) & 0x10000000);
1143 if (!(regs
->msr
& MSR_64BIT
))
1146 op
->ccval
|= 0x80000000;
1148 op
->ccval
|= 0x40000000;
1150 op
->ccval
|= 0x20000000;
1153 static nokprobe_inline
void set_ca32(struct instruction_op
*op
, bool val
)
1155 if (cpu_has_feature(CPU_FTR_ARCH_300
)) {
1157 op
->xerval
|= XER_CA32
;
1159 op
->xerval
&= ~XER_CA32
;
1163 static nokprobe_inline
void add_with_carry(const struct pt_regs
*regs
,
1164 struct instruction_op
*op
, int rd
,
1165 unsigned long val1
, unsigned long val2
,
1166 unsigned long carry_in
)
1168 unsigned long val
= val1
+ val2
;
1172 op
->type
= COMPUTE
| SETREG
| SETXER
;
1175 val
= truncate_if_32bit(regs
->msr
, val
);
1176 val1
= truncate_if_32bit(regs
->msr
, val1
);
1177 op
->xerval
= regs
->xer
;
1178 if (val
< val1
|| (carry_in
&& val
== val1
))
1179 op
->xerval
|= XER_CA
;
1181 op
->xerval
&= ~XER_CA
;
1183 set_ca32(op
, (unsigned int)val
< (unsigned int)val1
||
1184 (carry_in
&& (unsigned int)val
== (unsigned int)val1
));
1187 static nokprobe_inline
void do_cmp_signed(const struct pt_regs
*regs
,
1188 struct instruction_op
*op
,
1189 long v1
, long v2
, int crfld
)
1191 unsigned int crval
, shift
;
1193 op
->type
= COMPUTE
| SETCC
;
1194 crval
= (regs
->xer
>> 31) & 1; /* get SO bit */
1201 shift
= (7 - crfld
) * 4;
1202 op
->ccval
= (regs
->ccr
& ~(0xf << shift
)) | (crval
<< shift
);
1205 static nokprobe_inline
void do_cmp_unsigned(const struct pt_regs
*regs
,
1206 struct instruction_op
*op
,
1208 unsigned long v2
, int crfld
)
1210 unsigned int crval
, shift
;
1212 op
->type
= COMPUTE
| SETCC
;
1213 crval
= (regs
->xer
>> 31) & 1; /* get SO bit */
1220 shift
= (7 - crfld
) * 4;
1221 op
->ccval
= (regs
->ccr
& ~(0xf << shift
)) | (crval
<< shift
);
1224 static nokprobe_inline
void do_cmpb(const struct pt_regs
*regs
,
1225 struct instruction_op
*op
,
1226 unsigned long v1
, unsigned long v2
)
1228 unsigned long long out_val
, mask
;
1232 for (i
= 0; i
< 8; i
++) {
1233 mask
= 0xffUL
<< (i
* 8);
1234 if ((v1
& mask
) == (v2
& mask
))
1241 * The size parameter is used to adjust the equivalent popcnt instruction.
1242 * popcntb = 8, popcntw = 32, popcntd = 64
1244 static nokprobe_inline
void do_popcnt(const struct pt_regs
*regs
,
1245 struct instruction_op
*op
,
1246 unsigned long v1
, int size
)
1248 unsigned long long out
= v1
;
1250 out
-= (out
>> 1) & 0x5555555555555555ULL
;
1251 out
= (0x3333333333333333ULL
& out
) +
1252 (0x3333333333333333ULL
& (out
>> 2));
1253 out
= (out
+ (out
>> 4)) & 0x0f0f0f0f0f0f0f0fULL
;
1255 if (size
== 8) { /* popcntb */
1261 if (size
== 32) { /* popcntw */
1262 op
->val
= out
& 0x0000003f0000003fULL
;
1266 out
= (out
+ (out
>> 32)) & 0x7f;
1267 op
->val
= out
; /* popcntd */
1271 static nokprobe_inline
void do_bpermd(const struct pt_regs
*regs
,
1272 struct instruction_op
*op
,
1273 unsigned long v1
, unsigned long v2
)
1275 unsigned char perm
, idx
;
1279 for (i
= 0; i
< 8; i
++) {
1280 idx
= (v1
>> (i
* 8)) & 0xff;
1282 if (v2
& PPC_BIT(idx
))
1287 #endif /* CONFIG_PPC64 */
1289 * The size parameter adjusts the equivalent prty instruction.
1290 * prtyw = 32, prtyd = 64
1292 static nokprobe_inline
void do_prty(const struct pt_regs
*regs
,
1293 struct instruction_op
*op
,
1294 unsigned long v
, int size
)
1296 unsigned long long res
= v
^ (v
>> 8);
1299 if (size
== 32) { /* prtyw */
1300 op
->val
= res
& 0x0000000100000001ULL
;
1305 op
->val
= res
& 1; /*prtyd */
1308 static nokprobe_inline
int trap_compare(long v1
, long v2
)
1318 if ((unsigned long)v1
< (unsigned long)v2
)
1320 else if ((unsigned long)v1
> (unsigned long)v2
)
1326 * Elements of 32-bit rotate and mask instructions.
1328 #define MASK32(mb, me) ((0xffffffffUL >> (mb)) + \
1329 ((signed long)-0x80000000L >> (me)) + ((me) >= (mb)))
1330 #ifdef __powerpc64__
1331 #define MASK64_L(mb) (~0UL >> (mb))
1332 #define MASK64_R(me) ((signed long)-0x8000000000000000L >> (me))
1333 #define MASK64(mb, me) (MASK64_L(mb) + MASK64_R(me) + ((me) >= (mb)))
1334 #define DATA32(x) (((x) & 0xffffffffUL) | (((x) & 0xffffffffUL) << 32))
1336 #define DATA32(x) (x)
1338 #define ROTATE(x, n) ((n) ? (((x) << (n)) | ((x) >> (8 * sizeof(long) - (n)))) : (x))
1341 * Decode an instruction, and return information about it in *op
1342 * without changing *regs.
1343 * Integer arithmetic and logical instructions, branches, and barrier
1344 * instructions can be emulated just using the information in *op.
1346 * Return value is 1 if the instruction can be emulated just by
1347 * updating *regs with the information in *op, -1 if we need the
1348 * GPRs but *regs doesn't contain the full register set, or 0
1351 int analyse_instr(struct instruction_op
*op
, const struct pt_regs
*regs
,
1355 unsigned int suffixopcode
, prefixtype
, prefix_r
;
1357 unsigned int opcode
, ra
, rb
, rc
, rd
, spr
, u
;
1358 unsigned long int imm
;
1359 unsigned long int val
, val2
;
1360 unsigned int mb
, me
, sh
;
1361 unsigned int word
, suffix
;
1364 word
= ppc_inst_val(instr
);
1365 suffix
= ppc_inst_suffix(instr
);
1369 opcode
= ppc_inst_primary_opcode(instr
);
1373 imm
= (signed short)(word
& 0xfffc);
1374 if ((word
& 2) == 0)
1376 op
->val
= truncate_if_32bit(regs
->msr
, imm
);
1379 if (branch_taken(word
, regs
, op
))
1380 op
->type
|= BRTAKEN
;
1383 if ((word
& 0xfe2) == 2)
1385 else if (IS_ENABLED(CONFIG_PPC_BOOK3S_64
) &&
1386 (word
& 0xfe3) == 1) { /* scv */
1387 op
->type
= SYSCALL_VECTORED_0
;
1388 if (!cpu_has_feature(CPU_FTR_ARCH_300
))
1389 goto unknown_opcode
;
1394 op
->type
= BRANCH
| BRTAKEN
;
1395 imm
= word
& 0x03fffffc;
1396 if (imm
& 0x02000000)
1398 if ((word
& 2) == 0)
1400 op
->val
= truncate_if_32bit(regs
->msr
, imm
);
1405 switch ((word
>> 1) & 0x3ff) {
1407 op
->type
= COMPUTE
+ SETCC
;
1408 rd
= 7 - ((word
>> 23) & 0x7);
1409 ra
= 7 - ((word
>> 18) & 0x7);
1412 val
= (regs
->ccr
>> ra
) & 0xf;
1413 op
->ccval
= (regs
->ccr
& ~(0xfUL
<< rd
)) | (val
<< rd
);
1417 case 528: /* bcctr */
1419 imm
= (word
& 0x400)? regs
->ctr
: regs
->link
;
1420 op
->val
= truncate_if_32bit(regs
->msr
, imm
);
1423 if (branch_taken(word
, regs
, op
))
1424 op
->type
|= BRTAKEN
;
1427 case 18: /* rfid, scary */
1428 if (user_mode(regs
))
1433 case 150: /* isync */
1434 op
->type
= BARRIER
| BARRIER_ISYNC
;
1437 case 33: /* crnor */
1438 case 129: /* crandc */
1439 case 193: /* crxor */
1440 case 225: /* crnand */
1441 case 257: /* crand */
1442 case 289: /* creqv */
1443 case 417: /* crorc */
1444 case 449: /* cror */
1445 op
->type
= COMPUTE
+ SETCC
;
1446 ra
= (word
>> 16) & 0x1f;
1447 rb
= (word
>> 11) & 0x1f;
1448 rd
= (word
>> 21) & 0x1f;
1449 ra
= (regs
->ccr
>> (31 - ra
)) & 1;
1450 rb
= (regs
->ccr
>> (31 - rb
)) & 1;
1451 val
= (word
>> (6 + ra
* 2 + rb
)) & 1;
1452 op
->ccval
= (regs
->ccr
& ~(1UL << (31 - rd
))) |
1458 switch ((word
>> 1) & 0x3ff) {
1459 case 598: /* sync */
1460 op
->type
= BARRIER
+ BARRIER_SYNC
;
1461 #ifdef __powerpc64__
1462 switch ((word
>> 21) & 3) {
1463 case 1: /* lwsync */
1464 op
->type
= BARRIER
+ BARRIER_LWSYNC
;
1466 case 2: /* ptesync */
1467 op
->type
= BARRIER
+ BARRIER_PTESYNC
;
1473 case 854: /* eieio */
1474 op
->type
= BARRIER
+ BARRIER_EIEIO
;
1480 rd
= (word
>> 21) & 0x1f;
1481 ra
= (word
>> 16) & 0x1f;
1482 rb
= (word
>> 11) & 0x1f;
1483 rc
= (word
>> 6) & 0x1f;
1486 #ifdef __powerpc64__
1488 if (!cpu_has_feature(CPU_FTR_ARCH_31
))
1489 goto unknown_opcode
;
1491 prefix_r
= GET_PREFIX_R(word
);
1492 ra
= GET_PREFIX_RA(suffix
);
1493 rd
= (suffix
>> 21) & 0x1f;
1495 op
->val
= regs
->gpr
[rd
];
1496 suffixopcode
= get_op(suffix
);
1497 prefixtype
= (word
>> 24) & 0x3;
1498 switch (prefixtype
) {
1502 switch (suffixopcode
) {
1503 case 14: /* paddi */
1504 op
->type
= COMPUTE
| PREFIXED
;
1505 op
->val
= mlsd_8lsd_ea(word
, suffix
, regs
);
1511 if (rd
& trap_compare(regs
->gpr
[ra
], (short) word
))
1516 if (rd
& trap_compare((int)regs
->gpr
[ra
], (short) word
))
1520 #ifdef __powerpc64__
1523 * There are very many instructions with this primary opcode
1524 * introduced in the ISA as early as v2.03. However, the ones
1525 * we currently emulate were all introduced with ISA 3.0
1527 if (!cpu_has_feature(CPU_FTR_ARCH_300
))
1528 goto unknown_opcode
;
1530 switch (word
& 0x3f) {
1531 case 48: /* maddhd */
1532 asm volatile(PPC_MADDHD(%0, %1, %2, %3) :
1533 "=r" (op
->val
) : "r" (regs
->gpr
[ra
]),
1534 "r" (regs
->gpr
[rb
]), "r" (regs
->gpr
[rc
]));
1537 case 49: /* maddhdu */
1538 asm volatile(PPC_MADDHDU(%0, %1, %2, %3) :
1539 "=r" (op
->val
) : "r" (regs
->gpr
[ra
]),
1540 "r" (regs
->gpr
[rb
]), "r" (regs
->gpr
[rc
]));
1543 case 51: /* maddld */
1544 asm volatile(PPC_MADDLD(%0, %1, %2, %3) :
1545 "=r" (op
->val
) : "r" (regs
->gpr
[ra
]),
1546 "r" (regs
->gpr
[rb
]), "r" (regs
->gpr
[rc
]));
1551 * There are other instructions from ISA 3.0 with the same
1552 * primary opcode which do not have emulation support yet.
1554 goto unknown_opcode
;
1558 op
->val
= regs
->gpr
[ra
] * (short) word
;
1561 case 8: /* subfic */
1563 add_with_carry(regs
, op
, rd
, ~regs
->gpr
[ra
], imm
, 1);
1566 case 10: /* cmpli */
1567 imm
= (unsigned short) word
;
1568 val
= regs
->gpr
[ra
];
1569 #ifdef __powerpc64__
1571 val
= (unsigned int) val
;
1573 do_cmp_unsigned(regs
, op
, val
, imm
, rd
>> 2);
1578 val
= regs
->gpr
[ra
];
1579 #ifdef __powerpc64__
1583 do_cmp_signed(regs
, op
, val
, imm
, rd
>> 2);
1586 case 12: /* addic */
1588 add_with_carry(regs
, op
, rd
, regs
->gpr
[ra
], imm
, 0);
1591 case 13: /* addic. */
1593 add_with_carry(regs
, op
, rd
, regs
->gpr
[ra
], imm
, 0);
1600 imm
+= regs
->gpr
[ra
];
1604 case 15: /* addis */
1605 imm
= ((short) word
) << 16;
1607 imm
+= regs
->gpr
[ra
];
1612 if (((word
>> 1) & 0x1f) == 2) {
1614 if (!cpu_has_feature(CPU_FTR_ARCH_300
))
1615 goto unknown_opcode
;
1616 imm
= (short) (word
& 0xffc1); /* d0 + d2 fields */
1617 imm
|= (word
>> 15) & 0x3e; /* d1 field */
1618 op
->val
= regs
->nip
+ (imm
<< 16) + 4;
1624 case 20: /* rlwimi */
1625 mb
= (word
>> 6) & 0x1f;
1626 me
= (word
>> 1) & 0x1f;
1627 val
= DATA32(regs
->gpr
[rd
]);
1628 imm
= MASK32(mb
, me
);
1629 op
->val
= (regs
->gpr
[ra
] & ~imm
) | (ROTATE(val
, rb
) & imm
);
1632 case 21: /* rlwinm */
1633 mb
= (word
>> 6) & 0x1f;
1634 me
= (word
>> 1) & 0x1f;
1635 val
= DATA32(regs
->gpr
[rd
]);
1636 op
->val
= ROTATE(val
, rb
) & MASK32(mb
, me
);
1639 case 23: /* rlwnm */
1640 mb
= (word
>> 6) & 0x1f;
1641 me
= (word
>> 1) & 0x1f;
1642 rb
= regs
->gpr
[rb
] & 0x1f;
1643 val
= DATA32(regs
->gpr
[rd
]);
1644 op
->val
= ROTATE(val
, rb
) & MASK32(mb
, me
);
1648 op
->val
= regs
->gpr
[rd
] | (unsigned short) word
;
1649 goto logical_done_nocc
;
1652 imm
= (unsigned short) word
;
1653 op
->val
= regs
->gpr
[rd
] | (imm
<< 16);
1654 goto logical_done_nocc
;
1657 op
->val
= regs
->gpr
[rd
] ^ (unsigned short) word
;
1658 goto logical_done_nocc
;
1660 case 27: /* xoris */
1661 imm
= (unsigned short) word
;
1662 op
->val
= regs
->gpr
[rd
] ^ (imm
<< 16);
1663 goto logical_done_nocc
;
1665 case 28: /* andi. */
1666 op
->val
= regs
->gpr
[rd
] & (unsigned short) word
;
1668 goto logical_done_nocc
;
1670 case 29: /* andis. */
1671 imm
= (unsigned short) word
;
1672 op
->val
= regs
->gpr
[rd
] & (imm
<< 16);
1674 goto logical_done_nocc
;
1676 #ifdef __powerpc64__
1678 mb
= ((word
>> 6) & 0x1f) | (word
& 0x20);
1679 val
= regs
->gpr
[rd
];
1680 if ((word
& 0x10) == 0) {
1681 sh
= rb
| ((word
& 2) << 4);
1682 val
= ROTATE(val
, sh
);
1683 switch ((word
>> 2) & 3) {
1684 case 0: /* rldicl */
1685 val
&= MASK64_L(mb
);
1687 case 1: /* rldicr */
1688 val
&= MASK64_R(mb
);
1691 val
&= MASK64(mb
, 63 - sh
);
1693 case 3: /* rldimi */
1694 imm
= MASK64(mb
, 63 - sh
);
1695 val
= (regs
->gpr
[ra
] & ~imm
) |
1701 sh
= regs
->gpr
[rb
] & 0x3f;
1702 val
= ROTATE(val
, sh
);
1703 switch ((word
>> 1) & 7) {
1705 op
->val
= val
& MASK64_L(mb
);
1708 op
->val
= val
& MASK64_R(mb
);
1713 op
->type
= UNKNOWN
; /* illegal instruction */
1717 /* isel occupies 32 minor opcodes */
1718 if (((word
>> 1) & 0x1f) == 15) {
1719 mb
= (word
>> 6) & 0x1f; /* bc field */
1720 val
= (regs
->ccr
>> (31 - mb
)) & 1;
1721 val2
= (ra
) ? regs
->gpr
[ra
] : 0;
1723 op
->val
= (val
) ? val2
: regs
->gpr
[rb
];
1727 switch ((word
>> 1) & 0x3ff) {
1730 (rd
& trap_compare((int)regs
->gpr
[ra
],
1731 (int)regs
->gpr
[rb
])))
1734 #ifdef __powerpc64__
1736 if (rd
& trap_compare(regs
->gpr
[ra
], regs
->gpr
[rb
]))
1740 case 83: /* mfmsr */
1741 if (user_mode(regs
))
1746 case 146: /* mtmsr */
1747 if (user_mode(regs
))
1751 op
->val
= 0xffffffff & ~(MSR_ME
| MSR_LE
);
1754 case 178: /* mtmsrd */
1755 if (user_mode(regs
))
1759 /* only MSR_EE and MSR_RI get changed if bit 15 set */
1760 /* mtmsrd doesn't change MSR_HV, MSR_ME or MSR_LE */
1761 imm
= (word
& 0x10000)? 0x8002: 0xefffffffffffeffeUL
;
1768 if ((word
>> 20) & 1) {
1770 for (sh
= 0; sh
< 8; ++sh
) {
1771 if (word
& (0x80000 >> sh
))
1776 op
->val
= regs
->ccr
& imm
;
1779 case 128: /* setb */
1780 if (!cpu_has_feature(CPU_FTR_ARCH_300
))
1781 goto unknown_opcode
;
1783 * 'ra' encodes the CR field number (bfa) in the top 3 bits.
1784 * Since each CR field is 4 bits,
1785 * we can simply mask off the bottom two bits (bfa * 4)
1786 * to yield the first bit in the CR field.
1789 /* 'val' stores bits of the CR field (bfa) */
1790 val
= regs
->ccr
>> (CR0_SHIFT
- ra
);
1791 /* checks if the LT bit of CR field (bfa) is set */
1794 /* checks if the GT bit of CR field (bfa) is set */
1801 case 144: /* mtcrf */
1802 op
->type
= COMPUTE
+ SETCC
;
1804 val
= regs
->gpr
[rd
];
1805 op
->ccval
= regs
->ccr
;
1806 for (sh
= 0; sh
< 8; ++sh
) {
1807 if (word
& (0x80000 >> sh
))
1808 op
->ccval
= (op
->ccval
& ~imm
) |
1814 case 339: /* mfspr */
1815 spr
= ((word
>> 16) & 0x1f) | ((word
>> 6) & 0x3e0);
1819 if (spr
== SPRN_XER
|| spr
== SPRN_LR
||
1824 case 467: /* mtspr */
1825 spr
= ((word
>> 16) & 0x1f) | ((word
>> 6) & 0x3e0);
1827 op
->val
= regs
->gpr
[rd
];
1829 if (spr
== SPRN_XER
|| spr
== SPRN_LR
||
1835 * Compare instructions
1838 val
= regs
->gpr
[ra
];
1839 val2
= regs
->gpr
[rb
];
1840 #ifdef __powerpc64__
1841 if ((rd
& 1) == 0) {
1842 /* word (32-bit) compare */
1847 do_cmp_signed(regs
, op
, val
, val2
, rd
>> 2);
1851 val
= regs
->gpr
[ra
];
1852 val2
= regs
->gpr
[rb
];
1853 #ifdef __powerpc64__
1854 if ((rd
& 1) == 0) {
1855 /* word (32-bit) compare */
1856 val
= (unsigned int) val
;
1857 val2
= (unsigned int) val2
;
1860 do_cmp_unsigned(regs
, op
, val
, val2
, rd
>> 2);
1863 case 508: /* cmpb */
1864 do_cmpb(regs
, op
, regs
->gpr
[rd
], regs
->gpr
[rb
]);
1865 goto logical_done_nocc
;
1868 * Arithmetic instructions
1871 add_with_carry(regs
, op
, rd
, ~regs
->gpr
[ra
],
1874 #ifdef __powerpc64__
1875 case 9: /* mulhdu */
1876 asm("mulhdu %0,%1,%2" : "=r" (op
->val
) :
1877 "r" (regs
->gpr
[ra
]), "r" (regs
->gpr
[rb
]));
1881 add_with_carry(regs
, op
, rd
, regs
->gpr
[ra
],
1885 case 11: /* mulhwu */
1886 asm("mulhwu %0,%1,%2" : "=r" (op
->val
) :
1887 "r" (regs
->gpr
[ra
]), "r" (regs
->gpr
[rb
]));
1891 op
->val
= regs
->gpr
[rb
] - regs
->gpr
[ra
];
1893 #ifdef __powerpc64__
1894 case 73: /* mulhd */
1895 asm("mulhd %0,%1,%2" : "=r" (op
->val
) :
1896 "r" (regs
->gpr
[ra
]), "r" (regs
->gpr
[rb
]));
1899 case 75: /* mulhw */
1900 asm("mulhw %0,%1,%2" : "=r" (op
->val
) :
1901 "r" (regs
->gpr
[ra
]), "r" (regs
->gpr
[rb
]));
1905 op
->val
= -regs
->gpr
[ra
];
1908 case 136: /* subfe */
1909 add_with_carry(regs
, op
, rd
, ~regs
->gpr
[ra
],
1910 regs
->gpr
[rb
], regs
->xer
& XER_CA
);
1913 case 138: /* adde */
1914 add_with_carry(regs
, op
, rd
, regs
->gpr
[ra
],
1915 regs
->gpr
[rb
], regs
->xer
& XER_CA
);
1918 case 200: /* subfze */
1919 add_with_carry(regs
, op
, rd
, ~regs
->gpr
[ra
], 0L,
1920 regs
->xer
& XER_CA
);
1923 case 202: /* addze */
1924 add_with_carry(regs
, op
, rd
, regs
->gpr
[ra
], 0L,
1925 regs
->xer
& XER_CA
);
1928 case 232: /* subfme */
1929 add_with_carry(regs
, op
, rd
, ~regs
->gpr
[ra
], -1L,
1930 regs
->xer
& XER_CA
);
1932 #ifdef __powerpc64__
1933 case 233: /* mulld */
1934 op
->val
= regs
->gpr
[ra
] * regs
->gpr
[rb
];
1937 case 234: /* addme */
1938 add_with_carry(regs
, op
, rd
, regs
->gpr
[ra
], -1L,
1939 regs
->xer
& XER_CA
);
1942 case 235: /* mullw */
1943 op
->val
= (long)(int) regs
->gpr
[ra
] *
1944 (int) regs
->gpr
[rb
];
1947 #ifdef __powerpc64__
1948 case 265: /* modud */
1949 if (!cpu_has_feature(CPU_FTR_ARCH_300
))
1950 goto unknown_opcode
;
1951 op
->val
= regs
->gpr
[ra
] % regs
->gpr
[rb
];
1955 op
->val
= regs
->gpr
[ra
] + regs
->gpr
[rb
];
1958 case 267: /* moduw */
1959 if (!cpu_has_feature(CPU_FTR_ARCH_300
))
1960 goto unknown_opcode
;
1961 op
->val
= (unsigned int) regs
->gpr
[ra
] %
1962 (unsigned int) regs
->gpr
[rb
];
1964 #ifdef __powerpc64__
1965 case 457: /* divdu */
1966 op
->val
= regs
->gpr
[ra
] / regs
->gpr
[rb
];
1969 case 459: /* divwu */
1970 op
->val
= (unsigned int) regs
->gpr
[ra
] /
1971 (unsigned int) regs
->gpr
[rb
];
1973 #ifdef __powerpc64__
1974 case 489: /* divd */
1975 op
->val
= (long int) regs
->gpr
[ra
] /
1976 (long int) regs
->gpr
[rb
];
1979 case 491: /* divw */
1980 op
->val
= (int) regs
->gpr
[ra
] /
1981 (int) regs
->gpr
[rb
];
1983 #ifdef __powerpc64__
1984 case 425: /* divde[.] */
1985 asm volatile(PPC_DIVDE(%0, %1, %2) :
1986 "=r" (op
->val
) : "r" (regs
->gpr
[ra
]),
1987 "r" (regs
->gpr
[rb
]));
1989 case 393: /* divdeu[.] */
1990 asm volatile(PPC_DIVDEU(%0, %1, %2) :
1991 "=r" (op
->val
) : "r" (regs
->gpr
[ra
]),
1992 "r" (regs
->gpr
[rb
]));
1995 case 755: /* darn */
1996 if (!cpu_has_feature(CPU_FTR_ARCH_300
))
1997 goto unknown_opcode
;
2000 /* 32-bit conditioned */
2001 asm volatile(PPC_DARN(%0, 0) : "=r" (op
->val
));
2005 /* 64-bit conditioned */
2006 asm volatile(PPC_DARN(%0, 1) : "=r" (op
->val
));
2011 asm volatile(PPC_DARN(%0, 2) : "=r" (op
->val
));
2015 goto unknown_opcode
;
2016 #ifdef __powerpc64__
2017 case 777: /* modsd */
2018 if (!cpu_has_feature(CPU_FTR_ARCH_300
))
2019 goto unknown_opcode
;
2020 op
->val
= (long int) regs
->gpr
[ra
] %
2021 (long int) regs
->gpr
[rb
];
2024 case 779: /* modsw */
2025 if (!cpu_has_feature(CPU_FTR_ARCH_300
))
2026 goto unknown_opcode
;
2027 op
->val
= (int) regs
->gpr
[ra
] %
2028 (int) regs
->gpr
[rb
];
2033 * Logical instructions
2035 case 26: /* cntlzw */
2036 val
= (unsigned int) regs
->gpr
[rd
];
2037 op
->val
= ( val
? __builtin_clz(val
) : 32 );
2039 #ifdef __powerpc64__
2040 case 58: /* cntlzd */
2041 val
= regs
->gpr
[rd
];
2042 op
->val
= ( val
? __builtin_clzl(val
) : 64 );
2046 op
->val
= regs
->gpr
[rd
] & regs
->gpr
[rb
];
2050 op
->val
= regs
->gpr
[rd
] & ~regs
->gpr
[rb
];
2053 case 122: /* popcntb */
2054 do_popcnt(regs
, op
, regs
->gpr
[rd
], 8);
2055 goto logical_done_nocc
;
2058 op
->val
= ~(regs
->gpr
[rd
] | regs
->gpr
[rb
]);
2061 case 154: /* prtyw */
2062 do_prty(regs
, op
, regs
->gpr
[rd
], 32);
2063 goto logical_done_nocc
;
2065 case 186: /* prtyd */
2066 do_prty(regs
, op
, regs
->gpr
[rd
], 64);
2067 goto logical_done_nocc
;
2069 case 252: /* bpermd */
2070 do_bpermd(regs
, op
, regs
->gpr
[rd
], regs
->gpr
[rb
]);
2071 goto logical_done_nocc
;
2074 op
->val
= ~(regs
->gpr
[rd
] ^ regs
->gpr
[rb
]);
2078 op
->val
= regs
->gpr
[rd
] ^ regs
->gpr
[rb
];
2081 case 378: /* popcntw */
2082 do_popcnt(regs
, op
, regs
->gpr
[rd
], 32);
2083 goto logical_done_nocc
;
2086 op
->val
= regs
->gpr
[rd
] | ~regs
->gpr
[rb
];
2090 op
->val
= regs
->gpr
[rd
] | regs
->gpr
[rb
];
2093 case 476: /* nand */
2094 op
->val
= ~(regs
->gpr
[rd
] & regs
->gpr
[rb
]);
2097 case 506: /* popcntd */
2098 do_popcnt(regs
, op
, regs
->gpr
[rd
], 64);
2099 goto logical_done_nocc
;
2101 case 538: /* cnttzw */
2102 if (!cpu_has_feature(CPU_FTR_ARCH_300
))
2103 goto unknown_opcode
;
2104 val
= (unsigned int) regs
->gpr
[rd
];
2105 op
->val
= (val
? __builtin_ctz(val
) : 32);
2107 #ifdef __powerpc64__
2108 case 570: /* cnttzd */
2109 if (!cpu_has_feature(CPU_FTR_ARCH_300
))
2110 goto unknown_opcode
;
2111 val
= regs
->gpr
[rd
];
2112 op
->val
= (val
? __builtin_ctzl(val
) : 64);
2115 case 922: /* extsh */
2116 op
->val
= (signed short) regs
->gpr
[rd
];
2119 case 954: /* extsb */
2120 op
->val
= (signed char) regs
->gpr
[rd
];
2122 #ifdef __powerpc64__
2123 case 986: /* extsw */
2124 op
->val
= (signed int) regs
->gpr
[rd
];
2129 * Shift instructions
2132 sh
= regs
->gpr
[rb
] & 0x3f;
2134 op
->val
= (regs
->gpr
[rd
] << sh
) & 0xffffffffUL
;
2140 sh
= regs
->gpr
[rb
] & 0x3f;
2142 op
->val
= (regs
->gpr
[rd
] & 0xffffffffUL
) >> sh
;
2147 case 792: /* sraw */
2148 op
->type
= COMPUTE
+ SETREG
+ SETXER
;
2149 sh
= regs
->gpr
[rb
] & 0x3f;
2150 ival
= (signed int) regs
->gpr
[rd
];
2151 op
->val
= ival
>> (sh
< 32 ? sh
: 31);
2152 op
->xerval
= regs
->xer
;
2153 if (ival
< 0 && (sh
>= 32 || (ival
& ((1ul << sh
) - 1)) != 0))
2154 op
->xerval
|= XER_CA
;
2156 op
->xerval
&= ~XER_CA
;
2157 set_ca32(op
, op
->xerval
& XER_CA
);
2160 case 824: /* srawi */
2161 op
->type
= COMPUTE
+ SETREG
+ SETXER
;
2163 ival
= (signed int) regs
->gpr
[rd
];
2164 op
->val
= ival
>> sh
;
2165 op
->xerval
= regs
->xer
;
2166 if (ival
< 0 && (ival
& ((1ul << sh
) - 1)) != 0)
2167 op
->xerval
|= XER_CA
;
2169 op
->xerval
&= ~XER_CA
;
2170 set_ca32(op
, op
->xerval
& XER_CA
);
2173 #ifdef __powerpc64__
2175 sh
= regs
->gpr
[rb
] & 0x7f;
2177 op
->val
= regs
->gpr
[rd
] << sh
;
2183 sh
= regs
->gpr
[rb
] & 0x7f;
2185 op
->val
= regs
->gpr
[rd
] >> sh
;
2190 case 794: /* srad */
2191 op
->type
= COMPUTE
+ SETREG
+ SETXER
;
2192 sh
= regs
->gpr
[rb
] & 0x7f;
2193 ival
= (signed long int) regs
->gpr
[rd
];
2194 op
->val
= ival
>> (sh
< 64 ? sh
: 63);
2195 op
->xerval
= regs
->xer
;
2196 if (ival
< 0 && (sh
>= 64 || (ival
& ((1ul << sh
) - 1)) != 0))
2197 op
->xerval
|= XER_CA
;
2199 op
->xerval
&= ~XER_CA
;
2200 set_ca32(op
, op
->xerval
& XER_CA
);
2203 case 826: /* sradi with sh_5 = 0 */
2204 case 827: /* sradi with sh_5 = 1 */
2205 op
->type
= COMPUTE
+ SETREG
+ SETXER
;
2206 sh
= rb
| ((word
& 2) << 4);
2207 ival
= (signed long int) regs
->gpr
[rd
];
2208 op
->val
= ival
>> sh
;
2209 op
->xerval
= regs
->xer
;
2210 if (ival
< 0 && (ival
& ((1ul << sh
) - 1)) != 0)
2211 op
->xerval
|= XER_CA
;
2213 op
->xerval
&= ~XER_CA
;
2214 set_ca32(op
, op
->xerval
& XER_CA
);
2217 case 890: /* extswsli with sh_5 = 0 */
2218 case 891: /* extswsli with sh_5 = 1 */
2219 if (!cpu_has_feature(CPU_FTR_ARCH_300
))
2220 goto unknown_opcode
;
2221 op
->type
= COMPUTE
+ SETREG
;
2222 sh
= rb
| ((word
& 2) << 4);
2223 val
= (signed int) regs
->gpr
[rd
];
2225 op
->val
= ROTATE(val
, sh
) & MASK64(0, 63 - sh
);
2230 #endif /* __powerpc64__ */
2233 * Cache instructions
2235 case 54: /* dcbst */
2236 op
->type
= MKOP(CACHEOP
, DCBST
, 0);
2237 op
->ea
= xform_ea(word
, regs
);
2241 op
->type
= MKOP(CACHEOP
, DCBF
, 0);
2242 op
->ea
= xform_ea(word
, regs
);
2245 case 246: /* dcbtst */
2246 op
->type
= MKOP(CACHEOP
, DCBTST
, 0);
2247 op
->ea
= xform_ea(word
, regs
);
2251 case 278: /* dcbt */
2252 op
->type
= MKOP(CACHEOP
, DCBTST
, 0);
2253 op
->ea
= xform_ea(word
, regs
);
2257 case 982: /* icbi */
2258 op
->type
= MKOP(CACHEOP
, ICBI
, 0);
2259 op
->ea
= xform_ea(word
, regs
);
2262 case 1014: /* dcbz */
2263 op
->type
= MKOP(CACHEOP
, DCBZ
, 0);
2264 op
->ea
= xform_ea(word
, regs
);
2274 op
->update_reg
= ra
;
2276 op
->val
= regs
->gpr
[rd
];
2277 u
= (word
>> 20) & UPDATE
;
2283 op
->ea
= xform_ea(word
, regs
);
2284 switch ((word
>> 1) & 0x3ff) {
2285 case 20: /* lwarx */
2286 op
->type
= MKOP(LARX
, 0, 4);
2289 case 150: /* stwcx. */
2290 op
->type
= MKOP(STCX
, 0, 4);
2293 #ifdef CONFIG_PPC_HAS_LBARX_LHARX
2294 case 52: /* lbarx */
2295 op
->type
= MKOP(LARX
, 0, 1);
2298 case 694: /* stbcx. */
2299 op
->type
= MKOP(STCX
, 0, 1);
2302 case 116: /* lharx */
2303 op
->type
= MKOP(LARX
, 0, 2);
2306 case 726: /* sthcx. */
2307 op
->type
= MKOP(STCX
, 0, 2);
2310 #ifdef __powerpc64__
2311 case 84: /* ldarx */
2312 op
->type
= MKOP(LARX
, 0, 8);
2315 case 214: /* stdcx. */
2316 op
->type
= MKOP(STCX
, 0, 8);
2319 case 276: /* lqarx */
2320 if (!((rd
& 1) || rd
== ra
|| rd
== rb
))
2321 op
->type
= MKOP(LARX
, 0, 16);
2324 case 182: /* stqcx. */
2326 op
->type
= MKOP(STCX
, 0, 16);
2331 case 55: /* lwzux */
2332 op
->type
= MKOP(LOAD
, u
, 4);
2336 case 119: /* lbzux */
2337 op
->type
= MKOP(LOAD
, u
, 1);
2340 #ifdef CONFIG_ALTIVEC
2342 * Note: for the load/store vector element instructions,
2343 * bits of the EA say which field of the VMX register to use.
2346 op
->type
= MKOP(LOAD_VMX
, 0, 1);
2347 op
->element_size
= 1;
2350 case 39: /* lvehx */
2351 op
->type
= MKOP(LOAD_VMX
, 0, 2);
2352 op
->element_size
= 2;
2355 case 71: /* lvewx */
2356 op
->type
= MKOP(LOAD_VMX
, 0, 4);
2357 op
->element_size
= 4;
2361 case 359: /* lvxl */
2362 op
->type
= MKOP(LOAD_VMX
, 0, 16);
2363 op
->element_size
= 16;
2366 case 135: /* stvebx */
2367 op
->type
= MKOP(STORE_VMX
, 0, 1);
2368 op
->element_size
= 1;
2371 case 167: /* stvehx */
2372 op
->type
= MKOP(STORE_VMX
, 0, 2);
2373 op
->element_size
= 2;
2376 case 199: /* stvewx */
2377 op
->type
= MKOP(STORE_VMX
, 0, 4);
2378 op
->element_size
= 4;
2381 case 231: /* stvx */
2382 case 487: /* stvxl */
2383 op
->type
= MKOP(STORE_VMX
, 0, 16);
2385 #endif /* CONFIG_ALTIVEC */
2387 #ifdef __powerpc64__
2390 op
->type
= MKOP(LOAD
, u
, 8);
2393 case 149: /* stdx */
2394 case 181: /* stdux */
2395 op
->type
= MKOP(STORE
, u
, 8);
2399 case 151: /* stwx */
2400 case 183: /* stwux */
2401 op
->type
= MKOP(STORE
, u
, 4);
2404 case 215: /* stbx */
2405 case 247: /* stbux */
2406 op
->type
= MKOP(STORE
, u
, 1);
2409 case 279: /* lhzx */
2410 case 311: /* lhzux */
2411 op
->type
= MKOP(LOAD
, u
, 2);
2414 #ifdef __powerpc64__
2415 case 341: /* lwax */
2416 case 373: /* lwaux */
2417 op
->type
= MKOP(LOAD
, SIGNEXT
| u
, 4);
2421 case 343: /* lhax */
2422 case 375: /* lhaux */
2423 op
->type
= MKOP(LOAD
, SIGNEXT
| u
, 2);
2426 case 407: /* sthx */
2427 case 439: /* sthux */
2428 op
->type
= MKOP(STORE
, u
, 2);
2431 #ifdef __powerpc64__
2432 case 532: /* ldbrx */
2433 op
->type
= MKOP(LOAD
, BYTEREV
, 8);
2437 case 533: /* lswx */
2438 op
->type
= MKOP(LOAD_MULTI
, 0, regs
->xer
& 0x7f);
2441 case 534: /* lwbrx */
2442 op
->type
= MKOP(LOAD
, BYTEREV
, 4);
2445 case 597: /* lswi */
2447 rb
= 32; /* # bytes to load */
2448 op
->type
= MKOP(LOAD_MULTI
, 0, rb
);
2449 op
->ea
= ra
? regs
->gpr
[ra
] : 0;
2452 #ifdef CONFIG_PPC_FPU
2453 case 535: /* lfsx */
2454 case 567: /* lfsux */
2455 op
->type
= MKOP(LOAD_FP
, u
| FPCONV
, 4);
2458 case 599: /* lfdx */
2459 case 631: /* lfdux */
2460 op
->type
= MKOP(LOAD_FP
, u
, 8);
2463 case 663: /* stfsx */
2464 case 695: /* stfsux */
2465 op
->type
= MKOP(STORE_FP
, u
| FPCONV
, 4);
2468 case 727: /* stfdx */
2469 case 759: /* stfdux */
2470 op
->type
= MKOP(STORE_FP
, u
, 8);
2473 #ifdef __powerpc64__
2474 case 791: /* lfdpx */
2475 op
->type
= MKOP(LOAD_FP
, 0, 16);
2478 case 855: /* lfiwax */
2479 op
->type
= MKOP(LOAD_FP
, SIGNEXT
, 4);
2482 case 887: /* lfiwzx */
2483 op
->type
= MKOP(LOAD_FP
, 0, 4);
2486 case 919: /* stfdpx */
2487 op
->type
= MKOP(STORE_FP
, 0, 16);
2490 case 983: /* stfiwx */
2491 op
->type
= MKOP(STORE_FP
, 0, 4);
2493 #endif /* __powerpc64 */
2494 #endif /* CONFIG_PPC_FPU */
2496 #ifdef __powerpc64__
2497 case 660: /* stdbrx */
2498 op
->type
= MKOP(STORE
, BYTEREV
, 8);
2499 op
->val
= byterev_8(regs
->gpr
[rd
]);
2503 case 661: /* stswx */
2504 op
->type
= MKOP(STORE_MULTI
, 0, regs
->xer
& 0x7f);
2507 case 662: /* stwbrx */
2508 op
->type
= MKOP(STORE
, BYTEREV
, 4);
2509 op
->val
= byterev_4(regs
->gpr
[rd
]);
2512 case 725: /* stswi */
2514 rb
= 32; /* # bytes to store */
2515 op
->type
= MKOP(STORE_MULTI
, 0, rb
);
2516 op
->ea
= ra
? regs
->gpr
[ra
] : 0;
2519 case 790: /* lhbrx */
2520 op
->type
= MKOP(LOAD
, BYTEREV
, 2);
2523 case 918: /* sthbrx */
2524 op
->type
= MKOP(STORE
, BYTEREV
, 2);
2525 op
->val
= byterev_2(regs
->gpr
[rd
]);
2529 case 12: /* lxsiwzx */
2530 op
->reg
= rd
| ((word
& 1) << 5);
2531 op
->type
= MKOP(LOAD_VSX
, 0, 4);
2532 op
->element_size
= 8;
2535 case 76: /* lxsiwax */
2536 op
->reg
= rd
| ((word
& 1) << 5);
2537 op
->type
= MKOP(LOAD_VSX
, SIGNEXT
, 4);
2538 op
->element_size
= 8;
2541 case 140: /* stxsiwx */
2542 op
->reg
= rd
| ((word
& 1) << 5);
2543 op
->type
= MKOP(STORE_VSX
, 0, 4);
2544 op
->element_size
= 8;
2547 case 268: /* lxvx */
2548 if (!cpu_has_feature(CPU_FTR_ARCH_300
))
2549 goto unknown_opcode
;
2550 op
->reg
= rd
| ((word
& 1) << 5);
2551 op
->type
= MKOP(LOAD_VSX
, 0, 16);
2552 op
->element_size
= 16;
2553 op
->vsx_flags
= VSX_CHECK_VEC
;
2556 case 269: /* lxvl */
2557 case 301: { /* lxvll */
2559 if (!cpu_has_feature(CPU_FTR_ARCH_300
))
2560 goto unknown_opcode
;
2561 op
->reg
= rd
| ((word
& 1) << 5);
2562 op
->ea
= ra
? regs
->gpr
[ra
] : 0;
2563 nb
= regs
->gpr
[rb
] & 0xff;
2566 op
->type
= MKOP(LOAD_VSX
, 0, nb
);
2567 op
->element_size
= 16;
2568 op
->vsx_flags
= ((word
& 0x20) ? VSX_LDLEFT
: 0) |
2572 case 332: /* lxvdsx */
2573 op
->reg
= rd
| ((word
& 1) << 5);
2574 op
->type
= MKOP(LOAD_VSX
, 0, 8);
2575 op
->element_size
= 8;
2576 op
->vsx_flags
= VSX_SPLAT
;
2579 case 333: /* lxvpx */
2580 if (!cpu_has_feature(CPU_FTR_ARCH_31
))
2581 goto unknown_opcode
;
2582 op
->reg
= VSX_REGISTER_XTP(rd
);
2583 op
->type
= MKOP(LOAD_VSX
, 0, 32);
2584 op
->element_size
= 32;
2587 case 364: /* lxvwsx */
2588 if (!cpu_has_feature(CPU_FTR_ARCH_300
))
2589 goto unknown_opcode
;
2590 op
->reg
= rd
| ((word
& 1) << 5);
2591 op
->type
= MKOP(LOAD_VSX
, 0, 4);
2592 op
->element_size
= 4;
2593 op
->vsx_flags
= VSX_SPLAT
| VSX_CHECK_VEC
;
2596 case 396: /* stxvx */
2597 if (!cpu_has_feature(CPU_FTR_ARCH_300
))
2598 goto unknown_opcode
;
2599 op
->reg
= rd
| ((word
& 1) << 5);
2600 op
->type
= MKOP(STORE_VSX
, 0, 16);
2601 op
->element_size
= 16;
2602 op
->vsx_flags
= VSX_CHECK_VEC
;
2605 case 397: /* stxvl */
2606 case 429: { /* stxvll */
2608 if (!cpu_has_feature(CPU_FTR_ARCH_300
))
2609 goto unknown_opcode
;
2610 op
->reg
= rd
| ((word
& 1) << 5);
2611 op
->ea
= ra
? regs
->gpr
[ra
] : 0;
2612 nb
= regs
->gpr
[rb
] & 0xff;
2615 op
->type
= MKOP(STORE_VSX
, 0, nb
);
2616 op
->element_size
= 16;
2617 op
->vsx_flags
= ((word
& 0x20) ? VSX_LDLEFT
: 0) |
2621 case 461: /* stxvpx */
2622 if (!cpu_has_feature(CPU_FTR_ARCH_31
))
2623 goto unknown_opcode
;
2624 op
->reg
= VSX_REGISTER_XTP(rd
);
2625 op
->type
= MKOP(STORE_VSX
, 0, 32);
2626 op
->element_size
= 32;
2628 case 524: /* lxsspx */
2629 op
->reg
= rd
| ((word
& 1) << 5);
2630 op
->type
= MKOP(LOAD_VSX
, 0, 4);
2631 op
->element_size
= 8;
2632 op
->vsx_flags
= VSX_FPCONV
;
2635 case 588: /* lxsdx */
2636 op
->reg
= rd
| ((word
& 1) << 5);
2637 op
->type
= MKOP(LOAD_VSX
, 0, 8);
2638 op
->element_size
= 8;
2641 case 652: /* stxsspx */
2642 op
->reg
= rd
| ((word
& 1) << 5);
2643 op
->type
= MKOP(STORE_VSX
, 0, 4);
2644 op
->element_size
= 8;
2645 op
->vsx_flags
= VSX_FPCONV
;
2648 case 716: /* stxsdx */
2649 op
->reg
= rd
| ((word
& 1) << 5);
2650 op
->type
= MKOP(STORE_VSX
, 0, 8);
2651 op
->element_size
= 8;
2654 case 780: /* lxvw4x */
2655 op
->reg
= rd
| ((word
& 1) << 5);
2656 op
->type
= MKOP(LOAD_VSX
, 0, 16);
2657 op
->element_size
= 4;
2660 case 781: /* lxsibzx */
2661 if (!cpu_has_feature(CPU_FTR_ARCH_300
))
2662 goto unknown_opcode
;
2663 op
->reg
= rd
| ((word
& 1) << 5);
2664 op
->type
= MKOP(LOAD_VSX
, 0, 1);
2665 op
->element_size
= 8;
2666 op
->vsx_flags
= VSX_CHECK_VEC
;
2669 case 812: /* lxvh8x */
2670 if (!cpu_has_feature(CPU_FTR_ARCH_300
))
2671 goto unknown_opcode
;
2672 op
->reg
= rd
| ((word
& 1) << 5);
2673 op
->type
= MKOP(LOAD_VSX
, 0, 16);
2674 op
->element_size
= 2;
2675 op
->vsx_flags
= VSX_CHECK_VEC
;
2678 case 813: /* lxsihzx */
2679 if (!cpu_has_feature(CPU_FTR_ARCH_300
))
2680 goto unknown_opcode
;
2681 op
->reg
= rd
| ((word
& 1) << 5);
2682 op
->type
= MKOP(LOAD_VSX
, 0, 2);
2683 op
->element_size
= 8;
2684 op
->vsx_flags
= VSX_CHECK_VEC
;
2687 case 844: /* lxvd2x */
2688 op
->reg
= rd
| ((word
& 1) << 5);
2689 op
->type
= MKOP(LOAD_VSX
, 0, 16);
2690 op
->element_size
= 8;
2693 case 876: /* lxvb16x */
2694 if (!cpu_has_feature(CPU_FTR_ARCH_300
))
2695 goto unknown_opcode
;
2696 op
->reg
= rd
| ((word
& 1) << 5);
2697 op
->type
= MKOP(LOAD_VSX
, 0, 16);
2698 op
->element_size
= 1;
2699 op
->vsx_flags
= VSX_CHECK_VEC
;
2702 case 908: /* stxvw4x */
2703 op
->reg
= rd
| ((word
& 1) << 5);
2704 op
->type
= MKOP(STORE_VSX
, 0, 16);
2705 op
->element_size
= 4;
2708 case 909: /* stxsibx */
2709 if (!cpu_has_feature(CPU_FTR_ARCH_300
))
2710 goto unknown_opcode
;
2711 op
->reg
= rd
| ((word
& 1) << 5);
2712 op
->type
= MKOP(STORE_VSX
, 0, 1);
2713 op
->element_size
= 8;
2714 op
->vsx_flags
= VSX_CHECK_VEC
;
2717 case 940: /* stxvh8x */
2718 if (!cpu_has_feature(CPU_FTR_ARCH_300
))
2719 goto unknown_opcode
;
2720 op
->reg
= rd
| ((word
& 1) << 5);
2721 op
->type
= MKOP(STORE_VSX
, 0, 16);
2722 op
->element_size
= 2;
2723 op
->vsx_flags
= VSX_CHECK_VEC
;
2726 case 941: /* stxsihx */
2727 if (!cpu_has_feature(CPU_FTR_ARCH_300
))
2728 goto unknown_opcode
;
2729 op
->reg
= rd
| ((word
& 1) << 5);
2730 op
->type
= MKOP(STORE_VSX
, 0, 2);
2731 op
->element_size
= 8;
2732 op
->vsx_flags
= VSX_CHECK_VEC
;
2735 case 972: /* stxvd2x */
2736 op
->reg
= rd
| ((word
& 1) << 5);
2737 op
->type
= MKOP(STORE_VSX
, 0, 16);
2738 op
->element_size
= 8;
2741 case 1004: /* stxvb16x */
2742 if (!cpu_has_feature(CPU_FTR_ARCH_300
))
2743 goto unknown_opcode
;
2744 op
->reg
= rd
| ((word
& 1) << 5);
2745 op
->type
= MKOP(STORE_VSX
, 0, 16);
2746 op
->element_size
= 1;
2747 op
->vsx_flags
= VSX_CHECK_VEC
;
2750 #endif /* CONFIG_VSX */
2756 op
->type
= MKOP(LOAD
, u
, 4);
2757 op
->ea
= dform_ea(word
, regs
);
2762 op
->type
= MKOP(LOAD
, u
, 1);
2763 op
->ea
= dform_ea(word
, regs
);
2768 op
->type
= MKOP(STORE
, u
, 4);
2769 op
->ea
= dform_ea(word
, regs
);
2774 op
->type
= MKOP(STORE
, u
, 1);
2775 op
->ea
= dform_ea(word
, regs
);
2780 op
->type
= MKOP(LOAD
, u
, 2);
2781 op
->ea
= dform_ea(word
, regs
);
2786 op
->type
= MKOP(LOAD
, SIGNEXT
| u
, 2);
2787 op
->ea
= dform_ea(word
, regs
);
2792 op
->type
= MKOP(STORE
, u
, 2);
2793 op
->ea
= dform_ea(word
, regs
);
2798 break; /* invalid form, ra in range to load */
2799 op
->type
= MKOP(LOAD_MULTI
, 0, 4 * (32 - rd
));
2800 op
->ea
= dform_ea(word
, regs
);
2804 op
->type
= MKOP(STORE_MULTI
, 0, 4 * (32 - rd
));
2805 op
->ea
= dform_ea(word
, regs
);
2808 #ifdef CONFIG_PPC_FPU
2811 op
->type
= MKOP(LOAD_FP
, u
| FPCONV
, 4);
2812 op
->ea
= dform_ea(word
, regs
);
2817 op
->type
= MKOP(LOAD_FP
, u
, 8);
2818 op
->ea
= dform_ea(word
, regs
);
2822 case 53: /* stfsu */
2823 op
->type
= MKOP(STORE_FP
, u
| FPCONV
, 4);
2824 op
->ea
= dform_ea(word
, regs
);
2828 case 55: /* stfdu */
2829 op
->type
= MKOP(STORE_FP
, u
, 8);
2830 op
->ea
= dform_ea(word
, regs
);
2834 #ifdef __powerpc64__
2836 if (!((rd
& 1) || (rd
== ra
)))
2837 op
->type
= MKOP(LOAD
, 0, 16);
2838 op
->ea
= dqform_ea(word
, regs
);
2843 case 57: /* lfdp, lxsd, lxssp */
2844 op
->ea
= dsform_ea(word
, regs
);
2848 break; /* reg must be even */
2849 op
->type
= MKOP(LOAD_FP
, 0, 16);
2852 if (!cpu_has_feature(CPU_FTR_ARCH_300
))
2853 goto unknown_opcode
;
2855 op
->type
= MKOP(LOAD_VSX
, 0, 8);
2856 op
->element_size
= 8;
2857 op
->vsx_flags
= VSX_CHECK_VEC
;
2860 if (!cpu_has_feature(CPU_FTR_ARCH_300
))
2861 goto unknown_opcode
;
2863 op
->type
= MKOP(LOAD_VSX
, 0, 4);
2864 op
->element_size
= 8;
2865 op
->vsx_flags
= VSX_FPCONV
| VSX_CHECK_VEC
;
2869 #endif /* CONFIG_VSX */
2871 #ifdef __powerpc64__
2872 case 58: /* ld[u], lwa */
2873 op
->ea
= dsform_ea(word
, regs
);
2876 op
->type
= MKOP(LOAD
, 0, 8);
2879 op
->type
= MKOP(LOAD
, UPDATE
, 8);
2882 op
->type
= MKOP(LOAD
, SIGNEXT
, 4);
2890 if (!cpu_has_feature(CPU_FTR_ARCH_31
))
2891 goto unknown_opcode
;
2892 op
->ea
= dqform_ea(word
, regs
);
2893 op
->reg
= VSX_REGISTER_XTP(rd
);
2894 op
->element_size
= 32;
2895 switch (word
& 0xf) {
2897 op
->type
= MKOP(LOAD_VSX
, 0, 32);
2900 op
->type
= MKOP(STORE_VSX
, 0, 32);
2905 case 61: /* stfdp, lxv, stxsd, stxssp, stxv */
2907 case 0: /* stfdp with LSB of DS field = 0 */
2908 case 4: /* stfdp with LSB of DS field = 1 */
2909 op
->ea
= dsform_ea(word
, regs
);
2910 op
->type
= MKOP(STORE_FP
, 0, 16);
2914 if (!cpu_has_feature(CPU_FTR_ARCH_300
))
2915 goto unknown_opcode
;
2916 op
->ea
= dqform_ea(word
, regs
);
2919 op
->type
= MKOP(LOAD_VSX
, 0, 16);
2920 op
->element_size
= 16;
2921 op
->vsx_flags
= VSX_CHECK_VEC
;
2924 case 2: /* stxsd with LSB of DS field = 0 */
2925 case 6: /* stxsd with LSB of DS field = 1 */
2926 if (!cpu_has_feature(CPU_FTR_ARCH_300
))
2927 goto unknown_opcode
;
2928 op
->ea
= dsform_ea(word
, regs
);
2930 op
->type
= MKOP(STORE_VSX
, 0, 8);
2931 op
->element_size
= 8;
2932 op
->vsx_flags
= VSX_CHECK_VEC
;
2935 case 3: /* stxssp with LSB of DS field = 0 */
2936 case 7: /* stxssp with LSB of DS field = 1 */
2937 if (!cpu_has_feature(CPU_FTR_ARCH_300
))
2938 goto unknown_opcode
;
2939 op
->ea
= dsform_ea(word
, regs
);
2941 op
->type
= MKOP(STORE_VSX
, 0, 4);
2942 op
->element_size
= 8;
2943 op
->vsx_flags
= VSX_FPCONV
| VSX_CHECK_VEC
;
2947 if (!cpu_has_feature(CPU_FTR_ARCH_300
))
2948 goto unknown_opcode
;
2949 op
->ea
= dqform_ea(word
, regs
);
2952 op
->type
= MKOP(STORE_VSX
, 0, 16);
2953 op
->element_size
= 16;
2954 op
->vsx_flags
= VSX_CHECK_VEC
;
2958 #endif /* CONFIG_VSX */
2960 #ifdef __powerpc64__
2961 case 62: /* std[u] */
2962 op
->ea
= dsform_ea(word
, regs
);
2965 op
->type
= MKOP(STORE
, 0, 8);
2968 op
->type
= MKOP(STORE
, UPDATE
, 8);
2972 op
->type
= MKOP(STORE
, 0, 16);
2976 case 1: /* Prefixed instructions */
2977 if (!cpu_has_feature(CPU_FTR_ARCH_31
))
2978 goto unknown_opcode
;
2980 prefix_r
= GET_PREFIX_R(word
);
2981 ra
= GET_PREFIX_RA(suffix
);
2982 op
->update_reg
= ra
;
2983 rd
= (suffix
>> 21) & 0x1f;
2985 op
->val
= regs
->gpr
[rd
];
2987 suffixopcode
= get_op(suffix
);
2988 prefixtype
= (word
>> 24) & 0x3;
2989 switch (prefixtype
) {
2990 case 0: /* Type 00 Eight-Byte Load/Store */
2993 op
->ea
= mlsd_8lsd_ea(word
, suffix
, regs
);
2994 switch (suffixopcode
) {
2996 op
->type
= MKOP(LOAD
, PREFIXED
| SIGNEXT
, 4);
2999 case 42: /* plxsd */
3001 op
->type
= MKOP(LOAD_VSX
, PREFIXED
, 8);
3002 op
->element_size
= 8;
3003 op
->vsx_flags
= VSX_CHECK_VEC
;
3005 case 43: /* plxssp */
3007 op
->type
= MKOP(LOAD_VSX
, PREFIXED
, 4);
3008 op
->element_size
= 8;
3009 op
->vsx_flags
= VSX_FPCONV
| VSX_CHECK_VEC
;
3011 case 46: /* pstxsd */
3013 op
->type
= MKOP(STORE_VSX
, PREFIXED
, 8);
3014 op
->element_size
= 8;
3015 op
->vsx_flags
= VSX_CHECK_VEC
;
3017 case 47: /* pstxssp */
3019 op
->type
= MKOP(STORE_VSX
, PREFIXED
, 4);
3020 op
->element_size
= 8;
3021 op
->vsx_flags
= VSX_FPCONV
| VSX_CHECK_VEC
;
3023 case 51: /* plxv1 */
3026 case 50: /* plxv0 */
3027 op
->type
= MKOP(LOAD_VSX
, PREFIXED
, 16);
3028 op
->element_size
= 16;
3029 op
->vsx_flags
= VSX_CHECK_VEC
;
3031 case 55: /* pstxv1 */
3034 case 54: /* pstxv0 */
3035 op
->type
= MKOP(STORE_VSX
, PREFIXED
, 16);
3036 op
->element_size
= 16;
3037 op
->vsx_flags
= VSX_CHECK_VEC
;
3039 #endif /* CONFIG_VSX */
3041 op
->type
= MKOP(LOAD
, PREFIXED
, 16);
3044 op
->type
= MKOP(LOAD
, PREFIXED
, 8);
3047 case 58: /* plxvp */
3048 op
->reg
= VSX_REGISTER_XTP(rd
);
3049 op
->type
= MKOP(LOAD_VSX
, PREFIXED
, 32);
3050 op
->element_size
= 32;
3052 #endif /* CONFIG_VSX */
3054 op
->type
= MKOP(STORE
, PREFIXED
, 16);
3057 op
->type
= MKOP(STORE
, PREFIXED
, 8);
3060 case 62: /* pstxvp */
3061 op
->reg
= VSX_REGISTER_XTP(rd
);
3062 op
->type
= MKOP(STORE_VSX
, PREFIXED
, 32);
3063 op
->element_size
= 32;
3065 #endif /* CONFIG_VSX */
3068 case 1: /* Type 01 Eight-Byte Register-to-Register */
3070 case 2: /* Type 10 Modified Load/Store */
3073 op
->ea
= mlsd_8lsd_ea(word
, suffix
, regs
);
3074 switch (suffixopcode
) {
3076 op
->type
= MKOP(LOAD
, PREFIXED
, 4);
3079 op
->type
= MKOP(LOAD
, PREFIXED
, 1);
3082 op
->type
= MKOP(STORE
, PREFIXED
, 4);
3085 op
->type
= MKOP(STORE
, PREFIXED
, 1);
3088 op
->type
= MKOP(LOAD
, PREFIXED
, 2);
3091 op
->type
= MKOP(LOAD
, PREFIXED
| SIGNEXT
, 2);
3094 op
->type
= MKOP(STORE
, PREFIXED
, 2);
3097 op
->type
= MKOP(LOAD_FP
, PREFIXED
| FPCONV
, 4);
3100 op
->type
= MKOP(LOAD_FP
, PREFIXED
, 8);
3102 case 52: /* pstfs */
3103 op
->type
= MKOP(STORE_FP
, PREFIXED
| FPCONV
, 4);
3105 case 54: /* pstfd */
3106 op
->type
= MKOP(STORE_FP
, PREFIXED
, 8);
3110 case 3: /* Type 11 Modified Register-to-Register */
3113 #endif /* __powerpc64__ */
3117 if (OP_IS_LOAD_STORE(op
->type
) && (op
->type
& UPDATE
)) {
3118 switch (GETTYPE(op
->type
)) {
3121 goto unknown_opcode
;
3127 goto unknown_opcode
;
3132 if ((GETTYPE(op
->type
) == LOAD_VSX
||
3133 GETTYPE(op
->type
) == STORE_VSX
) &&
3134 !cpu_has_feature(CPU_FTR_VSX
)) {
3137 #endif /* CONFIG_VSX */
3162 op
->type
= INTERRUPT
| 0x700;
3163 op
->val
= SRR1_PROGPRIV
;
3167 op
->type
= INTERRUPT
| 0x700;
3168 op
->val
= SRR1_PROGTRAP
;
3171 EXPORT_SYMBOL_GPL(analyse_instr
);
3172 NOKPROBE_SYMBOL(analyse_instr
);
3175 * For PPC32 we always use stwu with r1 to change the stack pointer.
3176 * So this emulated store may corrupt the exception frame, now we
3177 * have to provide the exception frame trampoline, which is pushed
3178 * below the kprobed function stack. So we only update gpr[1] but
3179 * don't emulate the real store operation. We will do real store
3180 * operation safely in exception return code by checking this flag.
3182 static nokprobe_inline
int handle_stack_update(unsigned long ea
, struct pt_regs
*regs
)
3185 * Check if we already set since that means we'll
3186 * lose the previous value.
3188 WARN_ON(test_thread_flag(TIF_EMULATE_STACK_STORE
));
3189 set_thread_flag(TIF_EMULATE_STACK_STORE
);
3193 static nokprobe_inline
void do_signext(unsigned long *valp
, int size
)
3197 *valp
= (signed short) *valp
;
3200 *valp
= (signed int) *valp
;
3205 static nokprobe_inline
void do_byterev(unsigned long *valp
, int size
)
3209 *valp
= byterev_2(*valp
);
3212 *valp
= byterev_4(*valp
);
3214 #ifdef __powerpc64__
3216 *valp
= byterev_8(*valp
);
3223 * Emulate an instruction that can be executed just by updating
3226 void emulate_update_regs(struct pt_regs
*regs
, struct instruction_op
*op
)
3228 unsigned long next_pc
;
3230 next_pc
= truncate_if_32bit(regs
->msr
, regs
->nip
+ GETLENGTH(op
->type
));
3231 switch (GETTYPE(op
->type
)) {
3233 if (op
->type
& SETREG
)
3234 regs
->gpr
[op
->reg
] = op
->val
;
3235 if (op
->type
& SETCC
)
3236 regs
->ccr
= op
->ccval
;
3237 if (op
->type
& SETXER
)
3238 regs
->xer
= op
->xerval
;
3242 if (op
->type
& SETLK
)
3243 regs
->link
= next_pc
;
3244 if (op
->type
& BRTAKEN
)
3246 if (op
->type
& DECCTR
)
3251 switch (op
->type
& BARRIER_MASK
) {
3262 case BARRIER_LWSYNC
:
3263 asm volatile("lwsync" : : : "memory");
3265 case BARRIER_PTESYNC
:
3266 asm volatile("ptesync" : : : "memory");
3275 regs
->gpr
[op
->reg
] = regs
->xer
& 0xffffffffUL
;
3278 regs
->gpr
[op
->reg
] = regs
->link
;
3281 regs
->gpr
[op
->reg
] = regs
->ctr
;
3291 regs
->xer
= op
->val
& 0xffffffffUL
;
3294 regs
->link
= op
->val
;
3297 regs
->ctr
= op
->val
;
3307 regs_set_return_ip(regs
, next_pc
);
3309 NOKPROBE_SYMBOL(emulate_update_regs
);
3312 * Emulate a previously-analysed load or store instruction.
3313 * Return values are:
3314 * 0 = instruction emulated successfully
3315 * -EFAULT = address out of range or access faulted (regs->dar
3316 * contains the faulting address)
3317 * -EACCES = misaligned access, instruction requires alignment
3318 * -EINVAL = unknown operation in *op
3320 int emulate_loadstore(struct pt_regs
*regs
, struct instruction_op
*op
)
3322 int err
, size
, type
;
3330 size
= GETSIZE(op
->type
);
3331 type
= GETTYPE(op
->type
);
3332 cross_endian
= (regs
->msr
& MSR_LE
) != (MSR_KERNEL
& MSR_LE
);
3333 ea
= truncate_if_32bit(regs
->msr
, op
->ea
);
3337 if (ea
& (size
- 1))
3338 return -EACCES
; /* can't handle misaligned */
3339 if (!address_ok(regs
, ea
, size
))
3344 #ifdef CONFIG_PPC_HAS_LBARX_LHARX
3346 __get_user_asmx(val
, ea
, err
, "lbarx");
3349 __get_user_asmx(val
, ea
, err
, "lharx");
3353 __get_user_asmx(val
, ea
, err
, "lwarx");
3355 #ifdef __powerpc64__
3357 __get_user_asmx(val
, ea
, err
, "ldarx");
3360 err
= do_lqarx(ea
, ®s
->gpr
[op
->reg
]);
3371 regs
->gpr
[op
->reg
] = val
;
3375 if (ea
& (size
- 1))
3376 return -EACCES
; /* can't handle misaligned */
3377 if (!address_ok(regs
, ea
, size
))
3381 #ifdef __powerpc64__
3383 __put_user_asmx(op
->val
, ea
, err
, "stbcx.", cr
);
3386 __put_user_asmx(op
->val
, ea
, err
, "sthcx.", cr
);
3390 __put_user_asmx(op
->val
, ea
, err
, "stwcx.", cr
);
3392 #ifdef __powerpc64__
3394 __put_user_asmx(op
->val
, ea
, err
, "stdcx.", cr
);
3397 err
= do_stqcx(ea
, regs
->gpr
[op
->reg
],
3398 regs
->gpr
[op
->reg
+ 1], &cr
);
3405 regs
->ccr
= (regs
->ccr
& 0x0fffffff) |
3407 ((regs
->xer
>> 3) & 0x10000000);
3413 #ifdef __powerpc64__
3415 err
= emulate_lq(regs
, ea
, op
->reg
, cross_endian
);
3419 err
= read_mem(®s
->gpr
[op
->reg
], ea
, size
, regs
);
3421 if (op
->type
& SIGNEXT
)
3422 do_signext(®s
->gpr
[op
->reg
], size
);
3423 if ((op
->type
& BYTEREV
) == (cross_endian
? 0 : BYTEREV
))
3424 do_byterev(®s
->gpr
[op
->reg
], size
);
3428 #ifdef CONFIG_PPC_FPU
3431 * If the instruction is in userspace, we can emulate it even
3432 * if the VMX state is not live, because we have the state
3433 * stored in the thread_struct. If the instruction is in
3434 * the kernel, we must not touch the state in the thread_struct.
3436 if (!user_mode(regs
) && !(regs
->msr
& MSR_FP
))
3438 err
= do_fp_load(op
, ea
, regs
, cross_endian
);
3441 #ifdef CONFIG_ALTIVEC
3443 if (!user_mode(regs
) && !(regs
->msr
& MSR_VEC
))
3445 err
= do_vec_load(op
->reg
, ea
, size
, regs
, cross_endian
);
3450 unsigned long msrbit
= MSR_VSX
;
3453 * Some VSX instructions check the MSR_VEC bit rather than MSR_VSX
3454 * when the target of the instruction is a vector register.
3456 if (op
->reg
>= 32 && (op
->vsx_flags
& VSX_CHECK_VEC
))
3458 if (!user_mode(regs
) && !(regs
->msr
& msrbit
))
3460 err
= do_vsx_load(op
, ea
, regs
, cross_endian
);
3465 if (!address_ok(regs
, ea
, size
))
3468 for (i
= 0; i
< size
; i
+= 4) {
3469 unsigned int v32
= 0;
3474 err
= copy_mem_in((u8
*) &v32
, ea
, nb
, regs
);
3477 if (unlikely(cross_endian
))
3478 v32
= byterev_4(v32
);
3479 regs
->gpr
[rd
] = v32
;
3481 /* reg number wraps from 31 to 0 for lsw[ix] */
3482 rd
= (rd
+ 1) & 0x1f;
3487 #ifdef __powerpc64__
3489 err
= emulate_stq(regs
, ea
, op
->reg
, cross_endian
);
3493 if ((op
->type
& UPDATE
) && size
== sizeof(long) &&
3494 op
->reg
== 1 && op
->update_reg
== 1 && !user_mode(regs
) &&
3495 ea
>= regs
->gpr
[1] - STACK_INT_FRAME_SIZE
) {
3496 err
= handle_stack_update(ea
, regs
);
3499 if (unlikely(cross_endian
))
3500 do_byterev(&op
->val
, size
);
3501 err
= write_mem(op
->val
, ea
, size
, regs
);
3504 #ifdef CONFIG_PPC_FPU
3506 if (!user_mode(regs
) && !(regs
->msr
& MSR_FP
))
3508 err
= do_fp_store(op
, ea
, regs
, cross_endian
);
3511 #ifdef CONFIG_ALTIVEC
3513 if (!user_mode(regs
) && !(regs
->msr
& MSR_VEC
))
3515 err
= do_vec_store(op
->reg
, ea
, size
, regs
, cross_endian
);
3520 unsigned long msrbit
= MSR_VSX
;
3523 * Some VSX instructions check the MSR_VEC bit rather than MSR_VSX
3524 * when the target of the instruction is a vector register.
3526 if (op
->reg
>= 32 && (op
->vsx_flags
& VSX_CHECK_VEC
))
3528 if (!user_mode(regs
) && !(regs
->msr
& msrbit
))
3530 err
= do_vsx_store(op
, ea
, regs
, cross_endian
);
3535 if (!address_ok(regs
, ea
, size
))
3538 for (i
= 0; i
< size
; i
+= 4) {
3539 unsigned int v32
= regs
->gpr
[rd
];
3544 if (unlikely(cross_endian
))
3545 v32
= byterev_4(v32
);
3546 err
= copy_mem_out((u8
*) &v32
, ea
, nb
, regs
);
3550 /* reg number wraps from 31 to 0 for stsw[ix] */
3551 rd
= (rd
+ 1) & 0x1f;
3562 if (op
->type
& UPDATE
)
3563 regs
->gpr
[op
->update_reg
] = op
->ea
;
3567 NOKPROBE_SYMBOL(emulate_loadstore
);
3570 * Emulate instructions that cause a transfer of control,
3571 * loads and stores, and a few other instructions.
3572 * Returns 1 if the step was emulated, 0 if not,
3573 * or -1 if the instruction is one that should not be stepped,
3574 * such as an rfid, or a mtmsrd that would clear MSR_RI.
3576 int emulate_step(struct pt_regs
*regs
, ppc_inst_t instr
)
3578 struct instruction_op op
;
3583 r
= analyse_instr(&op
, regs
, instr
);
3587 emulate_update_regs(regs
, &op
);
3592 type
= GETTYPE(op
.type
);
3594 if (OP_IS_LOAD_STORE(type
)) {
3595 err
= emulate_loadstore(regs
, &op
);
3603 ea
= truncate_if_32bit(regs
->msr
, op
.ea
);
3604 if (!address_ok(regs
, ea
, 8))
3606 switch (op
.type
& CACHEOP_MASK
) {
3608 __cacheop_user_asmx(ea
, err
, "dcbst");
3611 __cacheop_user_asmx(ea
, err
, "dcbf");
3615 prefetchw((void *) ea
);
3619 prefetch((void *) ea
);
3622 __cacheop_user_asmx(ea
, err
, "icbi");
3625 err
= emulate_dcbz(ea
, regs
);
3635 regs
->gpr
[op
.reg
] = regs
->msr
& MSR_MASK
;
3639 val
= regs
->gpr
[op
.reg
];
3640 if ((val
& MSR_RI
) == 0)
3641 /* can't step mtmsr[d] that would clear MSR_RI */
3643 /* here op.val is the mask of bits to change */
3644 regs_set_return_msr(regs
, (regs
->msr
& ~op
.val
) | (val
& op
.val
));
3647 case SYSCALL
: /* sc */
3649 * Per ISA v3.1, section 7.5.15 'Trace Interrupt', we can't
3650 * single step a system call instruction:
3652 * Successful completion for an instruction means that the
3653 * instruction caused no other interrupt. Thus a Trace
3654 * interrupt never occurs for a System Call or System Call
3655 * Vectored instruction, or for a Trap instruction that
3659 case SYSCALL_VECTORED_0
: /* scv 0 */
3667 regs_set_return_ip(regs
,
3668 truncate_if_32bit(regs
->msr
, regs
->nip
+ GETLENGTH(op
.type
)));
3671 NOKPROBE_SYMBOL(emulate_step
);