1 /* align.c - handle alignment exceptions for the Power PC.
3 * Copyright (c) 1996 Paul Mackerras <paulus@cs.anu.edu.au>
4 * Copyright (c) 1998-1999 TiVo, Inc.
5 * PowerPC 403GCX modifications.
6 * Copyright (c) 1999 Grant Erickson <grant@lcse.umn.edu>
7 * PowerPC 403GCX/405GP modifications.
8 * Copyright (c) 2001-2002 PPC64 team, IBM Corp
9 * 64-bit and Power4 support
10 * Copyright (c) 2005 Benjamin Herrenschmidt, IBM Corp
11 * <benh@kernel.crashing.org>
12 * Merge ppc32 and ppc64 implementations
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation; either version
17 * 2 of the License, or (at your option) any later version.
20 #include <linux/kernel.h>
22 #include <asm/processor.h>
23 #include <asm/uaccess.h>
24 #include <asm/cache.h>
25 #include <asm/cputable.h>
26 #include <asm/emulated_ops.h>
27 #include <asm/switch_to.h>
28 #include <asm/disassemble.h>
35 #define IS_XFORM(inst) (((inst) >> 26) == 31)
36 #define IS_DSFORM(inst) (((inst) >> 26) >= 56)
38 #define INVALID { 0, 0 }
40 /* Bits in the flags field */
41 #define LD 0 /* load */
42 #define ST 1 /* store */
43 #define SE 2 /* sign-extend value, or FP ld/st as word */
44 #define F 4 /* to/from fp regs */
45 #define U 8 /* update index register */
46 #define M 0x10 /* multiple load/store */
47 #define SW 0x20 /* byte swap */
48 #define S 0x40 /* single-precision fp or... */
49 #define SX 0x40 /* ... byte count in XER */
50 #define HARD 0x80 /* string, stwcx. */
51 #define E4 0x40 /* SPE endianness is word */
52 #define E8 0x80 /* SPE endianness is double word */
53 #define SPLT 0x80 /* VSX SPLAT load */
55 /* DSISR bits reported for a DCBZ instruction: */
56 #define DCBZ 0x5f /* 8xx/82xx dcbz faults when cache not enabled */
58 #define SWAP(a, b) (t = (a), (a) = (b), (b) = t)
61 * The PowerPC stores certain bits of the instruction that caused the
62 * alignment exception in the DSISR register. This array maps those
63 * bits to information about the operand length and what the
64 * instruction would do.
66 static struct aligninfo aligninfo
[128] = {
67 { 4, LD
}, /* 00 0 0000: lwz / lwarx */
68 INVALID
, /* 00 0 0001 */
69 { 4, ST
}, /* 00 0 0010: stw */
70 INVALID
, /* 00 0 0011 */
71 { 2, LD
}, /* 00 0 0100: lhz */
72 { 2, LD
+SE
}, /* 00 0 0101: lha */
73 { 2, ST
}, /* 00 0 0110: sth */
74 { 4, LD
+M
}, /* 00 0 0111: lmw */
75 { 4, LD
+F
+S
}, /* 00 0 1000: lfs */
76 { 8, LD
+F
}, /* 00 0 1001: lfd */
77 { 4, ST
+F
+S
}, /* 00 0 1010: stfs */
78 { 8, ST
+F
}, /* 00 0 1011: stfd */
79 INVALID
, /* 00 0 1100 */
80 { 8, LD
}, /* 00 0 1101: ld/ldu/lwa */
81 INVALID
, /* 00 0 1110 */
82 { 8, ST
}, /* 00 0 1111: std/stdu */
83 { 4, LD
+U
}, /* 00 1 0000: lwzu */
84 INVALID
, /* 00 1 0001 */
85 { 4, ST
+U
}, /* 00 1 0010: stwu */
86 INVALID
, /* 00 1 0011 */
87 { 2, LD
+U
}, /* 00 1 0100: lhzu */
88 { 2, LD
+SE
+U
}, /* 00 1 0101: lhau */
89 { 2, ST
+U
}, /* 00 1 0110: sthu */
90 { 4, ST
+M
}, /* 00 1 0111: stmw */
91 { 4, LD
+F
+S
+U
}, /* 00 1 1000: lfsu */
92 { 8, LD
+F
+U
}, /* 00 1 1001: lfdu */
93 { 4, ST
+F
+S
+U
}, /* 00 1 1010: stfsu */
94 { 8, ST
+F
+U
}, /* 00 1 1011: stfdu */
95 { 16, LD
+F
}, /* 00 1 1100: lfdp */
96 INVALID
, /* 00 1 1101 */
97 { 16, ST
+F
}, /* 00 1 1110: stfdp */
98 INVALID
, /* 00 1 1111 */
99 { 8, LD
}, /* 01 0 0000: ldx */
100 INVALID
, /* 01 0 0001 */
101 { 8, ST
}, /* 01 0 0010: stdx */
102 INVALID
, /* 01 0 0011 */
103 INVALID
, /* 01 0 0100 */
104 { 4, LD
+SE
}, /* 01 0 0101: lwax */
105 INVALID
, /* 01 0 0110 */
106 INVALID
, /* 01 0 0111 */
107 { 4, LD
+M
+HARD
+SX
}, /* 01 0 1000: lswx */
108 { 4, LD
+M
+HARD
}, /* 01 0 1001: lswi */
109 { 4, ST
+M
+HARD
+SX
}, /* 01 0 1010: stswx */
110 { 4, ST
+M
+HARD
}, /* 01 0 1011: stswi */
111 INVALID
, /* 01 0 1100 */
112 { 8, LD
+U
}, /* 01 0 1101: ldu */
113 INVALID
, /* 01 0 1110 */
114 { 8, ST
+U
}, /* 01 0 1111: stdu */
115 { 8, LD
+U
}, /* 01 1 0000: ldux */
116 INVALID
, /* 01 1 0001 */
117 { 8, ST
+U
}, /* 01 1 0010: stdux */
118 INVALID
, /* 01 1 0011 */
119 INVALID
, /* 01 1 0100 */
120 { 4, LD
+SE
+U
}, /* 01 1 0101: lwaux */
121 INVALID
, /* 01 1 0110 */
122 INVALID
, /* 01 1 0111 */
123 INVALID
, /* 01 1 1000 */
124 INVALID
, /* 01 1 1001 */
125 INVALID
, /* 01 1 1010 */
126 INVALID
, /* 01 1 1011 */
127 INVALID
, /* 01 1 1100 */
128 INVALID
, /* 01 1 1101 */
129 INVALID
, /* 01 1 1110 */
130 INVALID
, /* 01 1 1111 */
131 INVALID
, /* 10 0 0000 */
132 INVALID
, /* 10 0 0001 */
133 INVALID
, /* 10 0 0010: stwcx. */
134 INVALID
, /* 10 0 0011 */
135 INVALID
, /* 10 0 0100 */
136 INVALID
, /* 10 0 0101 */
137 INVALID
, /* 10 0 0110 */
138 INVALID
, /* 10 0 0111 */
139 { 4, LD
+SW
}, /* 10 0 1000: lwbrx */
140 INVALID
, /* 10 0 1001 */
141 { 4, ST
+SW
}, /* 10 0 1010: stwbrx */
142 INVALID
, /* 10 0 1011 */
143 { 2, LD
+SW
}, /* 10 0 1100: lhbrx */
144 { 4, LD
+SE
}, /* 10 0 1101 lwa */
145 { 2, ST
+SW
}, /* 10 0 1110: sthbrx */
146 INVALID
, /* 10 0 1111 */
147 INVALID
, /* 10 1 0000 */
148 INVALID
, /* 10 1 0001 */
149 INVALID
, /* 10 1 0010 */
150 INVALID
, /* 10 1 0011 */
151 INVALID
, /* 10 1 0100 */
152 INVALID
, /* 10 1 0101 */
153 INVALID
, /* 10 1 0110 */
154 INVALID
, /* 10 1 0111 */
155 INVALID
, /* 10 1 1000 */
156 INVALID
, /* 10 1 1001 */
157 INVALID
, /* 10 1 1010 */
158 INVALID
, /* 10 1 1011 */
159 INVALID
, /* 10 1 1100 */
160 INVALID
, /* 10 1 1101 */
161 INVALID
, /* 10 1 1110 */
162 { 0, ST
+HARD
}, /* 10 1 1111: dcbz */
163 { 4, LD
}, /* 11 0 0000: lwzx */
164 INVALID
, /* 11 0 0001 */
165 { 4, ST
}, /* 11 0 0010: stwx */
166 INVALID
, /* 11 0 0011 */
167 { 2, LD
}, /* 11 0 0100: lhzx */
168 { 2, LD
+SE
}, /* 11 0 0101: lhax */
169 { 2, ST
}, /* 11 0 0110: sthx */
170 INVALID
, /* 11 0 0111 */
171 { 4, LD
+F
+S
}, /* 11 0 1000: lfsx */
172 { 8, LD
+F
}, /* 11 0 1001: lfdx */
173 { 4, ST
+F
+S
}, /* 11 0 1010: stfsx */
174 { 8, ST
+F
}, /* 11 0 1011: stfdx */
175 { 16, LD
+F
}, /* 11 0 1100: lfdpx */
176 { 4, LD
+F
+SE
}, /* 11 0 1101: lfiwax */
177 { 16, ST
+F
}, /* 11 0 1110: stfdpx */
178 { 4, ST
+F
}, /* 11 0 1111: stfiwx */
179 { 4, LD
+U
}, /* 11 1 0000: lwzux */
180 INVALID
, /* 11 1 0001 */
181 { 4, ST
+U
}, /* 11 1 0010: stwux */
182 INVALID
, /* 11 1 0011 */
183 { 2, LD
+U
}, /* 11 1 0100: lhzux */
184 { 2, LD
+SE
+U
}, /* 11 1 0101: lhaux */
185 { 2, ST
+U
}, /* 11 1 0110: sthux */
186 INVALID
, /* 11 1 0111 */
187 { 4, LD
+F
+S
+U
}, /* 11 1 1000: lfsux */
188 { 8, LD
+F
+U
}, /* 11 1 1001: lfdux */
189 { 4, ST
+F
+S
+U
}, /* 11 1 1010: stfsux */
190 { 8, ST
+F
+U
}, /* 11 1 1011: stfdux */
191 INVALID
, /* 11 1 1100 */
192 { 4, LD
+F
}, /* 11 1 1101: lfiwzx */
193 INVALID
, /* 11 1 1110 */
194 INVALID
, /* 11 1 1111 */
198 * Create a DSISR value from the instruction
200 static inline unsigned make_dsisr(unsigned instr
)
205 /* bits 6:15 --> 22:31 */
206 dsisr
= (instr
& 0x03ff0000) >> 16;
208 if (IS_XFORM(instr
)) {
209 /* bits 29:30 --> 15:16 */
210 dsisr
|= (instr
& 0x00000006) << 14;
212 dsisr
|= (instr
& 0x00000040) << 8;
213 /* bits 21:24 --> 18:21 */
214 dsisr
|= (instr
& 0x00000780) << 3;
217 dsisr
|= (instr
& 0x04000000) >> 12;
218 /* bits 1: 4 --> 18:21 */
219 dsisr
|= (instr
& 0x78000000) >> 17;
220 /* bits 30:31 --> 12:13 */
221 if (IS_DSFORM(instr
))
222 dsisr
|= (instr
& 0x00000003) << 18;
229 * The dcbz (data cache block zero) instruction
230 * gives an alignment fault if used on non-cacheable
231 * memory. We handle the fault mainly for the
232 * case when we are running with the cache disabled
235 static int emulate_dcbz(struct pt_regs
*regs
, unsigned char __user
*addr
)
241 size
= ppc64_caches
.dline_size
;
243 size
= L1_CACHE_BYTES
;
245 p
= (long __user
*) (regs
->dar
& -size
);
246 if (user_mode(regs
) && !access_ok(VERIFY_WRITE
, p
, size
))
248 for (i
= 0; i
< size
/ sizeof(long); ++i
)
249 if (__put_user_inatomic(0, p
+i
))
255 * Emulate load & store multiple instructions
256 * On 64-bit machines, these instructions only affect/use the
257 * bottom 4 bytes of each register, and the loads clear the
258 * top 4 bytes of the affected register.
261 #define REG_BYTE(rp, i) *((u8 *)((rp) + ((i) >> 2)) + ((i) & 3) + 4)
263 #define REG_BYTE(rp, i) *((u8 *)(rp) + (i))
266 #define SWIZ_PTR(p) ((unsigned char __user *)((p) ^ swiz))
268 static int emulate_multiple(struct pt_regs
*regs
, unsigned char __user
*addr
,
269 unsigned int reg
, unsigned int nb
,
270 unsigned int flags
, unsigned int instr
,
274 unsigned int nb0
, i
, bswiz
;
278 * We do not try to emulate 8 bytes multiple as they aren't really
279 * available in our operating environments and we don't try to
280 * emulate multiples operations in kernel land as they should never
281 * be used/generated there at least not on unaligned boundaries
283 if (unlikely((nb
> 4) || !user_mode(regs
)))
286 /* lmw, stmw, lswi/x, stswi/x */
290 nb
= regs
->xer
& 127;
294 unsigned long pc
= regs
->nip
^ (swiz
& 4);
296 if (__get_user_inatomic(instr
,
297 (unsigned int __user
*)pc
))
299 if (swiz
== 0 && (flags
& SW
))
300 instr
= cpu_to_le32(instr
);
301 nb
= (instr
>> 11) & 0x1f;
305 if (nb
+ reg
* 4 > 128) {
306 nb0
= nb
+ reg
* 4 - 128;
314 if (!access_ok((flags
& ST
? VERIFY_WRITE
: VERIFY_READ
), addr
, nb
+nb0
))
315 return -EFAULT
; /* bad address */
317 rptr
= ®s
->gpr
[reg
];
318 p
= (unsigned long) addr
;
319 bswiz
= (flags
& SW
)? 3: 0;
323 * This zeroes the top 4 bytes of the affected registers
324 * in 64-bit mode, and also zeroes out any remaining
325 * bytes of the last register for lsw*.
327 memset(rptr
, 0, ((nb
+ 3) / 4) * sizeof(unsigned long));
329 memset(®s
->gpr
[0], 0,
330 ((nb0
+ 3) / 4) * sizeof(unsigned long));
332 for (i
= 0; i
< nb
; ++i
, ++p
)
333 if (__get_user_inatomic(REG_BYTE(rptr
, i
^ bswiz
),
337 rptr
= ®s
->gpr
[0];
339 for (i
= 0; i
< nb0
; ++i
, ++p
)
340 if (__get_user_inatomic(REG_BYTE(rptr
,
347 for (i
= 0; i
< nb
; ++i
, ++p
)
348 if (__put_user_inatomic(REG_BYTE(rptr
, i
^ bswiz
),
352 rptr
= ®s
->gpr
[0];
354 for (i
= 0; i
< nb0
; ++i
, ++p
)
355 if (__put_user_inatomic(REG_BYTE(rptr
,
365 * Emulate floating-point pair loads and stores.
366 * Only POWER6 has these instructions, and it does true little-endian,
367 * so we don't need the address swizzling.
369 static int emulate_fp_pair(unsigned char __user
*addr
, unsigned int reg
,
372 char *ptr0
= (char *) ¤t
->thread
.TS_FPR(reg
);
373 char *ptr1
= (char *) ¤t
->thread
.TS_FPR(reg
+1);
379 return 0; /* invalid form: FRS/FRT must be even */
383 for (i
= 0; i
< 8; ++i
) {
385 ret
|= __get_user(ptr0
[i
^sw
], addr
+ i
);
386 ret
|= __get_user(ptr1
[i
^sw
], addr
+ i
+ 8);
388 ret
|= __put_user(ptr0
[i
^sw
], addr
+ i
);
389 ret
|= __put_user(ptr1
[i
^sw
], addr
+ i
+ 8);
394 return 1; /* exception handled and fixed up */
399 static struct aligninfo spe_aligninfo
[32] = {
400 { 8, LD
+E8
}, /* 0 00 00: evldd[x] */
401 { 8, LD
+E4
}, /* 0 00 01: evldw[x] */
402 { 8, LD
}, /* 0 00 10: evldh[x] */
403 INVALID
, /* 0 00 11 */
404 { 2, LD
}, /* 0 01 00: evlhhesplat[x] */
405 INVALID
, /* 0 01 01 */
406 { 2, LD
}, /* 0 01 10: evlhhousplat[x] */
407 { 2, LD
+SE
}, /* 0 01 11: evlhhossplat[x] */
408 { 4, LD
}, /* 0 10 00: evlwhe[x] */
409 INVALID
, /* 0 10 01 */
410 { 4, LD
}, /* 0 10 10: evlwhou[x] */
411 { 4, LD
+SE
}, /* 0 10 11: evlwhos[x] */
412 { 4, LD
+E4
}, /* 0 11 00: evlwwsplat[x] */
413 INVALID
, /* 0 11 01 */
414 { 4, LD
}, /* 0 11 10: evlwhsplat[x] */
415 INVALID
, /* 0 11 11 */
417 { 8, ST
+E8
}, /* 1 00 00: evstdd[x] */
418 { 8, ST
+E4
}, /* 1 00 01: evstdw[x] */
419 { 8, ST
}, /* 1 00 10: evstdh[x] */
420 INVALID
, /* 1 00 11 */
421 INVALID
, /* 1 01 00 */
422 INVALID
, /* 1 01 01 */
423 INVALID
, /* 1 01 10 */
424 INVALID
, /* 1 01 11 */
425 { 4, ST
}, /* 1 10 00: evstwhe[x] */
426 INVALID
, /* 1 10 01 */
427 { 4, ST
}, /* 1 10 10: evstwho[x] */
428 INVALID
, /* 1 10 11 */
429 { 4, ST
+E4
}, /* 1 11 00: evstwwe[x] */
430 INVALID
, /* 1 11 01 */
431 { 4, ST
+E4
}, /* 1 11 10: evstwwo[x] */
432 INVALID
, /* 1 11 11 */
438 #define EVLHHESPLAT 0x04
439 #define EVLHHOUSPLAT 0x06
440 #define EVLHHOSSPLAT 0x07
444 #define EVLWWSPLAT 0x0C
445 #define EVLWHSPLAT 0x0E
455 * Emulate SPE loads and stores.
456 * Only Book-E has these instructions, and it does true little-endian,
457 * so we don't need the address swizzling.
459 static int emulate_spe(struct pt_regs
*regs
, unsigned int reg
,
469 unsigned char __user
*p
, *addr
;
470 unsigned long *evr
= ¤t
->thread
.evr
[reg
];
471 unsigned int nb
, flags
;
473 instr
= (instr
>> 1) & 0x1f;
475 /* DAR has the operand effective address */
476 addr
= (unsigned char __user
*)regs
->dar
;
478 nb
= spe_aligninfo
[instr
].len
;
479 flags
= spe_aligninfo
[instr
].flags
;
481 /* Verify the address of the operand */
482 if (unlikely(user_mode(regs
) &&
483 !access_ok((flags
& ST
? VERIFY_WRITE
: VERIFY_READ
),
488 if (unlikely(!user_mode(regs
)))
491 flush_spe_to_thread(current
);
493 /* If we are loading, get the data from user space, else
494 * get it from register values
503 data
.w
[1] = regs
->gpr
[reg
];
506 data
.h
[2] = *evr
>> 16;
507 data
.h
[3] = regs
->gpr
[reg
] >> 16;
510 data
.h
[2] = *evr
& 0xffff;
511 data
.h
[3] = regs
->gpr
[reg
] & 0xffff;
517 data
.w
[1] = regs
->gpr
[reg
];
523 temp
.ll
= data
.ll
= 0;
529 ret
|= __get_user_inatomic(temp
.v
[0], p
++);
530 ret
|= __get_user_inatomic(temp
.v
[1], p
++);
531 ret
|= __get_user_inatomic(temp
.v
[2], p
++);
532 ret
|= __get_user_inatomic(temp
.v
[3], p
++);
534 ret
|= __get_user_inatomic(temp
.v
[4], p
++);
535 ret
|= __get_user_inatomic(temp
.v
[5], p
++);
537 ret
|= __get_user_inatomic(temp
.v
[6], p
++);
538 ret
|= __get_user_inatomic(temp
.v
[7], p
++);
550 data
.h
[0] = temp
.h
[3];
551 data
.h
[2] = temp
.h
[3];
555 data
.h
[1] = temp
.h
[3];
556 data
.h
[3] = temp
.h
[3];
559 data
.h
[0] = temp
.h
[2];
560 data
.h
[2] = temp
.h
[3];
564 data
.h
[1] = temp
.h
[2];
565 data
.h
[3] = temp
.h
[3];
568 data
.w
[0] = temp
.w
[1];
569 data
.w
[1] = temp
.w
[1];
572 data
.h
[0] = temp
.h
[2];
573 data
.h
[1] = temp
.h
[2];
574 data
.h
[2] = temp
.h
[3];
575 data
.h
[3] = temp
.h
[3];
583 switch (flags
& 0xf0) {
585 SWAP(data
.v
[0], data
.v
[7]);
586 SWAP(data
.v
[1], data
.v
[6]);
587 SWAP(data
.v
[2], data
.v
[5]);
588 SWAP(data
.v
[3], data
.v
[4]);
592 SWAP(data
.v
[0], data
.v
[3]);
593 SWAP(data
.v
[1], data
.v
[2]);
594 SWAP(data
.v
[4], data
.v
[7]);
595 SWAP(data
.v
[5], data
.v
[6]);
597 /* Its half word endian */
599 SWAP(data
.v
[0], data
.v
[1]);
600 SWAP(data
.v
[2], data
.v
[3]);
601 SWAP(data
.v
[4], data
.v
[5]);
602 SWAP(data
.v
[6], data
.v
[7]);
608 data
.w
[0] = (s16
)data
.h
[1];
609 data
.w
[1] = (s16
)data
.h
[3];
612 /* Store result to memory or update registers */
618 ret
|= __put_user_inatomic(data
.v
[0], p
++);
619 ret
|= __put_user_inatomic(data
.v
[1], p
++);
620 ret
|= __put_user_inatomic(data
.v
[2], p
++);
621 ret
|= __put_user_inatomic(data
.v
[3], p
++);
623 ret
|= __put_user_inatomic(data
.v
[4], p
++);
624 ret
|= __put_user_inatomic(data
.v
[5], p
++);
626 ret
|= __put_user_inatomic(data
.v
[6], p
++);
627 ret
|= __put_user_inatomic(data
.v
[7], p
++);
633 regs
->gpr
[reg
] = data
.w
[1];
638 #endif /* CONFIG_SPE */
642 * Emulate VSX instructions...
644 static int emulate_vsx(unsigned char __user
*addr
, unsigned int reg
,
645 unsigned int areg
, struct pt_regs
*regs
,
646 unsigned int flags
, unsigned int length
,
655 flush_vsx_to_thread(current
);
658 ptr
= (char *) ¤t
->thread
.TS_FPR(reg
);
660 ptr
= (char *) ¤t
->thread
.vr
[reg
- 32];
662 lptr
= (unsigned long *) ptr
;
667 for (j
= 0; j
< length
; j
+= elsize
) {
668 for (i
= 0; i
< elsize
; ++i
) {
670 ret
|= __put_user(ptr
[i
^sw
], addr
+ i
);
672 ret
|= __get_user(ptr
[i
^sw
], addr
+ i
);
680 regs
->gpr
[areg
] = regs
->dar
;
682 /* Splat load copies the same data to top and bottom 8 bytes */
685 /* For 8 byte loads, zero the top 8 bytes */
686 else if (!(flags
& ST
) && (8 == length
))
696 * Called on alignment exception. Attempts to fixup
698 * Return 1 on success
699 * Return 0 if unable to handle the interrupt
700 * Return -EFAULT if data address is bad
703 int fix_alignment(struct pt_regs
*regs
)
705 unsigned int instr
, nb
, flags
, instruction
= 0;
706 unsigned int reg
, areg
;
708 unsigned char __user
*addr
;
709 unsigned long p
, swiz
;
720 unsigned char hi48
[6];
726 * We require a complete register set, if not, then our assembly
729 CHECK_FULL_REGS(regs
);
733 /* Some processors don't provide us with a DSISR we can use here,
734 * let's make one up from the instruction
736 if (cpu_has_feature(CPU_FTR_NODSISRALIGN
)) {
737 unsigned long pc
= regs
->nip
;
739 if (cpu_has_feature(CPU_FTR_PPC_LE
) && (regs
->msr
& MSR_LE
))
741 if (unlikely(__get_user_inatomic(instr
,
742 (unsigned int __user
*)pc
)))
744 if (cpu_has_feature(CPU_FTR_REAL_LE
) && (regs
->msr
& MSR_LE
))
745 instr
= cpu_to_le32(instr
);
746 dsisr
= make_dsisr(instr
);
750 /* extract the operation and registers from the dsisr */
751 reg
= (dsisr
>> 5) & 0x1f; /* source/dest register */
752 areg
= dsisr
& 0x1f; /* register to update */
755 if ((instr
>> 26) == 0x4) {
756 PPC_WARN_ALIGNMENT(spe
, regs
);
757 return emulate_spe(regs
, reg
, instr
);
761 instr
= (dsisr
>> 10) & 0x7f;
762 instr
|= (dsisr
>> 13) & 0x60;
764 /* Lookup the operation in our table */
765 nb
= aligninfo
[instr
].len
;
766 flags
= aligninfo
[instr
].flags
;
769 * Handle some cases which give overlaps in the DSISR values.
771 if (IS_XFORM(instruction
)) {
772 switch (get_xop(instruction
)) {
773 case 532: /* ldbrx */
777 case 660: /* stdbrx */
783 case 116: /* lharx */
784 case 276: /* lqarx */
785 return 0; /* not emulated ever */
789 /* Byteswap little endian loads and stores */
791 if (regs
->msr
& MSR_LE
) {
794 * So-called "PowerPC little endian" mode works by
795 * swizzling addresses rather than by actually doing
796 * any byte-swapping. To emulate this, we XOR each
797 * byte address with 7. We also byte-swap, because
798 * the processor's address swizzling depends on the
799 * operand size (it xors the address with 7 for bytes,
800 * 6 for halfwords, 4 for words, 0 for doublewords) but
801 * we will xor with 7 and load/store each byte separately.
803 if (cpu_has_feature(CPU_FTR_PPC_LE
))
807 /* DAR has the operand effective address */
808 addr
= (unsigned char __user
*)regs
->dar
;
811 if ((instruction
& 0xfc00003e) == 0x7c000018) {
814 /* Additional register addressing bit (64 VSX vs 32 FPR/GPR) */
815 reg
|= (instruction
& 0x1) << 5;
816 /* Simple inline decoder instead of a table */
817 /* VSX has only 8 and 16 byte memory accesses */
819 if (instruction
& 0x200)
822 /* Vector stores in little-endian mode swap individual
823 elements, so process them separately */
825 if (instruction
& 0x80)
829 if (regs
->msr
& MSR_LE
)
831 if (instruction
& 0x100)
833 if (instruction
& 0x040)
835 /* splat load needs a special decoder */
836 if ((instruction
& 0x400) == 0){
840 PPC_WARN_ALIGNMENT(vsx
, regs
);
841 return emulate_vsx(addr
, reg
, areg
, regs
, flags
, nb
, elsize
);
844 /* A size of 0 indicates an instruction we don't support, with
845 * the exception of DCBZ which is handled as a special case here
848 PPC_WARN_ALIGNMENT(dcbz
, regs
);
849 return emulate_dcbz(regs
, addr
);
851 if (unlikely(nb
== 0))
854 /* Load/Store Multiple instructions are handled in their own
858 PPC_WARN_ALIGNMENT(multiple
, regs
);
859 return emulate_multiple(regs
, addr
, reg
, nb
,
863 /* Verify the address of the operand */
864 if (unlikely(user_mode(regs
) &&
865 !access_ok((flags
& ST
? VERIFY_WRITE
: VERIFY_READ
),
869 /* Force the fprs into the save area so we can reference them */
872 if (unlikely(!user_mode(regs
)))
874 flush_fp_to_thread(current
);
877 /* Special case for 16-byte FP loads and stores */
879 PPC_WARN_ALIGNMENT(fp_pair
, regs
);
880 return emulate_fp_pair(addr
, reg
, flags
);
883 PPC_WARN_ALIGNMENT(unaligned
, regs
);
885 /* If we are loading, get the data from user space, else
886 * get it from register values
891 p
= (unsigned long) addr
;
894 ret
|= __get_user_inatomic(data
.v
[0], SWIZ_PTR(p
++));
895 ret
|= __get_user_inatomic(data
.v
[1], SWIZ_PTR(p
++));
896 ret
|= __get_user_inatomic(data
.v
[2], SWIZ_PTR(p
++));
897 ret
|= __get_user_inatomic(data
.v
[3], SWIZ_PTR(p
++));
899 ret
|= __get_user_inatomic(data
.v
[4], SWIZ_PTR(p
++));
900 ret
|= __get_user_inatomic(data
.v
[5], SWIZ_PTR(p
++));
902 ret
|= __get_user_inatomic(data
.v
[6], SWIZ_PTR(p
++));
903 ret
|= __get_user_inatomic(data
.v
[7], SWIZ_PTR(p
++));
907 } else if (flags
& F
) {
908 data
.dd
= current
->thread
.TS_FPR(reg
);
910 /* Single-precision FP store requires conversion... */
911 #ifdef CONFIG_PPC_FPU
914 cvt_df(&data
.dd
, (float *)&data
.v
[4]);
921 data
.ll
= regs
->gpr
[reg
];
926 SWAP(data
.v
[0], data
.v
[7]);
927 SWAP(data
.v
[1], data
.v
[6]);
928 SWAP(data
.v
[2], data
.v
[5]);
929 SWAP(data
.v
[3], data
.v
[4]);
932 SWAP(data
.v
[4], data
.v
[7]);
933 SWAP(data
.v
[5], data
.v
[6]);
936 SWAP(data
.v
[6], data
.v
[7]);
941 /* Perform other misc operations like sign extension
942 * or floating point single precision conversion
944 switch (flags
& ~(U
|SW
)) {
945 case LD
+SE
: /* sign extending integer loads */
946 case LD
+F
+SE
: /* sign extend for lfiwax */
948 data
.ll
= data
.x16
.low16
;
949 else /* nb must be 4 */
950 data
.ll
= data
.x32
.low32
;
953 /* Single-precision FP load requires conversion... */
955 #ifdef CONFIG_PPC_FPU
958 cvt_fd((float *)&data
.v
[4], &data
.dd
);
966 /* Store result to memory or update registers */
969 p
= (unsigned long) addr
;
972 ret
|= __put_user_inatomic(data
.v
[0], SWIZ_PTR(p
++));
973 ret
|= __put_user_inatomic(data
.v
[1], SWIZ_PTR(p
++));
974 ret
|= __put_user_inatomic(data
.v
[2], SWIZ_PTR(p
++));
975 ret
|= __put_user_inatomic(data
.v
[3], SWIZ_PTR(p
++));
977 ret
|= __put_user_inatomic(data
.v
[4], SWIZ_PTR(p
++));
978 ret
|= __put_user_inatomic(data
.v
[5], SWIZ_PTR(p
++));
980 ret
|= __put_user_inatomic(data
.v
[6], SWIZ_PTR(p
++));
981 ret
|= __put_user_inatomic(data
.v
[7], SWIZ_PTR(p
++));
985 } else if (flags
& F
)
986 current
->thread
.TS_FPR(reg
) = data
.dd
;
988 regs
->gpr
[reg
] = data
.ll
;
990 /* Update RA as needed */
992 regs
->gpr
[areg
] = regs
->dar
;