blob: d5b45bb7d108493b69f8ebc1e2904c77da6a31ea [file] [log] [blame]
David Howellsb920de12008-02-08 04:19:31 -08001/* MN10300 Misalignment fixup handler
2 *
3 * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com)
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public Licence
8 * as published by the Free Software Foundation; either version
9 * 2 of the Licence, or (at your option) any later version.
10 */
11#include <linux/module.h>
12#include <linux/sched.h>
13#include <linux/kernel.h>
14#include <linux/string.h>
15#include <linux/errno.h>
16#include <linux/ptrace.h>
17#include <linux/timer.h>
18#include <linux/mm.h>
19#include <linux/smp.h>
20#include <linux/smp_lock.h>
21#include <linux/init.h>
22#include <linux/delay.h>
23#include <linux/spinlock.h>
24#include <linux/interrupt.h>
25#include <linux/pci.h>
26#include <asm/processor.h>
27#include <asm/system.h>
28#include <asm/uaccess.h>
29#include <asm/io.h>
30#include <asm/atomic.h>
31#include <asm/smp.h>
32#include <asm/pgalloc.h>
33#include <asm/cpu-regs.h>
34#include <asm/busctl-regs.h>
35#include <asm/fpu.h>
36#include <asm/gdb-stub.h>
37#include <asm/asm-offsets.h>
38
39#if 0
David Howells31ea24b2008-11-12 15:34:59 +000040#define kdebug(FMT, ...) printk(KERN_DEBUG "MISALIGN: "FMT"\n", ##__VA_ARGS__)
David Howellsb920de12008-02-08 04:19:31 -080041#else
42#define kdebug(FMT, ...) do {} while (0)
43#endif
44
45static int misalignment_addr(unsigned long *registers, unsigned params,
David Howellsb308bf32008-11-12 15:35:14 +000046 unsigned opcode, unsigned long disp,
David Howellsb920de12008-02-08 04:19:31 -080047 void **_address, unsigned long **_postinc);
48
49static int misalignment_reg(unsigned long *registers, unsigned params,
David Howellsb308bf32008-11-12 15:35:14 +000050 unsigned opcode, unsigned long disp,
David Howellsb920de12008-02-08 04:19:31 -080051 unsigned long **_register);
52
David Howellsddb6d052008-11-12 15:35:30 +000053static void misalignment_MOV_Lcc(struct pt_regs *regs, uint32_t opcode);
54
David Howellsb920de12008-02-08 04:19:31 -080055static const unsigned Dreg_index[] = {
56 REG_D0 >> 2, REG_D1 >> 2, REG_D2 >> 2, REG_D3 >> 2
57};
58
59static const unsigned Areg_index[] = {
60 REG_A0 >> 2, REG_A1 >> 2, REG_A2 >> 2, REG_A3 >> 2
61};
62
63static const unsigned Rreg_index[] = {
64 REG_E0 >> 2, REG_E1 >> 2, REG_E2 >> 2, REG_E3 >> 2,
65 REG_E4 >> 2, REG_E5 >> 2, REG_E6 >> 2, REG_E7 >> 2,
66 REG_A0 >> 2, REG_A1 >> 2, REG_A2 >> 2, REG_A3 >> 2,
67 REG_D0 >> 2, REG_D1 >> 2, REG_D2 >> 2, REG_D3 >> 2
68};
69
70enum format_id {
71 FMT_S0,
72 FMT_S1,
73 FMT_S2,
74 FMT_S4,
75 FMT_D0,
76 FMT_D1,
77 FMT_D2,
78 FMT_D4,
79 FMT_D6,
80 FMT_D7,
81 FMT_D8,
82 FMT_D9,
David Howellsddb6d052008-11-12 15:35:30 +000083 FMT_D10,
David Howellsb920de12008-02-08 04:19:31 -080084};
85
David Howells31ea24b2008-11-12 15:34:59 +000086static const struct {
David Howellsb920de12008-02-08 04:19:31 -080087 u_int8_t opsz, dispsz;
88} format_tbl[16] = {
89 [FMT_S0] = { 8, 0 },
90 [FMT_S1] = { 8, 8 },
91 [FMT_S2] = { 8, 16 },
92 [FMT_S4] = { 8, 32 },
93 [FMT_D0] = { 16, 0 },
94 [FMT_D1] = { 16, 8 },
95 [FMT_D2] = { 16, 16 },
96 [FMT_D4] = { 16, 32 },
97 [FMT_D6] = { 24, 0 },
98 [FMT_D7] = { 24, 8 },
99 [FMT_D8] = { 24, 24 },
100 [FMT_D9] = { 24, 32 },
David Howellsddb6d052008-11-12 15:35:30 +0000101 [FMT_D10] = { 32, 0 },
David Howellsb920de12008-02-08 04:19:31 -0800102};
103
104enum value_id {
105 DM0, /* data reg in opcode in bits 0-1 */
106 DM1, /* data reg in opcode in bits 2-3 */
107 DM2, /* data reg in opcode in bits 4-5 */
108 AM0, /* addr reg in opcode in bits 0-1 */
109 AM1, /* addr reg in opcode in bits 2-3 */
110 AM2, /* addr reg in opcode in bits 4-5 */
111 RM0, /* reg in opcode in bits 0-3 */
112 RM1, /* reg in opcode in bits 2-5 */
113 RM2, /* reg in opcode in bits 4-7 */
114 RM4, /* reg in opcode in bits 8-11 */
115 RM6, /* reg in opcode in bits 12-15 */
116
117 RD0, /* reg in displacement in bits 0-3 */
118 RD2, /* reg in displacement in bits 4-7 */
119
120 SP, /* stack pointer */
121
122 SD8, /* 8-bit signed displacement */
123 SD16, /* 16-bit signed displacement */
124 SD24, /* 24-bit signed displacement */
125 SIMM4_2, /* 4-bit signed displacement in opcode bits 4-7 */
126 SIMM8, /* 8-bit signed immediate */
David Howellsee6e7402008-11-12 15:35:09 +0000127 IMM8, /* 8-bit unsigned immediate */
128 IMM16, /* 16-bit unsigned immediate */
David Howellsb920de12008-02-08 04:19:31 -0800129 IMM24, /* 24-bit unsigned immediate */
130 IMM32, /* 32-bit unsigned immediate */
David Howellsee6e7402008-11-12 15:35:09 +0000131 IMM32_HIGH8, /* 32-bit unsigned immediate, LSB in opcode */
132
133 IMM32_MEM, /* 32-bit unsigned displacement */
134 IMM32_HIGH8_MEM, /* 32-bit unsigned displacement, LSB in opcode */
David Howellsb920de12008-02-08 04:19:31 -0800135
136 DN0 = DM0,
137 DN1 = DM1,
138 DN2 = DM2,
139 AN0 = AM0,
140 AN1 = AM1,
141 AN2 = AM2,
142 RN0 = RM0,
143 RN1 = RM1,
144 RN2 = RM2,
145 RN4 = RM4,
146 RN6 = RM6,
147 DI = DM1,
148 RI = RM2,
149
150};
151
152struct mn10300_opcode {
153 const char *name;
154 u_int32_t opcode;
155 u_int32_t opmask;
156 unsigned exclusion;
157
158 enum format_id format;
159
160 unsigned cpu_mask;
161#define AM33 330
162
163 unsigned params[2];
164#define MEM(ADDR) (0x80000000 | (ADDR))
165#define MEM2(ADDR1, ADDR2) (0x80000000 | (ADDR1) << 8 | (ADDR2))
166#define MEMINC(ADDR) (0x81000000 | (ADDR))
167#define MEMINC2(ADDR, INC) (0x81000000 | (ADDR) << 8 | (INC))
168};
169
170/* LIBOPCODES EXCERPT
171 Assemble Matsushita MN10300 instructions.
172 Copyright 1996, 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
173
174 This program is free software; you can redistribute it and/or modify
175 it under the terms of the GNU General Public Licence as published by
176 the Free Software Foundation; either version 2 of the Licence, or
177 (at your option) any later version.
178
179 This program is distributed in the hope that it will be useful,
180 but WITHOUT ANY WARRANTY; without even the implied warranty of
181 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
182 GNU General Public Licence for more details.
183
184 You should have received a copy of the GNU General Public Licence
185 along with this program; if not, write to the Free Software
186 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
187*/
188static const struct mn10300_opcode mn10300_opcodes[] = {
David Howellsee6e7402008-11-12 15:35:09 +0000189{ "mov", 0x4200, 0xf300, 0, FMT_S1, 0, {DM1, MEM2(IMM8, SP)}},
190{ "mov", 0x4300, 0xf300, 0, FMT_S1, 0, {AM1, MEM2(IMM8, SP)}},
191{ "mov", 0x5800, 0xfc00, 0, FMT_S1, 0, {MEM2(IMM8, SP), DN0}},
192{ "mov", 0x5c00, 0xfc00, 0, FMT_S1, 0, {MEM2(IMM8, SP), AN0}},
David Howellsb920de12008-02-08 04:19:31 -0800193{ "mov", 0x60, 0xf0, 0, FMT_S0, 0, {DM1, MEM(AN0)}},
194{ "mov", 0x70, 0xf0, 0, FMT_S0, 0, {MEM(AM0), DN1}},
195{ "mov", 0xf000, 0xfff0, 0, FMT_D0, 0, {MEM(AM0), AN1}},
196{ "mov", 0xf010, 0xfff0, 0, FMT_D0, 0, {AM1, MEM(AN0)}},
197{ "mov", 0xf300, 0xffc0, 0, FMT_D0, 0, {MEM2(DI, AM0), DN2}},
198{ "mov", 0xf340, 0xffc0, 0, FMT_D0, 0, {DM2, MEM2(DI, AN0)}},
199{ "mov", 0xf380, 0xffc0, 0, FMT_D0, 0, {MEM2(DI, AM0), AN2}},
200{ "mov", 0xf3c0, 0xffc0, 0, FMT_D0, 0, {AM2, MEM2(DI, AN0)}},
201{ "mov", 0xf80000, 0xfff000, 0, FMT_D1, 0, {MEM2(SD8, AM0), DN1}},
202{ "mov", 0xf81000, 0xfff000, 0, FMT_D1, 0, {DM1, MEM2(SD8, AN0)}},
203{ "mov", 0xf82000, 0xfff000, 0, FMT_D1, 0, {MEM2(SD8,AM0), AN1}},
204{ "mov", 0xf83000, 0xfff000, 0, FMT_D1, 0, {AM1, MEM2(SD8, AN0)}},
205{ "mov", 0xf8f000, 0xfffc00, 0, FMT_D1, AM33, {MEM2(SD8, AM0), SP}},
206{ "mov", 0xf8f400, 0xfffc00, 0, FMT_D1, AM33, {SP, MEM2(SD8, AN0)}},
207{ "mov", 0xf90a00, 0xffff00, 0, FMT_D6, AM33, {MEM(RM0), RN2}},
208{ "mov", 0xf91a00, 0xffff00, 0, FMT_D6, AM33, {RM2, MEM(RN0)}},
209{ "mov", 0xf96a00, 0xffff00, 0x12, FMT_D6, AM33, {MEMINC(RM0), RN2}},
210{ "mov", 0xf97a00, 0xffff00, 0, FMT_D6, AM33, {RM2, MEMINC(RN0)}},
211{ "mov", 0xfa000000, 0xfff00000, 0, FMT_D2, 0, {MEM2(SD16, AM0), DN1}},
212{ "mov", 0xfa100000, 0xfff00000, 0, FMT_D2, 0, {DM1, MEM2(SD16, AN0)}},
213{ "mov", 0xfa200000, 0xfff00000, 0, FMT_D2, 0, {MEM2(SD16, AM0), AN1}},
214{ "mov", 0xfa300000, 0xfff00000, 0, FMT_D2, 0, {AM1, MEM2(SD16, AN0)}},
David Howellsee6e7402008-11-12 15:35:09 +0000215{ "mov", 0xfa900000, 0xfff30000, 0, FMT_D2, 0, {AM1, MEM2(IMM16, SP)}},
216{ "mov", 0xfa910000, 0xfff30000, 0, FMT_D2, 0, {DM1, MEM2(IMM16, SP)}},
217{ "mov", 0xfab00000, 0xfffc0000, 0, FMT_D2, 0, {MEM2(IMM16, SP), AN0}},
218{ "mov", 0xfab40000, 0xfffc0000, 0, FMT_D2, 0, {MEM2(IMM16, SP), DN0}},
David Howellsb920de12008-02-08 04:19:31 -0800219{ "mov", 0xfb0a0000, 0xffff0000, 0, FMT_D7, AM33, {MEM2(SD8, RM0), RN2}},
220{ "mov", 0xfb1a0000, 0xffff0000, 0, FMT_D7, AM33, {RM2, MEM2(SD8, RN0)}},
221{ "mov", 0xfb6a0000, 0xffff0000, 0x22, FMT_D7, AM33, {MEMINC2 (RM0, SIMM8), RN2}},
222{ "mov", 0xfb7a0000, 0xffff0000, 0, FMT_D7, AM33, {RM2, MEMINC2 (RN0, SIMM8)}},
David Howellsee6e7402008-11-12 15:35:09 +0000223{ "mov", 0xfb8a0000, 0xffff0f00, 0, FMT_D7, AM33, {MEM2(IMM8, SP), RN2}},
David Howellsb920de12008-02-08 04:19:31 -0800224{ "mov", 0xfb8e0000, 0xffff000f, 0, FMT_D7, AM33, {MEM2(RI, RM0), RD2}},
David Howellsee6e7402008-11-12 15:35:09 +0000225{ "mov", 0xfb9a0000, 0xffff0f00, 0, FMT_D7, AM33, {RM2, MEM2(IMM8, SP)}},
David Howellsb920de12008-02-08 04:19:31 -0800226{ "mov", 0xfb9e0000, 0xffff000f, 0, FMT_D7, AM33, {RD2, MEM2(RI, RN0)}},
227{ "mov", 0xfc000000, 0xfff00000, 0, FMT_D4, 0, {MEM2(IMM32,AM0), DN1}},
228{ "mov", 0xfc100000, 0xfff00000, 0, FMT_D4, 0, {DM1, MEM2(IMM32,AN0)}},
229{ "mov", 0xfc200000, 0xfff00000, 0, FMT_D4, 0, {MEM2(IMM32,AM0), AN1}},
230{ "mov", 0xfc300000, 0xfff00000, 0, FMT_D4, 0, {AM1, MEM2(IMM32,AN0)}},
David Howellsee6e7402008-11-12 15:35:09 +0000231{ "mov", 0xfc800000, 0xfff30000, 0, FMT_D4, 0, {AM1, MEM(IMM32_MEM)}},
232{ "mov", 0xfc810000, 0xfff30000, 0, FMT_D4, 0, {DM1, MEM(IMM32_MEM)}},
233{ "mov", 0xfc900000, 0xfff30000, 0, FMT_D4, 0, {AM1, MEM2(IMM32, SP)}},
234{ "mov", 0xfc910000, 0xfff30000, 0, FMT_D4, 0, {DM1, MEM2(IMM32, SP)}},
235{ "mov", 0xfca00000, 0xfffc0000, 0, FMT_D4, 0, {MEM(IMM32_MEM), AN0}},
236{ "mov", 0xfca40000, 0xfffc0000, 0, FMT_D4, 0, {MEM(IMM32_MEM), DN0}},
237{ "mov", 0xfcb00000, 0xfffc0000, 0, FMT_D4, 0, {MEM2(IMM32, SP), AN0}},
238{ "mov", 0xfcb40000, 0xfffc0000, 0, FMT_D4, 0, {MEM2(IMM32, SP), DN0}},
David Howellsb920de12008-02-08 04:19:31 -0800239{ "mov", 0xfd0a0000, 0xffff0000, 0, FMT_D8, AM33, {MEM2(SD24, RM0), RN2}},
240{ "mov", 0xfd1a0000, 0xffff0000, 0, FMT_D8, AM33, {RM2, MEM2(SD24, RN0)}},
241{ "mov", 0xfd6a0000, 0xffff0000, 0x22, FMT_D8, AM33, {MEMINC2 (RM0, IMM24), RN2}},
242{ "mov", 0xfd7a0000, 0xffff0000, 0, FMT_D8, AM33, {RM2, MEMINC2 (RN0, IMM24)}},
David Howellsee6e7402008-11-12 15:35:09 +0000243{ "mov", 0xfd8a0000, 0xffff0f00, 0, FMT_D8, AM33, {MEM2(IMM24, SP), RN2}},
244{ "mov", 0xfd9a0000, 0xffff0f00, 0, FMT_D8, AM33, {RM2, MEM2(IMM24, SP)}},
David Howellsb920de12008-02-08 04:19:31 -0800245{ "mov", 0xfe0a0000, 0xffff0000, 0, FMT_D9, AM33, {MEM2(IMM32_HIGH8,RM0), RN2}},
David Howellsee6e7402008-11-12 15:35:09 +0000246{ "mov", 0xfe0a0000, 0xffff0000, 0, FMT_D9, AM33, {MEM2(IMM32_HIGH8,RM0), RN2}},
247{ "mov", 0xfe0e0000, 0xffff0f00, 0, FMT_D9, AM33, {MEM(IMM32_HIGH8_MEM), RN2}},
David Howellsb920de12008-02-08 04:19:31 -0800248{ "mov", 0xfe1a0000, 0xffff0000, 0, FMT_D9, AM33, {RM2, MEM2(IMM32_HIGH8, RN0)}},
David Howellsee6e7402008-11-12 15:35:09 +0000249{ "mov", 0xfe1a0000, 0xffff0000, 0, FMT_D9, AM33, {RM2, MEM2(IMM32_HIGH8, RN0)}},
250{ "mov", 0xfe1e0000, 0xffff0f00, 0, FMT_D9, AM33, {RM2, MEM(IMM32_HIGH8_MEM)}},
David Howellsb920de12008-02-08 04:19:31 -0800251{ "mov", 0xfe6a0000, 0xffff0000, 0x22, FMT_D9, AM33, {MEMINC2 (RM0, IMM32_HIGH8), RN2}},
252{ "mov", 0xfe7a0000, 0xffff0000, 0, FMT_D9, AM33, {RN2, MEMINC2 (RM0, IMM32_HIGH8)}},
David Howellsee6e7402008-11-12 15:35:09 +0000253{ "mov", 0xfe8a0000, 0xffff0f00, 0, FMT_D9, AM33, {MEM2(IMM32_HIGH8, SP), RN2}},
254{ "mov", 0xfe9a0000, 0xffff0f00, 0, FMT_D9, AM33, {RM2, MEM2(IMM32_HIGH8, SP)}},
David Howellsb920de12008-02-08 04:19:31 -0800255
256{ "movhu", 0xf060, 0xfff0, 0, FMT_D0, 0, {MEM(AM0), DN1}},
257{ "movhu", 0xf070, 0xfff0, 0, FMT_D0, 0, {DM1, MEM(AN0)}},
258{ "movhu", 0xf480, 0xffc0, 0, FMT_D0, 0, {MEM2(DI, AM0), DN2}},
259{ "movhu", 0xf4c0, 0xffc0, 0, FMT_D0, 0, {DM2, MEM2(DI, AN0)}},
260{ "movhu", 0xf86000, 0xfff000, 0, FMT_D1, 0, {MEM2(SD8, AM0), DN1}},
261{ "movhu", 0xf87000, 0xfff000, 0, FMT_D1, 0, {DM1, MEM2(SD8, AN0)}},
David Howellsee6e7402008-11-12 15:35:09 +0000262{ "movhu", 0xf89300, 0xfff300, 0, FMT_D1, 0, {DM1, MEM2(IMM8, SP)}},
263{ "movhu", 0xf8bc00, 0xfffc00, 0, FMT_D1, 0, {MEM2(IMM8, SP), DN0}},
David Howellsb920de12008-02-08 04:19:31 -0800264{ "movhu", 0xf94a00, 0xffff00, 0, FMT_D6, AM33, {MEM(RM0), RN2}},
265{ "movhu", 0xf95a00, 0xffff00, 0, FMT_D6, AM33, {RM2, MEM(RN0)}},
266{ "movhu", 0xf9ea00, 0xffff00, 0x12, FMT_D6, AM33, {MEMINC(RM0), RN2}},
267{ "movhu", 0xf9fa00, 0xffff00, 0, FMT_D6, AM33, {RM2, MEMINC(RN0)}},
268{ "movhu", 0xfa600000, 0xfff00000, 0, FMT_D2, 0, {MEM2(SD16, AM0), DN1}},
269{ "movhu", 0xfa700000, 0xfff00000, 0, FMT_D2, 0, {DM1, MEM2(SD16, AN0)}},
David Howellsee6e7402008-11-12 15:35:09 +0000270{ "movhu", 0xfa930000, 0xfff30000, 0, FMT_D2, 0, {DM1, MEM2(IMM16, SP)}},
271{ "movhu", 0xfabc0000, 0xfffc0000, 0, FMT_D2, 0, {MEM2(IMM16, SP), DN0}},
David Howellsb920de12008-02-08 04:19:31 -0800272{ "movhu", 0xfb4a0000, 0xffff0000, 0, FMT_D7, AM33, {MEM2(SD8, RM0), RN2}},
273{ "movhu", 0xfb5a0000, 0xffff0000, 0, FMT_D7, AM33, {RM2, MEM2(SD8, RN0)}},
David Howellsee6e7402008-11-12 15:35:09 +0000274{ "movhu", 0xfbca0000, 0xffff0f00, 0, FMT_D7, AM33, {MEM2(IMM8, SP), RN2}},
David Howellsb920de12008-02-08 04:19:31 -0800275{ "movhu", 0xfbce0000, 0xffff000f, 0, FMT_D7, AM33, {MEM2(RI, RM0), RD2}},
David Howellsee6e7402008-11-12 15:35:09 +0000276{ "movhu", 0xfbda0000, 0xffff0f00, 0, FMT_D7, AM33, {RM2, MEM2(IMM8, SP)}},
David Howellsb920de12008-02-08 04:19:31 -0800277{ "movhu", 0xfbde0000, 0xffff000f, 0, FMT_D7, AM33, {RD2, MEM2(RI, RN0)}},
278{ "movhu", 0xfbea0000, 0xffff0000, 0x22, FMT_D7, AM33, {MEMINC2 (RM0, SIMM8), RN2}},
279{ "movhu", 0xfbfa0000, 0xffff0000, 0, FMT_D7, AM33, {RM2, MEMINC2 (RN0, SIMM8)}},
280{ "movhu", 0xfc600000, 0xfff00000, 0, FMT_D4, 0, {MEM2(IMM32,AM0), DN1}},
281{ "movhu", 0xfc700000, 0xfff00000, 0, FMT_D4, 0, {DM1, MEM2(IMM32,AN0)}},
David Howellsee6e7402008-11-12 15:35:09 +0000282{ "movhu", 0xfc830000, 0xfff30000, 0, FMT_D4, 0, {DM1, MEM(IMM32_MEM)}},
283{ "movhu", 0xfc930000, 0xfff30000, 0, FMT_D4, 0, {DM1, MEM2(IMM32, SP)}},
284{ "movhu", 0xfcac0000, 0xfffc0000, 0, FMT_D4, 0, {MEM(IMM32_MEM), DN0}},
285{ "movhu", 0xfcbc0000, 0xfffc0000, 0, FMT_D4, 0, {MEM2(IMM32, SP), DN0}},
David Howellsb920de12008-02-08 04:19:31 -0800286{ "movhu", 0xfd4a0000, 0xffff0000, 0, FMT_D8, AM33, {MEM2(SD24, RM0), RN2}},
287{ "movhu", 0xfd5a0000, 0xffff0000, 0, FMT_D8, AM33, {RM2, MEM2(SD24, RN0)}},
David Howellsee6e7402008-11-12 15:35:09 +0000288{ "movhu", 0xfdca0000, 0xffff0f00, 0, FMT_D8, AM33, {MEM2(IMM24, SP), RN2}},
289{ "movhu", 0xfdda0000, 0xffff0f00, 0, FMT_D8, AM33, {RM2, MEM2(IMM24, SP)}},
David Howellsb920de12008-02-08 04:19:31 -0800290{ "movhu", 0xfdea0000, 0xffff0000, 0x22, FMT_D8, AM33, {MEMINC2 (RM0, IMM24), RN2}},
291{ "movhu", 0xfdfa0000, 0xffff0000, 0, FMT_D8, AM33, {RM2, MEMINC2 (RN0, IMM24)}},
292{ "movhu", 0xfe4a0000, 0xffff0000, 0, FMT_D9, AM33, {MEM2(IMM32_HIGH8,RM0), RN2}},
David Howellsee6e7402008-11-12 15:35:09 +0000293{ "movhu", 0xfe4e0000, 0xffff0f00, 0, FMT_D9, AM33, {MEM(IMM32_HIGH8_MEM), RN2}},
David Howellsb920de12008-02-08 04:19:31 -0800294{ "movhu", 0xfe5a0000, 0xffff0000, 0, FMT_D9, AM33, {RM2, MEM2(IMM32_HIGH8, RN0)}},
David Howellsee6e7402008-11-12 15:35:09 +0000295{ "movhu", 0xfe5e0000, 0xffff0f00, 0, FMT_D9, AM33, {RM2, MEM(IMM32_HIGH8_MEM)}},
296{ "movhu", 0xfeca0000, 0xffff0f00, 0, FMT_D9, AM33, {MEM2(IMM32_HIGH8, SP), RN2}},
297{ "movhu", 0xfeda0000, 0xffff0f00, 0, FMT_D9, AM33, {RM2, MEM2(IMM32_HIGH8, SP)}},
David Howellsb920de12008-02-08 04:19:31 -0800298{ "movhu", 0xfeea0000, 0xffff0000, 0x22, FMT_D9, AM33, {MEMINC2 (RM0, IMM32_HIGH8), RN2}},
299{ "movhu", 0xfefa0000, 0xffff0000, 0, FMT_D9, AM33, {RN2, MEMINC2 (RM0, IMM32_HIGH8)}},
David Howellsddb6d052008-11-12 15:35:30 +0000300
301{ "mov_llt", 0xf7e00000, 0xffff000f, 0x22, FMT_D10, AM33, {MEMINC2 (RN4,SIMM4_2), RM6}},
302{ "mov_lgt", 0xf7e00001, 0xffff000f, 0x22, FMT_D10, AM33, {MEMINC2 (RN4,SIMM4_2), RM6}},
303{ "mov_lge", 0xf7e00002, 0xffff000f, 0x22, FMT_D10, AM33, {MEMINC2 (RN4,SIMM4_2), RM6}},
304{ "mov_lle", 0xf7e00003, 0xffff000f, 0x22, FMT_D10, AM33, {MEMINC2 (RN4,SIMM4_2), RM6}},
305{ "mov_lcs", 0xf7e00004, 0xffff000f, 0x22, FMT_D10, AM33, {MEMINC2 (RN4,SIMM4_2), RM6}},
306{ "mov_lhi", 0xf7e00005, 0xffff000f, 0x22, FMT_D10, AM33, {MEMINC2 (RN4,SIMM4_2), RM6}},
307{ "mov_lcc", 0xf7e00006, 0xffff000f, 0x22, FMT_D10, AM33, {MEMINC2 (RN4,SIMM4_2), RM6}},
308{ "mov_lls", 0xf7e00007, 0xffff000f, 0x22, FMT_D10, AM33, {MEMINC2 (RN4,SIMM4_2), RM6}},
309{ "mov_leq", 0xf7e00008, 0xffff000f, 0x22, FMT_D10, AM33, {MEMINC2 (RN4,SIMM4_2), RM6}},
310{ "mov_lne", 0xf7e00009, 0xffff000f, 0x22, FMT_D10, AM33, {MEMINC2 (RN4,SIMM4_2), RM6}},
311{ "mov_lra", 0xf7e0000a, 0xffff000f, 0x22, FMT_D10, AM33, {MEMINC2 (RN4,SIMM4_2), RM6}},
312
David Howellsb920de12008-02-08 04:19:31 -0800313{ 0, 0, 0, 0, 0, 0, {0}},
314};
315
316/*
317 * fix up misalignment problems where possible
318 */
319asmlinkage void misalignment(struct pt_regs *regs, enum exception_code code)
320{
321 const struct exception_table_entry *fixup;
322 const struct mn10300_opcode *pop;
323 unsigned long *registers = (unsigned long *) regs;
David Howellsb308bf32008-11-12 15:35:14 +0000324 unsigned long data, *store, *postinc, disp;
David Howellsb920de12008-02-08 04:19:31 -0800325 mm_segment_t seg;
326 siginfo_t info;
David Howellsb308bf32008-11-12 15:35:14 +0000327 uint32_t opcode, noc, xo, xm;
David Howellsb920de12008-02-08 04:19:31 -0800328 uint8_t *pc, byte;
329 void *address;
David Howellsb308bf32008-11-12 15:35:14 +0000330 unsigned tmp, npop, dispsz, loop;
David Howellsb920de12008-02-08 04:19:31 -0800331
David Howells31ea24b2008-11-12 15:34:59 +0000332 kdebug("==>misalignment({pc=%lx})", regs->pc);
David Howellsb920de12008-02-08 04:19:31 -0800333
David Howellsb920de12008-02-08 04:19:31 -0800334 if (regs->epsw & EPSW_IE)
335 asm volatile("or %0,epsw" : : "i"(EPSW_IE));
336
337 seg = get_fs();
338 set_fs(KERNEL_DS);
339
340 fixup = search_exception_tables(regs->pc);
341
342 /* first thing to do is to match the opcode */
343 pc = (u_int8_t *) regs->pc;
344
345 if (__get_user(byte, pc) != 0)
346 goto fetch_error;
347 opcode = byte;
348 noc = 8;
349
350 for (pop = mn10300_opcodes; pop->name; pop++) {
David Howells31ea24b2008-11-12 15:34:59 +0000351 npop = ilog2(pop->opcode | pop->opmask);
David Howellsb920de12008-02-08 04:19:31 -0800352 if (npop <= 0 || npop > 31)
353 continue;
354 npop = (npop + 8) & ~7;
355
356 got_more_bits:
357 if (npop == noc) {
358 if ((opcode & pop->opmask) == pop->opcode)
359 goto found_opcode;
360 } else if (npop > noc) {
361 xo = pop->opcode >> (npop - noc);
362 xm = pop->opmask >> (npop - noc);
363
364 if ((opcode & xm) != xo)
365 continue;
366
367 /* we've got a partial match (an exact match on the
368 * first N bytes), so we need to get some more data */
369 pc++;
370 if (__get_user(byte, pc) != 0)
371 goto fetch_error;
372 opcode = opcode << 8 | byte;
373 noc += 8;
374 goto got_more_bits;
375 } else {
376 /* there's already been a partial match as long as the
377 * complete match we're now considering, so this one
378 * should't match */
379 continue;
380 }
381 }
382
383 /* didn't manage to find a fixup */
384 if (!user_mode(regs))
385 printk(KERN_CRIT "MISALIGN: %lx: unsupported instruction %x\n",
386 regs->pc, opcode);
387
388failed:
389 set_fs(seg);
390 if (die_if_no_fixup("misalignment error", regs, code))
391 return;
392
393 info.si_signo = SIGBUS;
394 info.si_errno = 0;
395 info.si_code = BUS_ADRALN;
396 info.si_addr = (void *) regs->pc;
397 force_sig_info(SIGBUS, &info, current);
398 return;
399
400 /* error reading opcodes */
401fetch_error:
402 if (!user_mode(regs))
403 printk(KERN_CRIT
404 "MISALIGN: %p: fault whilst reading instruction data\n",
405 pc);
406 goto failed;
407
408bad_addr_mode:
409 if (!user_mode(regs))
410 printk(KERN_CRIT
411 "MISALIGN: %lx: unsupported addressing mode %x\n",
412 regs->pc, opcode);
413 goto failed;
414
415bad_reg_mode:
416 if (!user_mode(regs))
417 printk(KERN_CRIT
418 "MISALIGN: %lx: unsupported register mode %x\n",
419 regs->pc, opcode);
420 goto failed;
421
422unsupported_instruction:
423 if (!user_mode(regs))
424 printk(KERN_CRIT
425 "MISALIGN: %lx: unsupported instruction %x (%s)\n",
426 regs->pc, opcode, pop->name);
427 goto failed;
428
429transfer_failed:
430 set_fs(seg);
431 if (fixup) {
432 regs->pc = fixup->fixup;
433 return;
434 }
435 if (die_if_no_fixup("misalignment fixup", regs, code))
436 return;
437
438 info.si_signo = SIGSEGV;
439 info.si_errno = 0;
440 info.si_code = 0;
441 info.si_addr = (void *) regs->pc;
442 force_sig_info(SIGSEGV, &info, current);
443 return;
444
445 /* we matched the opcode */
446found_opcode:
David Howells31ea24b2008-11-12 15:34:59 +0000447 kdebug("%lx: %x==%x { %x, %x }",
David Howellsb920de12008-02-08 04:19:31 -0800448 regs->pc, opcode, pop->opcode, pop->params[0], pop->params[1]);
449
450 tmp = format_tbl[pop->format].opsz;
451 if (tmp > noc)
452 BUG(); /* match was less complete than it ought to have been */
453
454 if (tmp < noc) {
455 tmp = noc - tmp;
456 opcode >>= tmp;
457 pc -= tmp >> 3;
458 }
459
460 /* grab the extra displacement (note it's LSB first) */
461 disp = 0;
David Howellsb308bf32008-11-12 15:35:14 +0000462 dispsz = format_tbl[pop->format].dispsz;
463 for (loop = 0; loop < dispsz; loop += 8) {
David Howellsb920de12008-02-08 04:19:31 -0800464 pc++;
465 if (__get_user(byte, pc) != 0)
466 goto fetch_error;
David Howellsb308bf32008-11-12 15:35:14 +0000467 disp |= byte << loop;
468 kdebug("{%p} disp[%02x]=%02x", pc, loop, byte);
David Howellsb920de12008-02-08 04:19:31 -0800469 }
470
David Howellsb308bf32008-11-12 15:35:14 +0000471 kdebug("disp=%lx", disp);
472
David Howellsb920de12008-02-08 04:19:31 -0800473 set_fs(KERNEL_XDS);
474 if (fixup || regs->epsw & EPSW_nSL)
475 set_fs(seg);
476
477 tmp = (pop->params[0] ^ pop->params[1]) & 0x80000000;
478 if (!tmp) {
479 if (!user_mode(regs))
480 printk(KERN_CRIT
481 "MISALIGN: %lx:"
482 " insn not move to/from memory %x\n",
483 regs->pc, opcode);
484 goto failed;
485 }
486
487 if (pop->params[0] & 0x80000000) {
488 /* move memory to register */
489 if (!misalignment_addr(registers, pop->params[0], opcode, disp,
490 &address, &postinc))
491 goto bad_addr_mode;
492
493 if (!misalignment_reg(registers, pop->params[1], opcode, disp,
494 &store))
495 goto bad_reg_mode;
496
David Howellsddb6d052008-11-12 15:35:30 +0000497 if (strcmp(pop->name, "mov") == 0 ||
498 memcmp(pop->name, "mov_l", 5) == 0) {
David Howells31ea24b2008-11-12 15:34:59 +0000499 kdebug("mov (%p),DARn", address);
David Howellsb920de12008-02-08 04:19:31 -0800500 if (copy_from_user(&data, (void *) address, 4) != 0)
501 goto transfer_failed;
502 if (pop->params[0] & 0x1000000)
503 *postinc += 4;
504 } else if (strcmp(pop->name, "movhu") == 0) {
David Howells31ea24b2008-11-12 15:34:59 +0000505 kdebug("movhu (%p),DARn", address);
David Howellsb920de12008-02-08 04:19:31 -0800506 data = 0;
507 if (copy_from_user(&data, (void *) address, 2) != 0)
508 goto transfer_failed;
509 if (pop->params[0] & 0x1000000)
510 *postinc += 2;
511 } else {
512 goto unsupported_instruction;
513 }
514
515 *store = data;
David Howellsddb6d052008-11-12 15:35:30 +0000516 kdebug("loaded %lx", data);
David Howellsb920de12008-02-08 04:19:31 -0800517 } else {
518 /* move register to memory */
519 if (!misalignment_reg(registers, pop->params[0], opcode, disp,
520 &store))
521 goto bad_reg_mode;
522
523 if (!misalignment_addr(registers, pop->params[1], opcode, disp,
524 &address, &postinc))
525 goto bad_addr_mode;
526
527 data = *store;
528
529 if (strcmp(pop->name, "mov") == 0) {
David Howells31ea24b2008-11-12 15:34:59 +0000530 kdebug("mov %lx,(%p)", data, address);
David Howellsb920de12008-02-08 04:19:31 -0800531 if (copy_to_user((void *) address, &data, 4) != 0)
532 goto transfer_failed;
533 if (pop->params[1] & 0x1000000)
534 *postinc += 4;
535 } else if (strcmp(pop->name, "movhu") == 0) {
David Howells31ea24b2008-11-12 15:34:59 +0000536 kdebug("movhu %hx,(%p)", (uint16_t) data, address);
David Howellsb920de12008-02-08 04:19:31 -0800537 if (copy_to_user((void *) address, &data, 2) != 0)
538 goto transfer_failed;
539 if (pop->params[1] & 0x1000000)
540 *postinc += 2;
541 } else {
542 goto unsupported_instruction;
543 }
544 }
545
546 tmp = format_tbl[pop->format].opsz + format_tbl[pop->format].dispsz;
547 regs->pc += tmp >> 3;
548
David Howellsddb6d052008-11-12 15:35:30 +0000549 /* handle MOV_Lcc, which are currently the only FMT_D10 insns that
550 * access memory */
551 if (pop->format == FMT_D10)
552 misalignment_MOV_Lcc(regs, opcode);
553
David Howellsb920de12008-02-08 04:19:31 -0800554 set_fs(seg);
555 return;
556}
557
558/*
559 * determine the address that was being accessed
560 */
561static int misalignment_addr(unsigned long *registers, unsigned params,
David Howellsb308bf32008-11-12 15:35:14 +0000562 unsigned opcode, unsigned long disp,
David Howellsb920de12008-02-08 04:19:31 -0800563 void **_address, unsigned long **_postinc)
564{
565 unsigned long *postinc = NULL, address = 0, tmp;
566
David Howellsf911c682008-11-12 15:35:20 +0000567 params &= 0x00ffffff;
David Howellsb920de12008-02-08 04:19:31 -0800568
569 do {
570 switch (params & 0xff) {
571 case DM0:
572 postinc = &registers[Dreg_index[opcode & 0x03]];
573 address += *postinc;
574 break;
575 case DM1:
576 postinc = &registers[Dreg_index[opcode >> 2 & 0x0c]];
577 address += *postinc;
578 break;
579 case DM2:
580 postinc = &registers[Dreg_index[opcode >> 4 & 0x30]];
581 address += *postinc;
582 break;
583 case AM0:
584 postinc = &registers[Areg_index[opcode & 0x03]];
585 address += *postinc;
586 break;
587 case AM1:
588 postinc = &registers[Areg_index[opcode >> 2 & 0x0c]];
589 address += *postinc;
590 break;
591 case AM2:
592 postinc = &registers[Areg_index[opcode >> 4 & 0x30]];
593 address += *postinc;
594 break;
595 case RM0:
596 postinc = &registers[Rreg_index[opcode & 0x0f]];
597 address += *postinc;
598 break;
599 case RM1:
600 postinc = &registers[Rreg_index[opcode >> 2 & 0x0f]];
601 address += *postinc;
602 break;
603 case RM2:
604 postinc = &registers[Rreg_index[opcode >> 4 & 0x0f]];
605 address += *postinc;
606 break;
607 case RM4:
608 postinc = &registers[Rreg_index[opcode >> 8 & 0x0f]];
609 address += *postinc;
610 break;
611 case RM6:
612 postinc = &registers[Rreg_index[opcode >> 12 & 0x0f]];
613 address += *postinc;
614 break;
615 case RD0:
616 postinc = &registers[Rreg_index[disp & 0x0f]];
617 address += *postinc;
618 break;
619 case RD2:
620 postinc = &registers[Rreg_index[disp >> 4 & 0x0f]];
621 address += *postinc;
622 break;
David Howellsee6e7402008-11-12 15:35:09 +0000623 case SP:
624 address += registers[REG_SP >> 2];
625 break;
David Howellsb920de12008-02-08 04:19:31 -0800626
627 case SD8:
628 case SIMM8:
629 address += (int32_t) (int8_t) (disp & 0xff);
630 break;
631 case SD16:
632 address += (int32_t) (int16_t) (disp & 0xffff);
633 break;
634 case SD24:
635 tmp = disp << 8;
636 asm("asr 8,%0" : "=r"(tmp) : "0"(tmp));
637 address += tmp;
638 break;
639 case SIMM4_2:
640 tmp = opcode >> 4 & 0x0f;
641 tmp <<= 28;
642 asm("asr 28,%0" : "=r"(tmp) : "0"(tmp));
643 address += tmp;
644 break;
645 case IMM24:
646 address += disp & 0x00ffffff;
647 break;
648 case IMM32:
David Howellsee6e7402008-11-12 15:35:09 +0000649 case IMM32_MEM:
David Howellsb920de12008-02-08 04:19:31 -0800650 case IMM32_HIGH8:
David Howellsee6e7402008-11-12 15:35:09 +0000651 case IMM32_HIGH8_MEM:
David Howellsb920de12008-02-08 04:19:31 -0800652 address += disp;
653 break;
654 default:
David Howellsf911c682008-11-12 15:35:20 +0000655 BUG();
David Howellsb920de12008-02-08 04:19:31 -0800656 return 0;
657 }
658 } while ((params >>= 8));
659
660 *_address = (void *) address;
661 *_postinc = postinc;
662 return 1;
663}
664
665/*
666 * determine the register that is acting as source/dest
667 */
668static int misalignment_reg(unsigned long *registers, unsigned params,
David Howellsb308bf32008-11-12 15:35:14 +0000669 unsigned opcode, unsigned long disp,
David Howellsb920de12008-02-08 04:19:31 -0800670 unsigned long **_register)
671{
672 params &= 0x7fffffff;
673
674 if (params & 0xffffff00)
675 return 0;
676
677 switch (params & 0xff) {
678 case DM0:
679 *_register = &registers[Dreg_index[opcode & 0x03]];
680 break;
681 case DM1:
682 *_register = &registers[Dreg_index[opcode >> 2 & 0x03]];
683 break;
684 case DM2:
685 *_register = &registers[Dreg_index[opcode >> 4 & 0x03]];
686 break;
687 case AM0:
688 *_register = &registers[Areg_index[opcode & 0x03]];
689 break;
690 case AM1:
691 *_register = &registers[Areg_index[opcode >> 2 & 0x03]];
692 break;
693 case AM2:
694 *_register = &registers[Areg_index[opcode >> 4 & 0x03]];
695 break;
696 case RM0:
697 *_register = &registers[Rreg_index[opcode & 0x0f]];
698 break;
699 case RM1:
700 *_register = &registers[Rreg_index[opcode >> 2 & 0x0f]];
701 break;
702 case RM2:
703 *_register = &registers[Rreg_index[opcode >> 4 & 0x0f]];
704 break;
705 case RM4:
706 *_register = &registers[Rreg_index[opcode >> 8 & 0x0f]];
707 break;
708 case RM6:
709 *_register = &registers[Rreg_index[opcode >> 12 & 0x0f]];
710 break;
711 case RD0:
712 *_register = &registers[Rreg_index[disp & 0x0f]];
713 break;
714 case RD2:
715 *_register = &registers[Rreg_index[disp >> 4 & 0x0f]];
716 break;
717 case SP:
718 *_register = &registers[REG_SP >> 2];
719 break;
720
721 default:
David Howellsf911c682008-11-12 15:35:20 +0000722 BUG();
David Howellsb920de12008-02-08 04:19:31 -0800723 return 0;
724 }
725
726 return 1;
727}
David Howells9f555882008-11-12 15:35:04 +0000728
729/*
David Howellsddb6d052008-11-12 15:35:30 +0000730 * handle the conditional loop part of the move-and-loop instructions
731 */
732static void misalignment_MOV_Lcc(struct pt_regs *regs, uint32_t opcode)
733{
734 unsigned long epsw = regs->epsw;
735 unsigned long NxorV;
736
737 kdebug("MOV_Lcc %x [flags=%lx]", opcode, epsw & 0xf);
738
739 /* calculate N^V and shift onto the same bit position as Z */
740 NxorV = ((epsw >> 3) ^ epsw >> 1) & 1;
741
742 switch (opcode & 0xf) {
743 case 0x0: /* MOV_LLT: N^V */
744 if (NxorV)
745 goto take_the_loop;
746 return;
747 case 0x1: /* MOV_LGT: ~(Z or (N^V))*/
748 if (!((epsw & EPSW_FLAG_Z) | NxorV))
749 goto take_the_loop;
750 return;
751 case 0x2: /* MOV_LGE: ~(N^V) */
752 if (!NxorV)
753 goto take_the_loop;
754 return;
755 case 0x3: /* MOV_LLE: Z or (N^V) */
756 if ((epsw & EPSW_FLAG_Z) | NxorV)
757 goto take_the_loop;
758 return;
759
760 case 0x4: /* MOV_LCS: C */
761 if (epsw & EPSW_FLAG_C)
762 goto take_the_loop;
763 return;
764 case 0x5: /* MOV_LHI: ~(C or Z) */
765 if (!(epsw & (EPSW_FLAG_C | EPSW_FLAG_Z)))
766 goto take_the_loop;
767 return;
768 case 0x6: /* MOV_LCC: ~C */
769 if (!(epsw & EPSW_FLAG_C))
770 goto take_the_loop;
771 return;
772 case 0x7: /* MOV_LLS: C or Z */
773 if (epsw & (EPSW_FLAG_C | EPSW_FLAG_Z))
774 goto take_the_loop;
775 return;
776
777 case 0x8: /* MOV_LEQ: Z */
778 if (epsw & EPSW_FLAG_Z)
779 goto take_the_loop;
780 return;
781 case 0x9: /* MOV_LNE: ~Z */
782 if (!(epsw & EPSW_FLAG_Z))
783 goto take_the_loop;
784 return;
785 case 0xa: /* MOV_LRA: always */
786 goto take_the_loop;
787
788 default:
789 BUG();
790 }
791
792take_the_loop:
793 /* wind the PC back to just after the SETLB insn */
794 kdebug("loop LAR=%lx", regs->lar);
795 regs->pc = regs->lar - 4;
796}
797
798/*
David Howells9f555882008-11-12 15:35:04 +0000799 * misalignment handler tests
800 */
801#ifdef CONFIG_TEST_MISALIGNMENT_HANDLER
802static u8 __initdata testbuf[512] __attribute__((aligned(16))) = {
803 [257] = 0x11,
804 [258] = 0x22,
805 [259] = 0x33,
806 [260] = 0x44,
807};
808
809#define ASSERTCMP(X, OP, Y) \
810do { \
811 if (unlikely(!((X) OP (Y)))) { \
812 printk(KERN_ERR "\n"); \
813 printk(KERN_ERR "MISALIGN: Assertion failed at line %u\n", \
814 __LINE__); \
815 printk(KERN_ERR "0x%lx " #OP " 0x%lx is false\n", \
816 (unsigned long)(X), (unsigned long)(Y)); \
817 BUG(); \
818 } \
819} while(0)
820
821static int __init test_misalignment(void)
822{
823 register void *r asm("e0");
824 register u32 y asm("e1");
825 void *p = testbuf, *q;
826 u32 tmp, tmp2, x;
827
828 printk(KERN_NOTICE "==>test_misalignment() [testbuf=%p]\n", p);
829 p++;
830
831 printk(KERN_NOTICE "___ MOV (Am),Dn ___\n");
832 q = p + 256;
833 asm volatile("mov (%0),%1" : "+a"(q), "=d"(x));
834 ASSERTCMP(q, ==, p + 256);
835 ASSERTCMP(x, ==, 0x44332211);
836
837 printk(KERN_NOTICE "___ MOV (256,Am),Dn ___\n");
838 q = p;
839 asm volatile("mov (256,%0),%1" : "+a"(q), "=d"(x));
840 ASSERTCMP(q, ==, p);
841 ASSERTCMP(x, ==, 0x44332211);
842
843 printk(KERN_NOTICE "___ MOV (Di,Am),Dn ___\n");
844 tmp = 256;
845 q = p;
846 asm volatile("mov (%2,%0),%1" : "+a"(q), "=d"(x), "+d"(tmp));
847 ASSERTCMP(q, ==, p);
848 ASSERTCMP(x, ==, 0x44332211);
849 ASSERTCMP(tmp, ==, 256);
850
851 printk(KERN_NOTICE "___ MOV (256,Rm),Rn ___\n");
852 r = p;
853 asm volatile("mov (256,%0),%1" : "+r"(r), "=r"(y));
854 ASSERTCMP(r, ==, p);
855 ASSERTCMP(y, ==, 0x44332211);
856
857 printk(KERN_NOTICE "___ MOV (Rm+),Rn ___\n");
858 r = p + 256;
859 asm volatile("mov (%0+),%1" : "+r"(r), "=r"(y));
860 ASSERTCMP(r, ==, p + 256 + 4);
861 ASSERTCMP(y, ==, 0x44332211);
862
863 printk(KERN_NOTICE "___ MOV (Rm+,8),Rn ___\n");
864 r = p + 256;
865 asm volatile("mov (%0+,8),%1" : "+r"(r), "=r"(y));
866 ASSERTCMP(r, ==, p + 256 + 8);
867 ASSERTCMP(y, ==, 0x44332211);
868
869 printk(KERN_NOTICE "___ MOV (7,SP),Rn ___\n");
870 asm volatile(
871 "add -16,sp \n"
872 "mov +0x11,%0 \n"
873 "movbu %0,(7,sp) \n"
874 "mov +0x22,%0 \n"
875 "movbu %0,(8,sp) \n"
876 "mov +0x33,%0 \n"
877 "movbu %0,(9,sp) \n"
878 "mov +0x44,%0 \n"
879 "movbu %0,(10,sp) \n"
880 "mov (7,sp),%1 \n"
881 "add +16,sp \n"
882 : "+a"(q), "=d"(x));
883 ASSERTCMP(x, ==, 0x44332211);
884
885 printk(KERN_NOTICE "___ MOV (259,SP),Rn ___\n");
886 asm volatile(
887 "add -264,sp \n"
888 "mov +0x11,%0 \n"
889 "movbu %0,(259,sp) \n"
890 "mov +0x22,%0 \n"
891 "movbu %0,(260,sp) \n"
892 "mov +0x33,%0 \n"
893 "movbu %0,(261,sp) \n"
894 "mov +0x55,%0 \n"
895 "movbu %0,(262,sp) \n"
896 "mov (259,sp),%1 \n"
897 "add +264,sp \n"
898 : "+d"(tmp), "=d"(x));
899 ASSERTCMP(x, ==, 0x55332211);
900
901 printk(KERN_NOTICE "___ MOV (260,SP),Rn ___\n");
902 asm volatile(
903 "add -264,sp \n"
904 "mov +0x11,%0 \n"
905 "movbu %0,(260,sp) \n"
906 "mov +0x22,%0 \n"
907 "movbu %0,(261,sp) \n"
908 "mov +0x33,%0 \n"
909 "movbu %0,(262,sp) \n"
910 "mov +0x55,%0 \n"
911 "movbu %0,(263,sp) \n"
912 "mov (260,sp),%1 \n"
913 "add +264,sp \n"
914 : "+d"(tmp), "=d"(x));
915 ASSERTCMP(x, ==, 0x55332211);
916
917
918 printk(KERN_NOTICE "___ MOV_LNE ___\n");
919 tmp = 1;
920 tmp2 = 2;
921 q = p + 256;
922 asm volatile(
923 "setlb \n"
924 "mov %2,%3 \n"
925 "mov %1,%2 \n"
926 "cmp +0,%1 \n"
927 "mov_lne (%0+,4),%1"
928 : "+r"(q), "+d"(tmp), "+d"(tmp2), "=d"(x)
929 :
930 : "cc");
931 ASSERTCMP(q, ==, p + 256 + 12);
932 ASSERTCMP(x, ==, 0x44332211);
933
934 printk(KERN_NOTICE "___ MOV in SETLB ___\n");
935 tmp = 1;
936 tmp2 = 2;
937 q = p + 256;
938 asm volatile(
939 "setlb \n"
940 "mov %1,%3 \n"
941 "mov (%0+),%1 \n"
942 "cmp +0,%1 \n"
943 "lne "
944 : "+a"(q), "+d"(tmp), "+d"(tmp2), "=d"(x)
945 :
946 : "cc");
947
948 ASSERTCMP(q, ==, p + 256 + 8);
949 ASSERTCMP(x, ==, 0x44332211);
950
951 printk(KERN_NOTICE "<==test_misalignment()\n");
952 return 0;
953}
954
955arch_initcall(test_misalignment);
956
957#endif /* CONFIG_TEST_MISALIGNMENT_HANDLER */