Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1 | /* |
| 2 | * Single-step support. |
| 3 | * |
| 4 | * Copyright (C) 2004 Paul Mackerras <paulus@au.ibm.com>, IBM |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public License |
| 8 | * as published by the Free Software Foundation; either version |
| 9 | * 2 of the License, or (at your option) any later version. |
| 10 | */ |
| 11 | #include <linux/kernel.h> |
Gui,Jian | 0d69a05 | 2006-11-01 10:50:15 +0800 | [diff] [blame] | 12 | #include <linux/kprobes.h> |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 13 | #include <linux/ptrace.h> |
Linus Torvalds | 268bb0c | 2011-05-20 12:50:29 -0700 | [diff] [blame] | 14 | #include <linux/prefetch.h> |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 15 | #include <asm/sstep.h> |
| 16 | #include <asm/processor.h> |
Linus Torvalds | 7c0f6ba | 2016-12-24 11:46:01 -0800 | [diff] [blame] | 17 | #include <linux/uaccess.h> |
Michael Ellerman | 5e9d0e3 | 2016-11-18 11:51:14 +1100 | [diff] [blame] | 18 | #include <asm/cpu_has_feature.h> |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 19 | #include <asm/cputable.h> |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 20 | |
| 21 | extern char system_call_common[]; |
| 22 | |
Paul Mackerras | c032524 | 2005-10-28 22:48:08 +1000 | [diff] [blame] | 23 | #ifdef CONFIG_PPC64 |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 24 | /* Bits in SRR1 that are copied from MSR */ |
Stephen Rothwell | af30837 | 2006-03-23 17:38:10 +1100 | [diff] [blame] | 25 | #define MSR_MASK 0xffffffff87c0ffffUL |
Paul Mackerras | c032524 | 2005-10-28 22:48:08 +1000 | [diff] [blame] | 26 | #else |
| 27 | #define MSR_MASK 0x87c0ffff |
| 28 | #endif |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 29 | |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 30 | /* Bits in XER */ |
| 31 | #define XER_SO 0x80000000U |
| 32 | #define XER_OV 0x40000000U |
| 33 | #define XER_CA 0x20000000U |
| 34 | |
Sean MacLennan | cd64d16 | 2010-09-01 07:21:21 +0000 | [diff] [blame] | 35 | #ifdef CONFIG_PPC_FPU |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 36 | /* |
| 37 | * Functions in ldstfp.S |
| 38 | */ |
Paul Mackerras | c22435a5 | 2017-08-30 14:12:33 +1000 | [diff] [blame] | 39 | extern void get_fpr(int rn, double *p); |
| 40 | extern void put_fpr(int rn, const double *p); |
| 41 | extern void get_vr(int rn, __vector128 *p); |
| 42 | extern void put_vr(int rn, __vector128 *p); |
Paul Mackerras | 350779a | 2017-08-30 14:12:27 +1000 | [diff] [blame] | 43 | extern void load_vsrn(int vsr, const void *p); |
| 44 | extern void store_vsrn(int vsr, void *p); |
| 45 | extern void conv_sp_to_dp(const float *sp, double *dp); |
| 46 | extern void conv_dp_to_sp(const double *dp, float *sp); |
| 47 | #endif |
| 48 | |
| 49 | #ifdef __powerpc64__ |
| 50 | /* |
| 51 | * Functions in quad.S |
| 52 | */ |
| 53 | extern int do_lq(unsigned long ea, unsigned long *regs); |
| 54 | extern int do_stq(unsigned long ea, unsigned long val0, unsigned long val1); |
| 55 | extern int do_lqarx(unsigned long ea, unsigned long *regs); |
| 56 | extern int do_stqcx(unsigned long ea, unsigned long val0, unsigned long val1, |
| 57 | unsigned int *crp); |
| 58 | #endif |
| 59 | |
| 60 | #ifdef __LITTLE_ENDIAN__ |
| 61 | #define IS_LE 1 |
| 62 | #define IS_BE 0 |
| 63 | #else |
| 64 | #define IS_LE 0 |
| 65 | #define IS_BE 1 |
Sean MacLennan | cd64d16 | 2010-09-01 07:21:21 +0000 | [diff] [blame] | 66 | #endif |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 67 | |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 68 | /* |
Michael Ellerman | b91e136 | 2011-04-07 21:56:04 +0000 | [diff] [blame] | 69 | * Emulate the truncation of 64 bit values in 32-bit mode. |
| 70 | */ |
Naveen N. Rao | 71f6e58 | 2017-04-12 16:48:51 +0530 | [diff] [blame] | 71 | static nokprobe_inline unsigned long truncate_if_32bit(unsigned long msr, |
| 72 | unsigned long val) |
Michael Ellerman | b91e136 | 2011-04-07 21:56:04 +0000 | [diff] [blame] | 73 | { |
| 74 | #ifdef __powerpc64__ |
| 75 | if ((msr & MSR_64BIT) == 0) |
| 76 | val &= 0xffffffffUL; |
| 77 | #endif |
| 78 | return val; |
| 79 | } |
| 80 | |
| 81 | /* |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 82 | * Determine whether a conditional branch instruction would branch. |
| 83 | */ |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 84 | static nokprobe_inline int branch_taken(unsigned int instr, |
| 85 | const struct pt_regs *regs, |
| 86 | struct instruction_op *op) |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 87 | { |
| 88 | unsigned int bo = (instr >> 21) & 0x1f; |
| 89 | unsigned int bi; |
| 90 | |
| 91 | if ((bo & 4) == 0) { |
| 92 | /* decrement counter */ |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 93 | op->type |= DECCTR; |
| 94 | if (((bo >> 1) & 1) ^ (regs->ctr == 1)) |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 95 | return 0; |
| 96 | } |
| 97 | if ((bo & 0x10) == 0) { |
| 98 | /* check bit from CR */ |
| 99 | bi = (instr >> 16) & 0x1f; |
| 100 | if (((regs->ccr >> (31 - bi)) & 1) != ((bo >> 3) & 1)) |
| 101 | return 0; |
| 102 | } |
| 103 | return 1; |
| 104 | } |
| 105 | |
Paul Mackerras | b9da9c8 | 2017-08-30 14:12:37 +1000 | [diff] [blame^] | 106 | static nokprobe_inline long address_ok(struct pt_regs *regs, |
| 107 | unsigned long ea, int nb) |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 108 | { |
| 109 | if (!user_mode(regs)) |
| 110 | return 1; |
Paul Mackerras | b9da9c8 | 2017-08-30 14:12:37 +1000 | [diff] [blame^] | 111 | if (__access_ok(ea, nb, USER_DS)) |
| 112 | return 1; |
| 113 | if (__access_ok(ea, 1, USER_DS)) |
| 114 | /* Access overlaps the end of the user region */ |
| 115 | regs->dar = USER_DS.seg; |
| 116 | else |
| 117 | regs->dar = ea; |
| 118 | return 0; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 119 | } |
| 120 | |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 121 | /* |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 122 | * Calculate effective address for a D-form instruction |
| 123 | */ |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 124 | static nokprobe_inline unsigned long dform_ea(unsigned int instr, |
| 125 | const struct pt_regs *regs) |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 126 | { |
| 127 | int ra; |
| 128 | unsigned long ea; |
| 129 | |
| 130 | ra = (instr >> 16) & 0x1f; |
| 131 | ea = (signed short) instr; /* sign-extend */ |
Paul Mackerras | be96f63 | 2014-09-02 14:35:07 +1000 | [diff] [blame] | 132 | if (ra) |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 133 | ea += regs->gpr[ra]; |
Michael Ellerman | b91e136 | 2011-04-07 21:56:04 +0000 | [diff] [blame] | 134 | |
Paul Mackerras | d120cdb | 2017-08-30 14:12:28 +1000 | [diff] [blame] | 135 | return ea; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | #ifdef __powerpc64__ |
| 139 | /* |
| 140 | * Calculate effective address for a DS-form instruction |
| 141 | */ |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 142 | static nokprobe_inline unsigned long dsform_ea(unsigned int instr, |
| 143 | const struct pt_regs *regs) |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 144 | { |
| 145 | int ra; |
| 146 | unsigned long ea; |
| 147 | |
| 148 | ra = (instr >> 16) & 0x1f; |
| 149 | ea = (signed short) (instr & ~3); /* sign-extend */ |
Paul Mackerras | be96f63 | 2014-09-02 14:35:07 +1000 | [diff] [blame] | 150 | if (ra) |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 151 | ea += regs->gpr[ra]; |
Michael Ellerman | b91e136 | 2011-04-07 21:56:04 +0000 | [diff] [blame] | 152 | |
Paul Mackerras | d120cdb | 2017-08-30 14:12:28 +1000 | [diff] [blame] | 153 | return ea; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 154 | } |
Paul Mackerras | 350779a | 2017-08-30 14:12:27 +1000 | [diff] [blame] | 155 | |
| 156 | /* |
| 157 | * Calculate effective address for a DQ-form instruction |
| 158 | */ |
| 159 | static nokprobe_inline unsigned long dqform_ea(unsigned int instr, |
| 160 | const struct pt_regs *regs) |
| 161 | { |
| 162 | int ra; |
| 163 | unsigned long ea; |
| 164 | |
| 165 | ra = (instr >> 16) & 0x1f; |
| 166 | ea = (signed short) (instr & ~0xf); /* sign-extend */ |
| 167 | if (ra) |
| 168 | ea += regs->gpr[ra]; |
| 169 | |
Paul Mackerras | d120cdb | 2017-08-30 14:12:28 +1000 | [diff] [blame] | 170 | return ea; |
Paul Mackerras | 350779a | 2017-08-30 14:12:27 +1000 | [diff] [blame] | 171 | } |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 172 | #endif /* __powerpc64 */ |
| 173 | |
| 174 | /* |
| 175 | * Calculate effective address for an X-form instruction |
| 176 | */ |
Naveen N. Rao | 71f6e58 | 2017-04-12 16:48:51 +0530 | [diff] [blame] | 177 | static nokprobe_inline unsigned long xform_ea(unsigned int instr, |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 178 | const struct pt_regs *regs) |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 179 | { |
| 180 | int ra, rb; |
| 181 | unsigned long ea; |
| 182 | |
| 183 | ra = (instr >> 16) & 0x1f; |
| 184 | rb = (instr >> 11) & 0x1f; |
| 185 | ea = regs->gpr[rb]; |
Paul Mackerras | be96f63 | 2014-09-02 14:35:07 +1000 | [diff] [blame] | 186 | if (ra) |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 187 | ea += regs->gpr[ra]; |
Michael Ellerman | b91e136 | 2011-04-07 21:56:04 +0000 | [diff] [blame] | 188 | |
Paul Mackerras | d120cdb | 2017-08-30 14:12:28 +1000 | [diff] [blame] | 189 | return ea; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | /* |
| 193 | * Return the largest power of 2, not greater than sizeof(unsigned long), |
| 194 | * such that x is a multiple of it. |
| 195 | */ |
Naveen N. Rao | 71f6e58 | 2017-04-12 16:48:51 +0530 | [diff] [blame] | 196 | static nokprobe_inline unsigned long max_align(unsigned long x) |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 197 | { |
| 198 | x |= sizeof(unsigned long); |
| 199 | return x & -x; /* isolates rightmost bit */ |
| 200 | } |
| 201 | |
Naveen N. Rao | 71f6e58 | 2017-04-12 16:48:51 +0530 | [diff] [blame] | 202 | static nokprobe_inline unsigned long byterev_2(unsigned long x) |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 203 | { |
| 204 | return ((x >> 8) & 0xff) | ((x & 0xff) << 8); |
| 205 | } |
| 206 | |
Naveen N. Rao | 71f6e58 | 2017-04-12 16:48:51 +0530 | [diff] [blame] | 207 | static nokprobe_inline unsigned long byterev_4(unsigned long x) |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 208 | { |
| 209 | return ((x >> 24) & 0xff) | ((x >> 8) & 0xff00) | |
| 210 | ((x & 0xff00) << 8) | ((x & 0xff) << 24); |
| 211 | } |
| 212 | |
| 213 | #ifdef __powerpc64__ |
Naveen N. Rao | 71f6e58 | 2017-04-12 16:48:51 +0530 | [diff] [blame] | 214 | static nokprobe_inline unsigned long byterev_8(unsigned long x) |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 215 | { |
| 216 | return (byterev_4(x) << 32) | byterev_4(x >> 32); |
| 217 | } |
| 218 | #endif |
| 219 | |
Naveen N. Rao | 71f6e58 | 2017-04-12 16:48:51 +0530 | [diff] [blame] | 220 | static nokprobe_inline int read_mem_aligned(unsigned long *dest, |
Paul Mackerras | b9da9c8 | 2017-08-30 14:12:37 +1000 | [diff] [blame^] | 221 | unsigned long ea, int nb, |
| 222 | struct pt_regs *regs) |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 223 | { |
| 224 | int err = 0; |
| 225 | unsigned long x = 0; |
| 226 | |
| 227 | switch (nb) { |
| 228 | case 1: |
| 229 | err = __get_user(x, (unsigned char __user *) ea); |
| 230 | break; |
| 231 | case 2: |
| 232 | err = __get_user(x, (unsigned short __user *) ea); |
| 233 | break; |
| 234 | case 4: |
| 235 | err = __get_user(x, (unsigned int __user *) ea); |
| 236 | break; |
| 237 | #ifdef __powerpc64__ |
| 238 | case 8: |
| 239 | err = __get_user(x, (unsigned long __user *) ea); |
| 240 | break; |
| 241 | #endif |
| 242 | } |
| 243 | if (!err) |
| 244 | *dest = x; |
Paul Mackerras | b9da9c8 | 2017-08-30 14:12:37 +1000 | [diff] [blame^] | 245 | else |
| 246 | regs->dar = ea; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 247 | return err; |
| 248 | } |
| 249 | |
Paul Mackerras | e0a0986 | 2017-08-30 14:12:32 +1000 | [diff] [blame] | 250 | /* |
| 251 | * Copy from userspace to a buffer, using the largest possible |
| 252 | * aligned accesses, up to sizeof(long). |
| 253 | */ |
Paul Mackerras | b9da9c8 | 2017-08-30 14:12:37 +1000 | [diff] [blame^] | 254 | static int nokprobe_inline copy_mem_in(u8 *dest, unsigned long ea, int nb, |
| 255 | struct pt_regs *regs) |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 256 | { |
Paul Mackerras | e0a0986 | 2017-08-30 14:12:32 +1000 | [diff] [blame] | 257 | int err = 0; |
| 258 | int c; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 259 | |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 260 | for (; nb > 0; nb -= c) { |
| 261 | c = max_align(ea); |
| 262 | if (c > nb) |
| 263 | c = max_align(nb); |
Paul Mackerras | e0a0986 | 2017-08-30 14:12:32 +1000 | [diff] [blame] | 264 | switch (c) { |
| 265 | case 1: |
| 266 | err = __get_user(*dest, (unsigned char __user *) ea); |
| 267 | break; |
| 268 | case 2: |
| 269 | err = __get_user(*(u16 *)dest, |
| 270 | (unsigned short __user *) ea); |
| 271 | break; |
| 272 | case 4: |
| 273 | err = __get_user(*(u32 *)dest, |
| 274 | (unsigned int __user *) ea); |
| 275 | break; |
| 276 | #ifdef __powerpc64__ |
| 277 | case 8: |
| 278 | err = __get_user(*(unsigned long *)dest, |
| 279 | (unsigned long __user *) ea); |
| 280 | break; |
| 281 | #endif |
| 282 | } |
Paul Mackerras | b9da9c8 | 2017-08-30 14:12:37 +1000 | [diff] [blame^] | 283 | if (err) { |
| 284 | regs->dar = ea; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 285 | return err; |
Paul Mackerras | b9da9c8 | 2017-08-30 14:12:37 +1000 | [diff] [blame^] | 286 | } |
Paul Mackerras | e0a0986 | 2017-08-30 14:12:32 +1000 | [diff] [blame] | 287 | dest += c; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 288 | ea += c; |
| 289 | } |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 290 | return 0; |
| 291 | } |
| 292 | |
Paul Mackerras | e0a0986 | 2017-08-30 14:12:32 +1000 | [diff] [blame] | 293 | static nokprobe_inline int read_mem_unaligned(unsigned long *dest, |
| 294 | unsigned long ea, int nb, |
| 295 | struct pt_regs *regs) |
| 296 | { |
| 297 | union { |
| 298 | unsigned long ul; |
| 299 | u8 b[sizeof(unsigned long)]; |
| 300 | } u; |
| 301 | int i; |
| 302 | int err; |
| 303 | |
| 304 | u.ul = 0; |
| 305 | i = IS_BE ? sizeof(unsigned long) - nb : 0; |
Paul Mackerras | b9da9c8 | 2017-08-30 14:12:37 +1000 | [diff] [blame^] | 306 | err = copy_mem_in(&u.b[i], ea, nb, regs); |
Paul Mackerras | e0a0986 | 2017-08-30 14:12:32 +1000 | [diff] [blame] | 307 | if (!err) |
| 308 | *dest = u.ul; |
| 309 | return err; |
| 310 | } |
| 311 | |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 312 | /* |
| 313 | * Read memory at address ea for nb bytes, return 0 for success |
Paul Mackerras | e0a0986 | 2017-08-30 14:12:32 +1000 | [diff] [blame] | 314 | * or -EFAULT if an error occurred. N.B. nb must be 1, 2, 4 or 8. |
| 315 | * If nb < sizeof(long), the result is right-justified on BE systems. |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 316 | */ |
Naveen N. Rao | 71f6e58 | 2017-04-12 16:48:51 +0530 | [diff] [blame] | 317 | static int read_mem(unsigned long *dest, unsigned long ea, int nb, |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 318 | struct pt_regs *regs) |
| 319 | { |
| 320 | if (!address_ok(regs, ea, nb)) |
| 321 | return -EFAULT; |
| 322 | if ((ea & (nb - 1)) == 0) |
Paul Mackerras | b9da9c8 | 2017-08-30 14:12:37 +1000 | [diff] [blame^] | 323 | return read_mem_aligned(dest, ea, nb, regs); |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 324 | return read_mem_unaligned(dest, ea, nb, regs); |
| 325 | } |
Naveen N. Rao | 71f6e58 | 2017-04-12 16:48:51 +0530 | [diff] [blame] | 326 | NOKPROBE_SYMBOL(read_mem); |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 327 | |
Naveen N. Rao | 71f6e58 | 2017-04-12 16:48:51 +0530 | [diff] [blame] | 328 | static nokprobe_inline int write_mem_aligned(unsigned long val, |
Paul Mackerras | b9da9c8 | 2017-08-30 14:12:37 +1000 | [diff] [blame^] | 329 | unsigned long ea, int nb, |
| 330 | struct pt_regs *regs) |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 331 | { |
| 332 | int err = 0; |
| 333 | |
| 334 | switch (nb) { |
| 335 | case 1: |
| 336 | err = __put_user(val, (unsigned char __user *) ea); |
| 337 | break; |
| 338 | case 2: |
| 339 | err = __put_user(val, (unsigned short __user *) ea); |
| 340 | break; |
| 341 | case 4: |
| 342 | err = __put_user(val, (unsigned int __user *) ea); |
| 343 | break; |
| 344 | #ifdef __powerpc64__ |
| 345 | case 8: |
| 346 | err = __put_user(val, (unsigned long __user *) ea); |
| 347 | break; |
| 348 | #endif |
| 349 | } |
Paul Mackerras | b9da9c8 | 2017-08-30 14:12:37 +1000 | [diff] [blame^] | 350 | if (err) |
| 351 | regs->dar = ea; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 352 | return err; |
| 353 | } |
| 354 | |
Paul Mackerras | e0a0986 | 2017-08-30 14:12:32 +1000 | [diff] [blame] | 355 | /* |
| 356 | * Copy from a buffer to userspace, using the largest possible |
| 357 | * aligned accesses, up to sizeof(long). |
| 358 | */ |
Paul Mackerras | b9da9c8 | 2017-08-30 14:12:37 +1000 | [diff] [blame^] | 359 | static int nokprobe_inline copy_mem_out(u8 *dest, unsigned long ea, int nb, |
| 360 | struct pt_regs *regs) |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 361 | { |
Paul Mackerras | e0a0986 | 2017-08-30 14:12:32 +1000 | [diff] [blame] | 362 | int err = 0; |
| 363 | int c; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 364 | |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 365 | for (; nb > 0; nb -= c) { |
| 366 | c = max_align(ea); |
| 367 | if (c > nb) |
| 368 | c = max_align(nb); |
Paul Mackerras | e0a0986 | 2017-08-30 14:12:32 +1000 | [diff] [blame] | 369 | switch (c) { |
| 370 | case 1: |
| 371 | err = __put_user(*dest, (unsigned char __user *) ea); |
| 372 | break; |
| 373 | case 2: |
| 374 | err = __put_user(*(u16 *)dest, |
| 375 | (unsigned short __user *) ea); |
| 376 | break; |
| 377 | case 4: |
| 378 | err = __put_user(*(u32 *)dest, |
| 379 | (unsigned int __user *) ea); |
| 380 | break; |
| 381 | #ifdef __powerpc64__ |
| 382 | case 8: |
| 383 | err = __put_user(*(unsigned long *)dest, |
| 384 | (unsigned long __user *) ea); |
| 385 | break; |
| 386 | #endif |
| 387 | } |
Paul Mackerras | b9da9c8 | 2017-08-30 14:12:37 +1000 | [diff] [blame^] | 388 | if (err) { |
| 389 | regs->dar = ea; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 390 | return err; |
Paul Mackerras | b9da9c8 | 2017-08-30 14:12:37 +1000 | [diff] [blame^] | 391 | } |
Paul Mackerras | e0a0986 | 2017-08-30 14:12:32 +1000 | [diff] [blame] | 392 | dest += c; |
Tom Musta | 17e8de7 | 2013-08-22 09:25:28 -0500 | [diff] [blame] | 393 | ea += c; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 394 | } |
| 395 | return 0; |
| 396 | } |
| 397 | |
Paul Mackerras | e0a0986 | 2017-08-30 14:12:32 +1000 | [diff] [blame] | 398 | static nokprobe_inline int write_mem_unaligned(unsigned long val, |
| 399 | unsigned long ea, int nb, |
| 400 | struct pt_regs *regs) |
| 401 | { |
| 402 | union { |
| 403 | unsigned long ul; |
| 404 | u8 b[sizeof(unsigned long)]; |
| 405 | } u; |
| 406 | int i; |
| 407 | |
| 408 | u.ul = val; |
| 409 | i = IS_BE ? sizeof(unsigned long) - nb : 0; |
Paul Mackerras | b9da9c8 | 2017-08-30 14:12:37 +1000 | [diff] [blame^] | 410 | return copy_mem_out(&u.b[i], ea, nb, regs); |
Paul Mackerras | e0a0986 | 2017-08-30 14:12:32 +1000 | [diff] [blame] | 411 | } |
| 412 | |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 413 | /* |
| 414 | * Write memory at address ea for nb bytes, return 0 for success |
Paul Mackerras | e0a0986 | 2017-08-30 14:12:32 +1000 | [diff] [blame] | 415 | * or -EFAULT if an error occurred. N.B. nb must be 1, 2, 4 or 8. |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 416 | */ |
Naveen N. Rao | 71f6e58 | 2017-04-12 16:48:51 +0530 | [diff] [blame] | 417 | static int write_mem(unsigned long val, unsigned long ea, int nb, |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 418 | struct pt_regs *regs) |
| 419 | { |
| 420 | if (!address_ok(regs, ea, nb)) |
| 421 | return -EFAULT; |
| 422 | if ((ea & (nb - 1)) == 0) |
Paul Mackerras | b9da9c8 | 2017-08-30 14:12:37 +1000 | [diff] [blame^] | 423 | return write_mem_aligned(val, ea, nb, regs); |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 424 | return write_mem_unaligned(val, ea, nb, regs); |
| 425 | } |
Naveen N. Rao | 71f6e58 | 2017-04-12 16:48:51 +0530 | [diff] [blame] | 426 | NOKPROBE_SYMBOL(write_mem); |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 427 | |
Sean MacLennan | cd64d16 | 2010-09-01 07:21:21 +0000 | [diff] [blame] | 428 | #ifdef CONFIG_PPC_FPU |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 429 | /* |
Paul Mackerras | c22435a5 | 2017-08-30 14:12:33 +1000 | [diff] [blame] | 430 | * These access either the real FP register or the image in the |
| 431 | * thread_struct, depending on regs->msr & MSR_FP. |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 432 | */ |
Paul Mackerras | c22435a5 | 2017-08-30 14:12:33 +1000 | [diff] [blame] | 433 | static int do_fp_load(int rn, unsigned long ea, int nb, struct pt_regs *regs) |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 434 | { |
| 435 | int err; |
Paul Mackerras | c22435a5 | 2017-08-30 14:12:33 +1000 | [diff] [blame] | 436 | union { |
| 437 | float f; |
Paul Mackerras | 1f41fb7 | 2017-08-30 14:12:35 +1000 | [diff] [blame] | 438 | double d[2]; |
| 439 | unsigned long l[2]; |
| 440 | u8 b[2 * sizeof(double)]; |
Paul Mackerras | c22435a5 | 2017-08-30 14:12:33 +1000 | [diff] [blame] | 441 | } u; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 442 | |
| 443 | if (!address_ok(regs, ea, nb)) |
| 444 | return -EFAULT; |
Paul Mackerras | b9da9c8 | 2017-08-30 14:12:37 +1000 | [diff] [blame^] | 445 | err = copy_mem_in(u.b, ea, nb, regs); |
Paul Mackerras | c22435a5 | 2017-08-30 14:12:33 +1000 | [diff] [blame] | 446 | if (err) |
| 447 | return err; |
| 448 | preempt_disable(); |
| 449 | if (nb == 4) |
Paul Mackerras | 1f41fb7 | 2017-08-30 14:12:35 +1000 | [diff] [blame] | 450 | conv_sp_to_dp(&u.f, &u.d[0]); |
Paul Mackerras | c22435a5 | 2017-08-30 14:12:33 +1000 | [diff] [blame] | 451 | if (regs->msr & MSR_FP) |
Paul Mackerras | 1f41fb7 | 2017-08-30 14:12:35 +1000 | [diff] [blame] | 452 | put_fpr(rn, &u.d[0]); |
Paul Mackerras | c22435a5 | 2017-08-30 14:12:33 +1000 | [diff] [blame] | 453 | else |
Paul Mackerras | 1f41fb7 | 2017-08-30 14:12:35 +1000 | [diff] [blame] | 454 | current->thread.TS_FPR(rn) = u.l[0]; |
| 455 | if (nb == 16) { |
| 456 | /* lfdp */ |
| 457 | rn |= 1; |
| 458 | if (regs->msr & MSR_FP) |
| 459 | put_fpr(rn, &u.d[1]); |
| 460 | else |
| 461 | current->thread.TS_FPR(rn) = u.l[1]; |
| 462 | } |
Paul Mackerras | c22435a5 | 2017-08-30 14:12:33 +1000 | [diff] [blame] | 463 | preempt_enable(); |
| 464 | return 0; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 465 | } |
Naveen N. Rao | 71f6e58 | 2017-04-12 16:48:51 +0530 | [diff] [blame] | 466 | NOKPROBE_SYMBOL(do_fp_load); |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 467 | |
Paul Mackerras | c22435a5 | 2017-08-30 14:12:33 +1000 | [diff] [blame] | 468 | static int do_fp_store(int rn, unsigned long ea, int nb, struct pt_regs *regs) |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 469 | { |
Paul Mackerras | c22435a5 | 2017-08-30 14:12:33 +1000 | [diff] [blame] | 470 | union { |
| 471 | float f; |
Paul Mackerras | 1f41fb7 | 2017-08-30 14:12:35 +1000 | [diff] [blame] | 472 | double d[2]; |
| 473 | unsigned long l[2]; |
| 474 | u8 b[2 * sizeof(double)]; |
Paul Mackerras | c22435a5 | 2017-08-30 14:12:33 +1000 | [diff] [blame] | 475 | } u; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 476 | |
| 477 | if (!address_ok(regs, ea, nb)) |
| 478 | return -EFAULT; |
Paul Mackerras | c22435a5 | 2017-08-30 14:12:33 +1000 | [diff] [blame] | 479 | preempt_disable(); |
| 480 | if (regs->msr & MSR_FP) |
Paul Mackerras | 1f41fb7 | 2017-08-30 14:12:35 +1000 | [diff] [blame] | 481 | get_fpr(rn, &u.d[0]); |
Paul Mackerras | c22435a5 | 2017-08-30 14:12:33 +1000 | [diff] [blame] | 482 | else |
Paul Mackerras | 1f41fb7 | 2017-08-30 14:12:35 +1000 | [diff] [blame] | 483 | u.l[0] = current->thread.TS_FPR(rn); |
Paul Mackerras | c22435a5 | 2017-08-30 14:12:33 +1000 | [diff] [blame] | 484 | if (nb == 4) |
Paul Mackerras | 1f41fb7 | 2017-08-30 14:12:35 +1000 | [diff] [blame] | 485 | conv_dp_to_sp(&u.d[0], &u.f); |
| 486 | if (nb == 16) { |
| 487 | rn |= 1; |
| 488 | if (regs->msr & MSR_FP) |
| 489 | get_fpr(rn, &u.d[1]); |
| 490 | else |
| 491 | u.l[1] = current->thread.TS_FPR(rn); |
| 492 | } |
Paul Mackerras | c22435a5 | 2017-08-30 14:12:33 +1000 | [diff] [blame] | 493 | preempt_enable(); |
Paul Mackerras | b9da9c8 | 2017-08-30 14:12:37 +1000 | [diff] [blame^] | 494 | return copy_mem_out(u.b, ea, nb, regs); |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 495 | } |
Naveen N. Rao | 71f6e58 | 2017-04-12 16:48:51 +0530 | [diff] [blame] | 496 | NOKPROBE_SYMBOL(do_fp_store); |
Sean MacLennan | cd64d16 | 2010-09-01 07:21:21 +0000 | [diff] [blame] | 497 | #endif |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 498 | |
| 499 | #ifdef CONFIG_ALTIVEC |
| 500 | /* For Altivec/VMX, no need to worry about alignment */ |
Paul Mackerras | c22435a5 | 2017-08-30 14:12:33 +1000 | [diff] [blame] | 501 | static nokprobe_inline int do_vec_load(int rn, unsigned long ea, |
| 502 | int size, struct pt_regs *regs) |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 503 | { |
Paul Mackerras | c22435a5 | 2017-08-30 14:12:33 +1000 | [diff] [blame] | 504 | int err; |
| 505 | union { |
| 506 | __vector128 v; |
| 507 | u8 b[sizeof(__vector128)]; |
| 508 | } u = {}; |
| 509 | |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 510 | if (!address_ok(regs, ea & ~0xfUL, 16)) |
| 511 | return -EFAULT; |
Paul Mackerras | c22435a5 | 2017-08-30 14:12:33 +1000 | [diff] [blame] | 512 | /* align to multiple of size */ |
| 513 | ea &= ~(size - 1); |
Paul Mackerras | b9da9c8 | 2017-08-30 14:12:37 +1000 | [diff] [blame^] | 514 | err = copy_mem_in(&u.b[ea & 0xf], ea, size, regs); |
Paul Mackerras | c22435a5 | 2017-08-30 14:12:33 +1000 | [diff] [blame] | 515 | if (err) |
| 516 | return err; |
| 517 | |
| 518 | preempt_disable(); |
| 519 | if (regs->msr & MSR_VEC) |
| 520 | put_vr(rn, &u.v); |
| 521 | else |
| 522 | current->thread.vr_state.vr[rn] = u.v; |
| 523 | preempt_enable(); |
| 524 | return 0; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 525 | } |
| 526 | |
Paul Mackerras | c22435a5 | 2017-08-30 14:12:33 +1000 | [diff] [blame] | 527 | static nokprobe_inline int do_vec_store(int rn, unsigned long ea, |
| 528 | int size, struct pt_regs *regs) |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 529 | { |
Paul Mackerras | c22435a5 | 2017-08-30 14:12:33 +1000 | [diff] [blame] | 530 | union { |
| 531 | __vector128 v; |
| 532 | u8 b[sizeof(__vector128)]; |
| 533 | } u; |
| 534 | |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 535 | if (!address_ok(regs, ea & ~0xfUL, 16)) |
| 536 | return -EFAULT; |
Paul Mackerras | c22435a5 | 2017-08-30 14:12:33 +1000 | [diff] [blame] | 537 | /* align to multiple of size */ |
| 538 | ea &= ~(size - 1); |
| 539 | |
| 540 | preempt_disable(); |
| 541 | if (regs->msr & MSR_VEC) |
| 542 | get_vr(rn, &u.v); |
| 543 | else |
| 544 | u.v = current->thread.vr_state.vr[rn]; |
| 545 | preempt_enable(); |
Paul Mackerras | b9da9c8 | 2017-08-30 14:12:37 +1000 | [diff] [blame^] | 546 | return copy_mem_out(&u.b[ea & 0xf], ea, size, regs); |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 547 | } |
| 548 | #endif /* CONFIG_ALTIVEC */ |
| 549 | |
Paul Mackerras | 350779a | 2017-08-30 14:12:27 +1000 | [diff] [blame] | 550 | #ifdef __powerpc64__ |
| 551 | static nokprobe_inline int emulate_lq(struct pt_regs *regs, unsigned long ea, |
| 552 | int reg) |
| 553 | { |
| 554 | int err; |
| 555 | |
| 556 | if (!address_ok(regs, ea, 16)) |
| 557 | return -EFAULT; |
| 558 | /* if aligned, should be atomic */ |
| 559 | if ((ea & 0xf) == 0) |
| 560 | return do_lq(ea, ®s->gpr[reg]); |
| 561 | |
| 562 | err = read_mem(®s->gpr[reg + IS_LE], ea, 8, regs); |
| 563 | if (!err) |
| 564 | err = read_mem(®s->gpr[reg + IS_BE], ea + 8, 8, regs); |
| 565 | return err; |
| 566 | } |
| 567 | |
| 568 | static nokprobe_inline int emulate_stq(struct pt_regs *regs, unsigned long ea, |
| 569 | int reg) |
| 570 | { |
| 571 | int err; |
| 572 | |
| 573 | if (!address_ok(regs, ea, 16)) |
| 574 | return -EFAULT; |
| 575 | /* if aligned, should be atomic */ |
| 576 | if ((ea & 0xf) == 0) |
| 577 | return do_stq(ea, regs->gpr[reg], regs->gpr[reg + 1]); |
| 578 | |
| 579 | err = write_mem(regs->gpr[reg + IS_LE], ea, 8, regs); |
| 580 | if (!err) |
| 581 | err = write_mem(regs->gpr[reg + IS_BE], ea + 8, 8, regs); |
| 582 | return err; |
| 583 | } |
| 584 | #endif /* __powerpc64 */ |
| 585 | |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 586 | #ifdef CONFIG_VSX |
Paul Mackerras | 350779a | 2017-08-30 14:12:27 +1000 | [diff] [blame] | 587 | void emulate_vsx_load(struct instruction_op *op, union vsx_reg *reg, |
| 588 | const void *mem) |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 589 | { |
Paul Mackerras | 350779a | 2017-08-30 14:12:27 +1000 | [diff] [blame] | 590 | int size, read_size; |
| 591 | int i, j; |
| 592 | const unsigned int *wp; |
| 593 | const unsigned short *hp; |
| 594 | const unsigned char *bp; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 595 | |
Paul Mackerras | 350779a | 2017-08-30 14:12:27 +1000 | [diff] [blame] | 596 | size = GETSIZE(op->type); |
| 597 | reg->d[0] = reg->d[1] = 0; |
| 598 | |
| 599 | switch (op->element_size) { |
| 600 | case 16: |
| 601 | /* whole vector; lxv[x] or lxvl[l] */ |
| 602 | if (size == 0) |
| 603 | break; |
| 604 | memcpy(reg, mem, size); |
| 605 | if (IS_LE && (op->vsx_flags & VSX_LDLEFT)) { |
| 606 | /* reverse 16 bytes */ |
| 607 | unsigned long tmp; |
| 608 | tmp = byterev_8(reg->d[0]); |
| 609 | reg->d[0] = byterev_8(reg->d[1]); |
| 610 | reg->d[1] = tmp; |
| 611 | } |
| 612 | break; |
| 613 | case 8: |
| 614 | /* scalar loads, lxvd2x, lxvdsx */ |
| 615 | read_size = (size >= 8) ? 8 : size; |
| 616 | i = IS_LE ? 8 : 8 - read_size; |
| 617 | memcpy(®->b[i], mem, read_size); |
| 618 | if (size < 8) { |
| 619 | if (op->type & SIGNEXT) { |
| 620 | /* size == 4 is the only case here */ |
| 621 | reg->d[IS_LE] = (signed int) reg->d[IS_LE]; |
| 622 | } else if (op->vsx_flags & VSX_FPCONV) { |
| 623 | preempt_disable(); |
| 624 | conv_sp_to_dp(®->fp[1 + IS_LE], |
| 625 | ®->dp[IS_LE]); |
| 626 | preempt_enable(); |
| 627 | } |
| 628 | } else { |
| 629 | if (size == 16) |
| 630 | reg->d[IS_BE] = *(unsigned long *)(mem + 8); |
| 631 | else if (op->vsx_flags & VSX_SPLAT) |
| 632 | reg->d[IS_BE] = reg->d[IS_LE]; |
| 633 | } |
| 634 | break; |
| 635 | case 4: |
| 636 | /* lxvw4x, lxvwsx */ |
| 637 | wp = mem; |
| 638 | for (j = 0; j < size / 4; ++j) { |
| 639 | i = IS_LE ? 3 - j : j; |
| 640 | reg->w[i] = *wp++; |
| 641 | } |
| 642 | if (op->vsx_flags & VSX_SPLAT) { |
| 643 | u32 val = reg->w[IS_LE ? 3 : 0]; |
| 644 | for (; j < 4; ++j) { |
| 645 | i = IS_LE ? 3 - j : j; |
| 646 | reg->w[i] = val; |
| 647 | } |
| 648 | } |
| 649 | break; |
| 650 | case 2: |
| 651 | /* lxvh8x */ |
| 652 | hp = mem; |
| 653 | for (j = 0; j < size / 2; ++j) { |
| 654 | i = IS_LE ? 7 - j : j; |
| 655 | reg->h[i] = *hp++; |
| 656 | } |
| 657 | break; |
| 658 | case 1: |
| 659 | /* lxvb16x */ |
| 660 | bp = mem; |
| 661 | for (j = 0; j < size; ++j) { |
| 662 | i = IS_LE ? 15 - j : j; |
| 663 | reg->b[i] = *bp++; |
| 664 | } |
| 665 | break; |
| 666 | } |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 667 | } |
Paul Mackerras | 350779a | 2017-08-30 14:12:27 +1000 | [diff] [blame] | 668 | EXPORT_SYMBOL_GPL(emulate_vsx_load); |
| 669 | NOKPROBE_SYMBOL(emulate_vsx_load); |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 670 | |
Paul Mackerras | 350779a | 2017-08-30 14:12:27 +1000 | [diff] [blame] | 671 | void emulate_vsx_store(struct instruction_op *op, const union vsx_reg *reg, |
| 672 | void *mem) |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 673 | { |
Paul Mackerras | 350779a | 2017-08-30 14:12:27 +1000 | [diff] [blame] | 674 | int size, write_size; |
| 675 | int i, j; |
| 676 | union vsx_reg buf; |
| 677 | unsigned int *wp; |
| 678 | unsigned short *hp; |
| 679 | unsigned char *bp; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 680 | |
Paul Mackerras | 350779a | 2017-08-30 14:12:27 +1000 | [diff] [blame] | 681 | size = GETSIZE(op->type); |
| 682 | |
| 683 | switch (op->element_size) { |
| 684 | case 16: |
| 685 | /* stxv, stxvx, stxvl, stxvll */ |
| 686 | if (size == 0) |
| 687 | break; |
| 688 | if (IS_LE && (op->vsx_flags & VSX_LDLEFT)) { |
| 689 | /* reverse 16 bytes */ |
| 690 | buf.d[0] = byterev_8(reg->d[1]); |
| 691 | buf.d[1] = byterev_8(reg->d[0]); |
| 692 | reg = &buf; |
| 693 | } |
| 694 | memcpy(mem, reg, size); |
| 695 | break; |
| 696 | case 8: |
| 697 | /* scalar stores, stxvd2x */ |
| 698 | write_size = (size >= 8) ? 8 : size; |
| 699 | i = IS_LE ? 8 : 8 - write_size; |
| 700 | if (size < 8 && op->vsx_flags & VSX_FPCONV) { |
| 701 | buf.d[0] = buf.d[1] = 0; |
| 702 | preempt_disable(); |
| 703 | conv_dp_to_sp(®->dp[IS_LE], &buf.fp[1 + IS_LE]); |
| 704 | preempt_enable(); |
| 705 | reg = &buf; |
| 706 | } |
| 707 | memcpy(mem, ®->b[i], write_size); |
| 708 | if (size == 16) |
| 709 | memcpy(mem + 8, ®->d[IS_BE], 8); |
| 710 | break; |
| 711 | case 4: |
| 712 | /* stxvw4x */ |
| 713 | wp = mem; |
| 714 | for (j = 0; j < size / 4; ++j) { |
| 715 | i = IS_LE ? 3 - j : j; |
| 716 | *wp++ = reg->w[i]; |
| 717 | } |
| 718 | break; |
| 719 | case 2: |
| 720 | /* stxvh8x */ |
| 721 | hp = mem; |
| 722 | for (j = 0; j < size / 2; ++j) { |
| 723 | i = IS_LE ? 7 - j : j; |
| 724 | *hp++ = reg->h[i]; |
| 725 | } |
| 726 | break; |
| 727 | case 1: |
| 728 | /* stvxb16x */ |
| 729 | bp = mem; |
| 730 | for (j = 0; j < size; ++j) { |
| 731 | i = IS_LE ? 15 - j : j; |
| 732 | *bp++ = reg->b[i]; |
| 733 | } |
| 734 | break; |
| 735 | } |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 736 | } |
Paul Mackerras | 350779a | 2017-08-30 14:12:27 +1000 | [diff] [blame] | 737 | EXPORT_SYMBOL_GPL(emulate_vsx_store); |
| 738 | NOKPROBE_SYMBOL(emulate_vsx_store); |
Paul Mackerras | c22435a5 | 2017-08-30 14:12:33 +1000 | [diff] [blame] | 739 | |
| 740 | static nokprobe_inline int do_vsx_load(struct instruction_op *op, |
| 741 | unsigned long ea, struct pt_regs *regs) |
| 742 | { |
| 743 | int reg = op->reg; |
| 744 | u8 mem[16]; |
| 745 | union vsx_reg buf; |
| 746 | int size = GETSIZE(op->type); |
| 747 | |
Paul Mackerras | b9da9c8 | 2017-08-30 14:12:37 +1000 | [diff] [blame^] | 748 | if (!address_ok(regs, ea, size) || copy_mem_in(mem, ea, size, regs)) |
Paul Mackerras | c22435a5 | 2017-08-30 14:12:33 +1000 | [diff] [blame] | 749 | return -EFAULT; |
| 750 | |
| 751 | emulate_vsx_load(op, &buf, mem); |
| 752 | preempt_disable(); |
| 753 | if (reg < 32) { |
| 754 | /* FP regs + extensions */ |
| 755 | if (regs->msr & MSR_FP) { |
| 756 | load_vsrn(reg, &buf); |
| 757 | } else { |
| 758 | current->thread.fp_state.fpr[reg][0] = buf.d[0]; |
| 759 | current->thread.fp_state.fpr[reg][1] = buf.d[1]; |
| 760 | } |
| 761 | } else { |
| 762 | if (regs->msr & MSR_VEC) |
| 763 | load_vsrn(reg, &buf); |
| 764 | else |
| 765 | current->thread.vr_state.vr[reg - 32] = buf.v; |
| 766 | } |
| 767 | preempt_enable(); |
| 768 | return 0; |
| 769 | } |
| 770 | |
| 771 | static nokprobe_inline int do_vsx_store(struct instruction_op *op, |
| 772 | unsigned long ea, struct pt_regs *regs) |
| 773 | { |
| 774 | int reg = op->reg; |
| 775 | u8 mem[16]; |
| 776 | union vsx_reg buf; |
| 777 | int size = GETSIZE(op->type); |
| 778 | |
| 779 | if (!address_ok(regs, ea, size)) |
| 780 | return -EFAULT; |
| 781 | |
| 782 | preempt_disable(); |
| 783 | if (reg < 32) { |
| 784 | /* FP regs + extensions */ |
| 785 | if (regs->msr & MSR_FP) { |
| 786 | store_vsrn(reg, &buf); |
| 787 | } else { |
| 788 | buf.d[0] = current->thread.fp_state.fpr[reg][0]; |
| 789 | buf.d[1] = current->thread.fp_state.fpr[reg][1]; |
| 790 | } |
| 791 | } else { |
| 792 | if (regs->msr & MSR_VEC) |
| 793 | store_vsrn(reg, &buf); |
| 794 | else |
| 795 | buf.v = current->thread.vr_state.vr[reg - 32]; |
| 796 | } |
| 797 | preempt_enable(); |
| 798 | emulate_vsx_store(op, &buf, mem); |
Paul Mackerras | b9da9c8 | 2017-08-30 14:12:37 +1000 | [diff] [blame^] | 799 | return copy_mem_out(mem, ea, size, regs); |
Paul Mackerras | c22435a5 | 2017-08-30 14:12:33 +1000 | [diff] [blame] | 800 | } |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 801 | #endif /* CONFIG_VSX */ |
| 802 | |
Paul Mackerras | b2543f7 | 2017-08-30 14:12:36 +1000 | [diff] [blame] | 803 | int emulate_dcbz(unsigned long ea, struct pt_regs *regs) |
| 804 | { |
| 805 | int err; |
| 806 | unsigned long i, size; |
| 807 | |
| 808 | #ifdef __powerpc64__ |
| 809 | size = ppc64_caches.l1d.block_size; |
| 810 | if (!(regs->msr & MSR_64BIT)) |
| 811 | ea &= 0xffffffffUL; |
| 812 | #else |
| 813 | size = L1_CACHE_BYTES; |
| 814 | #endif |
| 815 | ea &= ~(size - 1); |
| 816 | if (!address_ok(regs, ea, size)) |
| 817 | return -EFAULT; |
| 818 | for (i = 0; i < size; i += sizeof(long)) { |
| 819 | err = __put_user(0, (unsigned long __user *) (ea + i)); |
Paul Mackerras | b9da9c8 | 2017-08-30 14:12:37 +1000 | [diff] [blame^] | 820 | if (err) { |
| 821 | regs->dar = ea; |
Paul Mackerras | b2543f7 | 2017-08-30 14:12:36 +1000 | [diff] [blame] | 822 | return err; |
Paul Mackerras | b9da9c8 | 2017-08-30 14:12:37 +1000 | [diff] [blame^] | 823 | } |
Paul Mackerras | b2543f7 | 2017-08-30 14:12:36 +1000 | [diff] [blame] | 824 | } |
| 825 | return 0; |
| 826 | } |
| 827 | NOKPROBE_SYMBOL(emulate_dcbz); |
| 828 | |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 829 | #define __put_user_asmx(x, addr, err, op, cr) \ |
| 830 | __asm__ __volatile__( \ |
| 831 | "1: " op " %2,0,%3\n" \ |
| 832 | " mfcr %1\n" \ |
| 833 | "2:\n" \ |
| 834 | ".section .fixup,\"ax\"\n" \ |
| 835 | "3: li %0,%4\n" \ |
| 836 | " b 2b\n" \ |
| 837 | ".previous\n" \ |
Nicholas Piggin | 24bfa6a | 2016-10-13 16:42:53 +1100 | [diff] [blame] | 838 | EX_TABLE(1b, 3b) \ |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 839 | : "=r" (err), "=r" (cr) \ |
| 840 | : "r" (x), "r" (addr), "i" (-EFAULT), "0" (err)) |
| 841 | |
| 842 | #define __get_user_asmx(x, addr, err, op) \ |
| 843 | __asm__ __volatile__( \ |
| 844 | "1: "op" %1,0,%2\n" \ |
| 845 | "2:\n" \ |
| 846 | ".section .fixup,\"ax\"\n" \ |
| 847 | "3: li %0,%3\n" \ |
| 848 | " b 2b\n" \ |
| 849 | ".previous\n" \ |
Nicholas Piggin | 24bfa6a | 2016-10-13 16:42:53 +1100 | [diff] [blame] | 850 | EX_TABLE(1b, 3b) \ |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 851 | : "=r" (err), "=r" (x) \ |
| 852 | : "r" (addr), "i" (-EFAULT), "0" (err)) |
| 853 | |
| 854 | #define __cacheop_user_asmx(addr, err, op) \ |
| 855 | __asm__ __volatile__( \ |
| 856 | "1: "op" 0,%1\n" \ |
| 857 | "2:\n" \ |
| 858 | ".section .fixup,\"ax\"\n" \ |
| 859 | "3: li %0,%3\n" \ |
| 860 | " b 2b\n" \ |
| 861 | ".previous\n" \ |
Nicholas Piggin | 24bfa6a | 2016-10-13 16:42:53 +1100 | [diff] [blame] | 862 | EX_TABLE(1b, 3b) \ |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 863 | : "=r" (err) \ |
| 864 | : "r" (addr), "i" (-EFAULT), "0" (err)) |
| 865 | |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 866 | static nokprobe_inline void set_cr0(const struct pt_regs *regs, |
| 867 | struct instruction_op *op, int rd) |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 868 | { |
| 869 | long val = regs->gpr[rd]; |
| 870 | |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 871 | op->type |= SETCC; |
| 872 | op->ccval = (regs->ccr & 0x0fffffff) | ((regs->xer >> 3) & 0x10000000); |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 873 | #ifdef __powerpc64__ |
Michael Ellerman | b91e136 | 2011-04-07 21:56:04 +0000 | [diff] [blame] | 874 | if (!(regs->msr & MSR_64BIT)) |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 875 | val = (int) val; |
| 876 | #endif |
| 877 | if (val < 0) |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 878 | op->ccval |= 0x80000000; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 879 | else if (val > 0) |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 880 | op->ccval |= 0x40000000; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 881 | else |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 882 | op->ccval |= 0x20000000; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 883 | } |
| 884 | |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 885 | static nokprobe_inline void add_with_carry(const struct pt_regs *regs, |
| 886 | struct instruction_op *op, int rd, |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 887 | unsigned long val1, unsigned long val2, |
| 888 | unsigned long carry_in) |
| 889 | { |
| 890 | unsigned long val = val1 + val2; |
| 891 | |
| 892 | if (carry_in) |
| 893 | ++val; |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 894 | op->type = COMPUTE + SETREG + SETXER; |
| 895 | op->reg = rd; |
| 896 | op->val = val; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 897 | #ifdef __powerpc64__ |
Michael Ellerman | b91e136 | 2011-04-07 21:56:04 +0000 | [diff] [blame] | 898 | if (!(regs->msr & MSR_64BIT)) { |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 899 | val = (unsigned int) val; |
| 900 | val1 = (unsigned int) val1; |
| 901 | } |
| 902 | #endif |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 903 | op->xerval = regs->xer; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 904 | if (val < val1 || (carry_in && val == val1)) |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 905 | op->xerval |= XER_CA; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 906 | else |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 907 | op->xerval &= ~XER_CA; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 908 | } |
| 909 | |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 910 | static nokprobe_inline void do_cmp_signed(const struct pt_regs *regs, |
| 911 | struct instruction_op *op, |
| 912 | long v1, long v2, int crfld) |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 913 | { |
| 914 | unsigned int crval, shift; |
| 915 | |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 916 | op->type = COMPUTE + SETCC; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 917 | crval = (regs->xer >> 31) & 1; /* get SO bit */ |
| 918 | if (v1 < v2) |
| 919 | crval |= 8; |
| 920 | else if (v1 > v2) |
| 921 | crval |= 4; |
| 922 | else |
| 923 | crval |= 2; |
| 924 | shift = (7 - crfld) * 4; |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 925 | op->ccval = (regs->ccr & ~(0xf << shift)) | (crval << shift); |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 926 | } |
| 927 | |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 928 | static nokprobe_inline void do_cmp_unsigned(const struct pt_regs *regs, |
| 929 | struct instruction_op *op, |
| 930 | unsigned long v1, |
| 931 | unsigned long v2, int crfld) |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 932 | { |
| 933 | unsigned int crval, shift; |
| 934 | |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 935 | op->type = COMPUTE + SETCC; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 936 | crval = (regs->xer >> 31) & 1; /* get SO bit */ |
| 937 | if (v1 < v2) |
| 938 | crval |= 8; |
| 939 | else if (v1 > v2) |
| 940 | crval |= 4; |
| 941 | else |
| 942 | crval |= 2; |
| 943 | shift = (7 - crfld) * 4; |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 944 | op->ccval = (regs->ccr & ~(0xf << shift)) | (crval << shift); |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 945 | } |
| 946 | |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 947 | static nokprobe_inline void do_cmpb(const struct pt_regs *regs, |
| 948 | struct instruction_op *op, |
| 949 | unsigned long v1, unsigned long v2) |
Matt Brown | 02c0f62 | 2017-07-31 10:58:22 +1000 | [diff] [blame] | 950 | { |
| 951 | unsigned long long out_val, mask; |
| 952 | int i; |
| 953 | |
| 954 | out_val = 0; |
| 955 | for (i = 0; i < 8; i++) { |
| 956 | mask = 0xffUL << (i * 8); |
| 957 | if ((v1 & mask) == (v2 & mask)) |
| 958 | out_val |= mask; |
| 959 | } |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 960 | op->val = out_val; |
Matt Brown | 02c0f62 | 2017-07-31 10:58:22 +1000 | [diff] [blame] | 961 | } |
| 962 | |
Matt Brown | dcbd19b | 2017-07-31 10:58:23 +1000 | [diff] [blame] | 963 | /* |
| 964 | * The size parameter is used to adjust the equivalent popcnt instruction. |
| 965 | * popcntb = 8, popcntw = 32, popcntd = 64 |
| 966 | */ |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 967 | static nokprobe_inline void do_popcnt(const struct pt_regs *regs, |
| 968 | struct instruction_op *op, |
| 969 | unsigned long v1, int size) |
Matt Brown | dcbd19b | 2017-07-31 10:58:23 +1000 | [diff] [blame] | 970 | { |
| 971 | unsigned long long out = v1; |
| 972 | |
| 973 | out -= (out >> 1) & 0x5555555555555555; |
| 974 | out = (0x3333333333333333 & out) + (0x3333333333333333 & (out >> 2)); |
| 975 | out = (out + (out >> 4)) & 0x0f0f0f0f0f0f0f0f; |
| 976 | |
| 977 | if (size == 8) { /* popcntb */ |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 978 | op->val = out; |
Matt Brown | dcbd19b | 2017-07-31 10:58:23 +1000 | [diff] [blame] | 979 | return; |
| 980 | } |
| 981 | out += out >> 8; |
| 982 | out += out >> 16; |
| 983 | if (size == 32) { /* popcntw */ |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 984 | op->val = out & 0x0000003f0000003f; |
Matt Brown | dcbd19b | 2017-07-31 10:58:23 +1000 | [diff] [blame] | 985 | return; |
| 986 | } |
| 987 | |
| 988 | out = (out + (out >> 32)) & 0x7f; |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 989 | op->val = out; /* popcntd */ |
Matt Brown | dcbd19b | 2017-07-31 10:58:23 +1000 | [diff] [blame] | 990 | } |
| 991 | |
Matt Brown | f312793 | 2017-07-31 10:58:24 +1000 | [diff] [blame] | 992 | #ifdef CONFIG_PPC64 |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 993 | static nokprobe_inline void do_bpermd(const struct pt_regs *regs, |
| 994 | struct instruction_op *op, |
| 995 | unsigned long v1, unsigned long v2) |
Matt Brown | f312793 | 2017-07-31 10:58:24 +1000 | [diff] [blame] | 996 | { |
| 997 | unsigned char perm, idx; |
| 998 | unsigned int i; |
| 999 | |
| 1000 | perm = 0; |
| 1001 | for (i = 0; i < 8; i++) { |
| 1002 | idx = (v1 >> (i * 8)) & 0xff; |
| 1003 | if (idx < 64) |
| 1004 | if (v2 & PPC_BIT(idx)) |
| 1005 | perm |= 1 << i; |
| 1006 | } |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 1007 | op->val = perm; |
Matt Brown | f312793 | 2017-07-31 10:58:24 +1000 | [diff] [blame] | 1008 | } |
| 1009 | #endif /* CONFIG_PPC64 */ |
Matt Brown | 2c979c4 | 2017-07-31 10:58:25 +1000 | [diff] [blame] | 1010 | /* |
| 1011 | * The size parameter adjusts the equivalent prty instruction. |
| 1012 | * prtyw = 32, prtyd = 64 |
| 1013 | */ |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 1014 | static nokprobe_inline void do_prty(const struct pt_regs *regs, |
| 1015 | struct instruction_op *op, |
| 1016 | unsigned long v, int size) |
Matt Brown | 2c979c4 | 2017-07-31 10:58:25 +1000 | [diff] [blame] | 1017 | { |
| 1018 | unsigned long long res = v ^ (v >> 8); |
| 1019 | |
| 1020 | res ^= res >> 16; |
| 1021 | if (size == 32) { /* prtyw */ |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 1022 | op->val = res & 0x0000000100000001; |
Matt Brown | 2c979c4 | 2017-07-31 10:58:25 +1000 | [diff] [blame] | 1023 | return; |
| 1024 | } |
| 1025 | |
| 1026 | res ^= res >> 32; |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 1027 | op->val = res & 1; /*prtyd */ |
Matt Brown | 2c979c4 | 2017-07-31 10:58:25 +1000 | [diff] [blame] | 1028 | } |
Matt Brown | f312793 | 2017-07-31 10:58:24 +1000 | [diff] [blame] | 1029 | |
Naveen N. Rao | 71f6e58 | 2017-04-12 16:48:51 +0530 | [diff] [blame] | 1030 | static nokprobe_inline int trap_compare(long v1, long v2) |
Paul Mackerras | cf87c3f | 2014-09-02 14:35:08 +1000 | [diff] [blame] | 1031 | { |
| 1032 | int ret = 0; |
| 1033 | |
| 1034 | if (v1 < v2) |
| 1035 | ret |= 0x10; |
| 1036 | else if (v1 > v2) |
| 1037 | ret |= 0x08; |
| 1038 | else |
| 1039 | ret |= 0x04; |
| 1040 | if ((unsigned long)v1 < (unsigned long)v2) |
| 1041 | ret |= 0x02; |
| 1042 | else if ((unsigned long)v1 > (unsigned long)v2) |
| 1043 | ret |= 0x01; |
| 1044 | return ret; |
| 1045 | } |
| 1046 | |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1047 | /* |
| 1048 | * Elements of 32-bit rotate and mask instructions. |
| 1049 | */ |
| 1050 | #define MASK32(mb, me) ((0xffffffffUL >> (mb)) + \ |
| 1051 | ((signed long)-0x80000000L >> (me)) + ((me) >= (mb))) |
| 1052 | #ifdef __powerpc64__ |
| 1053 | #define MASK64_L(mb) (~0UL >> (mb)) |
| 1054 | #define MASK64_R(me) ((signed long)-0x8000000000000000L >> (me)) |
| 1055 | #define MASK64(mb, me) (MASK64_L(mb) + MASK64_R(me) + ((me) >= (mb))) |
| 1056 | #define DATA32(x) (((x) & 0xffffffffUL) | (((x) & 0xffffffffUL) << 32)) |
| 1057 | #else |
| 1058 | #define DATA32(x) (x) |
| 1059 | #endif |
| 1060 | #define ROTATE(x, n) ((n) ? (((x) << (n)) | ((x) >> (8 * sizeof(long) - (n)))) : (x)) |
| 1061 | |
| 1062 | /* |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 1063 | * Decode an instruction, and return information about it in *op |
| 1064 | * without changing *regs. |
| 1065 | * Integer arithmetic and logical instructions, branches, and barrier |
| 1066 | * instructions can be emulated just using the information in *op. |
| 1067 | * |
| 1068 | * Return value is 1 if the instruction can be emulated just by |
| 1069 | * updating *regs with the information in *op, -1 if we need the |
| 1070 | * GPRs but *regs doesn't contain the full register set, or 0 |
| 1071 | * otherwise. |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1072 | */ |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 1073 | int analyse_instr(struct instruction_op *op, const struct pt_regs *regs, |
| 1074 | unsigned int instr) |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1075 | { |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1076 | unsigned int opcode, ra, rb, rd, spr, u; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1077 | unsigned long int imm; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1078 | unsigned long int val, val2; |
Paul Mackerras | be96f63 | 2014-09-02 14:35:07 +1000 | [diff] [blame] | 1079 | unsigned int mb, me, sh; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1080 | long ival; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1081 | |
Paul Mackerras | be96f63 | 2014-09-02 14:35:07 +1000 | [diff] [blame] | 1082 | op->type = COMPUTE; |
| 1083 | |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1084 | opcode = instr >> 26; |
| 1085 | switch (opcode) { |
| 1086 | case 16: /* bc */ |
Paul Mackerras | be96f63 | 2014-09-02 14:35:07 +1000 | [diff] [blame] | 1087 | op->type = BRANCH; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1088 | imm = (signed short)(instr & 0xfffc); |
| 1089 | if ((instr & 2) == 0) |
| 1090 | imm += regs->nip; |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 1091 | op->val = truncate_if_32bit(regs->msr, imm); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1092 | if (instr & 1) |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 1093 | op->type |= SETLK; |
| 1094 | if (branch_taken(instr, regs, op)) |
| 1095 | op->type |= BRTAKEN; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1096 | return 1; |
Paul Mackerras | c032524 | 2005-10-28 22:48:08 +1000 | [diff] [blame] | 1097 | #ifdef CONFIG_PPC64 |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1098 | case 17: /* sc */ |
Paul Mackerras | be96f63 | 2014-09-02 14:35:07 +1000 | [diff] [blame] | 1099 | if ((instr & 0xfe2) == 2) |
| 1100 | op->type = SYSCALL; |
| 1101 | else |
| 1102 | op->type = UNKNOWN; |
| 1103 | return 0; |
Paul Mackerras | c032524 | 2005-10-28 22:48:08 +1000 | [diff] [blame] | 1104 | #endif |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1105 | case 18: /* b */ |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 1106 | op->type = BRANCH | BRTAKEN; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1107 | imm = instr & 0x03fffffc; |
| 1108 | if (imm & 0x02000000) |
| 1109 | imm -= 0x04000000; |
| 1110 | if ((instr & 2) == 0) |
| 1111 | imm += regs->nip; |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 1112 | op->val = truncate_if_32bit(regs->msr, imm); |
Michael Ellerman | b91e136 | 2011-04-07 21:56:04 +0000 | [diff] [blame] | 1113 | if (instr & 1) |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 1114 | op->type |= SETLK; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1115 | return 1; |
| 1116 | case 19: |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1117 | switch ((instr >> 1) & 0x3ff) { |
Paul Mackerras | cf87c3f | 2014-09-02 14:35:08 +1000 | [diff] [blame] | 1118 | case 0: /* mcrf */ |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 1119 | op->type = COMPUTE + SETCC; |
Anton Blanchard | 87c4b83e | 2017-06-15 09:46:38 +1000 | [diff] [blame] | 1120 | rd = 7 - ((instr >> 23) & 0x7); |
| 1121 | ra = 7 - ((instr >> 18) & 0x7); |
| 1122 | rd *= 4; |
| 1123 | ra *= 4; |
Paul Mackerras | cf87c3f | 2014-09-02 14:35:08 +1000 | [diff] [blame] | 1124 | val = (regs->ccr >> ra) & 0xf; |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 1125 | op->ccval = (regs->ccr & ~(0xfUL << rd)) | (val << rd); |
| 1126 | return 1; |
Paul Mackerras | cf87c3f | 2014-09-02 14:35:08 +1000 | [diff] [blame] | 1127 | |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1128 | case 16: /* bclr */ |
| 1129 | case 528: /* bcctr */ |
Paul Mackerras | be96f63 | 2014-09-02 14:35:07 +1000 | [diff] [blame] | 1130 | op->type = BRANCH; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1131 | imm = (instr & 0x400)? regs->ctr: regs->link; |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 1132 | op->val = truncate_if_32bit(regs->msr, imm); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1133 | if (instr & 1) |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 1134 | op->type |= SETLK; |
| 1135 | if (branch_taken(instr, regs, op)) |
| 1136 | op->type |= BRTAKEN; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1137 | return 1; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1138 | |
| 1139 | case 18: /* rfid, scary */ |
Paul Mackerras | be96f63 | 2014-09-02 14:35:07 +1000 | [diff] [blame] | 1140 | if (regs->msr & MSR_PR) |
| 1141 | goto priv; |
| 1142 | op->type = RFI; |
| 1143 | return 0; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1144 | |
| 1145 | case 150: /* isync */ |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 1146 | op->type = BARRIER | BARRIER_ISYNC; |
| 1147 | return 1; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1148 | |
| 1149 | case 33: /* crnor */ |
| 1150 | case 129: /* crandc */ |
| 1151 | case 193: /* crxor */ |
| 1152 | case 225: /* crnand */ |
| 1153 | case 257: /* crand */ |
| 1154 | case 289: /* creqv */ |
| 1155 | case 417: /* crorc */ |
| 1156 | case 449: /* cror */ |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 1157 | op->type = COMPUTE + SETCC; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1158 | ra = (instr >> 16) & 0x1f; |
| 1159 | rb = (instr >> 11) & 0x1f; |
| 1160 | rd = (instr >> 21) & 0x1f; |
| 1161 | ra = (regs->ccr >> (31 - ra)) & 1; |
| 1162 | rb = (regs->ccr >> (31 - rb)) & 1; |
| 1163 | val = (instr >> (6 + ra * 2 + rb)) & 1; |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 1164 | op->ccval = (regs->ccr & ~(1UL << (31 - rd))) | |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1165 | (val << (31 - rd)); |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 1166 | return 1; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1167 | } |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1168 | break; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1169 | case 31: |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1170 | switch ((instr >> 1) & 0x3ff) { |
| 1171 | case 598: /* sync */ |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 1172 | op->type = BARRIER + BARRIER_SYNC; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1173 | #ifdef __powerpc64__ |
| 1174 | switch ((instr >> 21) & 3) { |
| 1175 | case 1: /* lwsync */ |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 1176 | op->type = BARRIER + BARRIER_LWSYNC; |
| 1177 | break; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1178 | case 2: /* ptesync */ |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 1179 | op->type = BARRIER + BARRIER_PTESYNC; |
| 1180 | break; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1181 | } |
| 1182 | #endif |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 1183 | return 1; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1184 | |
| 1185 | case 854: /* eieio */ |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 1186 | op->type = BARRIER + BARRIER_EIEIO; |
| 1187 | return 1; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1188 | } |
| 1189 | break; |
| 1190 | } |
| 1191 | |
| 1192 | /* Following cases refer to regs->gpr[], so we need all regs */ |
| 1193 | if (!FULL_REGS(regs)) |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 1194 | return -1; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1195 | |
| 1196 | rd = (instr >> 21) & 0x1f; |
| 1197 | ra = (instr >> 16) & 0x1f; |
| 1198 | rb = (instr >> 11) & 0x1f; |
| 1199 | |
| 1200 | switch (opcode) { |
Paul Mackerras | cf87c3f | 2014-09-02 14:35:08 +1000 | [diff] [blame] | 1201 | #ifdef __powerpc64__ |
| 1202 | case 2: /* tdi */ |
| 1203 | if (rd & trap_compare(regs->gpr[ra], (short) instr)) |
| 1204 | goto trap; |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 1205 | return 1; |
Paul Mackerras | cf87c3f | 2014-09-02 14:35:08 +1000 | [diff] [blame] | 1206 | #endif |
| 1207 | case 3: /* twi */ |
| 1208 | if (rd & trap_compare((int)regs->gpr[ra], (short) instr)) |
| 1209 | goto trap; |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 1210 | return 1; |
Paul Mackerras | cf87c3f | 2014-09-02 14:35:08 +1000 | [diff] [blame] | 1211 | |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1212 | case 7: /* mulli */ |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 1213 | op->val = regs->gpr[ra] * (short) instr; |
| 1214 | goto compute_done; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1215 | |
| 1216 | case 8: /* subfic */ |
| 1217 | imm = (short) instr; |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 1218 | add_with_carry(regs, op, rd, ~regs->gpr[ra], imm, 1); |
| 1219 | return 1; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1220 | |
| 1221 | case 10: /* cmpli */ |
| 1222 | imm = (unsigned short) instr; |
| 1223 | val = regs->gpr[ra]; |
| 1224 | #ifdef __powerpc64__ |
| 1225 | if ((rd & 1) == 0) |
| 1226 | val = (unsigned int) val; |
| 1227 | #endif |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 1228 | do_cmp_unsigned(regs, op, val, imm, rd >> 2); |
| 1229 | return 1; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1230 | |
| 1231 | case 11: /* cmpi */ |
| 1232 | imm = (short) instr; |
| 1233 | val = regs->gpr[ra]; |
| 1234 | #ifdef __powerpc64__ |
| 1235 | if ((rd & 1) == 0) |
| 1236 | val = (int) val; |
| 1237 | #endif |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 1238 | do_cmp_signed(regs, op, val, imm, rd >> 2); |
| 1239 | return 1; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1240 | |
| 1241 | case 12: /* addic */ |
| 1242 | imm = (short) instr; |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 1243 | add_with_carry(regs, op, rd, regs->gpr[ra], imm, 0); |
| 1244 | return 1; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1245 | |
| 1246 | case 13: /* addic. */ |
| 1247 | imm = (short) instr; |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 1248 | add_with_carry(regs, op, rd, regs->gpr[ra], imm, 0); |
| 1249 | set_cr0(regs, op, rd); |
| 1250 | return 1; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1251 | |
| 1252 | case 14: /* addi */ |
| 1253 | imm = (short) instr; |
| 1254 | if (ra) |
| 1255 | imm += regs->gpr[ra]; |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 1256 | op->val = imm; |
| 1257 | goto compute_done; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1258 | |
| 1259 | case 15: /* addis */ |
| 1260 | imm = ((short) instr) << 16; |
| 1261 | if (ra) |
| 1262 | imm += regs->gpr[ra]; |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 1263 | op->val = imm; |
| 1264 | goto compute_done; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1265 | |
Paul Mackerras | 958465e | 2017-08-30 14:12:31 +1000 | [diff] [blame] | 1266 | case 19: |
| 1267 | if (((instr >> 1) & 0x1f) == 2) { |
| 1268 | /* addpcis */ |
| 1269 | imm = (short) (instr & 0xffc1); /* d0 + d2 fields */ |
| 1270 | imm |= (instr >> 15) & 0x3e; /* d1 field */ |
| 1271 | op->val = regs->nip + (imm << 16) + 4; |
| 1272 | goto compute_done; |
| 1273 | } |
| 1274 | op->type = UNKNOWN; |
| 1275 | return 0; |
| 1276 | |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1277 | case 20: /* rlwimi */ |
| 1278 | mb = (instr >> 6) & 0x1f; |
| 1279 | me = (instr >> 1) & 0x1f; |
| 1280 | val = DATA32(regs->gpr[rd]); |
| 1281 | imm = MASK32(mb, me); |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 1282 | op->val = (regs->gpr[ra] & ~imm) | (ROTATE(val, rb) & imm); |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1283 | goto logical_done; |
| 1284 | |
| 1285 | case 21: /* rlwinm */ |
| 1286 | mb = (instr >> 6) & 0x1f; |
| 1287 | me = (instr >> 1) & 0x1f; |
| 1288 | val = DATA32(regs->gpr[rd]); |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 1289 | op->val = ROTATE(val, rb) & MASK32(mb, me); |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1290 | goto logical_done; |
| 1291 | |
| 1292 | case 23: /* rlwnm */ |
| 1293 | mb = (instr >> 6) & 0x1f; |
| 1294 | me = (instr >> 1) & 0x1f; |
| 1295 | rb = regs->gpr[rb] & 0x1f; |
| 1296 | val = DATA32(regs->gpr[rd]); |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 1297 | op->val = ROTATE(val, rb) & MASK32(mb, me); |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1298 | goto logical_done; |
| 1299 | |
| 1300 | case 24: /* ori */ |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 1301 | op->val = regs->gpr[rd] | (unsigned short) instr; |
| 1302 | goto logical_done_nocc; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1303 | |
| 1304 | case 25: /* oris */ |
| 1305 | imm = (unsigned short) instr; |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 1306 | op->val = regs->gpr[rd] | (imm << 16); |
| 1307 | goto logical_done_nocc; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1308 | |
| 1309 | case 26: /* xori */ |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 1310 | op->val = regs->gpr[rd] ^ (unsigned short) instr; |
| 1311 | goto logical_done_nocc; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1312 | |
| 1313 | case 27: /* xoris */ |
| 1314 | imm = (unsigned short) instr; |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 1315 | op->val = regs->gpr[rd] ^ (imm << 16); |
| 1316 | goto logical_done_nocc; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1317 | |
| 1318 | case 28: /* andi. */ |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 1319 | op->val = regs->gpr[rd] & (unsigned short) instr; |
| 1320 | set_cr0(regs, op, ra); |
| 1321 | goto logical_done_nocc; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1322 | |
| 1323 | case 29: /* andis. */ |
| 1324 | imm = (unsigned short) instr; |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 1325 | op->val = regs->gpr[rd] & (imm << 16); |
| 1326 | set_cr0(regs, op, ra); |
| 1327 | goto logical_done_nocc; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1328 | |
| 1329 | #ifdef __powerpc64__ |
| 1330 | case 30: /* rld* */ |
| 1331 | mb = ((instr >> 6) & 0x1f) | (instr & 0x20); |
| 1332 | val = regs->gpr[rd]; |
| 1333 | if ((instr & 0x10) == 0) { |
| 1334 | sh = rb | ((instr & 2) << 4); |
| 1335 | val = ROTATE(val, sh); |
| 1336 | switch ((instr >> 2) & 3) { |
| 1337 | case 0: /* rldicl */ |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 1338 | val &= MASK64_L(mb); |
| 1339 | break; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1340 | case 1: /* rldicr */ |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 1341 | val &= MASK64_R(mb); |
| 1342 | break; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1343 | case 2: /* rldic */ |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 1344 | val &= MASK64(mb, 63 - sh); |
| 1345 | break; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1346 | case 3: /* rldimi */ |
| 1347 | imm = MASK64(mb, 63 - sh); |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 1348 | val = (regs->gpr[ra] & ~imm) | |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1349 | (val & imm); |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1350 | } |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 1351 | op->val = val; |
| 1352 | goto logical_done; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1353 | } else { |
| 1354 | sh = regs->gpr[rb] & 0x3f; |
| 1355 | val = ROTATE(val, sh); |
| 1356 | switch ((instr >> 1) & 7) { |
| 1357 | case 0: /* rldcl */ |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 1358 | op->val = val & MASK64_L(mb); |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1359 | goto logical_done; |
| 1360 | case 1: /* rldcr */ |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 1361 | op->val = val & MASK64_R(mb); |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1362 | goto logical_done; |
| 1363 | } |
| 1364 | } |
| 1365 | #endif |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 1366 | op->type = UNKNOWN; /* illegal instruction */ |
| 1367 | return 0; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1368 | |
| 1369 | case 31: |
Paul Mackerras | f1bbb99 | 2017-08-30 14:12:29 +1000 | [diff] [blame] | 1370 | /* isel occupies 32 minor opcodes */ |
| 1371 | if (((instr >> 1) & 0x1f) == 15) { |
| 1372 | mb = (instr >> 6) & 0x1f; /* bc field */ |
| 1373 | val = (regs->ccr >> (31 - mb)) & 1; |
| 1374 | val2 = (ra) ? regs->gpr[ra] : 0; |
| 1375 | |
| 1376 | op->val = (val) ? val2 : regs->gpr[rb]; |
| 1377 | goto compute_done; |
| 1378 | } |
| 1379 | |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1380 | switch ((instr >> 1) & 0x3ff) { |
Paul Mackerras | cf87c3f | 2014-09-02 14:35:08 +1000 | [diff] [blame] | 1381 | case 4: /* tw */ |
| 1382 | if (rd == 0x1f || |
| 1383 | (rd & trap_compare((int)regs->gpr[ra], |
| 1384 | (int)regs->gpr[rb]))) |
| 1385 | goto trap; |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 1386 | return 1; |
Paul Mackerras | cf87c3f | 2014-09-02 14:35:08 +1000 | [diff] [blame] | 1387 | #ifdef __powerpc64__ |
| 1388 | case 68: /* td */ |
| 1389 | if (rd & trap_compare(regs->gpr[ra], regs->gpr[rb])) |
| 1390 | goto trap; |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 1391 | return 1; |
Paul Mackerras | cf87c3f | 2014-09-02 14:35:08 +1000 | [diff] [blame] | 1392 | #endif |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1393 | case 83: /* mfmsr */ |
| 1394 | if (regs->msr & MSR_PR) |
Paul Mackerras | be96f63 | 2014-09-02 14:35:07 +1000 | [diff] [blame] | 1395 | goto priv; |
| 1396 | op->type = MFMSR; |
| 1397 | op->reg = rd; |
| 1398 | return 0; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1399 | case 146: /* mtmsr */ |
| 1400 | if (regs->msr & MSR_PR) |
Paul Mackerras | be96f63 | 2014-09-02 14:35:07 +1000 | [diff] [blame] | 1401 | goto priv; |
| 1402 | op->type = MTMSR; |
| 1403 | op->reg = rd; |
| 1404 | op->val = 0xffffffff & ~(MSR_ME | MSR_LE); |
| 1405 | return 0; |
Paul Mackerras | c032524 | 2005-10-28 22:48:08 +1000 | [diff] [blame] | 1406 | #ifdef CONFIG_PPC64 |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1407 | case 178: /* mtmsrd */ |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1408 | if (regs->msr & MSR_PR) |
Paul Mackerras | be96f63 | 2014-09-02 14:35:07 +1000 | [diff] [blame] | 1409 | goto priv; |
| 1410 | op->type = MTMSR; |
| 1411 | op->reg = rd; |
| 1412 | /* only MSR_EE and MSR_RI get changed if bit 15 set */ |
| 1413 | /* mtmsrd doesn't change MSR_HV, MSR_ME or MSR_LE */ |
| 1414 | imm = (instr & 0x10000)? 0x8002: 0xefffffffffffeffeUL; |
| 1415 | op->val = imm; |
| 1416 | return 0; |
Paul Mackerras | c032524 | 2005-10-28 22:48:08 +1000 | [diff] [blame] | 1417 | #endif |
Paul Mackerras | be96f63 | 2014-09-02 14:35:07 +1000 | [diff] [blame] | 1418 | |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1419 | case 19: /* mfcr */ |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 1420 | imm = 0xffffffffUL; |
Anton Blanchard | 64e756c | 2017-06-15 09:46:39 +1000 | [diff] [blame] | 1421 | if ((instr >> 20) & 1) { |
| 1422 | imm = 0xf0000000UL; |
| 1423 | for (sh = 0; sh < 8; ++sh) { |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 1424 | if (instr & (0x80000 >> sh)) |
Anton Blanchard | 64e756c | 2017-06-15 09:46:39 +1000 | [diff] [blame] | 1425 | break; |
Anton Blanchard | 64e756c | 2017-06-15 09:46:39 +1000 | [diff] [blame] | 1426 | imm >>= 4; |
| 1427 | } |
Anton Blanchard | 64e756c | 2017-06-15 09:46:39 +1000 | [diff] [blame] | 1428 | } |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 1429 | op->val = regs->ccr & imm; |
| 1430 | goto compute_done; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1431 | |
| 1432 | case 144: /* mtcrf */ |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 1433 | op->type = COMPUTE + SETCC; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1434 | imm = 0xf0000000UL; |
| 1435 | val = regs->gpr[rd]; |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 1436 | op->val = regs->ccr; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1437 | for (sh = 0; sh < 8; ++sh) { |
| 1438 | if (instr & (0x80000 >> sh)) |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 1439 | op->val = (op->val & ~imm) | |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1440 | (val & imm); |
| 1441 | imm >>= 4; |
| 1442 | } |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 1443 | return 1; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1444 | |
| 1445 | case 339: /* mfspr */ |
Paul Mackerras | be96f63 | 2014-09-02 14:35:07 +1000 | [diff] [blame] | 1446 | spr = ((instr >> 16) & 0x1f) | ((instr >> 6) & 0x3e0); |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 1447 | op->type = MFSPR; |
| 1448 | op->reg = rd; |
| 1449 | op->spr = spr; |
| 1450 | if (spr == SPRN_XER || spr == SPRN_LR || |
| 1451 | spr == SPRN_CTR) |
| 1452 | return 1; |
| 1453 | return 0; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1454 | |
| 1455 | case 467: /* mtspr */ |
Paul Mackerras | be96f63 | 2014-09-02 14:35:07 +1000 | [diff] [blame] | 1456 | spr = ((instr >> 16) & 0x1f) | ((instr >> 6) & 0x3e0); |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 1457 | op->type = MTSPR; |
| 1458 | op->val = regs->gpr[rd]; |
| 1459 | op->spr = spr; |
| 1460 | if (spr == SPRN_XER || spr == SPRN_LR || |
| 1461 | spr == SPRN_CTR) |
| 1462 | return 1; |
| 1463 | return 0; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1464 | |
| 1465 | /* |
| 1466 | * Compare instructions |
| 1467 | */ |
| 1468 | case 0: /* cmp */ |
| 1469 | val = regs->gpr[ra]; |
| 1470 | val2 = regs->gpr[rb]; |
| 1471 | #ifdef __powerpc64__ |
| 1472 | if ((rd & 1) == 0) { |
| 1473 | /* word (32-bit) compare */ |
| 1474 | val = (int) val; |
| 1475 | val2 = (int) val2; |
| 1476 | } |
| 1477 | #endif |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 1478 | do_cmp_signed(regs, op, val, val2, rd >> 2); |
| 1479 | return 1; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1480 | |
| 1481 | case 32: /* cmpl */ |
| 1482 | val = regs->gpr[ra]; |
| 1483 | val2 = regs->gpr[rb]; |
| 1484 | #ifdef __powerpc64__ |
| 1485 | if ((rd & 1) == 0) { |
| 1486 | /* word (32-bit) compare */ |
| 1487 | val = (unsigned int) val; |
| 1488 | val2 = (unsigned int) val2; |
| 1489 | } |
| 1490 | #endif |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 1491 | do_cmp_unsigned(regs, op, val, val2, rd >> 2); |
| 1492 | return 1; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1493 | |
Matt Brown | 02c0f62 | 2017-07-31 10:58:22 +1000 | [diff] [blame] | 1494 | case 508: /* cmpb */ |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 1495 | do_cmpb(regs, op, regs->gpr[rd], regs->gpr[rb]); |
| 1496 | goto logical_done_nocc; |
Matt Brown | 02c0f62 | 2017-07-31 10:58:22 +1000 | [diff] [blame] | 1497 | |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1498 | /* |
| 1499 | * Arithmetic instructions |
| 1500 | */ |
| 1501 | case 8: /* subfc */ |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 1502 | add_with_carry(regs, op, rd, ~regs->gpr[ra], |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1503 | regs->gpr[rb], 1); |
| 1504 | goto arith_done; |
| 1505 | #ifdef __powerpc64__ |
| 1506 | case 9: /* mulhdu */ |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 1507 | asm("mulhdu %0,%1,%2" : "=r" (op->val) : |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1508 | "r" (regs->gpr[ra]), "r" (regs->gpr[rb])); |
| 1509 | goto arith_done; |
| 1510 | #endif |
| 1511 | case 10: /* addc */ |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 1512 | add_with_carry(regs, op, rd, regs->gpr[ra], |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1513 | regs->gpr[rb], 0); |
| 1514 | goto arith_done; |
| 1515 | |
| 1516 | case 11: /* mulhwu */ |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 1517 | asm("mulhwu %0,%1,%2" : "=r" (op->val) : |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1518 | "r" (regs->gpr[ra]), "r" (regs->gpr[rb])); |
| 1519 | goto arith_done; |
| 1520 | |
| 1521 | case 40: /* subf */ |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 1522 | op->val = regs->gpr[rb] - regs->gpr[ra]; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1523 | goto arith_done; |
| 1524 | #ifdef __powerpc64__ |
| 1525 | case 73: /* mulhd */ |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 1526 | asm("mulhd %0,%1,%2" : "=r" (op->val) : |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1527 | "r" (regs->gpr[ra]), "r" (regs->gpr[rb])); |
| 1528 | goto arith_done; |
| 1529 | #endif |
| 1530 | case 75: /* mulhw */ |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 1531 | asm("mulhw %0,%1,%2" : "=r" (op->val) : |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1532 | "r" (regs->gpr[ra]), "r" (regs->gpr[rb])); |
| 1533 | goto arith_done; |
| 1534 | |
| 1535 | case 104: /* neg */ |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 1536 | op->val = -regs->gpr[ra]; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1537 | goto arith_done; |
| 1538 | |
| 1539 | case 136: /* subfe */ |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 1540 | add_with_carry(regs, op, rd, ~regs->gpr[ra], |
| 1541 | regs->gpr[rb], regs->xer & XER_CA); |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1542 | goto arith_done; |
| 1543 | |
| 1544 | case 138: /* adde */ |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 1545 | add_with_carry(regs, op, rd, regs->gpr[ra], |
| 1546 | regs->gpr[rb], regs->xer & XER_CA); |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1547 | goto arith_done; |
| 1548 | |
| 1549 | case 200: /* subfze */ |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 1550 | add_with_carry(regs, op, rd, ~regs->gpr[ra], 0L, |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1551 | regs->xer & XER_CA); |
| 1552 | goto arith_done; |
| 1553 | |
| 1554 | case 202: /* addze */ |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 1555 | add_with_carry(regs, op, rd, regs->gpr[ra], 0L, |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1556 | regs->xer & XER_CA); |
| 1557 | goto arith_done; |
| 1558 | |
| 1559 | case 232: /* subfme */ |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 1560 | add_with_carry(regs, op, rd, ~regs->gpr[ra], -1L, |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1561 | regs->xer & XER_CA); |
| 1562 | goto arith_done; |
| 1563 | #ifdef __powerpc64__ |
| 1564 | case 233: /* mulld */ |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 1565 | op->val = regs->gpr[ra] * regs->gpr[rb]; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1566 | goto arith_done; |
| 1567 | #endif |
| 1568 | case 234: /* addme */ |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 1569 | add_with_carry(regs, op, rd, regs->gpr[ra], -1L, |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1570 | regs->xer & XER_CA); |
| 1571 | goto arith_done; |
| 1572 | |
| 1573 | case 235: /* mullw */ |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 1574 | op->val = (unsigned int) regs->gpr[ra] * |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1575 | (unsigned int) regs->gpr[rb]; |
| 1576 | goto arith_done; |
| 1577 | |
| 1578 | case 266: /* add */ |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 1579 | op->val = regs->gpr[ra] + regs->gpr[rb]; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1580 | goto arith_done; |
| 1581 | #ifdef __powerpc64__ |
| 1582 | case 457: /* divdu */ |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 1583 | op->val = regs->gpr[ra] / regs->gpr[rb]; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1584 | goto arith_done; |
| 1585 | #endif |
| 1586 | case 459: /* divwu */ |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 1587 | op->val = (unsigned int) regs->gpr[ra] / |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1588 | (unsigned int) regs->gpr[rb]; |
| 1589 | goto arith_done; |
| 1590 | #ifdef __powerpc64__ |
| 1591 | case 489: /* divd */ |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 1592 | op->val = (long int) regs->gpr[ra] / |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1593 | (long int) regs->gpr[rb]; |
| 1594 | goto arith_done; |
| 1595 | #endif |
| 1596 | case 491: /* divw */ |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 1597 | op->val = (int) regs->gpr[ra] / |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1598 | (int) regs->gpr[rb]; |
| 1599 | goto arith_done; |
| 1600 | |
| 1601 | |
| 1602 | /* |
| 1603 | * Logical instructions |
| 1604 | */ |
| 1605 | case 26: /* cntlzw */ |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 1606 | op->val = __builtin_clz((unsigned int) regs->gpr[rd]); |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1607 | goto logical_done; |
| 1608 | #ifdef __powerpc64__ |
| 1609 | case 58: /* cntlzd */ |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 1610 | op->val = __builtin_clzl(regs->gpr[rd]); |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1611 | goto logical_done; |
| 1612 | #endif |
| 1613 | case 28: /* and */ |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 1614 | op->val = regs->gpr[rd] & regs->gpr[rb]; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1615 | goto logical_done; |
| 1616 | |
| 1617 | case 60: /* andc */ |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 1618 | op->val = regs->gpr[rd] & ~regs->gpr[rb]; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1619 | goto logical_done; |
| 1620 | |
Matt Brown | dcbd19b | 2017-07-31 10:58:23 +1000 | [diff] [blame] | 1621 | case 122: /* popcntb */ |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 1622 | do_popcnt(regs, op, regs->gpr[rd], 8); |
Paul Mackerras | 5762e08 | 2017-08-30 14:12:30 +1000 | [diff] [blame] | 1623 | goto logical_done_nocc; |
Matt Brown | dcbd19b | 2017-07-31 10:58:23 +1000 | [diff] [blame] | 1624 | |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1625 | case 124: /* nor */ |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 1626 | op->val = ~(regs->gpr[rd] | regs->gpr[rb]); |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1627 | goto logical_done; |
Matt Brown | 2c979c4 | 2017-07-31 10:58:25 +1000 | [diff] [blame] | 1628 | |
| 1629 | case 154: /* prtyw */ |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 1630 | do_prty(regs, op, regs->gpr[rd], 32); |
Paul Mackerras | 5762e08 | 2017-08-30 14:12:30 +1000 | [diff] [blame] | 1631 | goto logical_done_nocc; |
Matt Brown | 2c979c4 | 2017-07-31 10:58:25 +1000 | [diff] [blame] | 1632 | |
| 1633 | case 186: /* prtyd */ |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 1634 | do_prty(regs, op, regs->gpr[rd], 64); |
Paul Mackerras | 5762e08 | 2017-08-30 14:12:30 +1000 | [diff] [blame] | 1635 | goto logical_done_nocc; |
Matt Brown | f312793 | 2017-07-31 10:58:24 +1000 | [diff] [blame] | 1636 | #ifdef CONFIG_PPC64 |
| 1637 | case 252: /* bpermd */ |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 1638 | do_bpermd(regs, op, regs->gpr[rd], regs->gpr[rb]); |
Paul Mackerras | 5762e08 | 2017-08-30 14:12:30 +1000 | [diff] [blame] | 1639 | goto logical_done_nocc; |
Matt Brown | f312793 | 2017-07-31 10:58:24 +1000 | [diff] [blame] | 1640 | #endif |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1641 | case 284: /* xor */ |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 1642 | op->val = ~(regs->gpr[rd] ^ regs->gpr[rb]); |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1643 | goto logical_done; |
| 1644 | |
| 1645 | case 316: /* xor */ |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 1646 | op->val = regs->gpr[rd] ^ regs->gpr[rb]; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1647 | goto logical_done; |
| 1648 | |
Matt Brown | dcbd19b | 2017-07-31 10:58:23 +1000 | [diff] [blame] | 1649 | case 378: /* popcntw */ |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 1650 | do_popcnt(regs, op, regs->gpr[rd], 32); |
Paul Mackerras | 5762e08 | 2017-08-30 14:12:30 +1000 | [diff] [blame] | 1651 | goto logical_done_nocc; |
Matt Brown | dcbd19b | 2017-07-31 10:58:23 +1000 | [diff] [blame] | 1652 | |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1653 | case 412: /* orc */ |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 1654 | op->val = regs->gpr[rd] | ~regs->gpr[rb]; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1655 | goto logical_done; |
| 1656 | |
| 1657 | case 444: /* or */ |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 1658 | op->val = regs->gpr[rd] | regs->gpr[rb]; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1659 | goto logical_done; |
| 1660 | |
| 1661 | case 476: /* nand */ |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 1662 | op->val = ~(regs->gpr[rd] & regs->gpr[rb]); |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1663 | goto logical_done; |
Matt Brown | dcbd19b | 2017-07-31 10:58:23 +1000 | [diff] [blame] | 1664 | #ifdef CONFIG_PPC64 |
| 1665 | case 506: /* popcntd */ |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 1666 | do_popcnt(regs, op, regs->gpr[rd], 64); |
Paul Mackerras | 5762e08 | 2017-08-30 14:12:30 +1000 | [diff] [blame] | 1667 | goto logical_done_nocc; |
Matt Brown | dcbd19b | 2017-07-31 10:58:23 +1000 | [diff] [blame] | 1668 | #endif |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1669 | case 922: /* extsh */ |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 1670 | op->val = (signed short) regs->gpr[rd]; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1671 | goto logical_done; |
| 1672 | |
| 1673 | case 954: /* extsb */ |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 1674 | op->val = (signed char) regs->gpr[rd]; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1675 | goto logical_done; |
| 1676 | #ifdef __powerpc64__ |
| 1677 | case 986: /* extsw */ |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 1678 | op->val = (signed int) regs->gpr[rd]; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1679 | goto logical_done; |
| 1680 | #endif |
| 1681 | |
| 1682 | /* |
| 1683 | * Shift instructions |
| 1684 | */ |
| 1685 | case 24: /* slw */ |
| 1686 | sh = regs->gpr[rb] & 0x3f; |
| 1687 | if (sh < 32) |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 1688 | op->val = (regs->gpr[rd] << sh) & 0xffffffffUL; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1689 | else |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 1690 | op->val = 0; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1691 | goto logical_done; |
| 1692 | |
| 1693 | case 536: /* srw */ |
| 1694 | sh = regs->gpr[rb] & 0x3f; |
| 1695 | if (sh < 32) |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 1696 | op->val = (regs->gpr[rd] & 0xffffffffUL) >> sh; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1697 | else |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 1698 | op->val = 0; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1699 | goto logical_done; |
| 1700 | |
| 1701 | case 792: /* sraw */ |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 1702 | op->type = COMPUTE + SETREG + SETXER; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1703 | sh = regs->gpr[rb] & 0x3f; |
| 1704 | ival = (signed int) regs->gpr[rd]; |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 1705 | op->val = ival >> (sh < 32 ? sh : 31); |
| 1706 | op->xerval = regs->xer; |
Paul Mackerras | e698b96 | 2014-07-19 17:47:57 +1000 | [diff] [blame] | 1707 | if (ival < 0 && (sh >= 32 || (ival & ((1ul << sh) - 1)) != 0)) |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 1708 | op->xerval |= XER_CA; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1709 | else |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 1710 | op->xerval &= ~XER_CA; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1711 | goto logical_done; |
| 1712 | |
| 1713 | case 824: /* srawi */ |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 1714 | op->type = COMPUTE + SETREG + SETXER; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1715 | sh = rb; |
| 1716 | ival = (signed int) regs->gpr[rd]; |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 1717 | op->val = ival >> sh; |
| 1718 | op->xerval = regs->xer; |
Paul Mackerras | e698b96 | 2014-07-19 17:47:57 +1000 | [diff] [blame] | 1719 | if (ival < 0 && (ival & ((1ul << sh) - 1)) != 0) |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 1720 | op->xerval |= XER_CA; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1721 | else |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 1722 | op->xerval &= ~XER_CA; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1723 | goto logical_done; |
| 1724 | |
| 1725 | #ifdef __powerpc64__ |
| 1726 | case 27: /* sld */ |
Paul Mackerras | e698b96 | 2014-07-19 17:47:57 +1000 | [diff] [blame] | 1727 | sh = regs->gpr[rb] & 0x7f; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1728 | if (sh < 64) |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 1729 | op->val = regs->gpr[rd] << sh; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1730 | else |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 1731 | op->val = 0; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1732 | goto logical_done; |
| 1733 | |
| 1734 | case 539: /* srd */ |
| 1735 | sh = regs->gpr[rb] & 0x7f; |
| 1736 | if (sh < 64) |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 1737 | op->val = regs->gpr[rd] >> sh; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1738 | else |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 1739 | op->val = 0; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1740 | goto logical_done; |
| 1741 | |
| 1742 | case 794: /* srad */ |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 1743 | op->type = COMPUTE + SETREG + SETXER; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1744 | sh = regs->gpr[rb] & 0x7f; |
| 1745 | ival = (signed long int) regs->gpr[rd]; |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 1746 | op->val = ival >> (sh < 64 ? sh : 63); |
| 1747 | op->xerval = regs->xer; |
Paul Mackerras | e698b96 | 2014-07-19 17:47:57 +1000 | [diff] [blame] | 1748 | if (ival < 0 && (sh >= 64 || (ival & ((1ul << sh) - 1)) != 0)) |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 1749 | op->xerval |= XER_CA; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1750 | else |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 1751 | op->xerval &= ~XER_CA; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1752 | goto logical_done; |
| 1753 | |
| 1754 | case 826: /* sradi with sh_5 = 0 */ |
| 1755 | case 827: /* sradi with sh_5 = 1 */ |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 1756 | op->type = COMPUTE + SETREG + SETXER; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1757 | sh = rb | ((instr & 2) << 4); |
| 1758 | ival = (signed long int) regs->gpr[rd]; |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 1759 | op->val = ival >> sh; |
| 1760 | op->xerval = regs->xer; |
Paul Mackerras | e698b96 | 2014-07-19 17:47:57 +1000 | [diff] [blame] | 1761 | if (ival < 0 && (ival & ((1ul << sh) - 1)) != 0) |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 1762 | op->xerval |= XER_CA; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1763 | else |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 1764 | op->xerval &= ~XER_CA; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1765 | goto logical_done; |
| 1766 | #endif /* __powerpc64__ */ |
| 1767 | |
| 1768 | /* |
| 1769 | * Cache instructions |
| 1770 | */ |
| 1771 | case 54: /* dcbst */ |
Paul Mackerras | be96f63 | 2014-09-02 14:35:07 +1000 | [diff] [blame] | 1772 | op->type = MKOP(CACHEOP, DCBST, 0); |
| 1773 | op->ea = xform_ea(instr, regs); |
| 1774 | return 0; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1775 | |
| 1776 | case 86: /* dcbf */ |
Paul Mackerras | be96f63 | 2014-09-02 14:35:07 +1000 | [diff] [blame] | 1777 | op->type = MKOP(CACHEOP, DCBF, 0); |
| 1778 | op->ea = xform_ea(instr, regs); |
| 1779 | return 0; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1780 | |
| 1781 | case 246: /* dcbtst */ |
Paul Mackerras | be96f63 | 2014-09-02 14:35:07 +1000 | [diff] [blame] | 1782 | op->type = MKOP(CACHEOP, DCBTST, 0); |
| 1783 | op->ea = xform_ea(instr, regs); |
| 1784 | op->reg = rd; |
| 1785 | return 0; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1786 | |
| 1787 | case 278: /* dcbt */ |
Paul Mackerras | be96f63 | 2014-09-02 14:35:07 +1000 | [diff] [blame] | 1788 | op->type = MKOP(CACHEOP, DCBTST, 0); |
| 1789 | op->ea = xform_ea(instr, regs); |
| 1790 | op->reg = rd; |
| 1791 | return 0; |
Paul Mackerras | cf87c3f | 2014-09-02 14:35:08 +1000 | [diff] [blame] | 1792 | |
| 1793 | case 982: /* icbi */ |
| 1794 | op->type = MKOP(CACHEOP, ICBI, 0); |
| 1795 | op->ea = xform_ea(instr, regs); |
| 1796 | return 0; |
Paul Mackerras | b2543f7 | 2017-08-30 14:12:36 +1000 | [diff] [blame] | 1797 | |
| 1798 | case 1014: /* dcbz */ |
| 1799 | op->type = MKOP(CACHEOP, DCBZ, 0); |
| 1800 | op->ea = xform_ea(instr, regs); |
| 1801 | return 0; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1802 | } |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1803 | break; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1804 | } |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1805 | |
Paul Mackerras | 350779a | 2017-08-30 14:12:27 +1000 | [diff] [blame] | 1806 | /* |
| 1807 | * Loads and stores. |
| 1808 | */ |
Paul Mackerras | be96f63 | 2014-09-02 14:35:07 +1000 | [diff] [blame] | 1809 | op->type = UNKNOWN; |
| 1810 | op->update_reg = ra; |
| 1811 | op->reg = rd; |
| 1812 | op->val = regs->gpr[rd]; |
| 1813 | u = (instr >> 20) & UPDATE; |
Paul Mackerras | 350779a | 2017-08-30 14:12:27 +1000 | [diff] [blame] | 1814 | op->vsx_flags = 0; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1815 | |
| 1816 | switch (opcode) { |
| 1817 | case 31: |
Paul Mackerras | be96f63 | 2014-09-02 14:35:07 +1000 | [diff] [blame] | 1818 | u = instr & UPDATE; |
| 1819 | op->ea = xform_ea(instr, regs); |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1820 | switch ((instr >> 1) & 0x3ff) { |
| 1821 | case 20: /* lwarx */ |
Paul Mackerras | be96f63 | 2014-09-02 14:35:07 +1000 | [diff] [blame] | 1822 | op->type = MKOP(LARX, 0, 4); |
| 1823 | break; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1824 | |
| 1825 | case 150: /* stwcx. */ |
Paul Mackerras | be96f63 | 2014-09-02 14:35:07 +1000 | [diff] [blame] | 1826 | op->type = MKOP(STCX, 0, 4); |
| 1827 | break; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1828 | |
| 1829 | #ifdef __powerpc64__ |
| 1830 | case 84: /* ldarx */ |
Paul Mackerras | be96f63 | 2014-09-02 14:35:07 +1000 | [diff] [blame] | 1831 | op->type = MKOP(LARX, 0, 8); |
| 1832 | break; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1833 | |
| 1834 | case 214: /* stdcx. */ |
Paul Mackerras | be96f63 | 2014-09-02 14:35:07 +1000 | [diff] [blame] | 1835 | op->type = MKOP(STCX, 0, 8); |
| 1836 | break; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1837 | |
Paul Mackerras | 350779a | 2017-08-30 14:12:27 +1000 | [diff] [blame] | 1838 | case 52: /* lbarx */ |
| 1839 | op->type = MKOP(LARX, 0, 1); |
| 1840 | break; |
| 1841 | |
| 1842 | case 694: /* stbcx. */ |
| 1843 | op->type = MKOP(STCX, 0, 1); |
| 1844 | break; |
| 1845 | |
| 1846 | case 116: /* lharx */ |
| 1847 | op->type = MKOP(LARX, 0, 2); |
| 1848 | break; |
| 1849 | |
| 1850 | case 726: /* sthcx. */ |
| 1851 | op->type = MKOP(STCX, 0, 2); |
| 1852 | break; |
| 1853 | |
| 1854 | case 276: /* lqarx */ |
| 1855 | if (!((rd & 1) || rd == ra || rd == rb)) |
| 1856 | op->type = MKOP(LARX, 0, 16); |
| 1857 | break; |
| 1858 | |
| 1859 | case 182: /* stqcx. */ |
| 1860 | if (!(rd & 1)) |
| 1861 | op->type = MKOP(STCX, 0, 16); |
Paul Mackerras | be96f63 | 2014-09-02 14:35:07 +1000 | [diff] [blame] | 1862 | break; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1863 | #endif |
| 1864 | |
| 1865 | case 23: /* lwzx */ |
| 1866 | case 55: /* lwzux */ |
Paul Mackerras | be96f63 | 2014-09-02 14:35:07 +1000 | [diff] [blame] | 1867 | op->type = MKOP(LOAD, u, 4); |
| 1868 | break; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1869 | |
| 1870 | case 87: /* lbzx */ |
| 1871 | case 119: /* lbzux */ |
Paul Mackerras | be96f63 | 2014-09-02 14:35:07 +1000 | [diff] [blame] | 1872 | op->type = MKOP(LOAD, u, 1); |
| 1873 | break; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1874 | |
| 1875 | #ifdef CONFIG_ALTIVEC |
Paul Mackerras | e61ccc7 | 2017-08-30 14:12:34 +1000 | [diff] [blame] | 1876 | /* |
| 1877 | * Note: for the load/store vector element instructions, |
| 1878 | * bits of the EA say which field of the VMX register to use. |
| 1879 | */ |
| 1880 | case 7: /* lvebx */ |
| 1881 | op->type = MKOP(LOAD_VMX, 0, 1); |
| 1882 | op->element_size = 1; |
| 1883 | break; |
| 1884 | |
| 1885 | case 39: /* lvehx */ |
| 1886 | op->type = MKOP(LOAD_VMX, 0, 2); |
| 1887 | op->element_size = 2; |
| 1888 | break; |
| 1889 | |
| 1890 | case 71: /* lvewx */ |
| 1891 | op->type = MKOP(LOAD_VMX, 0, 4); |
| 1892 | op->element_size = 4; |
| 1893 | break; |
| 1894 | |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1895 | case 103: /* lvx */ |
| 1896 | case 359: /* lvxl */ |
Paul Mackerras | be96f63 | 2014-09-02 14:35:07 +1000 | [diff] [blame] | 1897 | op->type = MKOP(LOAD_VMX, 0, 16); |
Paul Mackerras | 350779a | 2017-08-30 14:12:27 +1000 | [diff] [blame] | 1898 | op->element_size = 16; |
Paul Mackerras | be96f63 | 2014-09-02 14:35:07 +1000 | [diff] [blame] | 1899 | break; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1900 | |
Paul Mackerras | e61ccc7 | 2017-08-30 14:12:34 +1000 | [diff] [blame] | 1901 | case 135: /* stvebx */ |
| 1902 | op->type = MKOP(STORE_VMX, 0, 1); |
| 1903 | op->element_size = 1; |
| 1904 | break; |
| 1905 | |
| 1906 | case 167: /* stvehx */ |
| 1907 | op->type = MKOP(STORE_VMX, 0, 2); |
| 1908 | op->element_size = 2; |
| 1909 | break; |
| 1910 | |
| 1911 | case 199: /* stvewx */ |
| 1912 | op->type = MKOP(STORE_VMX, 0, 4); |
| 1913 | op->element_size = 4; |
| 1914 | break; |
| 1915 | |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1916 | case 231: /* stvx */ |
| 1917 | case 487: /* stvxl */ |
Paul Mackerras | be96f63 | 2014-09-02 14:35:07 +1000 | [diff] [blame] | 1918 | op->type = MKOP(STORE_VMX, 0, 16); |
| 1919 | break; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1920 | #endif /* CONFIG_ALTIVEC */ |
| 1921 | |
| 1922 | #ifdef __powerpc64__ |
Paul Mackerras | 350779a | 2017-08-30 14:12:27 +1000 | [diff] [blame] | 1923 | case 21: /* ldx */ |
| 1924 | case 53: /* ldux */ |
| 1925 | op->type = MKOP(LOAD, u, 8); |
| 1926 | break; |
| 1927 | |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1928 | case 149: /* stdx */ |
| 1929 | case 181: /* stdux */ |
Paul Mackerras | be96f63 | 2014-09-02 14:35:07 +1000 | [diff] [blame] | 1930 | op->type = MKOP(STORE, u, 8); |
| 1931 | break; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1932 | #endif |
| 1933 | |
| 1934 | case 151: /* stwx */ |
| 1935 | case 183: /* stwux */ |
Paul Mackerras | be96f63 | 2014-09-02 14:35:07 +1000 | [diff] [blame] | 1936 | op->type = MKOP(STORE, u, 4); |
| 1937 | break; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1938 | |
| 1939 | case 215: /* stbx */ |
| 1940 | case 247: /* stbux */ |
Paul Mackerras | be96f63 | 2014-09-02 14:35:07 +1000 | [diff] [blame] | 1941 | op->type = MKOP(STORE, u, 1); |
| 1942 | break; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1943 | |
| 1944 | case 279: /* lhzx */ |
| 1945 | case 311: /* lhzux */ |
Paul Mackerras | be96f63 | 2014-09-02 14:35:07 +1000 | [diff] [blame] | 1946 | op->type = MKOP(LOAD, u, 2); |
| 1947 | break; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1948 | |
| 1949 | #ifdef __powerpc64__ |
| 1950 | case 341: /* lwax */ |
| 1951 | case 373: /* lwaux */ |
Paul Mackerras | be96f63 | 2014-09-02 14:35:07 +1000 | [diff] [blame] | 1952 | op->type = MKOP(LOAD, SIGNEXT | u, 4); |
| 1953 | break; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1954 | #endif |
| 1955 | |
| 1956 | case 343: /* lhax */ |
| 1957 | case 375: /* lhaux */ |
Paul Mackerras | be96f63 | 2014-09-02 14:35:07 +1000 | [diff] [blame] | 1958 | op->type = MKOP(LOAD, SIGNEXT | u, 2); |
| 1959 | break; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1960 | |
| 1961 | case 407: /* sthx */ |
| 1962 | case 439: /* sthux */ |
Paul Mackerras | be96f63 | 2014-09-02 14:35:07 +1000 | [diff] [blame] | 1963 | op->type = MKOP(STORE, u, 2); |
| 1964 | break; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1965 | |
| 1966 | #ifdef __powerpc64__ |
| 1967 | case 532: /* ldbrx */ |
Paul Mackerras | be96f63 | 2014-09-02 14:35:07 +1000 | [diff] [blame] | 1968 | op->type = MKOP(LOAD, BYTEREV, 8); |
| 1969 | break; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1970 | |
| 1971 | #endif |
Paul Mackerras | c9f6f4e | 2014-09-02 14:35:09 +1000 | [diff] [blame] | 1972 | case 533: /* lswx */ |
| 1973 | op->type = MKOP(LOAD_MULTI, 0, regs->xer & 0x7f); |
| 1974 | break; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1975 | |
| 1976 | case 534: /* lwbrx */ |
Paul Mackerras | be96f63 | 2014-09-02 14:35:07 +1000 | [diff] [blame] | 1977 | op->type = MKOP(LOAD, BYTEREV, 4); |
| 1978 | break; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1979 | |
Paul Mackerras | c9f6f4e | 2014-09-02 14:35:09 +1000 | [diff] [blame] | 1980 | case 597: /* lswi */ |
| 1981 | if (rb == 0) |
| 1982 | rb = 32; /* # bytes to load */ |
| 1983 | op->type = MKOP(LOAD_MULTI, 0, rb); |
Paul Mackerras | d120cdb | 2017-08-30 14:12:28 +1000 | [diff] [blame] | 1984 | op->ea = ra ? regs->gpr[ra] : 0; |
Paul Mackerras | c9f6f4e | 2014-09-02 14:35:09 +1000 | [diff] [blame] | 1985 | break; |
| 1986 | |
Paul Bolle | b69a1da | 2014-05-20 21:59:42 +0200 | [diff] [blame] | 1987 | #ifdef CONFIG_PPC_FPU |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1988 | case 535: /* lfsx */ |
| 1989 | case 567: /* lfsux */ |
Paul Mackerras | be96f63 | 2014-09-02 14:35:07 +1000 | [diff] [blame] | 1990 | op->type = MKOP(LOAD_FP, u, 4); |
| 1991 | break; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1992 | |
| 1993 | case 599: /* lfdx */ |
| 1994 | case 631: /* lfdux */ |
Paul Mackerras | be96f63 | 2014-09-02 14:35:07 +1000 | [diff] [blame] | 1995 | op->type = MKOP(LOAD_FP, u, 8); |
| 1996 | break; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 1997 | |
| 1998 | case 663: /* stfsx */ |
| 1999 | case 695: /* stfsux */ |
Paul Mackerras | be96f63 | 2014-09-02 14:35:07 +1000 | [diff] [blame] | 2000 | op->type = MKOP(STORE_FP, u, 4); |
| 2001 | break; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 2002 | |
| 2003 | case 727: /* stfdx */ |
| 2004 | case 759: /* stfdux */ |
Paul Mackerras | be96f63 | 2014-09-02 14:35:07 +1000 | [diff] [blame] | 2005 | op->type = MKOP(STORE_FP, u, 8); |
| 2006 | break; |
Paul Mackerras | 1f41fb7 | 2017-08-30 14:12:35 +1000 | [diff] [blame] | 2007 | |
| 2008 | #ifdef __powerpc64__ |
| 2009 | case 791: /* lfdpx */ |
| 2010 | op->type = MKOP(LOAD_FP, 0, 16); |
| 2011 | break; |
| 2012 | |
| 2013 | case 919: /* stfdpx */ |
| 2014 | op->type = MKOP(STORE_FP, 0, 16); |
| 2015 | break; |
| 2016 | #endif /* __powerpc64 */ |
| 2017 | #endif /* CONFIG_PPC_FPU */ |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 2018 | |
| 2019 | #ifdef __powerpc64__ |
| 2020 | case 660: /* stdbrx */ |
Paul Mackerras | be96f63 | 2014-09-02 14:35:07 +1000 | [diff] [blame] | 2021 | op->type = MKOP(STORE, BYTEREV, 8); |
| 2022 | op->val = byterev_8(regs->gpr[rd]); |
| 2023 | break; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 2024 | |
| 2025 | #endif |
Paul Mackerras | c9f6f4e | 2014-09-02 14:35:09 +1000 | [diff] [blame] | 2026 | case 661: /* stswx */ |
| 2027 | op->type = MKOP(STORE_MULTI, 0, regs->xer & 0x7f); |
| 2028 | break; |
| 2029 | |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 2030 | case 662: /* stwbrx */ |
Paul Mackerras | be96f63 | 2014-09-02 14:35:07 +1000 | [diff] [blame] | 2031 | op->type = MKOP(STORE, BYTEREV, 4); |
| 2032 | op->val = byterev_4(regs->gpr[rd]); |
| 2033 | break; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 2034 | |
Paul Mackerras | 1f41fb7 | 2017-08-30 14:12:35 +1000 | [diff] [blame] | 2035 | case 725: /* stswi */ |
Paul Mackerras | c9f6f4e | 2014-09-02 14:35:09 +1000 | [diff] [blame] | 2036 | if (rb == 0) |
| 2037 | rb = 32; /* # bytes to store */ |
| 2038 | op->type = MKOP(STORE_MULTI, 0, rb); |
Paul Mackerras | d120cdb | 2017-08-30 14:12:28 +1000 | [diff] [blame] | 2039 | op->ea = ra ? regs->gpr[ra] : 0; |
Paul Mackerras | c9f6f4e | 2014-09-02 14:35:09 +1000 | [diff] [blame] | 2040 | break; |
| 2041 | |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 2042 | case 790: /* lhbrx */ |
Paul Mackerras | be96f63 | 2014-09-02 14:35:07 +1000 | [diff] [blame] | 2043 | op->type = MKOP(LOAD, BYTEREV, 2); |
| 2044 | break; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 2045 | |
| 2046 | case 918: /* sthbrx */ |
Paul Mackerras | be96f63 | 2014-09-02 14:35:07 +1000 | [diff] [blame] | 2047 | op->type = MKOP(STORE, BYTEREV, 2); |
| 2048 | op->val = byterev_2(regs->gpr[rd]); |
| 2049 | break; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 2050 | |
| 2051 | #ifdef CONFIG_VSX |
Paul Mackerras | 350779a | 2017-08-30 14:12:27 +1000 | [diff] [blame] | 2052 | case 12: /* lxsiwzx */ |
Paul Mackerras | be96f63 | 2014-09-02 14:35:07 +1000 | [diff] [blame] | 2053 | op->reg = rd | ((instr & 1) << 5); |
Paul Mackerras | 350779a | 2017-08-30 14:12:27 +1000 | [diff] [blame] | 2054 | op->type = MKOP(LOAD_VSX, 0, 4); |
| 2055 | op->element_size = 8; |
| 2056 | break; |
| 2057 | |
| 2058 | case 76: /* lxsiwax */ |
| 2059 | op->reg = rd | ((instr & 1) << 5); |
| 2060 | op->type = MKOP(LOAD_VSX, SIGNEXT, 4); |
| 2061 | op->element_size = 8; |
| 2062 | break; |
| 2063 | |
| 2064 | case 140: /* stxsiwx */ |
| 2065 | op->reg = rd | ((instr & 1) << 5); |
| 2066 | op->type = MKOP(STORE_VSX, 0, 4); |
| 2067 | op->element_size = 8; |
| 2068 | break; |
| 2069 | |
| 2070 | case 268: /* lxvx */ |
| 2071 | op->reg = rd | ((instr & 1) << 5); |
| 2072 | op->type = MKOP(LOAD_VSX, 0, 16); |
| 2073 | op->element_size = 16; |
| 2074 | op->vsx_flags = VSX_CHECK_VEC; |
| 2075 | break; |
| 2076 | |
| 2077 | case 269: /* lxvl */ |
| 2078 | case 301: { /* lxvll */ |
| 2079 | int nb; |
| 2080 | op->reg = rd | ((instr & 1) << 5); |
| 2081 | op->ea = ra ? regs->gpr[ra] : 0; |
| 2082 | nb = regs->gpr[rb] & 0xff; |
| 2083 | if (nb > 16) |
| 2084 | nb = 16; |
| 2085 | op->type = MKOP(LOAD_VSX, 0, nb); |
| 2086 | op->element_size = 16; |
| 2087 | op->vsx_flags = ((instr & 0x20) ? VSX_LDLEFT : 0) | |
| 2088 | VSX_CHECK_VEC; |
| 2089 | break; |
| 2090 | } |
| 2091 | case 332: /* lxvdsx */ |
| 2092 | op->reg = rd | ((instr & 1) << 5); |
| 2093 | op->type = MKOP(LOAD_VSX, 0, 8); |
| 2094 | op->element_size = 8; |
| 2095 | op->vsx_flags = VSX_SPLAT; |
| 2096 | break; |
| 2097 | |
| 2098 | case 364: /* lxvwsx */ |
| 2099 | op->reg = rd | ((instr & 1) << 5); |
| 2100 | op->type = MKOP(LOAD_VSX, 0, 4); |
| 2101 | op->element_size = 4; |
| 2102 | op->vsx_flags = VSX_SPLAT | VSX_CHECK_VEC; |
| 2103 | break; |
| 2104 | |
| 2105 | case 396: /* stxvx */ |
| 2106 | op->reg = rd | ((instr & 1) << 5); |
| 2107 | op->type = MKOP(STORE_VSX, 0, 16); |
| 2108 | op->element_size = 16; |
| 2109 | op->vsx_flags = VSX_CHECK_VEC; |
| 2110 | break; |
| 2111 | |
| 2112 | case 397: /* stxvl */ |
| 2113 | case 429: { /* stxvll */ |
| 2114 | int nb; |
| 2115 | op->reg = rd | ((instr & 1) << 5); |
| 2116 | op->ea = ra ? regs->gpr[ra] : 0; |
| 2117 | nb = regs->gpr[rb] & 0xff; |
| 2118 | if (nb > 16) |
| 2119 | nb = 16; |
| 2120 | op->type = MKOP(STORE_VSX, 0, nb); |
| 2121 | op->element_size = 16; |
| 2122 | op->vsx_flags = ((instr & 0x20) ? VSX_LDLEFT : 0) | |
| 2123 | VSX_CHECK_VEC; |
| 2124 | break; |
| 2125 | } |
| 2126 | case 524: /* lxsspx */ |
| 2127 | op->reg = rd | ((instr & 1) << 5); |
| 2128 | op->type = MKOP(LOAD_VSX, 0, 4); |
| 2129 | op->element_size = 8; |
| 2130 | op->vsx_flags = VSX_FPCONV; |
| 2131 | break; |
| 2132 | |
| 2133 | case 588: /* lxsdx */ |
| 2134 | op->reg = rd | ((instr & 1) << 5); |
| 2135 | op->type = MKOP(LOAD_VSX, 0, 8); |
| 2136 | op->element_size = 8; |
| 2137 | break; |
| 2138 | |
| 2139 | case 652: /* stxsspx */ |
| 2140 | op->reg = rd | ((instr & 1) << 5); |
| 2141 | op->type = MKOP(STORE_VSX, 0, 4); |
| 2142 | op->element_size = 8; |
| 2143 | op->vsx_flags = VSX_FPCONV; |
| 2144 | break; |
| 2145 | |
| 2146 | case 716: /* stxsdx */ |
| 2147 | op->reg = rd | ((instr & 1) << 5); |
| 2148 | op->type = MKOP(STORE_VSX, 0, 8); |
| 2149 | op->element_size = 8; |
| 2150 | break; |
| 2151 | |
| 2152 | case 780: /* lxvw4x */ |
| 2153 | op->reg = rd | ((instr & 1) << 5); |
| 2154 | op->type = MKOP(LOAD_VSX, 0, 16); |
| 2155 | op->element_size = 4; |
| 2156 | break; |
| 2157 | |
| 2158 | case 781: /* lxsibzx */ |
| 2159 | op->reg = rd | ((instr & 1) << 5); |
| 2160 | op->type = MKOP(LOAD_VSX, 0, 1); |
| 2161 | op->element_size = 8; |
| 2162 | op->vsx_flags = VSX_CHECK_VEC; |
| 2163 | break; |
| 2164 | |
| 2165 | case 812: /* lxvh8x */ |
| 2166 | op->reg = rd | ((instr & 1) << 5); |
| 2167 | op->type = MKOP(LOAD_VSX, 0, 16); |
| 2168 | op->element_size = 2; |
| 2169 | op->vsx_flags = VSX_CHECK_VEC; |
| 2170 | break; |
| 2171 | |
| 2172 | case 813: /* lxsihzx */ |
| 2173 | op->reg = rd | ((instr & 1) << 5); |
| 2174 | op->type = MKOP(LOAD_VSX, 0, 2); |
| 2175 | op->element_size = 8; |
| 2176 | op->vsx_flags = VSX_CHECK_VEC; |
| 2177 | break; |
| 2178 | |
| 2179 | case 844: /* lxvd2x */ |
| 2180 | op->reg = rd | ((instr & 1) << 5); |
| 2181 | op->type = MKOP(LOAD_VSX, 0, 16); |
| 2182 | op->element_size = 8; |
| 2183 | break; |
| 2184 | |
| 2185 | case 876: /* lxvb16x */ |
| 2186 | op->reg = rd | ((instr & 1) << 5); |
| 2187 | op->type = MKOP(LOAD_VSX, 0, 16); |
| 2188 | op->element_size = 1; |
| 2189 | op->vsx_flags = VSX_CHECK_VEC; |
| 2190 | break; |
| 2191 | |
| 2192 | case 908: /* stxvw4x */ |
| 2193 | op->reg = rd | ((instr & 1) << 5); |
| 2194 | op->type = MKOP(STORE_VSX, 0, 16); |
| 2195 | op->element_size = 4; |
| 2196 | break; |
| 2197 | |
| 2198 | case 909: /* stxsibx */ |
| 2199 | op->reg = rd | ((instr & 1) << 5); |
| 2200 | op->type = MKOP(STORE_VSX, 0, 1); |
| 2201 | op->element_size = 8; |
| 2202 | op->vsx_flags = VSX_CHECK_VEC; |
| 2203 | break; |
| 2204 | |
| 2205 | case 940: /* stxvh8x */ |
| 2206 | op->reg = rd | ((instr & 1) << 5); |
| 2207 | op->type = MKOP(STORE_VSX, 0, 16); |
| 2208 | op->element_size = 2; |
| 2209 | op->vsx_flags = VSX_CHECK_VEC; |
| 2210 | break; |
| 2211 | |
| 2212 | case 941: /* stxsihx */ |
| 2213 | op->reg = rd | ((instr & 1) << 5); |
| 2214 | op->type = MKOP(STORE_VSX, 0, 2); |
| 2215 | op->element_size = 8; |
| 2216 | op->vsx_flags = VSX_CHECK_VEC; |
Paul Mackerras | be96f63 | 2014-09-02 14:35:07 +1000 | [diff] [blame] | 2217 | break; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 2218 | |
| 2219 | case 972: /* stxvd2x */ |
Paul Mackerras | be96f63 | 2014-09-02 14:35:07 +1000 | [diff] [blame] | 2220 | op->reg = rd | ((instr & 1) << 5); |
Paul Mackerras | 350779a | 2017-08-30 14:12:27 +1000 | [diff] [blame] | 2221 | op->type = MKOP(STORE_VSX, 0, 16); |
| 2222 | op->element_size = 8; |
| 2223 | break; |
| 2224 | |
| 2225 | case 1004: /* stxvb16x */ |
| 2226 | op->reg = rd | ((instr & 1) << 5); |
| 2227 | op->type = MKOP(STORE_VSX, 0, 16); |
| 2228 | op->element_size = 1; |
| 2229 | op->vsx_flags = VSX_CHECK_VEC; |
Paul Mackerras | be96f63 | 2014-09-02 14:35:07 +1000 | [diff] [blame] | 2230 | break; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 2231 | |
| 2232 | #endif /* CONFIG_VSX */ |
| 2233 | } |
| 2234 | break; |
| 2235 | |
| 2236 | case 32: /* lwz */ |
| 2237 | case 33: /* lwzu */ |
Paul Mackerras | be96f63 | 2014-09-02 14:35:07 +1000 | [diff] [blame] | 2238 | op->type = MKOP(LOAD, u, 4); |
| 2239 | op->ea = dform_ea(instr, regs); |
| 2240 | break; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 2241 | |
| 2242 | case 34: /* lbz */ |
| 2243 | case 35: /* lbzu */ |
Paul Mackerras | be96f63 | 2014-09-02 14:35:07 +1000 | [diff] [blame] | 2244 | op->type = MKOP(LOAD, u, 1); |
| 2245 | op->ea = dform_ea(instr, regs); |
| 2246 | break; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 2247 | |
| 2248 | case 36: /* stw */ |
Tiejun Chen | 8e9f693 | 2012-09-16 23:54:31 +0000 | [diff] [blame] | 2249 | case 37: /* stwu */ |
Paul Mackerras | be96f63 | 2014-09-02 14:35:07 +1000 | [diff] [blame] | 2250 | op->type = MKOP(STORE, u, 4); |
| 2251 | op->ea = dform_ea(instr, regs); |
| 2252 | break; |
Tiejun Chen | 8e9f693 | 2012-09-16 23:54:31 +0000 | [diff] [blame] | 2253 | |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 2254 | case 38: /* stb */ |
| 2255 | case 39: /* stbu */ |
Paul Mackerras | be96f63 | 2014-09-02 14:35:07 +1000 | [diff] [blame] | 2256 | op->type = MKOP(STORE, u, 1); |
| 2257 | op->ea = dform_ea(instr, regs); |
| 2258 | break; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 2259 | |
| 2260 | case 40: /* lhz */ |
| 2261 | case 41: /* lhzu */ |
Paul Mackerras | be96f63 | 2014-09-02 14:35:07 +1000 | [diff] [blame] | 2262 | op->type = MKOP(LOAD, u, 2); |
| 2263 | op->ea = dform_ea(instr, regs); |
| 2264 | break; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 2265 | |
| 2266 | case 42: /* lha */ |
| 2267 | case 43: /* lhau */ |
Paul Mackerras | be96f63 | 2014-09-02 14:35:07 +1000 | [diff] [blame] | 2268 | op->type = MKOP(LOAD, SIGNEXT | u, 2); |
| 2269 | op->ea = dform_ea(instr, regs); |
| 2270 | break; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 2271 | |
| 2272 | case 44: /* sth */ |
| 2273 | case 45: /* sthu */ |
Paul Mackerras | be96f63 | 2014-09-02 14:35:07 +1000 | [diff] [blame] | 2274 | op->type = MKOP(STORE, u, 2); |
| 2275 | op->ea = dform_ea(instr, regs); |
| 2276 | break; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 2277 | |
| 2278 | case 46: /* lmw */ |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 2279 | if (ra >= rd) |
| 2280 | break; /* invalid form, ra in range to load */ |
Paul Mackerras | c9f6f4e | 2014-09-02 14:35:09 +1000 | [diff] [blame] | 2281 | op->type = MKOP(LOAD_MULTI, 0, 4 * (32 - rd)); |
Paul Mackerras | be96f63 | 2014-09-02 14:35:07 +1000 | [diff] [blame] | 2282 | op->ea = dform_ea(instr, regs); |
| 2283 | break; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 2284 | |
| 2285 | case 47: /* stmw */ |
Paul Mackerras | c9f6f4e | 2014-09-02 14:35:09 +1000 | [diff] [blame] | 2286 | op->type = MKOP(STORE_MULTI, 0, 4 * (32 - rd)); |
Paul Mackerras | be96f63 | 2014-09-02 14:35:07 +1000 | [diff] [blame] | 2287 | op->ea = dform_ea(instr, regs); |
| 2288 | break; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 2289 | |
Sean MacLennan | cd64d16 | 2010-09-01 07:21:21 +0000 | [diff] [blame] | 2290 | #ifdef CONFIG_PPC_FPU |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 2291 | case 48: /* lfs */ |
| 2292 | case 49: /* lfsu */ |
Paul Mackerras | be96f63 | 2014-09-02 14:35:07 +1000 | [diff] [blame] | 2293 | op->type = MKOP(LOAD_FP, u, 4); |
| 2294 | op->ea = dform_ea(instr, regs); |
| 2295 | break; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 2296 | |
| 2297 | case 50: /* lfd */ |
| 2298 | case 51: /* lfdu */ |
Paul Mackerras | be96f63 | 2014-09-02 14:35:07 +1000 | [diff] [blame] | 2299 | op->type = MKOP(LOAD_FP, u, 8); |
| 2300 | op->ea = dform_ea(instr, regs); |
| 2301 | break; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 2302 | |
| 2303 | case 52: /* stfs */ |
| 2304 | case 53: /* stfsu */ |
Paul Mackerras | be96f63 | 2014-09-02 14:35:07 +1000 | [diff] [blame] | 2305 | op->type = MKOP(STORE_FP, u, 4); |
| 2306 | op->ea = dform_ea(instr, regs); |
| 2307 | break; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 2308 | |
| 2309 | case 54: /* stfd */ |
| 2310 | case 55: /* stfdu */ |
Paul Mackerras | be96f63 | 2014-09-02 14:35:07 +1000 | [diff] [blame] | 2311 | op->type = MKOP(STORE_FP, u, 8); |
| 2312 | op->ea = dform_ea(instr, regs); |
| 2313 | break; |
Sean MacLennan | cd64d16 | 2010-09-01 07:21:21 +0000 | [diff] [blame] | 2314 | #endif |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 2315 | |
| 2316 | #ifdef __powerpc64__ |
Paul Mackerras | 350779a | 2017-08-30 14:12:27 +1000 | [diff] [blame] | 2317 | case 56: /* lq */ |
| 2318 | if (!((rd & 1) || (rd == ra))) |
| 2319 | op->type = MKOP(LOAD, 0, 16); |
| 2320 | op->ea = dqform_ea(instr, regs); |
| 2321 | break; |
| 2322 | #endif |
| 2323 | |
| 2324 | #ifdef CONFIG_VSX |
Paul Mackerras | 1f41fb7 | 2017-08-30 14:12:35 +1000 | [diff] [blame] | 2325 | case 57: /* lfdp, lxsd, lxssp */ |
Paul Mackerras | 350779a | 2017-08-30 14:12:27 +1000 | [diff] [blame] | 2326 | op->ea = dsform_ea(instr, regs); |
| 2327 | switch (instr & 3) { |
Paul Mackerras | 1f41fb7 | 2017-08-30 14:12:35 +1000 | [diff] [blame] | 2328 | case 0: /* lfdp */ |
| 2329 | if (rd & 1) |
| 2330 | break; /* reg must be even */ |
| 2331 | op->type = MKOP(LOAD_FP, 0, 16); |
| 2332 | break; |
Paul Mackerras | 350779a | 2017-08-30 14:12:27 +1000 | [diff] [blame] | 2333 | case 2: /* lxsd */ |
| 2334 | op->reg = rd + 32; |
| 2335 | op->type = MKOP(LOAD_VSX, 0, 8); |
| 2336 | op->element_size = 8; |
| 2337 | op->vsx_flags = VSX_CHECK_VEC; |
| 2338 | break; |
| 2339 | case 3: /* lxssp */ |
| 2340 | op->reg = rd + 32; |
| 2341 | op->type = MKOP(LOAD_VSX, 0, 4); |
| 2342 | op->element_size = 8; |
| 2343 | op->vsx_flags = VSX_FPCONV | VSX_CHECK_VEC; |
| 2344 | break; |
| 2345 | } |
| 2346 | break; |
| 2347 | #endif /* CONFIG_VSX */ |
| 2348 | |
| 2349 | #ifdef __powerpc64__ |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 2350 | case 58: /* ld[u], lwa */ |
Paul Mackerras | be96f63 | 2014-09-02 14:35:07 +1000 | [diff] [blame] | 2351 | op->ea = dsform_ea(instr, regs); |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 2352 | switch (instr & 3) { |
| 2353 | case 0: /* ld */ |
Paul Mackerras | be96f63 | 2014-09-02 14:35:07 +1000 | [diff] [blame] | 2354 | op->type = MKOP(LOAD, 0, 8); |
| 2355 | break; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 2356 | case 1: /* ldu */ |
Paul Mackerras | be96f63 | 2014-09-02 14:35:07 +1000 | [diff] [blame] | 2357 | op->type = MKOP(LOAD, UPDATE, 8); |
| 2358 | break; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 2359 | case 2: /* lwa */ |
Paul Mackerras | be96f63 | 2014-09-02 14:35:07 +1000 | [diff] [blame] | 2360 | op->type = MKOP(LOAD, SIGNEXT, 4); |
| 2361 | break; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 2362 | } |
| 2363 | break; |
Paul Mackerras | 350779a | 2017-08-30 14:12:27 +1000 | [diff] [blame] | 2364 | #endif |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 2365 | |
Paul Mackerras | 350779a | 2017-08-30 14:12:27 +1000 | [diff] [blame] | 2366 | #ifdef CONFIG_VSX |
Paul Mackerras | 1f41fb7 | 2017-08-30 14:12:35 +1000 | [diff] [blame] | 2367 | case 61: /* stfdp, lxv, stxsd, stxssp, stxv */ |
Paul Mackerras | 350779a | 2017-08-30 14:12:27 +1000 | [diff] [blame] | 2368 | switch (instr & 7) { |
Paul Mackerras | 1f41fb7 | 2017-08-30 14:12:35 +1000 | [diff] [blame] | 2369 | case 0: /* stfdp with LSB of DS field = 0 */ |
| 2370 | case 4: /* stfdp with LSB of DS field = 1 */ |
| 2371 | op->ea = dsform_ea(instr, regs); |
| 2372 | op->type = MKOP(STORE_FP, 0, 16); |
| 2373 | break; |
| 2374 | |
Paul Mackerras | 350779a | 2017-08-30 14:12:27 +1000 | [diff] [blame] | 2375 | case 1: /* lxv */ |
| 2376 | op->ea = dqform_ea(instr, regs); |
| 2377 | if (instr & 8) |
| 2378 | op->reg = rd + 32; |
| 2379 | op->type = MKOP(LOAD_VSX, 0, 16); |
| 2380 | op->element_size = 16; |
| 2381 | op->vsx_flags = VSX_CHECK_VEC; |
| 2382 | break; |
| 2383 | |
| 2384 | case 2: /* stxsd with LSB of DS field = 0 */ |
| 2385 | case 6: /* stxsd with LSB of DS field = 1 */ |
| 2386 | op->ea = dsform_ea(instr, regs); |
| 2387 | op->reg = rd + 32; |
| 2388 | op->type = MKOP(STORE_VSX, 0, 8); |
| 2389 | op->element_size = 8; |
| 2390 | op->vsx_flags = VSX_CHECK_VEC; |
| 2391 | break; |
| 2392 | |
| 2393 | case 3: /* stxssp with LSB of DS field = 0 */ |
| 2394 | case 7: /* stxssp with LSB of DS field = 1 */ |
| 2395 | op->ea = dsform_ea(instr, regs); |
| 2396 | op->reg = rd + 32; |
| 2397 | op->type = MKOP(STORE_VSX, 0, 4); |
| 2398 | op->element_size = 8; |
| 2399 | op->vsx_flags = VSX_FPCONV | VSX_CHECK_VEC; |
| 2400 | break; |
| 2401 | |
| 2402 | case 5: /* stxv */ |
| 2403 | op->ea = dqform_ea(instr, regs); |
| 2404 | if (instr & 8) |
| 2405 | op->reg = rd + 32; |
| 2406 | op->type = MKOP(STORE_VSX, 0, 16); |
| 2407 | op->element_size = 16; |
| 2408 | op->vsx_flags = VSX_CHECK_VEC; |
| 2409 | break; |
| 2410 | } |
| 2411 | break; |
| 2412 | #endif /* CONFIG_VSX */ |
| 2413 | |
| 2414 | #ifdef __powerpc64__ |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 2415 | case 62: /* std[u] */ |
Paul Mackerras | be96f63 | 2014-09-02 14:35:07 +1000 | [diff] [blame] | 2416 | op->ea = dsform_ea(instr, regs); |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 2417 | switch (instr & 3) { |
| 2418 | case 0: /* std */ |
Paul Mackerras | be96f63 | 2014-09-02 14:35:07 +1000 | [diff] [blame] | 2419 | op->type = MKOP(STORE, 0, 8); |
| 2420 | break; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 2421 | case 1: /* stdu */ |
Paul Mackerras | be96f63 | 2014-09-02 14:35:07 +1000 | [diff] [blame] | 2422 | op->type = MKOP(STORE, UPDATE, 8); |
| 2423 | break; |
Paul Mackerras | 350779a | 2017-08-30 14:12:27 +1000 | [diff] [blame] | 2424 | case 2: /* stq */ |
| 2425 | if (!(rd & 1)) |
| 2426 | op->type = MKOP(STORE, 0, 16); |
| 2427 | break; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 2428 | } |
| 2429 | break; |
| 2430 | #endif /* __powerpc64__ */ |
| 2431 | |
| 2432 | } |
Paul Mackerras | be96f63 | 2014-09-02 14:35:07 +1000 | [diff] [blame] | 2433 | return 0; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 2434 | |
| 2435 | logical_done: |
| 2436 | if (instr & 1) |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 2437 | set_cr0(regs, op, ra); |
| 2438 | logical_done_nocc: |
| 2439 | op->reg = ra; |
| 2440 | op->type |= SETREG; |
| 2441 | return 1; |
Paul Mackerras | 0016a4c | 2010-06-15 14:48:58 +1000 | [diff] [blame] | 2442 | |
| 2443 | arith_done: |
| 2444 | if (instr & 1) |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 2445 | set_cr0(regs, op, rd); |
| 2446 | compute_done: |
| 2447 | op->reg = rd; |
| 2448 | op->type |= SETREG; |
Paul Mackerras | be96f63 | 2014-09-02 14:35:07 +1000 | [diff] [blame] | 2449 | return 1; |
| 2450 | |
| 2451 | priv: |
| 2452 | op->type = INTERRUPT | 0x700; |
| 2453 | op->val = SRR1_PROGPRIV; |
| 2454 | return 0; |
| 2455 | |
Paul Mackerras | cf87c3f | 2014-09-02 14:35:08 +1000 | [diff] [blame] | 2456 | trap: |
| 2457 | op->type = INTERRUPT | 0x700; |
| 2458 | op->val = SRR1_PROGTRAP; |
| 2459 | return 0; |
Paul Mackerras | be96f63 | 2014-09-02 14:35:07 +1000 | [diff] [blame] | 2460 | } |
| 2461 | EXPORT_SYMBOL_GPL(analyse_instr); |
Naveen N. Rao | 71f6e58 | 2017-04-12 16:48:51 +0530 | [diff] [blame] | 2462 | NOKPROBE_SYMBOL(analyse_instr); |
Paul Mackerras | be96f63 | 2014-09-02 14:35:07 +1000 | [diff] [blame] | 2463 | |
| 2464 | /* |
| 2465 | * For PPC32 we always use stwu with r1 to change the stack pointer. |
| 2466 | * So this emulated store may corrupt the exception frame, now we |
| 2467 | * have to provide the exception frame trampoline, which is pushed |
| 2468 | * below the kprobed function stack. So we only update gpr[1] but |
| 2469 | * don't emulate the real store operation. We will do real store |
| 2470 | * operation safely in exception return code by checking this flag. |
| 2471 | */ |
Naveen N. Rao | 71f6e58 | 2017-04-12 16:48:51 +0530 | [diff] [blame] | 2472 | static nokprobe_inline int handle_stack_update(unsigned long ea, struct pt_regs *regs) |
Paul Mackerras | be96f63 | 2014-09-02 14:35:07 +1000 | [diff] [blame] | 2473 | { |
| 2474 | #ifdef CONFIG_PPC32 |
| 2475 | /* |
| 2476 | * Check if we will touch kernel stack overflow |
| 2477 | */ |
| 2478 | if (ea - STACK_INT_FRAME_SIZE <= current->thread.ksp_limit) { |
| 2479 | printk(KERN_CRIT "Can't kprobe this since kernel stack would overflow.\n"); |
| 2480 | return -EINVAL; |
| 2481 | } |
| 2482 | #endif /* CONFIG_PPC32 */ |
| 2483 | /* |
| 2484 | * Check if we already set since that means we'll |
| 2485 | * lose the previous value. |
| 2486 | */ |
| 2487 | WARN_ON(test_thread_flag(TIF_EMULATE_STACK_STORE)); |
| 2488 | set_thread_flag(TIF_EMULATE_STACK_STORE); |
| 2489 | return 0; |
| 2490 | } |
| 2491 | |
Naveen N. Rao | 71f6e58 | 2017-04-12 16:48:51 +0530 | [diff] [blame] | 2492 | static nokprobe_inline void do_signext(unsigned long *valp, int size) |
Paul Mackerras | be96f63 | 2014-09-02 14:35:07 +1000 | [diff] [blame] | 2493 | { |
| 2494 | switch (size) { |
| 2495 | case 2: |
| 2496 | *valp = (signed short) *valp; |
| 2497 | break; |
| 2498 | case 4: |
| 2499 | *valp = (signed int) *valp; |
| 2500 | break; |
| 2501 | } |
| 2502 | } |
| 2503 | |
Naveen N. Rao | 71f6e58 | 2017-04-12 16:48:51 +0530 | [diff] [blame] | 2504 | static nokprobe_inline void do_byterev(unsigned long *valp, int size) |
Paul Mackerras | be96f63 | 2014-09-02 14:35:07 +1000 | [diff] [blame] | 2505 | { |
| 2506 | switch (size) { |
| 2507 | case 2: |
| 2508 | *valp = byterev_2(*valp); |
| 2509 | break; |
| 2510 | case 4: |
| 2511 | *valp = byterev_4(*valp); |
| 2512 | break; |
| 2513 | #ifdef __powerpc64__ |
| 2514 | case 8: |
| 2515 | *valp = byterev_8(*valp); |
| 2516 | break; |
| 2517 | #endif |
| 2518 | } |
| 2519 | } |
| 2520 | |
| 2521 | /* |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 2522 | * Emulate an instruction that can be executed just by updating |
| 2523 | * fields in *regs. |
| 2524 | */ |
| 2525 | void emulate_update_regs(struct pt_regs *regs, struct instruction_op *op) |
| 2526 | { |
| 2527 | unsigned long next_pc; |
| 2528 | |
| 2529 | next_pc = truncate_if_32bit(regs->msr, regs->nip + 4); |
| 2530 | switch (op->type & INSTR_TYPE_MASK) { |
| 2531 | case COMPUTE: |
| 2532 | if (op->type & SETREG) |
| 2533 | regs->gpr[op->reg] = op->val; |
| 2534 | if (op->type & SETCC) |
| 2535 | regs->ccr = op->ccval; |
| 2536 | if (op->type & SETXER) |
| 2537 | regs->xer = op->xerval; |
| 2538 | break; |
| 2539 | |
| 2540 | case BRANCH: |
| 2541 | if (op->type & SETLK) |
| 2542 | regs->link = next_pc; |
| 2543 | if (op->type & BRTAKEN) |
| 2544 | next_pc = op->val; |
| 2545 | if (op->type & DECCTR) |
| 2546 | --regs->ctr; |
| 2547 | break; |
| 2548 | |
| 2549 | case BARRIER: |
| 2550 | switch (op->type & BARRIER_MASK) { |
| 2551 | case BARRIER_SYNC: |
| 2552 | mb(); |
| 2553 | break; |
| 2554 | case BARRIER_ISYNC: |
| 2555 | isync(); |
| 2556 | break; |
| 2557 | case BARRIER_EIEIO: |
| 2558 | eieio(); |
| 2559 | break; |
| 2560 | case BARRIER_LWSYNC: |
| 2561 | asm volatile("lwsync" : : : "memory"); |
| 2562 | break; |
| 2563 | case BARRIER_PTESYNC: |
| 2564 | asm volatile("ptesync" : : : "memory"); |
| 2565 | break; |
| 2566 | } |
| 2567 | break; |
| 2568 | |
| 2569 | case MFSPR: |
| 2570 | switch (op->spr) { |
| 2571 | case SPRN_XER: |
| 2572 | regs->gpr[op->reg] = regs->xer & 0xffffffffUL; |
| 2573 | break; |
| 2574 | case SPRN_LR: |
| 2575 | regs->gpr[op->reg] = regs->link; |
| 2576 | break; |
| 2577 | case SPRN_CTR: |
| 2578 | regs->gpr[op->reg] = regs->ctr; |
| 2579 | break; |
| 2580 | default: |
| 2581 | WARN_ON_ONCE(1); |
| 2582 | } |
| 2583 | break; |
| 2584 | |
| 2585 | case MTSPR: |
| 2586 | switch (op->spr) { |
| 2587 | case SPRN_XER: |
| 2588 | regs->xer = op->val & 0xffffffffUL; |
| 2589 | break; |
| 2590 | case SPRN_LR: |
| 2591 | regs->link = op->val; |
| 2592 | break; |
| 2593 | case SPRN_CTR: |
| 2594 | regs->ctr = op->val; |
| 2595 | break; |
| 2596 | default: |
| 2597 | WARN_ON_ONCE(1); |
| 2598 | } |
| 2599 | break; |
| 2600 | |
| 2601 | default: |
| 2602 | WARN_ON_ONCE(1); |
| 2603 | } |
| 2604 | regs->nip = next_pc; |
| 2605 | } |
| 2606 | |
| 2607 | /* |
Paul Mackerras | be96f63 | 2014-09-02 14:35:07 +1000 | [diff] [blame] | 2608 | * Emulate instructions that cause a transfer of control, |
| 2609 | * loads and stores, and a few other instructions. |
| 2610 | * Returns 1 if the step was emulated, 0 if not, |
| 2611 | * or -1 if the instruction is one that should not be stepped, |
| 2612 | * such as an rfid, or a mtmsrd that would clear MSR_RI. |
| 2613 | */ |
Naveen N. Rao | 71f6e58 | 2017-04-12 16:48:51 +0530 | [diff] [blame] | 2614 | int emulate_step(struct pt_regs *regs, unsigned int instr) |
Paul Mackerras | be96f63 | 2014-09-02 14:35:07 +1000 | [diff] [blame] | 2615 | { |
| 2616 | struct instruction_op op; |
Paul Mackerras | d120cdb | 2017-08-30 14:12:28 +1000 | [diff] [blame] | 2617 | int r, err, size, type; |
Paul Mackerras | be96f63 | 2014-09-02 14:35:07 +1000 | [diff] [blame] | 2618 | unsigned long val; |
| 2619 | unsigned int cr; |
Paul Mackerras | c9f6f4e | 2014-09-02 14:35:09 +1000 | [diff] [blame] | 2620 | int i, rd, nb; |
Paul Mackerras | d120cdb | 2017-08-30 14:12:28 +1000 | [diff] [blame] | 2621 | unsigned long ea; |
Paul Mackerras | be96f63 | 2014-09-02 14:35:07 +1000 | [diff] [blame] | 2622 | |
| 2623 | r = analyse_instr(&op, regs, instr); |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 2624 | if (r < 0) |
Paul Mackerras | be96f63 | 2014-09-02 14:35:07 +1000 | [diff] [blame] | 2625 | return r; |
Paul Mackerras | 3cdfcbf | 2017-08-30 14:12:25 +1000 | [diff] [blame] | 2626 | if (r > 0) { |
| 2627 | emulate_update_regs(regs, &op); |
| 2628 | return 1; |
| 2629 | } |
Paul Mackerras | be96f63 | 2014-09-02 14:35:07 +1000 | [diff] [blame] | 2630 | |
| 2631 | err = 0; |
| 2632 | size = GETSIZE(op.type); |
Paul Mackerras | d120cdb | 2017-08-30 14:12:28 +1000 | [diff] [blame] | 2633 | type = op.type & INSTR_TYPE_MASK; |
| 2634 | |
| 2635 | ea = op.ea; |
| 2636 | if (OP_IS_LOAD_STORE(type) || type == CACHEOP) |
| 2637 | ea = truncate_if_32bit(regs->msr, op.ea); |
| 2638 | |
| 2639 | switch (type) { |
Paul Mackerras | be96f63 | 2014-09-02 14:35:07 +1000 | [diff] [blame] | 2640 | case CACHEOP: |
Paul Mackerras | d120cdb | 2017-08-30 14:12:28 +1000 | [diff] [blame] | 2641 | if (!address_ok(regs, ea, 8)) |
Paul Mackerras | be96f63 | 2014-09-02 14:35:07 +1000 | [diff] [blame] | 2642 | return 0; |
| 2643 | switch (op.type & CACHEOP_MASK) { |
| 2644 | case DCBST: |
Paul Mackerras | d120cdb | 2017-08-30 14:12:28 +1000 | [diff] [blame] | 2645 | __cacheop_user_asmx(ea, err, "dcbst"); |
Paul Mackerras | be96f63 | 2014-09-02 14:35:07 +1000 | [diff] [blame] | 2646 | break; |
| 2647 | case DCBF: |
Paul Mackerras | d120cdb | 2017-08-30 14:12:28 +1000 | [diff] [blame] | 2648 | __cacheop_user_asmx(ea, err, "dcbf"); |
Paul Mackerras | be96f63 | 2014-09-02 14:35:07 +1000 | [diff] [blame] | 2649 | break; |
| 2650 | case DCBTST: |
| 2651 | if (op.reg == 0) |
Paul Mackerras | d120cdb | 2017-08-30 14:12:28 +1000 | [diff] [blame] | 2652 | prefetchw((void *) ea); |
Paul Mackerras | be96f63 | 2014-09-02 14:35:07 +1000 | [diff] [blame] | 2653 | break; |
| 2654 | case DCBT: |
| 2655 | if (op.reg == 0) |
Paul Mackerras | d120cdb | 2017-08-30 14:12:28 +1000 | [diff] [blame] | 2656 | prefetch((void *) ea); |
Paul Mackerras | be96f63 | 2014-09-02 14:35:07 +1000 | [diff] [blame] | 2657 | break; |
Paul Mackerras | cf87c3f | 2014-09-02 14:35:08 +1000 | [diff] [blame] | 2658 | case ICBI: |
Paul Mackerras | d120cdb | 2017-08-30 14:12:28 +1000 | [diff] [blame] | 2659 | __cacheop_user_asmx(ea, err, "icbi"); |
Paul Mackerras | cf87c3f | 2014-09-02 14:35:08 +1000 | [diff] [blame] | 2660 | break; |
Paul Mackerras | b2543f7 | 2017-08-30 14:12:36 +1000 | [diff] [blame] | 2661 | case DCBZ: |
| 2662 | err = emulate_dcbz(ea, regs); |
| 2663 | break; |
Paul Mackerras | be96f63 | 2014-09-02 14:35:07 +1000 | [diff] [blame] | 2664 | } |
Paul Mackerras | b9da9c8 | 2017-08-30 14:12:37 +1000 | [diff] [blame^] | 2665 | if (err) { |
| 2666 | regs->dar = ea; |
Paul Mackerras | be96f63 | 2014-09-02 14:35:07 +1000 | [diff] [blame] | 2667 | return 0; |
Paul Mackerras | b9da9c8 | 2017-08-30 14:12:37 +1000 | [diff] [blame^] | 2668 | } |
Paul Mackerras | be96f63 | 2014-09-02 14:35:07 +1000 | [diff] [blame] | 2669 | goto instr_done; |
| 2670 | |
| 2671 | case LARX: |
Paul Mackerras | d120cdb | 2017-08-30 14:12:28 +1000 | [diff] [blame] | 2672 | if (ea & (size - 1)) |
Paul Mackerras | be96f63 | 2014-09-02 14:35:07 +1000 | [diff] [blame] | 2673 | break; /* can't handle misaligned */ |
Paul Mackerras | d120cdb | 2017-08-30 14:12:28 +1000 | [diff] [blame] | 2674 | if (!address_ok(regs, ea, size)) |
Markus Elfring | 3c4b66a | 2017-01-21 15:30:15 +0100 | [diff] [blame] | 2675 | return 0; |
Paul Mackerras | be96f63 | 2014-09-02 14:35:07 +1000 | [diff] [blame] | 2676 | err = 0; |
| 2677 | switch (size) { |
Paul Mackerras | 350779a | 2017-08-30 14:12:27 +1000 | [diff] [blame] | 2678 | #ifdef __powerpc64__ |
| 2679 | case 1: |
Paul Mackerras | d120cdb | 2017-08-30 14:12:28 +1000 | [diff] [blame] | 2680 | __get_user_asmx(val, ea, err, "lbarx"); |
Paul Mackerras | 350779a | 2017-08-30 14:12:27 +1000 | [diff] [blame] | 2681 | break; |
| 2682 | case 2: |
Paul Mackerras | d120cdb | 2017-08-30 14:12:28 +1000 | [diff] [blame] | 2683 | __get_user_asmx(val, ea, err, "lharx"); |
Paul Mackerras | 350779a | 2017-08-30 14:12:27 +1000 | [diff] [blame] | 2684 | break; |
| 2685 | #endif |
Paul Mackerras | be96f63 | 2014-09-02 14:35:07 +1000 | [diff] [blame] | 2686 | case 4: |
Paul Mackerras | d120cdb | 2017-08-30 14:12:28 +1000 | [diff] [blame] | 2687 | __get_user_asmx(val, ea, err, "lwarx"); |
Paul Mackerras | be96f63 | 2014-09-02 14:35:07 +1000 | [diff] [blame] | 2688 | break; |
Lennart Sorensen | dd21731 | 2016-05-05 16:44:44 -0400 | [diff] [blame] | 2689 | #ifdef __powerpc64__ |
Paul Mackerras | be96f63 | 2014-09-02 14:35:07 +1000 | [diff] [blame] | 2690 | case 8: |
Paul Mackerras | d120cdb | 2017-08-30 14:12:28 +1000 | [diff] [blame] | 2691 | __get_user_asmx(val, ea, err, "ldarx"); |
Paul Mackerras | be96f63 | 2014-09-02 14:35:07 +1000 | [diff] [blame] | 2692 | break; |
Paul Mackerras | 350779a | 2017-08-30 14:12:27 +1000 | [diff] [blame] | 2693 | case 16: |
Paul Mackerras | d120cdb | 2017-08-30 14:12:28 +1000 | [diff] [blame] | 2694 | err = do_lqarx(ea, ®s->gpr[op.reg]); |
Paul Mackerras | b9da9c8 | 2017-08-30 14:12:37 +1000 | [diff] [blame^] | 2695 | break; |
Lennart Sorensen | dd21731 | 2016-05-05 16:44:44 -0400 | [diff] [blame] | 2696 | #endif |
Paul Mackerras | be96f63 | 2014-09-02 14:35:07 +1000 | [diff] [blame] | 2697 | default: |
| 2698 | return 0; |
| 2699 | } |
Paul Mackerras | b9da9c8 | 2017-08-30 14:12:37 +1000 | [diff] [blame^] | 2700 | if (err) { |
| 2701 | regs->dar = ea; |
| 2702 | return 0; |
| 2703 | } |
| 2704 | if (size < 16) |
Paul Mackerras | be96f63 | 2014-09-02 14:35:07 +1000 | [diff] [blame] | 2705 | regs->gpr[op.reg] = val; |
| 2706 | goto ldst_done; |
| 2707 | |
| 2708 | case STCX: |
Paul Mackerras | d120cdb | 2017-08-30 14:12:28 +1000 | [diff] [blame] | 2709 | if (ea & (size - 1)) |
Paul Mackerras | be96f63 | 2014-09-02 14:35:07 +1000 | [diff] [blame] | 2710 | break; /* can't handle misaligned */ |
Paul Mackerras | d120cdb | 2017-08-30 14:12:28 +1000 | [diff] [blame] | 2711 | if (!address_ok(regs, ea, size)) |
Markus Elfring | 3c4b66a | 2017-01-21 15:30:15 +0100 | [diff] [blame] | 2712 | return 0; |
Paul Mackerras | be96f63 | 2014-09-02 14:35:07 +1000 | [diff] [blame] | 2713 | err = 0; |
| 2714 | switch (size) { |
Paul Mackerras | 350779a | 2017-08-30 14:12:27 +1000 | [diff] [blame] | 2715 | #ifdef __powerpc64__ |
| 2716 | case 1: |
Paul Mackerras | d120cdb | 2017-08-30 14:12:28 +1000 | [diff] [blame] | 2717 | __put_user_asmx(op.val, ea, err, "stbcx.", cr); |
Paul Mackerras | 350779a | 2017-08-30 14:12:27 +1000 | [diff] [blame] | 2718 | break; |
| 2719 | case 2: |
Paul Mackerras | d120cdb | 2017-08-30 14:12:28 +1000 | [diff] [blame] | 2720 | __put_user_asmx(op.val, ea, err, "stbcx.", cr); |
Paul Mackerras | 350779a | 2017-08-30 14:12:27 +1000 | [diff] [blame] | 2721 | break; |
| 2722 | #endif |
Paul Mackerras | be96f63 | 2014-09-02 14:35:07 +1000 | [diff] [blame] | 2723 | case 4: |
Paul Mackerras | d120cdb | 2017-08-30 14:12:28 +1000 | [diff] [blame] | 2724 | __put_user_asmx(op.val, ea, err, "stwcx.", cr); |
Paul Mackerras | be96f63 | 2014-09-02 14:35:07 +1000 | [diff] [blame] | 2725 | break; |
Lennart Sorensen | dd21731 | 2016-05-05 16:44:44 -0400 | [diff] [blame] | 2726 | #ifdef __powerpc64__ |
Paul Mackerras | be96f63 | 2014-09-02 14:35:07 +1000 | [diff] [blame] | 2727 | case 8: |
Paul Mackerras | d120cdb | 2017-08-30 14:12:28 +1000 | [diff] [blame] | 2728 | __put_user_asmx(op.val, ea, err, "stdcx.", cr); |
Paul Mackerras | be96f63 | 2014-09-02 14:35:07 +1000 | [diff] [blame] | 2729 | break; |
Paul Mackerras | 350779a | 2017-08-30 14:12:27 +1000 | [diff] [blame] | 2730 | case 16: |
Paul Mackerras | d120cdb | 2017-08-30 14:12:28 +1000 | [diff] [blame] | 2731 | err = do_stqcx(ea, regs->gpr[op.reg], |
Paul Mackerras | 350779a | 2017-08-30 14:12:27 +1000 | [diff] [blame] | 2732 | regs->gpr[op.reg + 1], &cr); |
| 2733 | break; |
Lennart Sorensen | dd21731 | 2016-05-05 16:44:44 -0400 | [diff] [blame] | 2734 | #endif |
Paul Mackerras | be96f63 | 2014-09-02 14:35:07 +1000 | [diff] [blame] | 2735 | default: |
| 2736 | return 0; |
| 2737 | } |
| 2738 | if (!err) |
| 2739 | regs->ccr = (regs->ccr & 0x0fffffff) | |
| 2740 | (cr & 0xe0000000) | |
| 2741 | ((regs->xer >> 3) & 0x10000000); |
Paul Mackerras | b9da9c8 | 2017-08-30 14:12:37 +1000 | [diff] [blame^] | 2742 | else |
| 2743 | regs->dar = ea; |
Paul Mackerras | be96f63 | 2014-09-02 14:35:07 +1000 | [diff] [blame] | 2744 | goto ldst_done; |
| 2745 | |
| 2746 | case LOAD: |
Paul Mackerras | 350779a | 2017-08-30 14:12:27 +1000 | [diff] [blame] | 2747 | #ifdef __powerpc64__ |
| 2748 | if (size == 16) { |
Paul Mackerras | d120cdb | 2017-08-30 14:12:28 +1000 | [diff] [blame] | 2749 | err = emulate_lq(regs, ea, op.reg); |
Paul Mackerras | 350779a | 2017-08-30 14:12:27 +1000 | [diff] [blame] | 2750 | goto ldst_done; |
| 2751 | } |
| 2752 | #endif |
Paul Mackerras | d120cdb | 2017-08-30 14:12:28 +1000 | [diff] [blame] | 2753 | err = read_mem(®s->gpr[op.reg], ea, size, regs); |
Paul Mackerras | be96f63 | 2014-09-02 14:35:07 +1000 | [diff] [blame] | 2754 | if (!err) { |
| 2755 | if (op.type & SIGNEXT) |
| 2756 | do_signext(®s->gpr[op.reg], size); |
| 2757 | if (op.type & BYTEREV) |
| 2758 | do_byterev(®s->gpr[op.reg], size); |
| 2759 | } |
| 2760 | goto ldst_done; |
| 2761 | |
Paul Mackerras | 7048c84 | 2014-11-03 15:46:43 +1100 | [diff] [blame] | 2762 | #ifdef CONFIG_PPC_FPU |
Paul Mackerras | be96f63 | 2014-09-02 14:35:07 +1000 | [diff] [blame] | 2763 | case LOAD_FP: |
Paul Mackerras | c22435a5 | 2017-08-30 14:12:33 +1000 | [diff] [blame] | 2764 | /* |
| 2765 | * If the instruction is in userspace, we can emulate it even |
| 2766 | * if the VMX state is not live, because we have the state |
| 2767 | * stored in the thread_struct. If the instruction is in |
| 2768 | * the kernel, we must not touch the state in the thread_struct. |
| 2769 | */ |
| 2770 | if (!(regs->msr & MSR_PR) && !(regs->msr & MSR_FP)) |
Paul Mackerras | ee0a54d | 2017-08-30 14:12:26 +1000 | [diff] [blame] | 2771 | return 0; |
Paul Mackerras | c22435a5 | 2017-08-30 14:12:33 +1000 | [diff] [blame] | 2772 | err = do_fp_load(op.reg, ea, size, regs); |
Paul Mackerras | be96f63 | 2014-09-02 14:35:07 +1000 | [diff] [blame] | 2773 | goto ldst_done; |
Paul Mackerras | 7048c84 | 2014-11-03 15:46:43 +1100 | [diff] [blame] | 2774 | #endif |
Paul Mackerras | be96f63 | 2014-09-02 14:35:07 +1000 | [diff] [blame] | 2775 | #ifdef CONFIG_ALTIVEC |
| 2776 | case LOAD_VMX: |
Paul Mackerras | c22435a5 | 2017-08-30 14:12:33 +1000 | [diff] [blame] | 2777 | if (!(regs->msr & MSR_PR) && !(regs->msr & MSR_VEC)) |
Paul Mackerras | ee0a54d | 2017-08-30 14:12:26 +1000 | [diff] [blame] | 2778 | return 0; |
Paul Mackerras | c22435a5 | 2017-08-30 14:12:33 +1000 | [diff] [blame] | 2779 | err = do_vec_load(op.reg, ea, size, regs); |
Paul Mackerras | be96f63 | 2014-09-02 14:35:07 +1000 | [diff] [blame] | 2780 | goto ldst_done; |
| 2781 | #endif |
| 2782 | #ifdef CONFIG_VSX |
Paul Mackerras | 350779a | 2017-08-30 14:12:27 +1000 | [diff] [blame] | 2783 | case LOAD_VSX: { |
Paul Mackerras | 350779a | 2017-08-30 14:12:27 +1000 | [diff] [blame] | 2784 | unsigned long msrbit = MSR_VSX; |
| 2785 | |
| 2786 | /* |
| 2787 | * Some VSX instructions check the MSR_VEC bit rather than MSR_VSX |
| 2788 | * when the target of the instruction is a vector register. |
| 2789 | */ |
| 2790 | if (op.reg >= 32 && (op.vsx_flags & VSX_CHECK_VEC)) |
| 2791 | msrbit = MSR_VEC; |
Paul Mackerras | c22435a5 | 2017-08-30 14:12:33 +1000 | [diff] [blame] | 2792 | if (!(regs->msr & MSR_PR) && !(regs->msr & msrbit)) |
Paul Mackerras | ee0a54d | 2017-08-30 14:12:26 +1000 | [diff] [blame] | 2793 | return 0; |
Paul Mackerras | c22435a5 | 2017-08-30 14:12:33 +1000 | [diff] [blame] | 2794 | err = do_vsx_load(&op, ea, regs); |
Paul Mackerras | be96f63 | 2014-09-02 14:35:07 +1000 | [diff] [blame] | 2795 | goto ldst_done; |
Paul Mackerras | 350779a | 2017-08-30 14:12:27 +1000 | [diff] [blame] | 2796 | } |
Paul Mackerras | be96f63 | 2014-09-02 14:35:07 +1000 | [diff] [blame] | 2797 | #endif |
| 2798 | case LOAD_MULTI: |
| 2799 | if (regs->msr & MSR_LE) |
| 2800 | return 0; |
| 2801 | rd = op.reg; |
Paul Mackerras | c9f6f4e | 2014-09-02 14:35:09 +1000 | [diff] [blame] | 2802 | for (i = 0; i < size; i += 4) { |
| 2803 | nb = size - i; |
| 2804 | if (nb > 4) |
| 2805 | nb = 4; |
Paul Mackerras | d120cdb | 2017-08-30 14:12:28 +1000 | [diff] [blame] | 2806 | err = read_mem(®s->gpr[rd], ea, nb, regs); |
Paul Mackerras | be96f63 | 2014-09-02 14:35:07 +1000 | [diff] [blame] | 2807 | if (err) |
| 2808 | return 0; |
Paul Mackerras | c9f6f4e | 2014-09-02 14:35:09 +1000 | [diff] [blame] | 2809 | if (nb < 4) /* left-justify last bytes */ |
| 2810 | regs->gpr[rd] <<= 32 - 8 * nb; |
Paul Mackerras | d120cdb | 2017-08-30 14:12:28 +1000 | [diff] [blame] | 2811 | ea += 4; |
Paul Mackerras | c9f6f4e | 2014-09-02 14:35:09 +1000 | [diff] [blame] | 2812 | ++rd; |
| 2813 | } |
Paul Mackerras | be96f63 | 2014-09-02 14:35:07 +1000 | [diff] [blame] | 2814 | goto instr_done; |
| 2815 | |
| 2816 | case STORE: |
Paul Mackerras | 350779a | 2017-08-30 14:12:27 +1000 | [diff] [blame] | 2817 | #ifdef __powerpc64__ |
| 2818 | if (size == 16) { |
Paul Mackerras | d120cdb | 2017-08-30 14:12:28 +1000 | [diff] [blame] | 2819 | err = emulate_stq(regs, ea, op.reg); |
Paul Mackerras | 350779a | 2017-08-30 14:12:27 +1000 | [diff] [blame] | 2820 | goto ldst_done; |
| 2821 | } |
| 2822 | #endif |
Paul Mackerras | be96f63 | 2014-09-02 14:35:07 +1000 | [diff] [blame] | 2823 | if ((op.type & UPDATE) && size == sizeof(long) && |
| 2824 | op.reg == 1 && op.update_reg == 1 && |
| 2825 | !(regs->msr & MSR_PR) && |
Paul Mackerras | d120cdb | 2017-08-30 14:12:28 +1000 | [diff] [blame] | 2826 | ea >= regs->gpr[1] - STACK_INT_FRAME_SIZE) { |
| 2827 | err = handle_stack_update(ea, regs); |
Paul Mackerras | be96f63 | 2014-09-02 14:35:07 +1000 | [diff] [blame] | 2828 | goto ldst_done; |
| 2829 | } |
Paul Mackerras | d120cdb | 2017-08-30 14:12:28 +1000 | [diff] [blame] | 2830 | err = write_mem(op.val, ea, size, regs); |
Paul Mackerras | be96f63 | 2014-09-02 14:35:07 +1000 | [diff] [blame] | 2831 | goto ldst_done; |
| 2832 | |
Paul Mackerras | 7048c84 | 2014-11-03 15:46:43 +1100 | [diff] [blame] | 2833 | #ifdef CONFIG_PPC_FPU |
Paul Mackerras | be96f63 | 2014-09-02 14:35:07 +1000 | [diff] [blame] | 2834 | case STORE_FP: |
Paul Mackerras | c22435a5 | 2017-08-30 14:12:33 +1000 | [diff] [blame] | 2835 | if (!(regs->msr & MSR_PR) && !(regs->msr & MSR_FP)) |
Paul Mackerras | ee0a54d | 2017-08-30 14:12:26 +1000 | [diff] [blame] | 2836 | return 0; |
Paul Mackerras | c22435a5 | 2017-08-30 14:12:33 +1000 | [diff] [blame] | 2837 | err = do_fp_store(op.reg, ea, size, regs); |
Paul Mackerras | be96f63 | 2014-09-02 14:35:07 +1000 | [diff] [blame] | 2838 | goto ldst_done; |
Paul Mackerras | 7048c84 | 2014-11-03 15:46:43 +1100 | [diff] [blame] | 2839 | #endif |
Paul Mackerras | be96f63 | 2014-09-02 14:35:07 +1000 | [diff] [blame] | 2840 | #ifdef CONFIG_ALTIVEC |
| 2841 | case STORE_VMX: |
Paul Mackerras | c22435a5 | 2017-08-30 14:12:33 +1000 | [diff] [blame] | 2842 | if (!(regs->msr & MSR_PR) && !(regs->msr & MSR_VEC)) |
Paul Mackerras | ee0a54d | 2017-08-30 14:12:26 +1000 | [diff] [blame] | 2843 | return 0; |
Paul Mackerras | c22435a5 | 2017-08-30 14:12:33 +1000 | [diff] [blame] | 2844 | err = do_vec_store(op.reg, ea, size, regs); |
Paul Mackerras | be96f63 | 2014-09-02 14:35:07 +1000 | [diff] [blame] | 2845 | goto ldst_done; |
| 2846 | #endif |
| 2847 | #ifdef CONFIG_VSX |
Paul Mackerras | 350779a | 2017-08-30 14:12:27 +1000 | [diff] [blame] | 2848 | case STORE_VSX: { |
Paul Mackerras | 350779a | 2017-08-30 14:12:27 +1000 | [diff] [blame] | 2849 | unsigned long msrbit = MSR_VSX; |
| 2850 | |
| 2851 | /* |
| 2852 | * Some VSX instructions check the MSR_VEC bit rather than MSR_VSX |
| 2853 | * when the target of the instruction is a vector register. |
| 2854 | */ |
| 2855 | if (op.reg >= 32 && (op.vsx_flags & VSX_CHECK_VEC)) |
| 2856 | msrbit = MSR_VEC; |
Paul Mackerras | c22435a5 | 2017-08-30 14:12:33 +1000 | [diff] [blame] | 2857 | if (!(regs->msr & MSR_PR) && !(regs->msr & msrbit)) |
Paul Mackerras | ee0a54d | 2017-08-30 14:12:26 +1000 | [diff] [blame] | 2858 | return 0; |
Paul Mackerras | c22435a5 | 2017-08-30 14:12:33 +1000 | [diff] [blame] | 2859 | err = do_vsx_store(&op, ea, regs); |
Paul Mackerras | be96f63 | 2014-09-02 14:35:07 +1000 | [diff] [blame] | 2860 | goto ldst_done; |
Paul Mackerras | 350779a | 2017-08-30 14:12:27 +1000 | [diff] [blame] | 2861 | } |
Paul Mackerras | be96f63 | 2014-09-02 14:35:07 +1000 | [diff] [blame] | 2862 | #endif |
| 2863 | case STORE_MULTI: |
| 2864 | if (regs->msr & MSR_LE) |
| 2865 | return 0; |
| 2866 | rd = op.reg; |
Paul Mackerras | c9f6f4e | 2014-09-02 14:35:09 +1000 | [diff] [blame] | 2867 | for (i = 0; i < size; i += 4) { |
| 2868 | val = regs->gpr[rd]; |
| 2869 | nb = size - i; |
| 2870 | if (nb > 4) |
| 2871 | nb = 4; |
| 2872 | else |
| 2873 | val >>= 32 - 8 * nb; |
Paul Mackerras | d120cdb | 2017-08-30 14:12:28 +1000 | [diff] [blame] | 2874 | err = write_mem(val, ea, nb, regs); |
Paul Mackerras | be96f63 | 2014-09-02 14:35:07 +1000 | [diff] [blame] | 2875 | if (err) |
| 2876 | return 0; |
Paul Mackerras | d120cdb | 2017-08-30 14:12:28 +1000 | [diff] [blame] | 2877 | ea += 4; |
Paul Mackerras | c9f6f4e | 2014-09-02 14:35:09 +1000 | [diff] [blame] | 2878 | ++rd; |
| 2879 | } |
Paul Mackerras | be96f63 | 2014-09-02 14:35:07 +1000 | [diff] [blame] | 2880 | goto instr_done; |
| 2881 | |
| 2882 | case MFMSR: |
| 2883 | regs->gpr[op.reg] = regs->msr & MSR_MASK; |
| 2884 | goto instr_done; |
| 2885 | |
| 2886 | case MTMSR: |
| 2887 | val = regs->gpr[op.reg]; |
| 2888 | if ((val & MSR_RI) == 0) |
| 2889 | /* can't step mtmsr[d] that would clear MSR_RI */ |
| 2890 | return -1; |
| 2891 | /* here op.val is the mask of bits to change */ |
| 2892 | regs->msr = (regs->msr & ~op.val) | (val & op.val); |
| 2893 | goto instr_done; |
| 2894 | |
| 2895 | #ifdef CONFIG_PPC64 |
| 2896 | case SYSCALL: /* sc */ |
| 2897 | /* |
| 2898 | * N.B. this uses knowledge about how the syscall |
| 2899 | * entry code works. If that is changed, this will |
| 2900 | * need to be changed also. |
| 2901 | */ |
| 2902 | if (regs->gpr[0] == 0x1ebe && |
| 2903 | cpu_has_feature(CPU_FTR_REAL_LE)) { |
| 2904 | regs->msr ^= MSR_LE; |
| 2905 | goto instr_done; |
| 2906 | } |
| 2907 | regs->gpr[9] = regs->gpr[13]; |
| 2908 | regs->gpr[10] = MSR_KERNEL; |
| 2909 | regs->gpr[11] = regs->nip + 4; |
| 2910 | regs->gpr[12] = regs->msr & MSR_MASK; |
| 2911 | regs->gpr[13] = (unsigned long) get_paca(); |
| 2912 | regs->nip = (unsigned long) &system_call_common; |
| 2913 | regs->msr = MSR_KERNEL; |
| 2914 | return 1; |
| 2915 | |
| 2916 | case RFI: |
| 2917 | return -1; |
| 2918 | #endif |
| 2919 | } |
| 2920 | return 0; |
| 2921 | |
| 2922 | ldst_done: |
| 2923 | if (err) |
| 2924 | return 0; |
| 2925 | if (op.type & UPDATE) |
| 2926 | regs->gpr[op.update_reg] = op.ea; |
| 2927 | |
| 2928 | instr_done: |
| 2929 | regs->nip = truncate_if_32bit(regs->msr, regs->nip + 4); |
| 2930 | return 1; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 2931 | } |
Naveen N. Rao | 71f6e58 | 2017-04-12 16:48:51 +0530 | [diff] [blame] | 2932 | NOKPROBE_SYMBOL(emulate_step); |