1 /* MN10300 Misalignment fixup handler
3 * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com)
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.
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>
19 #include <linux/smp.h>
20 #include <linux/init.h>
21 #include <linux/delay.h>
22 #include <linux/spinlock.h>
23 #include <linux/interrupt.h>
24 #include <linux/pci.h>
25 #include <asm/processor.h>
26 #include <asm/system.h>
27 #include <asm/uaccess.h>
29 #include <asm/atomic.h>
31 #include <asm/pgalloc.h>
32 #include <asm/cpu-regs.h>
33 #include <asm/busctl-regs.h>
35 #include <asm/gdb-stub.h>
36 #include <asm/asm-offsets.h>
38 #define kdebug(FMT, ...) do {} while (0)
40 static int misalignment_addr(unsigned long *registers
, unsigned long sp
,
41 unsigned params
, unsigned opcode
,
43 void **_address
, unsigned long **_postinc
,
46 static int misalignment_reg(unsigned long *registers
, unsigned params
,
47 unsigned opcode
, unsigned long disp
,
48 unsigned long **_register
);
50 static void misalignment_MOV_Lcc(struct pt_regs
*regs
, uint32_t opcode
);
52 static const unsigned Dreg_index
[] = {
53 REG_D0
>> 2, REG_D1
>> 2, REG_D2
>> 2, REG_D3
>> 2
56 static const unsigned Areg_index
[] = {
57 REG_A0
>> 2, REG_A1
>> 2, REG_A2
>> 2, REG_A3
>> 2
60 static const unsigned Rreg_index
[] = {
61 REG_E0
>> 2, REG_E1
>> 2, REG_E2
>> 2, REG_E3
>> 2,
62 REG_E4
>> 2, REG_E5
>> 2, REG_E6
>> 2, REG_E7
>> 2,
63 REG_A0
>> 2, REG_A1
>> 2, REG_A2
>> 2, REG_A3
>> 2,
64 REG_D0
>> 2, REG_D1
>> 2, REG_D2
>> 2, REG_D3
>> 2
84 u_int8_t opsz
, dispsz
;
92 [FMT_D2
] = { 16, 16 },
93 [FMT_D4
] = { 16, 32 },
96 [FMT_D8
] = { 24, 24 },
97 [FMT_D9
] = { 24, 32 },
98 [FMT_D10
] = { 32, 0 },
102 DM0
, /* data reg in opcode in bits 0-1 */
103 DM1
, /* data reg in opcode in bits 2-3 */
104 DM2
, /* data reg in opcode in bits 4-5 */
105 AM0
, /* addr reg in opcode in bits 0-1 */
106 AM1
, /* addr reg in opcode in bits 2-3 */
107 AM2
, /* addr reg in opcode in bits 4-5 */
108 RM0
, /* reg in opcode in bits 0-3 */
109 RM1
, /* reg in opcode in bits 2-5 */
110 RM2
, /* reg in opcode in bits 4-7 */
111 RM4
, /* reg in opcode in bits 8-11 */
112 RM6
, /* reg in opcode in bits 12-15 */
114 RD0
, /* reg in displacement in bits 0-3 */
115 RD2
, /* reg in displacement in bits 4-7 */
117 SP
, /* stack pointer */
119 SD8
, /* 8-bit signed displacement */
120 SD16
, /* 16-bit signed displacement */
121 SD24
, /* 24-bit signed displacement */
122 SIMM4_2
, /* 4-bit signed displacement in opcode bits 4-7 */
123 SIMM8
, /* 8-bit signed immediate */
124 IMM8
, /* 8-bit unsigned immediate */
125 IMM16
, /* 16-bit unsigned immediate */
126 IMM24
, /* 24-bit unsigned immediate */
127 IMM32
, /* 32-bit unsigned immediate */
128 IMM32_HIGH8
, /* 32-bit unsigned immediate, LSB in opcode */
130 IMM32_MEM
, /* 32-bit unsigned displacement */
131 IMM32_HIGH8_MEM
, /* 32-bit unsigned displacement, LSB in opcode */
149 struct mn10300_opcode
{
155 enum format_id format
;
161 #define MEM(ADDR) (0x80000000 | (ADDR))
162 #define MEM2(ADDR1, ADDR2) (0x80000000 | (ADDR1) << 8 | (ADDR2))
163 #define MEMINC(ADDR) (0x81000000 | (ADDR))
164 #define MEMINC2(ADDR, INC) (0x81000000 | (ADDR) << 8 | (INC))
167 /* LIBOPCODES EXCERPT
168 Assemble Matsushita MN10300 instructions.
169 Copyright 1996, 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
171 This program is free software; you can redistribute it and/or modify
172 it under the terms of the GNU General Public Licence as published by
173 the Free Software Foundation; either version 2 of the Licence, or
174 (at your option) any later version.
176 This program is distributed in the hope that it will be useful,
177 but WITHOUT ANY WARRANTY; without even the implied warranty of
178 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
179 GNU General Public Licence for more details.
181 You should have received a copy of the GNU General Public Licence
182 along with this program; if not, write to the Free Software
183 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
185 static const struct mn10300_opcode mn10300_opcodes
[] = {
186 { "mov", 0x4200, 0xf300, 0, FMT_S1
, 0, {DM1
, MEM2(IMM8
, SP
)}},
187 { "mov", 0x4300, 0xf300, 0, FMT_S1
, 0, {AM1
, MEM2(IMM8
, SP
)}},
188 { "mov", 0x5800, 0xfc00, 0, FMT_S1
, 0, {MEM2(IMM8
, SP
), DN0
}},
189 { "mov", 0x5c00, 0xfc00, 0, FMT_S1
, 0, {MEM2(IMM8
, SP
), AN0
}},
190 { "mov", 0x60, 0xf0, 0, FMT_S0
, 0, {DM1
, MEM(AN0
)}},
191 { "mov", 0x70, 0xf0, 0, FMT_S0
, 0, {MEM(AM0
), DN1
}},
192 { "mov", 0xf000, 0xfff0, 0, FMT_D0
, 0, {MEM(AM0
), AN1
}},
193 { "mov", 0xf010, 0xfff0, 0, FMT_D0
, 0, {AM1
, MEM(AN0
)}},
194 { "mov", 0xf300, 0xffc0, 0, FMT_D0
, 0, {MEM2(DI
, AM0
), DN2
}},
195 { "mov", 0xf340, 0xffc0, 0, FMT_D0
, 0, {DM2
, MEM2(DI
, AN0
)}},
196 { "mov", 0xf380, 0xffc0, 0, FMT_D0
, 0, {MEM2(DI
, AM0
), AN2
}},
197 { "mov", 0xf3c0, 0xffc0, 0, FMT_D0
, 0, {AM2
, MEM2(DI
, AN0
)}},
198 { "mov", 0xf80000, 0xfff000, 0, FMT_D1
, 0, {MEM2(SD8
, AM0
), DN1
}},
199 { "mov", 0xf81000, 0xfff000, 0, FMT_D1
, 0, {DM1
, MEM2(SD8
, AN0
)}},
200 { "mov", 0xf82000, 0xfff000, 0, FMT_D1
, 0, {MEM2(SD8
,AM0
), AN1
}},
201 { "mov", 0xf83000, 0xfff000, 0, FMT_D1
, 0, {AM1
, MEM2(SD8
, AN0
)}},
202 { "mov", 0xf90a00, 0xffff00, 0, FMT_D6
, AM33
, {MEM(RM0
), RN2
}},
203 { "mov", 0xf91a00, 0xffff00, 0, FMT_D6
, AM33
, {RM2
, MEM(RN0
)}},
204 { "mov", 0xf96a00, 0xffff00, 0x12, FMT_D6
, AM33
, {MEMINC(RM0
), RN2
}},
205 { "mov", 0xf97a00, 0xffff00, 0, FMT_D6
, AM33
, {RM2
, MEMINC(RN0
)}},
206 { "mov", 0xfa000000, 0xfff00000, 0, FMT_D2
, 0, {MEM2(SD16
, AM0
), DN1
}},
207 { "mov", 0xfa100000, 0xfff00000, 0, FMT_D2
, 0, {DM1
, MEM2(SD16
, AN0
)}},
208 { "mov", 0xfa200000, 0xfff00000, 0, FMT_D2
, 0, {MEM2(SD16
, AM0
), AN1
}},
209 { "mov", 0xfa300000, 0xfff00000, 0, FMT_D2
, 0, {AM1
, MEM2(SD16
, AN0
)}},
210 { "mov", 0xfa900000, 0xfff30000, 0, FMT_D2
, 0, {AM1
, MEM2(IMM16
, SP
)}},
211 { "mov", 0xfa910000, 0xfff30000, 0, FMT_D2
, 0, {DM1
, MEM2(IMM16
, SP
)}},
212 { "mov", 0xfab00000, 0xfffc0000, 0, FMT_D2
, 0, {MEM2(IMM16
, SP
), AN0
}},
213 { "mov", 0xfab40000, 0xfffc0000, 0, FMT_D2
, 0, {MEM2(IMM16
, SP
), DN0
}},
214 { "mov", 0xfb0a0000, 0xffff0000, 0, FMT_D7
, AM33
, {MEM2(SD8
, RM0
), RN2
}},
215 { "mov", 0xfb1a0000, 0xffff0000, 0, FMT_D7
, AM33
, {RM2
, MEM2(SD8
, RN0
)}},
216 { "mov", 0xfb6a0000, 0xffff0000, 0x22, FMT_D7
, AM33
, {MEMINC2 (RM0
, SIMM8
), RN2
}},
217 { "mov", 0xfb7a0000, 0xffff0000, 0, FMT_D7
, AM33
, {RM2
, MEMINC2 (RN0
, SIMM8
)}},
218 { "mov", 0xfb8a0000, 0xffff0f00, 0, FMT_D7
, AM33
, {MEM2(IMM8
, SP
), RN2
}},
219 { "mov", 0xfb8e0000, 0xffff000f, 0, FMT_D7
, AM33
, {MEM2(RI
, RM0
), RD2
}},
220 { "mov", 0xfb9a0000, 0xffff0f00, 0, FMT_D7
, AM33
, {RM2
, MEM2(IMM8
, SP
)}},
221 { "mov", 0xfb9e0000, 0xffff000f, 0, FMT_D7
, AM33
, {RD2
, MEM2(RI
, RN0
)}},
222 { "mov", 0xfc000000, 0xfff00000, 0, FMT_D4
, 0, {MEM2(IMM32
,AM0
), DN1
}},
223 { "mov", 0xfc100000, 0xfff00000, 0, FMT_D4
, 0, {DM1
, MEM2(IMM32
,AN0
)}},
224 { "mov", 0xfc200000, 0xfff00000, 0, FMT_D4
, 0, {MEM2(IMM32
,AM0
), AN1
}},
225 { "mov", 0xfc300000, 0xfff00000, 0, FMT_D4
, 0, {AM1
, MEM2(IMM32
,AN0
)}},
226 { "mov", 0xfc800000, 0xfff30000, 0, FMT_D4
, 0, {AM1
, MEM(IMM32_MEM
)}},
227 { "mov", 0xfc810000, 0xfff30000, 0, FMT_D4
, 0, {DM1
, MEM(IMM32_MEM
)}},
228 { "mov", 0xfc900000, 0xfff30000, 0, FMT_D4
, 0, {AM1
, MEM2(IMM32
, SP
)}},
229 { "mov", 0xfc910000, 0xfff30000, 0, FMT_D4
, 0, {DM1
, MEM2(IMM32
, SP
)}},
230 { "mov", 0xfca00000, 0xfffc0000, 0, FMT_D4
, 0, {MEM(IMM32_MEM
), AN0
}},
231 { "mov", 0xfca40000, 0xfffc0000, 0, FMT_D4
, 0, {MEM(IMM32_MEM
), DN0
}},
232 { "mov", 0xfcb00000, 0xfffc0000, 0, FMT_D4
, 0, {MEM2(IMM32
, SP
), AN0
}},
233 { "mov", 0xfcb40000, 0xfffc0000, 0, FMT_D4
, 0, {MEM2(IMM32
, SP
), DN0
}},
234 { "mov", 0xfd0a0000, 0xffff0000, 0, FMT_D8
, AM33
, {MEM2(SD24
, RM0
), RN2
}},
235 { "mov", 0xfd1a0000, 0xffff0000, 0, FMT_D8
, AM33
, {RM2
, MEM2(SD24
, RN0
)}},
236 { "mov", 0xfd6a0000, 0xffff0000, 0x22, FMT_D8
, AM33
, {MEMINC2 (RM0
, IMM24
), RN2
}},
237 { "mov", 0xfd7a0000, 0xffff0000, 0, FMT_D8
, AM33
, {RM2
, MEMINC2 (RN0
, IMM24
)}},
238 { "mov", 0xfd8a0000, 0xffff0f00, 0, FMT_D8
, AM33
, {MEM2(IMM24
, SP
), RN2
}},
239 { "mov", 0xfd9a0000, 0xffff0f00, 0, FMT_D8
, AM33
, {RM2
, MEM2(IMM24
, SP
)}},
240 { "mov", 0xfe0a0000, 0xffff0000, 0, FMT_D9
, AM33
, {MEM2(IMM32_HIGH8
,RM0
), RN2
}},
241 { "mov", 0xfe0a0000, 0xffff0000, 0, FMT_D9
, AM33
, {MEM2(IMM32_HIGH8
,RM0
), RN2
}},
242 { "mov", 0xfe0e0000, 0xffff0f00, 0, FMT_D9
, AM33
, {MEM(IMM32_HIGH8_MEM
), RN2
}},
243 { "mov", 0xfe1a0000, 0xffff0000, 0, FMT_D9
, AM33
, {RM2
, MEM2(IMM32_HIGH8
, RN0
)}},
244 { "mov", 0xfe1a0000, 0xffff0000, 0, FMT_D9
, AM33
, {RM2
, MEM2(IMM32_HIGH8
, RN0
)}},
245 { "mov", 0xfe1e0000, 0xffff0f00, 0, FMT_D9
, AM33
, {RM2
, MEM(IMM32_HIGH8_MEM
)}},
246 { "mov", 0xfe6a0000, 0xffff0000, 0x22, FMT_D9
, AM33
, {MEMINC2 (RM0
, IMM32_HIGH8
), RN2
}},
247 { "mov", 0xfe7a0000, 0xffff0000, 0, FMT_D9
, AM33
, {RN2
, MEMINC2 (RM0
, IMM32_HIGH8
)}},
248 { "mov", 0xfe8a0000, 0xffff0f00, 0, FMT_D9
, AM33
, {MEM2(IMM32_HIGH8
, SP
), RN2
}},
249 { "mov", 0xfe9a0000, 0xffff0f00, 0, FMT_D9
, AM33
, {RM2
, MEM2(IMM32_HIGH8
, SP
)}},
251 { "movhu", 0xf060, 0xfff0, 0, FMT_D0
, 0, {MEM(AM0
), DN1
}},
252 { "movhu", 0xf070, 0xfff0, 0, FMT_D0
, 0, {DM1
, MEM(AN0
)}},
253 { "movhu", 0xf480, 0xffc0, 0, FMT_D0
, 0, {MEM2(DI
, AM0
), DN2
}},
254 { "movhu", 0xf4c0, 0xffc0, 0, FMT_D0
, 0, {DM2
, MEM2(DI
, AN0
)}},
255 { "movhu", 0xf86000, 0xfff000, 0, FMT_D1
, 0, {MEM2(SD8
, AM0
), DN1
}},
256 { "movhu", 0xf87000, 0xfff000, 0, FMT_D1
, 0, {DM1
, MEM2(SD8
, AN0
)}},
257 { "movhu", 0xf89300, 0xfff300, 0, FMT_D1
, 0, {DM1
, MEM2(IMM8
, SP
)}},
258 { "movhu", 0xf8bc00, 0xfffc00, 0, FMT_D1
, 0, {MEM2(IMM8
, SP
), DN0
}},
259 { "movhu", 0xf94a00, 0xffff00, 0, FMT_D6
, AM33
, {MEM(RM0
), RN2
}},
260 { "movhu", 0xf95a00, 0xffff00, 0, FMT_D6
, AM33
, {RM2
, MEM(RN0
)}},
261 { "movhu", 0xf9ea00, 0xffff00, 0x12, FMT_D6
, AM33
, {MEMINC(RM0
), RN2
}},
262 { "movhu", 0xf9fa00, 0xffff00, 0, FMT_D6
, AM33
, {RM2
, MEMINC(RN0
)}},
263 { "movhu", 0xfa600000, 0xfff00000, 0, FMT_D2
, 0, {MEM2(SD16
, AM0
), DN1
}},
264 { "movhu", 0xfa700000, 0xfff00000, 0, FMT_D2
, 0, {DM1
, MEM2(SD16
, AN0
)}},
265 { "movhu", 0xfa930000, 0xfff30000, 0, FMT_D2
, 0, {DM1
, MEM2(IMM16
, SP
)}},
266 { "movhu", 0xfabc0000, 0xfffc0000, 0, FMT_D2
, 0, {MEM2(IMM16
, SP
), DN0
}},
267 { "movhu", 0xfb4a0000, 0xffff0000, 0, FMT_D7
, AM33
, {MEM2(SD8
, RM0
), RN2
}},
268 { "movhu", 0xfb5a0000, 0xffff0000, 0, FMT_D7
, AM33
, {RM2
, MEM2(SD8
, RN0
)}},
269 { "movhu", 0xfbca0000, 0xffff0f00, 0, FMT_D7
, AM33
, {MEM2(IMM8
, SP
), RN2
}},
270 { "movhu", 0xfbce0000, 0xffff000f, 0, FMT_D7
, AM33
, {MEM2(RI
, RM0
), RD2
}},
271 { "movhu", 0xfbda0000, 0xffff0f00, 0, FMT_D7
, AM33
, {RM2
, MEM2(IMM8
, SP
)}},
272 { "movhu", 0xfbde0000, 0xffff000f, 0, FMT_D7
, AM33
, {RD2
, MEM2(RI
, RN0
)}},
273 { "movhu", 0xfbea0000, 0xffff0000, 0x22, FMT_D7
, AM33
, {MEMINC2 (RM0
, SIMM8
), RN2
}},
274 { "movhu", 0xfbfa0000, 0xffff0000, 0, FMT_D7
, AM33
, {RM2
, MEMINC2 (RN0
, SIMM8
)}},
275 { "movhu", 0xfc600000, 0xfff00000, 0, FMT_D4
, 0, {MEM2(IMM32
,AM0
), DN1
}},
276 { "movhu", 0xfc700000, 0xfff00000, 0, FMT_D4
, 0, {DM1
, MEM2(IMM32
,AN0
)}},
277 { "movhu", 0xfc830000, 0xfff30000, 0, FMT_D4
, 0, {DM1
, MEM(IMM32_MEM
)}},
278 { "movhu", 0xfc930000, 0xfff30000, 0, FMT_D4
, 0, {DM1
, MEM2(IMM32
, SP
)}},
279 { "movhu", 0xfcac0000, 0xfffc0000, 0, FMT_D4
, 0, {MEM(IMM32_MEM
), DN0
}},
280 { "movhu", 0xfcbc0000, 0xfffc0000, 0, FMT_D4
, 0, {MEM2(IMM32
, SP
), DN0
}},
281 { "movhu", 0xfd4a0000, 0xffff0000, 0, FMT_D8
, AM33
, {MEM2(SD24
, RM0
), RN2
}},
282 { "movhu", 0xfd5a0000, 0xffff0000, 0, FMT_D8
, AM33
, {RM2
, MEM2(SD24
, RN0
)}},
283 { "movhu", 0xfdca0000, 0xffff0f00, 0, FMT_D8
, AM33
, {MEM2(IMM24
, SP
), RN2
}},
284 { "movhu", 0xfdda0000, 0xffff0f00, 0, FMT_D8
, AM33
, {RM2
, MEM2(IMM24
, SP
)}},
285 { "movhu", 0xfdea0000, 0xffff0000, 0x22, FMT_D8
, AM33
, {MEMINC2 (RM0
, IMM24
), RN2
}},
286 { "movhu", 0xfdfa0000, 0xffff0000, 0, FMT_D8
, AM33
, {RM2
, MEMINC2 (RN0
, IMM24
)}},
287 { "movhu", 0xfe4a0000, 0xffff0000, 0, FMT_D9
, AM33
, {MEM2(IMM32_HIGH8
,RM0
), RN2
}},
288 { "movhu", 0xfe4e0000, 0xffff0f00, 0, FMT_D9
, AM33
, {MEM(IMM32_HIGH8_MEM
), RN2
}},
289 { "movhu", 0xfe5a0000, 0xffff0000, 0, FMT_D9
, AM33
, {RM2
, MEM2(IMM32_HIGH8
, RN0
)}},
290 { "movhu", 0xfe5e0000, 0xffff0f00, 0, FMT_D9
, AM33
, {RM2
, MEM(IMM32_HIGH8_MEM
)}},
291 { "movhu", 0xfeca0000, 0xffff0f00, 0, FMT_D9
, AM33
, {MEM2(IMM32_HIGH8
, SP
), RN2
}},
292 { "movhu", 0xfeda0000, 0xffff0f00, 0, FMT_D9
, AM33
, {RM2
, MEM2(IMM32_HIGH8
, SP
)}},
293 { "movhu", 0xfeea0000, 0xffff0000, 0x22, FMT_D9
, AM33
, {MEMINC2 (RM0
, IMM32_HIGH8
), RN2
}},
294 { "movhu", 0xfefa0000, 0xffff0000, 0, FMT_D9
, AM33
, {RN2
, MEMINC2 (RM0
, IMM32_HIGH8
)}},
296 { "mov_llt", 0xf7e00000, 0xffff000f, 0x22, FMT_D10
, AM33
, {MEMINC2 (RN4
,SIMM4_2
), RM6
}},
297 { "mov_lgt", 0xf7e00001, 0xffff000f, 0x22, FMT_D10
, AM33
, {MEMINC2 (RN4
,SIMM4_2
), RM6
}},
298 { "mov_lge", 0xf7e00002, 0xffff000f, 0x22, FMT_D10
, AM33
, {MEMINC2 (RN4
,SIMM4_2
), RM6
}},
299 { "mov_lle", 0xf7e00003, 0xffff000f, 0x22, FMT_D10
, AM33
, {MEMINC2 (RN4
,SIMM4_2
), RM6
}},
300 { "mov_lcs", 0xf7e00004, 0xffff000f, 0x22, FMT_D10
, AM33
, {MEMINC2 (RN4
,SIMM4_2
), RM6
}},
301 { "mov_lhi", 0xf7e00005, 0xffff000f, 0x22, FMT_D10
, AM33
, {MEMINC2 (RN4
,SIMM4_2
), RM6
}},
302 { "mov_lcc", 0xf7e00006, 0xffff000f, 0x22, FMT_D10
, AM33
, {MEMINC2 (RN4
,SIMM4_2
), RM6
}},
303 { "mov_lls", 0xf7e00007, 0xffff000f, 0x22, FMT_D10
, AM33
, {MEMINC2 (RN4
,SIMM4_2
), RM6
}},
304 { "mov_leq", 0xf7e00008, 0xffff000f, 0x22, FMT_D10
, AM33
, {MEMINC2 (RN4
,SIMM4_2
), RM6
}},
305 { "mov_lne", 0xf7e00009, 0xffff000f, 0x22, FMT_D10
, AM33
, {MEMINC2 (RN4
,SIMM4_2
), RM6
}},
306 { "mov_lra", 0xf7e0000a, 0xffff000f, 0x22, FMT_D10
, AM33
, {MEMINC2 (RN4
,SIMM4_2
), RM6
}},
308 { "", 0, 0, 0, 0, 0, {0}},
312 * fix up misalignment problems where possible
314 asmlinkage
void misalignment(struct pt_regs
*regs
, enum exception_code code
)
316 const struct exception_table_entry
*fixup
;
317 const struct mn10300_opcode
*pop
;
318 unsigned long *registers
= (unsigned long *) regs
;
319 unsigned long data
, *store
, *postinc
, disp
, inc
, sp
;
322 uint32_t opcode
, noc
, xo
, xm
;
323 uint8_t *pc
, byte
, datasz
;
325 unsigned tmp
, npop
, dispsz
, loop
;
327 /* we don't fix up userspace misalignment faults */
331 sp
= (unsigned long) regs
+ sizeof(*regs
);
333 kdebug("==>misalignment({pc=%lx,sp=%lx})", regs
->pc
, sp
);
335 if (regs
->epsw
& EPSW_IE
)
336 asm volatile("or %0,epsw" : : "i"(EPSW_IE
));
341 fixup
= search_exception_tables(regs
->pc
);
343 /* first thing to do is to match the opcode */
344 pc
= (u_int8_t
*) regs
->pc
;
346 if (__get_user(byte
, pc
) != 0)
351 for (pop
= mn10300_opcodes
; pop
->name
[0]; pop
++) {
352 npop
= ilog2(pop
->opcode
| pop
->opmask
);
353 if (npop
<= 0 || npop
> 31)
355 npop
= (npop
+ 8) & ~7;
359 if ((opcode
& pop
->opmask
) == pop
->opcode
)
361 } else if (npop
> noc
) {
362 xo
= pop
->opcode
>> (npop
- noc
);
363 xm
= pop
->opmask
>> (npop
- noc
);
365 if ((opcode
& xm
) != xo
)
368 /* we've got a partial match (an exact match on the
369 * first N bytes), so we need to get some more data */
371 if (__get_user(byte
, pc
) != 0)
373 opcode
= opcode
<< 8 | byte
;
377 /* there's already been a partial match as long as the
378 * complete match we're now considering, so this one
384 /* didn't manage to find a fixup */
385 printk(KERN_CRIT
"MISALIGN: %lx: unsupported instruction %x\n",
390 if (die_if_no_fixup("misalignment error", regs
, code
))
394 info
.si_signo
= SIGBUS
;
396 info
.si_code
= BUS_ADRALN
;
397 info
.si_addr
= (void *) regs
->pc
;
398 force_sig_info(SIGBUS
, &info
, current
);
401 /* error reading opcodes */
404 "MISALIGN: %p: fault whilst reading instruction data\n",
410 "MISALIGN: %lx: unsupported addressing mode %x\n",
416 "MISALIGN: %lx: unsupported register mode %x\n",
420 unsupported_instruction
:
422 "MISALIGN: %lx: unsupported instruction %x (%s)\n",
423 regs
->pc
, opcode
, pop
->name
);
429 regs
->pc
= fixup
->fixup
;
432 if (die_if_no_fixup("misalignment fixup", regs
, code
))
435 info
.si_signo
= SIGSEGV
;
438 info
.si_addr
= (void *) regs
->pc
;
439 force_sig_info(SIGSEGV
, &info
, current
);
442 /* we matched the opcode */
444 kdebug("%lx: %x==%x { %x, %x }",
445 regs
->pc
, opcode
, pop
->opcode
, pop
->params
[0], pop
->params
[1]);
447 tmp
= format_tbl
[pop
->format
].opsz
;
449 BUG(); /* match was less complete than it ought to have been */
457 /* grab the extra displacement (note it's LSB first) */
459 dispsz
= format_tbl
[pop
->format
].dispsz
;
460 for (loop
= 0; loop
< dispsz
; loop
+= 8) {
462 if (__get_user(byte
, pc
) != 0)
464 disp
|= byte
<< loop
;
465 kdebug("{%p} disp[%02x]=%02x", pc
, loop
, byte
);
468 kdebug("disp=%lx", disp
);
474 tmp
= (pop
->params
[0] ^ pop
->params
[1]) & 0x80000000;
477 "MISALIGN: %lx: insn not move to/from memory %x\n",
482 /* determine the data transfer size of the move */
483 if (pop
->name
[3] == 0 || /* "mov" */
484 pop
->name
[4] == 'l') /* mov_lcc */
486 else if (pop
->name
[3] == 'h') /* movhu */
489 goto unsupported_instruction
;
491 if (pop
->params
[0] & 0x80000000) {
492 /* move memory to register */
493 if (!misalignment_addr(registers
, sp
,
494 pop
->params
[0], opcode
, disp
,
495 &address
, &postinc
, &inc
))
498 if (!misalignment_reg(registers
, pop
->params
[1], opcode
, disp
,
502 kdebug("mov%u (%p),DARn", datasz
, address
);
503 if (copy_from_user(&data
, (void *) address
, datasz
) != 0)
504 goto transfer_failed
;
505 if (pop
->params
[0] & 0x1000000) {
506 kdebug("inc=%lx", inc
);
511 kdebug("loaded %lx", data
);
513 /* move register to memory */
514 if (!misalignment_reg(registers
, pop
->params
[0], opcode
, disp
,
518 if (!misalignment_addr(registers
, sp
,
519 pop
->params
[1], opcode
, disp
,
520 &address
, &postinc
, &inc
))
525 kdebug("mov%u %lx,(%p)", datasz
, data
, address
);
526 if (copy_to_user((void *) address
, &data
, datasz
) != 0)
527 goto transfer_failed
;
528 if (pop
->params
[1] & 0x1000000)
532 tmp
= format_tbl
[pop
->format
].opsz
+ format_tbl
[pop
->format
].dispsz
;
533 regs
->pc
+= tmp
>> 3;
535 /* handle MOV_Lcc, which are currently the only FMT_D10 insns that
537 if (pop
->format
== FMT_D10
)
538 misalignment_MOV_Lcc(regs
, opcode
);
544 * determine the address that was being accessed
546 static int misalignment_addr(unsigned long *registers
, unsigned long sp
,
547 unsigned params
, unsigned opcode
,
549 void **_address
, unsigned long **_postinc
,
552 unsigned long *postinc
= NULL
, address
= 0, tmp
;
554 if (!(params
& 0x1000000)) {
560 params
&= 0x00ffffff;
563 switch (params
& 0xff) {
565 postinc
= ®isters
[Dreg_index
[opcode
& 0x03]];
569 postinc
= ®isters
[Dreg_index
[opcode
>> 2 & 0x03]];
573 postinc
= ®isters
[Dreg_index
[opcode
>> 4 & 0x03]];
577 postinc
= ®isters
[Areg_index
[opcode
& 0x03]];
581 postinc
= ®isters
[Areg_index
[opcode
>> 2 & 0x03]];
585 postinc
= ®isters
[Areg_index
[opcode
>> 4 & 0x03]];
589 postinc
= ®isters
[Rreg_index
[opcode
& 0x0f]];
593 postinc
= ®isters
[Rreg_index
[opcode
>> 2 & 0x0f]];
597 postinc
= ®isters
[Rreg_index
[opcode
>> 4 & 0x0f]];
601 postinc
= ®isters
[Rreg_index
[opcode
>> 8 & 0x0f]];
605 postinc
= ®isters
[Rreg_index
[opcode
>> 12 & 0x0f]];
609 postinc
= ®isters
[Rreg_index
[disp
& 0x0f]];
613 postinc
= ®isters
[Rreg_index
[disp
>> 4 & 0x0f]];
620 /* displacements are either to be added to the address
621 * before use, or, in the case of post-inc addressing,
622 * to be added into the base register after use */
625 disp
= (long) (int8_t) (disp
& 0xff);
626 goto displace_or_inc
;
628 disp
= (long) (int16_t) (disp
& 0xffff);
629 goto displace_or_inc
;
632 asm("asr 8,%0" : "=r"(tmp
) : "0"(tmp
) : "cc");
634 goto displace_or_inc
;
636 tmp
= opcode
>> 4 & 0x0f;
638 asm("asr 28,%0" : "=r"(tmp
) : "0"(tmp
) : "cc");
640 goto displace_or_inc
;
643 goto displace_or_inc
;
646 goto displace_or_inc
;
649 goto displace_or_inc
;
653 case IMM32_HIGH8_MEM
:
655 kdebug("%s %lx", _inc
? "incr" : "disp", disp
);
665 } while ((params
>>= 8));
667 *_address
= (void *) address
;
673 * determine the register that is acting as source/dest
675 static int misalignment_reg(unsigned long *registers
, unsigned params
,
676 unsigned opcode
, unsigned long disp
,
677 unsigned long **_register
)
679 params
&= 0x7fffffff;
681 if (params
& 0xffffff00)
684 switch (params
& 0xff) {
686 *_register
= ®isters
[Dreg_index
[opcode
& 0x03]];
689 *_register
= ®isters
[Dreg_index
[opcode
>> 2 & 0x03]];
692 *_register
= ®isters
[Dreg_index
[opcode
>> 4 & 0x03]];
695 *_register
= ®isters
[Areg_index
[opcode
& 0x03]];
698 *_register
= ®isters
[Areg_index
[opcode
>> 2 & 0x03]];
701 *_register
= ®isters
[Areg_index
[opcode
>> 4 & 0x03]];
704 *_register
= ®isters
[Rreg_index
[opcode
& 0x0f]];
707 *_register
= ®isters
[Rreg_index
[opcode
>> 2 & 0x0f]];
710 *_register
= ®isters
[Rreg_index
[opcode
>> 4 & 0x0f]];
713 *_register
= ®isters
[Rreg_index
[opcode
>> 8 & 0x0f]];
716 *_register
= ®isters
[Rreg_index
[opcode
>> 12 & 0x0f]];
719 *_register
= ®isters
[Rreg_index
[disp
& 0x0f]];
722 *_register
= ®isters
[Rreg_index
[disp
>> 4 & 0x0f]];
725 *_register
= ®isters
[REG_SP
>> 2];
737 * handle the conditional loop part of the move-and-loop instructions
739 static void misalignment_MOV_Lcc(struct pt_regs
*regs
, uint32_t opcode
)
741 unsigned long epsw
= regs
->epsw
;
744 kdebug("MOV_Lcc %x [flags=%lx]", opcode
, epsw
& 0xf);
746 /* calculate N^V and shift onto the same bit position as Z */
747 NxorV
= ((epsw
>> 3) ^ epsw
>> 1) & 1;
749 switch (opcode
& 0xf) {
750 case 0x0: /* MOV_LLT: N^V */
754 case 0x1: /* MOV_LGT: ~(Z or (N^V))*/
755 if (!((epsw
& EPSW_FLAG_Z
) | NxorV
))
758 case 0x2: /* MOV_LGE: ~(N^V) */
762 case 0x3: /* MOV_LLE: Z or (N^V) */
763 if ((epsw
& EPSW_FLAG_Z
) | NxorV
)
767 case 0x4: /* MOV_LCS: C */
768 if (epsw
& EPSW_FLAG_C
)
771 case 0x5: /* MOV_LHI: ~(C or Z) */
772 if (!(epsw
& (EPSW_FLAG_C
| EPSW_FLAG_Z
)))
775 case 0x6: /* MOV_LCC: ~C */
776 if (!(epsw
& EPSW_FLAG_C
))
779 case 0x7: /* MOV_LLS: C or Z */
780 if (epsw
& (EPSW_FLAG_C
| EPSW_FLAG_Z
))
784 case 0x8: /* MOV_LEQ: Z */
785 if (epsw
& EPSW_FLAG_Z
)
788 case 0x9: /* MOV_LNE: ~Z */
789 if (!(epsw
& EPSW_FLAG_Z
))
792 case 0xa: /* MOV_LRA: always */
800 /* wind the PC back to just after the SETLB insn */
801 kdebug("loop LAR=%lx", regs
->lar
);
802 regs
->pc
= regs
->lar
- 4;
806 * misalignment handler tests
808 #ifdef CONFIG_TEST_MISALIGNMENT_HANDLER
809 static u8 __initdata testbuf
[512] __attribute__((aligned(16))) = {
816 #define ASSERTCMP(X, OP, Y) \
818 if (unlikely(!((X) OP (Y)))) { \
819 printk(KERN_ERR "\n"); \
820 printk(KERN_ERR "MISALIGN: Assertion failed at line %u\n", \
822 printk(KERN_ERR "0x%lx " #OP " 0x%lx is false\n", \
823 (unsigned long)(X), (unsigned long)(Y)); \
828 static int __init
test_misalignment(void)
830 register void *r
asm("e0");
831 register u32 y
asm("e1");
832 void *p
= testbuf
, *q
;
835 printk(KERN_NOTICE
"==>test_misalignment() [testbuf=%p]\n", p
);
838 printk(KERN_NOTICE
"___ MOV (Am),Dn ___\n");
840 asm volatile("mov (%0),%1" : "+a"(q
), "=d"(x
));
841 ASSERTCMP(q
, ==, p
+ 256);
842 ASSERTCMP(x
, ==, 0x44332211);
844 printk(KERN_NOTICE
"___ MOV (256,Am),Dn ___\n");
846 asm volatile("mov (256,%0),%1" : "+a"(q
), "=d"(x
));
848 ASSERTCMP(x
, ==, 0x44332211);
850 printk(KERN_NOTICE
"___ MOV (Di,Am),Dn ___\n");
853 asm volatile("mov (%2,%0),%1" : "+a"(q
), "=d"(x
), "+d"(tmp
));
855 ASSERTCMP(x
, ==, 0x44332211);
856 ASSERTCMP(tmp
, ==, 256);
858 printk(KERN_NOTICE
"___ MOV (256,Rm),Rn ___\n");
860 asm volatile("mov (256,%0),%1" : "+r"(r
), "=r"(y
));
862 ASSERTCMP(y
, ==, 0x44332211);
864 printk(KERN_NOTICE
"___ MOV (Rm+),Rn ___\n");
866 asm volatile("mov (%0+),%1" : "+r"(r
), "=r"(y
));
867 ASSERTCMP(r
, ==, p
+ 256 + 4);
868 ASSERTCMP(y
, ==, 0x44332211);
870 printk(KERN_NOTICE
"___ MOV (Rm+,8),Rn ___\n");
872 asm volatile("mov (%0+,8),%1" : "+r"(r
), "=r"(y
));
873 ASSERTCMP(r
, ==, p
+ 256 + 8);
874 ASSERTCMP(y
, ==, 0x44332211);
876 printk(KERN_NOTICE
"___ MOV (7,SP),Rn ___\n");
886 "movbu %0,(10,sp) \n"
890 ASSERTCMP(x
, ==, 0x44332211);
892 printk(KERN_NOTICE
"___ MOV (259,SP),Rn ___\n");
896 "movbu %0,(259,sp) \n"
898 "movbu %0,(260,sp) \n"
900 "movbu %0,(261,sp) \n"
902 "movbu %0,(262,sp) \n"
905 : "+d"(tmp
), "=d"(x
));
906 ASSERTCMP(x
, ==, 0x55332211);
908 printk(KERN_NOTICE
"___ MOV (260,SP),Rn ___\n");
912 "movbu %0,(260,sp) \n"
914 "movbu %0,(261,sp) \n"
916 "movbu %0,(262,sp) \n"
918 "movbu %0,(263,sp) \n"
921 : "+d"(tmp
), "=d"(x
));
922 ASSERTCMP(x
, ==, 0x55332211);
925 printk(KERN_NOTICE
"___ MOV_LNE ___\n");
935 : "+r"(q
), "+d"(tmp
), "+d"(tmp2
), "=d"(x
)
938 ASSERTCMP(q
, ==, p
+ 256 + 12);
939 ASSERTCMP(x
, ==, 0x44332211);
941 printk(KERN_NOTICE
"___ MOV in SETLB ___\n");
951 : "+a"(q
), "+d"(tmp
), "+d"(tmp2
), "=d"(x
)
955 ASSERTCMP(q
, ==, p
+ 256 + 8);
956 ASSERTCMP(x
, ==, 0x44332211);
958 printk(KERN_NOTICE
"<==test_misalignment()\n");
962 arch_initcall(test_misalignment
);
964 #endif /* CONFIG_TEST_MISALIGNMENT_HANDLER */