misalignment.c 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977
  1. /* 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. #if 0
  39. #define kdebug(FMT, ...) printk(KERN_DEBUG "MISALIGN: "FMT"\n", ##__VA_ARGS__)
  40. #else
  41. #define kdebug(FMT, ...) do {} while (0)
  42. #endif
  43. static int misalignment_addr(unsigned long *registers, unsigned long sp,
  44. unsigned params, unsigned opcode,
  45. unsigned long disp,
  46. void **_address, unsigned long **_postinc,
  47. unsigned long *_inc);
  48. static int misalignment_reg(unsigned long *registers, unsigned params,
  49. unsigned opcode, unsigned long disp,
  50. unsigned long **_register);
  51. 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
  54. };
  55. static const unsigned Areg_index[] = {
  56. REG_A0 >> 2, REG_A1 >> 2, REG_A2 >> 2, REG_A3 >> 2
  57. };
  58. static const unsigned Rreg_index[] = {
  59. REG_E0 >> 2, REG_E1 >> 2, REG_E2 >> 2, REG_E3 >> 2,
  60. REG_E4 >> 2, REG_E5 >> 2, REG_E6 >> 2, REG_E7 >> 2,
  61. REG_A0 >> 2, REG_A1 >> 2, REG_A2 >> 2, REG_A3 >> 2,
  62. REG_D0 >> 2, REG_D1 >> 2, REG_D2 >> 2, REG_D3 >> 2
  63. };
  64. enum format_id {
  65. FMT_S0,
  66. FMT_S1,
  67. FMT_S2,
  68. FMT_S4,
  69. FMT_D0,
  70. FMT_D1,
  71. FMT_D2,
  72. FMT_D4,
  73. FMT_D6,
  74. FMT_D7,
  75. FMT_D8,
  76. FMT_D9,
  77. FMT_D10,
  78. };
  79. static const struct {
  80. u_int8_t opsz, dispsz;
  81. } format_tbl[16] = {
  82. [FMT_S0] = { 8, 0 },
  83. [FMT_S1] = { 8, 8 },
  84. [FMT_S2] = { 8, 16 },
  85. [FMT_S4] = { 8, 32 },
  86. [FMT_D0] = { 16, 0 },
  87. [FMT_D1] = { 16, 8 },
  88. [FMT_D2] = { 16, 16 },
  89. [FMT_D4] = { 16, 32 },
  90. [FMT_D6] = { 24, 0 },
  91. [FMT_D7] = { 24, 8 },
  92. [FMT_D8] = { 24, 24 },
  93. [FMT_D9] = { 24, 32 },
  94. [FMT_D10] = { 32, 0 },
  95. };
  96. enum value_id {
  97. DM0, /* data reg in opcode in bits 0-1 */
  98. DM1, /* data reg in opcode in bits 2-3 */
  99. DM2, /* data reg in opcode in bits 4-5 */
  100. AM0, /* addr reg in opcode in bits 0-1 */
  101. AM1, /* addr reg in opcode in bits 2-3 */
  102. AM2, /* addr reg in opcode in bits 4-5 */
  103. RM0, /* reg in opcode in bits 0-3 */
  104. RM1, /* reg in opcode in bits 2-5 */
  105. RM2, /* reg in opcode in bits 4-7 */
  106. RM4, /* reg in opcode in bits 8-11 */
  107. RM6, /* reg in opcode in bits 12-15 */
  108. RD0, /* reg in displacement in bits 0-3 */
  109. RD2, /* reg in displacement in bits 4-7 */
  110. SP, /* stack pointer */
  111. SD8, /* 8-bit signed displacement */
  112. SD16, /* 16-bit signed displacement */
  113. SD24, /* 24-bit signed displacement */
  114. SIMM4_2, /* 4-bit signed displacement in opcode bits 4-7 */
  115. SIMM8, /* 8-bit signed immediate */
  116. IMM8, /* 8-bit unsigned immediate */
  117. IMM16, /* 16-bit unsigned immediate */
  118. IMM24, /* 24-bit unsigned immediate */
  119. IMM32, /* 32-bit unsigned immediate */
  120. IMM32_HIGH8, /* 32-bit unsigned immediate, LSB in opcode */
  121. IMM32_MEM, /* 32-bit unsigned displacement */
  122. IMM32_HIGH8_MEM, /* 32-bit unsigned displacement, LSB in opcode */
  123. DN0 = DM0,
  124. DN1 = DM1,
  125. DN2 = DM2,
  126. AN0 = AM0,
  127. AN1 = AM1,
  128. AN2 = AM2,
  129. RN0 = RM0,
  130. RN1 = RM1,
  131. RN2 = RM2,
  132. RN4 = RM4,
  133. RN6 = RM6,
  134. DI = DM1,
  135. RI = RM2,
  136. };
  137. struct mn10300_opcode {
  138. const char name[8];
  139. u_int32_t opcode;
  140. u_int32_t opmask;
  141. unsigned exclusion;
  142. enum format_id format;
  143. unsigned cpu_mask;
  144. #define AM33 330
  145. unsigned params[2];
  146. #define MEM(ADDR) (0x80000000 | (ADDR))
  147. #define MEM2(ADDR1, ADDR2) (0x80000000 | (ADDR1) << 8 | (ADDR2))
  148. #define MEMINC(ADDR) (0x81000000 | (ADDR))
  149. #define MEMINC2(ADDR, INC) (0x81000000 | (ADDR) << 8 | (INC))
  150. };
  151. /* LIBOPCODES EXCERPT
  152. Assemble Matsushita MN10300 instructions.
  153. Copyright 1996, 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
  154. This program is free software; you can redistribute it and/or modify
  155. it under the terms of the GNU General Public Licence as published by
  156. the Free Software Foundation; either version 2 of the Licence, or
  157. (at your option) any later version.
  158. This program is distributed in the hope that it will be useful,
  159. but WITHOUT ANY WARRANTY; without even the implied warranty of
  160. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  161. GNU General Public Licence for more details.
  162. You should have received a copy of the GNU General Public Licence
  163. along with this program; if not, write to the Free Software
  164. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  165. */
  166. static const struct mn10300_opcode mn10300_opcodes[] = {
  167. { "mov", 0x4200, 0xf300, 0, FMT_S1, 0, {DM1, MEM2(IMM8, SP)}},
  168. { "mov", 0x4300, 0xf300, 0, FMT_S1, 0, {AM1, MEM2(IMM8, SP)}},
  169. { "mov", 0x5800, 0xfc00, 0, FMT_S1, 0, {MEM2(IMM8, SP), DN0}},
  170. { "mov", 0x5c00, 0xfc00, 0, FMT_S1, 0, {MEM2(IMM8, SP), AN0}},
  171. { "mov", 0x60, 0xf0, 0, FMT_S0, 0, {DM1, MEM(AN0)}},
  172. { "mov", 0x70, 0xf0, 0, FMT_S0, 0, {MEM(AM0), DN1}},
  173. { "mov", 0xf000, 0xfff0, 0, FMT_D0, 0, {MEM(AM0), AN1}},
  174. { "mov", 0xf010, 0xfff0, 0, FMT_D0, 0, {AM1, MEM(AN0)}},
  175. { "mov", 0xf300, 0xffc0, 0, FMT_D0, 0, {MEM2(DI, AM0), DN2}},
  176. { "mov", 0xf340, 0xffc0, 0, FMT_D0, 0, {DM2, MEM2(DI, AN0)}},
  177. { "mov", 0xf380, 0xffc0, 0, FMT_D0, 0, {MEM2(DI, AM0), AN2}},
  178. { "mov", 0xf3c0, 0xffc0, 0, FMT_D0, 0, {AM2, MEM2(DI, AN0)}},
  179. { "mov", 0xf80000, 0xfff000, 0, FMT_D1, 0, {MEM2(SD8, AM0), DN1}},
  180. { "mov", 0xf81000, 0xfff000, 0, FMT_D1, 0, {DM1, MEM2(SD8, AN0)}},
  181. { "mov", 0xf82000, 0xfff000, 0, FMT_D1, 0, {MEM2(SD8,AM0), AN1}},
  182. { "mov", 0xf83000, 0xfff000, 0, FMT_D1, 0, {AM1, MEM2(SD8, AN0)}},
  183. { "mov", 0xf8f000, 0xfffc00, 0, FMT_D1, AM33, {MEM2(SD8, AM0), SP}},
  184. { "mov", 0xf8f400, 0xfffc00, 0, FMT_D1, AM33, {SP, MEM2(SD8, AN0)}},
  185. { "mov", 0xf90a00, 0xffff00, 0, FMT_D6, AM33, {MEM(RM0), RN2}},
  186. { "mov", 0xf91a00, 0xffff00, 0, FMT_D6, AM33, {RM2, MEM(RN0)}},
  187. { "mov", 0xf96a00, 0xffff00, 0x12, FMT_D6, AM33, {MEMINC(RM0), RN2}},
  188. { "mov", 0xf97a00, 0xffff00, 0, FMT_D6, AM33, {RM2, MEMINC(RN0)}},
  189. { "mov", 0xfa000000, 0xfff00000, 0, FMT_D2, 0, {MEM2(SD16, AM0), DN1}},
  190. { "mov", 0xfa100000, 0xfff00000, 0, FMT_D2, 0, {DM1, MEM2(SD16, AN0)}},
  191. { "mov", 0xfa200000, 0xfff00000, 0, FMT_D2, 0, {MEM2(SD16, AM0), AN1}},
  192. { "mov", 0xfa300000, 0xfff00000, 0, FMT_D2, 0, {AM1, MEM2(SD16, AN0)}},
  193. { "mov", 0xfa900000, 0xfff30000, 0, FMT_D2, 0, {AM1, MEM2(IMM16, SP)}},
  194. { "mov", 0xfa910000, 0xfff30000, 0, FMT_D2, 0, {DM1, MEM2(IMM16, SP)}},
  195. { "mov", 0xfab00000, 0xfffc0000, 0, FMT_D2, 0, {MEM2(IMM16, SP), AN0}},
  196. { "mov", 0xfab40000, 0xfffc0000, 0, FMT_D2, 0, {MEM2(IMM16, SP), DN0}},
  197. { "mov", 0xfb0a0000, 0xffff0000, 0, FMT_D7, AM33, {MEM2(SD8, RM0), RN2}},
  198. { "mov", 0xfb1a0000, 0xffff0000, 0, FMT_D7, AM33, {RM2, MEM2(SD8, RN0)}},
  199. { "mov", 0xfb6a0000, 0xffff0000, 0x22, FMT_D7, AM33, {MEMINC2 (RM0, SIMM8), RN2}},
  200. { "mov", 0xfb7a0000, 0xffff0000, 0, FMT_D7, AM33, {RM2, MEMINC2 (RN0, SIMM8)}},
  201. { "mov", 0xfb8a0000, 0xffff0f00, 0, FMT_D7, AM33, {MEM2(IMM8, SP), RN2}},
  202. { "mov", 0xfb8e0000, 0xffff000f, 0, FMT_D7, AM33, {MEM2(RI, RM0), RD2}},
  203. { "mov", 0xfb9a0000, 0xffff0f00, 0, FMT_D7, AM33, {RM2, MEM2(IMM8, SP)}},
  204. { "mov", 0xfb9e0000, 0xffff000f, 0, FMT_D7, AM33, {RD2, MEM2(RI, RN0)}},
  205. { "mov", 0xfc000000, 0xfff00000, 0, FMT_D4, 0, {MEM2(IMM32,AM0), DN1}},
  206. { "mov", 0xfc100000, 0xfff00000, 0, FMT_D4, 0, {DM1, MEM2(IMM32,AN0)}},
  207. { "mov", 0xfc200000, 0xfff00000, 0, FMT_D4, 0, {MEM2(IMM32,AM0), AN1}},
  208. { "mov", 0xfc300000, 0xfff00000, 0, FMT_D4, 0, {AM1, MEM2(IMM32,AN0)}},
  209. { "mov", 0xfc800000, 0xfff30000, 0, FMT_D4, 0, {AM1, MEM(IMM32_MEM)}},
  210. { "mov", 0xfc810000, 0xfff30000, 0, FMT_D4, 0, {DM1, MEM(IMM32_MEM)}},
  211. { "mov", 0xfc900000, 0xfff30000, 0, FMT_D4, 0, {AM1, MEM2(IMM32, SP)}},
  212. { "mov", 0xfc910000, 0xfff30000, 0, FMT_D4, 0, {DM1, MEM2(IMM32, SP)}},
  213. { "mov", 0xfca00000, 0xfffc0000, 0, FMT_D4, 0, {MEM(IMM32_MEM), AN0}},
  214. { "mov", 0xfca40000, 0xfffc0000, 0, FMT_D4, 0, {MEM(IMM32_MEM), DN0}},
  215. { "mov", 0xfcb00000, 0xfffc0000, 0, FMT_D4, 0, {MEM2(IMM32, SP), AN0}},
  216. { "mov", 0xfcb40000, 0xfffc0000, 0, FMT_D4, 0, {MEM2(IMM32, SP), DN0}},
  217. { "mov", 0xfd0a0000, 0xffff0000, 0, FMT_D8, AM33, {MEM2(SD24, RM0), RN2}},
  218. { "mov", 0xfd1a0000, 0xffff0000, 0, FMT_D8, AM33, {RM2, MEM2(SD24, RN0)}},
  219. { "mov", 0xfd6a0000, 0xffff0000, 0x22, FMT_D8, AM33, {MEMINC2 (RM0, IMM24), RN2}},
  220. { "mov", 0xfd7a0000, 0xffff0000, 0, FMT_D8, AM33, {RM2, MEMINC2 (RN0, IMM24)}},
  221. { "mov", 0xfd8a0000, 0xffff0f00, 0, FMT_D8, AM33, {MEM2(IMM24, SP), RN2}},
  222. { "mov", 0xfd9a0000, 0xffff0f00, 0, FMT_D8, AM33, {RM2, MEM2(IMM24, SP)}},
  223. { "mov", 0xfe0a0000, 0xffff0000, 0, FMT_D9, AM33, {MEM2(IMM32_HIGH8,RM0), RN2}},
  224. { "mov", 0xfe0a0000, 0xffff0000, 0, FMT_D9, AM33, {MEM2(IMM32_HIGH8,RM0), RN2}},
  225. { "mov", 0xfe0e0000, 0xffff0f00, 0, FMT_D9, AM33, {MEM(IMM32_HIGH8_MEM), RN2}},
  226. { "mov", 0xfe1a0000, 0xffff0000, 0, FMT_D9, AM33, {RM2, MEM2(IMM32_HIGH8, RN0)}},
  227. { "mov", 0xfe1a0000, 0xffff0000, 0, FMT_D9, AM33, {RM2, MEM2(IMM32_HIGH8, RN0)}},
  228. { "mov", 0xfe1e0000, 0xffff0f00, 0, FMT_D9, AM33, {RM2, MEM(IMM32_HIGH8_MEM)}},
  229. { "mov", 0xfe6a0000, 0xffff0000, 0x22, FMT_D9, AM33, {MEMINC2 (RM0, IMM32_HIGH8), RN2}},
  230. { "mov", 0xfe7a0000, 0xffff0000, 0, FMT_D9, AM33, {RN2, MEMINC2 (RM0, IMM32_HIGH8)}},
  231. { "mov", 0xfe8a0000, 0xffff0f00, 0, FMT_D9, AM33, {MEM2(IMM32_HIGH8, SP), RN2}},
  232. { "mov", 0xfe9a0000, 0xffff0f00, 0, FMT_D9, AM33, {RM2, MEM2(IMM32_HIGH8, SP)}},
  233. { "movhu", 0xf060, 0xfff0, 0, FMT_D0, 0, {MEM(AM0), DN1}},
  234. { "movhu", 0xf070, 0xfff0, 0, FMT_D0, 0, {DM1, MEM(AN0)}},
  235. { "movhu", 0xf480, 0xffc0, 0, FMT_D0, 0, {MEM2(DI, AM0), DN2}},
  236. { "movhu", 0xf4c0, 0xffc0, 0, FMT_D0, 0, {DM2, MEM2(DI, AN0)}},
  237. { "movhu", 0xf86000, 0xfff000, 0, FMT_D1, 0, {MEM2(SD8, AM0), DN1}},
  238. { "movhu", 0xf87000, 0xfff000, 0, FMT_D1, 0, {DM1, MEM2(SD8, AN0)}},
  239. { "movhu", 0xf89300, 0xfff300, 0, FMT_D1, 0, {DM1, MEM2(IMM8, SP)}},
  240. { "movhu", 0xf8bc00, 0xfffc00, 0, FMT_D1, 0, {MEM2(IMM8, SP), DN0}},
  241. { "movhu", 0xf94a00, 0xffff00, 0, FMT_D6, AM33, {MEM(RM0), RN2}},
  242. { "movhu", 0xf95a00, 0xffff00, 0, FMT_D6, AM33, {RM2, MEM(RN0)}},
  243. { "movhu", 0xf9ea00, 0xffff00, 0x12, FMT_D6, AM33, {MEMINC(RM0), RN2}},
  244. { "movhu", 0xf9fa00, 0xffff00, 0, FMT_D6, AM33, {RM2, MEMINC(RN0)}},
  245. { "movhu", 0xfa600000, 0xfff00000, 0, FMT_D2, 0, {MEM2(SD16, AM0), DN1}},
  246. { "movhu", 0xfa700000, 0xfff00000, 0, FMT_D2, 0, {DM1, MEM2(SD16, AN0)}},
  247. { "movhu", 0xfa930000, 0xfff30000, 0, FMT_D2, 0, {DM1, MEM2(IMM16, SP)}},
  248. { "movhu", 0xfabc0000, 0xfffc0000, 0, FMT_D2, 0, {MEM2(IMM16, SP), DN0}},
  249. { "movhu", 0xfb4a0000, 0xffff0000, 0, FMT_D7, AM33, {MEM2(SD8, RM0), RN2}},
  250. { "movhu", 0xfb5a0000, 0xffff0000, 0, FMT_D7, AM33, {RM2, MEM2(SD8, RN0)}},
  251. { "movhu", 0xfbca0000, 0xffff0f00, 0, FMT_D7, AM33, {MEM2(IMM8, SP), RN2}},
  252. { "movhu", 0xfbce0000, 0xffff000f, 0, FMT_D7, AM33, {MEM2(RI, RM0), RD2}},
  253. { "movhu", 0xfbda0000, 0xffff0f00, 0, FMT_D7, AM33, {RM2, MEM2(IMM8, SP)}},
  254. { "movhu", 0xfbde0000, 0xffff000f, 0, FMT_D7, AM33, {RD2, MEM2(RI, RN0)}},
  255. { "movhu", 0xfbea0000, 0xffff0000, 0x22, FMT_D7, AM33, {MEMINC2 (RM0, SIMM8), RN2}},
  256. { "movhu", 0xfbfa0000, 0xffff0000, 0, FMT_D7, AM33, {RM2, MEMINC2 (RN0, SIMM8)}},
  257. { "movhu", 0xfc600000, 0xfff00000, 0, FMT_D4, 0, {MEM2(IMM32,AM0), DN1}},
  258. { "movhu", 0xfc700000, 0xfff00000, 0, FMT_D4, 0, {DM1, MEM2(IMM32,AN0)}},
  259. { "movhu", 0xfc830000, 0xfff30000, 0, FMT_D4, 0, {DM1, MEM(IMM32_MEM)}},
  260. { "movhu", 0xfc930000, 0xfff30000, 0, FMT_D4, 0, {DM1, MEM2(IMM32, SP)}},
  261. { "movhu", 0xfcac0000, 0xfffc0000, 0, FMT_D4, 0, {MEM(IMM32_MEM), DN0}},
  262. { "movhu", 0xfcbc0000, 0xfffc0000, 0, FMT_D4, 0, {MEM2(IMM32, SP), DN0}},
  263. { "movhu", 0xfd4a0000, 0xffff0000, 0, FMT_D8, AM33, {MEM2(SD24, RM0), RN2}},
  264. { "movhu", 0xfd5a0000, 0xffff0000, 0, FMT_D8, AM33, {RM2, MEM2(SD24, RN0)}},
  265. { "movhu", 0xfdca0000, 0xffff0f00, 0, FMT_D8, AM33, {MEM2(IMM24, SP), RN2}},
  266. { "movhu", 0xfdda0000, 0xffff0f00, 0, FMT_D8, AM33, {RM2, MEM2(IMM24, SP)}},
  267. { "movhu", 0xfdea0000, 0xffff0000, 0x22, FMT_D8, AM33, {MEMINC2 (RM0, IMM24), RN2}},
  268. { "movhu", 0xfdfa0000, 0xffff0000, 0, FMT_D8, AM33, {RM2, MEMINC2 (RN0, IMM24)}},
  269. { "movhu", 0xfe4a0000, 0xffff0000, 0, FMT_D9, AM33, {MEM2(IMM32_HIGH8,RM0), RN2}},
  270. { "movhu", 0xfe4e0000, 0xffff0f00, 0, FMT_D9, AM33, {MEM(IMM32_HIGH8_MEM), RN2}},
  271. { "movhu", 0xfe5a0000, 0xffff0000, 0, FMT_D9, AM33, {RM2, MEM2(IMM32_HIGH8, RN0)}},
  272. { "movhu", 0xfe5e0000, 0xffff0f00, 0, FMT_D9, AM33, {RM2, MEM(IMM32_HIGH8_MEM)}},
  273. { "movhu", 0xfeca0000, 0xffff0f00, 0, FMT_D9, AM33, {MEM2(IMM32_HIGH8, SP), RN2}},
  274. { "movhu", 0xfeda0000, 0xffff0f00, 0, FMT_D9, AM33, {RM2, MEM2(IMM32_HIGH8, SP)}},
  275. { "movhu", 0xfeea0000, 0xffff0000, 0x22, FMT_D9, AM33, {MEMINC2 (RM0, IMM32_HIGH8), RN2}},
  276. { "movhu", 0xfefa0000, 0xffff0000, 0, FMT_D9, AM33, {RN2, MEMINC2 (RM0, IMM32_HIGH8)}},
  277. { "mov_llt", 0xf7e00000, 0xffff000f, 0x22, FMT_D10, AM33, {MEMINC2 (RN4,SIMM4_2), RM6}},
  278. { "mov_lgt", 0xf7e00001, 0xffff000f, 0x22, FMT_D10, AM33, {MEMINC2 (RN4,SIMM4_2), RM6}},
  279. { "mov_lge", 0xf7e00002, 0xffff000f, 0x22, FMT_D10, AM33, {MEMINC2 (RN4,SIMM4_2), RM6}},
  280. { "mov_lle", 0xf7e00003, 0xffff000f, 0x22, FMT_D10, AM33, {MEMINC2 (RN4,SIMM4_2), RM6}},
  281. { "mov_lcs", 0xf7e00004, 0xffff000f, 0x22, FMT_D10, AM33, {MEMINC2 (RN4,SIMM4_2), RM6}},
  282. { "mov_lhi", 0xf7e00005, 0xffff000f, 0x22, FMT_D10, AM33, {MEMINC2 (RN4,SIMM4_2), RM6}},
  283. { "mov_lcc", 0xf7e00006, 0xffff000f, 0x22, FMT_D10, AM33, {MEMINC2 (RN4,SIMM4_2), RM6}},
  284. { "mov_lls", 0xf7e00007, 0xffff000f, 0x22, FMT_D10, AM33, {MEMINC2 (RN4,SIMM4_2), RM6}},
  285. { "mov_leq", 0xf7e00008, 0xffff000f, 0x22, FMT_D10, AM33, {MEMINC2 (RN4,SIMM4_2), RM6}},
  286. { "mov_lne", 0xf7e00009, 0xffff000f, 0x22, FMT_D10, AM33, {MEMINC2 (RN4,SIMM4_2), RM6}},
  287. { "mov_lra", 0xf7e0000a, 0xffff000f, 0x22, FMT_D10, AM33, {MEMINC2 (RN4,SIMM4_2), RM6}},
  288. { "", 0, 0, 0, 0, 0, {0}},
  289. };
  290. /*
  291. * fix up misalignment problems where possible
  292. */
  293. asmlinkage void misalignment(struct pt_regs *regs, enum exception_code code)
  294. {
  295. const struct exception_table_entry *fixup;
  296. const struct mn10300_opcode *pop;
  297. unsigned long *registers = (unsigned long *) regs;
  298. unsigned long data, *store, *postinc, disp, inc, sp;
  299. mm_segment_t seg;
  300. siginfo_t info;
  301. uint32_t opcode, noc, xo, xm;
  302. uint8_t *pc, byte, datasz;
  303. void *address;
  304. unsigned tmp, npop, dispsz, loop;
  305. if (user_mode(regs))
  306. sp = regs->sp;
  307. else
  308. sp = (unsigned long) regs + sizeof(*regs);
  309. kdebug("==>misalignment({pc=%lx,sp=%lx})", regs->pc, sp);
  310. if (regs->epsw & EPSW_IE)
  311. asm volatile("or %0,epsw" : : "i"(EPSW_IE));
  312. seg = get_fs();
  313. set_fs(KERNEL_DS);
  314. fixup = search_exception_tables(regs->pc);
  315. /* first thing to do is to match the opcode */
  316. pc = (u_int8_t *) regs->pc;
  317. if (__get_user(byte, pc) != 0)
  318. goto fetch_error;
  319. opcode = byte;
  320. noc = 8;
  321. for (pop = mn10300_opcodes; pop->name[0]; pop++) {
  322. npop = ilog2(pop->opcode | pop->opmask);
  323. if (npop <= 0 || npop > 31)
  324. continue;
  325. npop = (npop + 8) & ~7;
  326. got_more_bits:
  327. if (npop == noc) {
  328. if ((opcode & pop->opmask) == pop->opcode)
  329. goto found_opcode;
  330. } else if (npop > noc) {
  331. xo = pop->opcode >> (npop - noc);
  332. xm = pop->opmask >> (npop - noc);
  333. if ((opcode & xm) != xo)
  334. continue;
  335. /* we've got a partial match (an exact match on the
  336. * first N bytes), so we need to get some more data */
  337. pc++;
  338. if (__get_user(byte, pc) != 0)
  339. goto fetch_error;
  340. opcode = opcode << 8 | byte;
  341. noc += 8;
  342. goto got_more_bits;
  343. } else {
  344. /* there's already been a partial match as long as the
  345. * complete match we're now considering, so this one
  346. * should't match */
  347. continue;
  348. }
  349. }
  350. /* didn't manage to find a fixup */
  351. if (!user_mode(regs))
  352. printk(KERN_CRIT "MISALIGN: %lx: unsupported instruction %x\n",
  353. regs->pc, opcode);
  354. failed:
  355. set_fs(seg);
  356. if (die_if_no_fixup("misalignment error", regs, code))
  357. return;
  358. info.si_signo = SIGBUS;
  359. info.si_errno = 0;
  360. info.si_code = BUS_ADRALN;
  361. info.si_addr = (void *) regs->pc;
  362. force_sig_info(SIGBUS, &info, current);
  363. return;
  364. /* error reading opcodes */
  365. fetch_error:
  366. if (!user_mode(regs))
  367. printk(KERN_CRIT
  368. "MISALIGN: %p: fault whilst reading instruction data\n",
  369. pc);
  370. goto failed;
  371. bad_addr_mode:
  372. if (!user_mode(regs))
  373. printk(KERN_CRIT
  374. "MISALIGN: %lx: unsupported addressing mode %x\n",
  375. regs->pc, opcode);
  376. goto failed;
  377. bad_reg_mode:
  378. if (!user_mode(regs))
  379. printk(KERN_CRIT
  380. "MISALIGN: %lx: unsupported register mode %x\n",
  381. regs->pc, opcode);
  382. goto failed;
  383. unsupported_instruction:
  384. if (!user_mode(regs))
  385. printk(KERN_CRIT
  386. "MISALIGN: %lx: unsupported instruction %x (%s)\n",
  387. regs->pc, opcode, pop->name);
  388. goto failed;
  389. transfer_failed:
  390. set_fs(seg);
  391. if (fixup) {
  392. regs->pc = fixup->fixup;
  393. return;
  394. }
  395. if (die_if_no_fixup("misalignment fixup", regs, code))
  396. return;
  397. info.si_signo = SIGSEGV;
  398. info.si_errno = 0;
  399. info.si_code = 0;
  400. info.si_addr = (void *) regs->pc;
  401. force_sig_info(SIGSEGV, &info, current);
  402. return;
  403. /* we matched the opcode */
  404. found_opcode:
  405. kdebug("%lx: %x==%x { %x, %x }",
  406. regs->pc, opcode, pop->opcode, pop->params[0], pop->params[1]);
  407. tmp = format_tbl[pop->format].opsz;
  408. if (tmp > noc)
  409. BUG(); /* match was less complete than it ought to have been */
  410. if (tmp < noc) {
  411. tmp = noc - tmp;
  412. opcode >>= tmp;
  413. pc -= tmp >> 3;
  414. }
  415. /* grab the extra displacement (note it's LSB first) */
  416. disp = 0;
  417. dispsz = format_tbl[pop->format].dispsz;
  418. for (loop = 0; loop < dispsz; loop += 8) {
  419. pc++;
  420. if (__get_user(byte, pc) != 0)
  421. goto fetch_error;
  422. disp |= byte << loop;
  423. kdebug("{%p} disp[%02x]=%02x", pc, loop, byte);
  424. }
  425. kdebug("disp=%lx", disp);
  426. set_fs(KERNEL_XDS);
  427. if (fixup || regs->epsw & EPSW_nSL)
  428. set_fs(seg);
  429. tmp = (pop->params[0] ^ pop->params[1]) & 0x80000000;
  430. if (!tmp) {
  431. if (!user_mode(regs))
  432. printk(KERN_CRIT
  433. "MISALIGN: %lx:"
  434. " insn not move to/from memory %x\n",
  435. regs->pc, opcode);
  436. goto failed;
  437. }
  438. /* determine the data transfer size of the move */
  439. if (pop->name[3] == 0 || /* "mov" */
  440. pop->name[4] == 'l') /* mov_lcc */
  441. inc = datasz = 4;
  442. else if (pop->name[3] == 'h') /* movhu */
  443. inc = datasz = 2;
  444. else
  445. goto unsupported_instruction;
  446. if (pop->params[0] & 0x80000000) {
  447. /* move memory to register */
  448. if (!misalignment_addr(registers, sp,
  449. pop->params[0], opcode, disp,
  450. &address, &postinc, &inc))
  451. goto bad_addr_mode;
  452. if (!misalignment_reg(registers, pop->params[1], opcode, disp,
  453. &store))
  454. goto bad_reg_mode;
  455. kdebug("mov%u (%p),DARn", datasz, address);
  456. if (copy_from_user(&data, (void *) address, datasz) != 0)
  457. goto transfer_failed;
  458. if (pop->params[0] & 0x1000000) {
  459. kdebug("inc=%lx", inc);
  460. *postinc += inc;
  461. }
  462. *store = data;
  463. kdebug("loaded %lx", data);
  464. } else {
  465. /* move register to memory */
  466. if (!misalignment_reg(registers, pop->params[0], opcode, disp,
  467. &store))
  468. goto bad_reg_mode;
  469. if (!misalignment_addr(registers, sp,
  470. pop->params[1], opcode, disp,
  471. &address, &postinc, &inc))
  472. goto bad_addr_mode;
  473. data = *store;
  474. kdebug("mov%u %lx,(%p)", datasz, data, address);
  475. if (copy_to_user((void *) address, &data, datasz) != 0)
  476. goto transfer_failed;
  477. if (pop->params[1] & 0x1000000)
  478. *postinc += inc;
  479. }
  480. tmp = format_tbl[pop->format].opsz + format_tbl[pop->format].dispsz;
  481. regs->pc += tmp >> 3;
  482. /* handle MOV_Lcc, which are currently the only FMT_D10 insns that
  483. * access memory */
  484. if (pop->format == FMT_D10)
  485. misalignment_MOV_Lcc(regs, opcode);
  486. set_fs(seg);
  487. return;
  488. }
  489. /*
  490. * determine the address that was being accessed
  491. */
  492. static int misalignment_addr(unsigned long *registers, unsigned long sp,
  493. unsigned params, unsigned opcode,
  494. unsigned long disp,
  495. void **_address, unsigned long **_postinc,
  496. unsigned long *_inc)
  497. {
  498. unsigned long *postinc = NULL, address = 0, tmp;
  499. if (!(params & 0x1000000)) {
  500. kdebug("noinc");
  501. *_inc = 0;
  502. _inc = NULL;
  503. }
  504. params &= 0x00ffffff;
  505. do {
  506. switch (params & 0xff) {
  507. case DM0:
  508. postinc = &registers[Dreg_index[opcode & 0x03]];
  509. address += *postinc;
  510. break;
  511. case DM1:
  512. postinc = &registers[Dreg_index[opcode >> 2 & 0x03]];
  513. address += *postinc;
  514. break;
  515. case DM2:
  516. postinc = &registers[Dreg_index[opcode >> 4 & 0x03]];
  517. address += *postinc;
  518. break;
  519. case AM0:
  520. postinc = &registers[Areg_index[opcode & 0x03]];
  521. address += *postinc;
  522. break;
  523. case AM1:
  524. postinc = &registers[Areg_index[opcode >> 2 & 0x03]];
  525. address += *postinc;
  526. break;
  527. case AM2:
  528. postinc = &registers[Areg_index[opcode >> 4 & 0x03]];
  529. address += *postinc;
  530. break;
  531. case RM0:
  532. postinc = &registers[Rreg_index[opcode & 0x0f]];
  533. address += *postinc;
  534. break;
  535. case RM1:
  536. postinc = &registers[Rreg_index[opcode >> 2 & 0x0f]];
  537. address += *postinc;
  538. break;
  539. case RM2:
  540. postinc = &registers[Rreg_index[opcode >> 4 & 0x0f]];
  541. address += *postinc;
  542. break;
  543. case RM4:
  544. postinc = &registers[Rreg_index[opcode >> 8 & 0x0f]];
  545. address += *postinc;
  546. break;
  547. case RM6:
  548. postinc = &registers[Rreg_index[opcode >> 12 & 0x0f]];
  549. address += *postinc;
  550. break;
  551. case RD0:
  552. postinc = &registers[Rreg_index[disp & 0x0f]];
  553. address += *postinc;
  554. break;
  555. case RD2:
  556. postinc = &registers[Rreg_index[disp >> 4 & 0x0f]];
  557. address += *postinc;
  558. break;
  559. case SP:
  560. address += sp;
  561. break;
  562. /* displacements are either to be added to the address
  563. * before use, or, in the case of post-inc addressing,
  564. * to be added into the base register after use */
  565. case SD8:
  566. case SIMM8:
  567. disp = (long) (int8_t) (disp & 0xff);
  568. goto displace_or_inc;
  569. case SD16:
  570. disp = (long) (int16_t) (disp & 0xffff);
  571. goto displace_or_inc;
  572. case SD24:
  573. tmp = disp << 8;
  574. asm("asr 8,%0" : "=r"(tmp) : "0"(tmp));
  575. disp = (long) tmp;
  576. goto displace_or_inc;
  577. case SIMM4_2:
  578. tmp = opcode >> 4 & 0x0f;
  579. tmp <<= 28;
  580. asm("asr 28,%0" : "=r"(tmp) : "0"(tmp));
  581. disp = (long) tmp;
  582. goto displace_or_inc;
  583. case IMM8:
  584. disp &= 0x000000ff;
  585. goto displace_or_inc;
  586. case IMM16:
  587. disp &= 0x0000ffff;
  588. goto displace_or_inc;
  589. case IMM24:
  590. disp &= 0x00ffffff;
  591. goto displace_or_inc;
  592. case IMM32:
  593. case IMM32_MEM:
  594. case IMM32_HIGH8:
  595. case IMM32_HIGH8_MEM:
  596. displace_or_inc:
  597. kdebug("%s %lx", _inc ? "incr" : "disp", disp);
  598. if (!_inc)
  599. address += disp;
  600. else
  601. *_inc = disp;
  602. break;
  603. default:
  604. BUG();
  605. return 0;
  606. }
  607. } while ((params >>= 8));
  608. *_address = (void *) address;
  609. *_postinc = postinc;
  610. return 1;
  611. }
  612. /*
  613. * determine the register that is acting as source/dest
  614. */
  615. static int misalignment_reg(unsigned long *registers, unsigned params,
  616. unsigned opcode, unsigned long disp,
  617. unsigned long **_register)
  618. {
  619. params &= 0x7fffffff;
  620. if (params & 0xffffff00)
  621. return 0;
  622. switch (params & 0xff) {
  623. case DM0:
  624. *_register = &registers[Dreg_index[opcode & 0x03]];
  625. break;
  626. case DM1:
  627. *_register = &registers[Dreg_index[opcode >> 2 & 0x03]];
  628. break;
  629. case DM2:
  630. *_register = &registers[Dreg_index[opcode >> 4 & 0x03]];
  631. break;
  632. case AM0:
  633. *_register = &registers[Areg_index[opcode & 0x03]];
  634. break;
  635. case AM1:
  636. *_register = &registers[Areg_index[opcode >> 2 & 0x03]];
  637. break;
  638. case AM2:
  639. *_register = &registers[Areg_index[opcode >> 4 & 0x03]];
  640. break;
  641. case RM0:
  642. *_register = &registers[Rreg_index[opcode & 0x0f]];
  643. break;
  644. case RM1:
  645. *_register = &registers[Rreg_index[opcode >> 2 & 0x0f]];
  646. break;
  647. case RM2:
  648. *_register = &registers[Rreg_index[opcode >> 4 & 0x0f]];
  649. break;
  650. case RM4:
  651. *_register = &registers[Rreg_index[opcode >> 8 & 0x0f]];
  652. break;
  653. case RM6:
  654. *_register = &registers[Rreg_index[opcode >> 12 & 0x0f]];
  655. break;
  656. case RD0:
  657. *_register = &registers[Rreg_index[disp & 0x0f]];
  658. break;
  659. case RD2:
  660. *_register = &registers[Rreg_index[disp >> 4 & 0x0f]];
  661. break;
  662. case SP:
  663. *_register = &registers[REG_SP >> 2];
  664. break;
  665. default:
  666. BUG();
  667. return 0;
  668. }
  669. return 1;
  670. }
  671. /*
  672. * handle the conditional loop part of the move-and-loop instructions
  673. */
  674. static void misalignment_MOV_Lcc(struct pt_regs *regs, uint32_t opcode)
  675. {
  676. unsigned long epsw = regs->epsw;
  677. unsigned long NxorV;
  678. kdebug("MOV_Lcc %x [flags=%lx]", opcode, epsw & 0xf);
  679. /* calculate N^V and shift onto the same bit position as Z */
  680. NxorV = ((epsw >> 3) ^ epsw >> 1) & 1;
  681. switch (opcode & 0xf) {
  682. case 0x0: /* MOV_LLT: N^V */
  683. if (NxorV)
  684. goto take_the_loop;
  685. return;
  686. case 0x1: /* MOV_LGT: ~(Z or (N^V))*/
  687. if (!((epsw & EPSW_FLAG_Z) | NxorV))
  688. goto take_the_loop;
  689. return;
  690. case 0x2: /* MOV_LGE: ~(N^V) */
  691. if (!NxorV)
  692. goto take_the_loop;
  693. return;
  694. case 0x3: /* MOV_LLE: Z or (N^V) */
  695. if ((epsw & EPSW_FLAG_Z) | NxorV)
  696. goto take_the_loop;
  697. return;
  698. case 0x4: /* MOV_LCS: C */
  699. if (epsw & EPSW_FLAG_C)
  700. goto take_the_loop;
  701. return;
  702. case 0x5: /* MOV_LHI: ~(C or Z) */
  703. if (!(epsw & (EPSW_FLAG_C | EPSW_FLAG_Z)))
  704. goto take_the_loop;
  705. return;
  706. case 0x6: /* MOV_LCC: ~C */
  707. if (!(epsw & EPSW_FLAG_C))
  708. goto take_the_loop;
  709. return;
  710. case 0x7: /* MOV_LLS: C or Z */
  711. if (epsw & (EPSW_FLAG_C | EPSW_FLAG_Z))
  712. goto take_the_loop;
  713. return;
  714. case 0x8: /* MOV_LEQ: Z */
  715. if (epsw & EPSW_FLAG_Z)
  716. goto take_the_loop;
  717. return;
  718. case 0x9: /* MOV_LNE: ~Z */
  719. if (!(epsw & EPSW_FLAG_Z))
  720. goto take_the_loop;
  721. return;
  722. case 0xa: /* MOV_LRA: always */
  723. goto take_the_loop;
  724. default:
  725. BUG();
  726. }
  727. take_the_loop:
  728. /* wind the PC back to just after the SETLB insn */
  729. kdebug("loop LAR=%lx", regs->lar);
  730. regs->pc = regs->lar - 4;
  731. }
  732. /*
  733. * misalignment handler tests
  734. */
  735. #ifdef CONFIG_TEST_MISALIGNMENT_HANDLER
  736. static u8 __initdata testbuf[512] __attribute__((aligned(16))) = {
  737. [257] = 0x11,
  738. [258] = 0x22,
  739. [259] = 0x33,
  740. [260] = 0x44,
  741. };
  742. #define ASSERTCMP(X, OP, Y) \
  743. do { \
  744. if (unlikely(!((X) OP (Y)))) { \
  745. printk(KERN_ERR "\n"); \
  746. printk(KERN_ERR "MISALIGN: Assertion failed at line %u\n", \
  747. __LINE__); \
  748. printk(KERN_ERR "0x%lx " #OP " 0x%lx is false\n", \
  749. (unsigned long)(X), (unsigned long)(Y)); \
  750. BUG(); \
  751. } \
  752. } while(0)
  753. static int __init test_misalignment(void)
  754. {
  755. register void *r asm("e0");
  756. register u32 y asm("e1");
  757. void *p = testbuf, *q;
  758. u32 tmp, tmp2, x;
  759. printk(KERN_NOTICE "==>test_misalignment() [testbuf=%p]\n", p);
  760. p++;
  761. printk(KERN_NOTICE "___ MOV (Am),Dn ___\n");
  762. q = p + 256;
  763. asm volatile("mov (%0),%1" : "+a"(q), "=d"(x));
  764. ASSERTCMP(q, ==, p + 256);
  765. ASSERTCMP(x, ==, 0x44332211);
  766. printk(KERN_NOTICE "___ MOV (256,Am),Dn ___\n");
  767. q = p;
  768. asm volatile("mov (256,%0),%1" : "+a"(q), "=d"(x));
  769. ASSERTCMP(q, ==, p);
  770. ASSERTCMP(x, ==, 0x44332211);
  771. printk(KERN_NOTICE "___ MOV (Di,Am),Dn ___\n");
  772. tmp = 256;
  773. q = p;
  774. asm volatile("mov (%2,%0),%1" : "+a"(q), "=d"(x), "+d"(tmp));
  775. ASSERTCMP(q, ==, p);
  776. ASSERTCMP(x, ==, 0x44332211);
  777. ASSERTCMP(tmp, ==, 256);
  778. printk(KERN_NOTICE "___ MOV (256,Rm),Rn ___\n");
  779. r = p;
  780. asm volatile("mov (256,%0),%1" : "+r"(r), "=r"(y));
  781. ASSERTCMP(r, ==, p);
  782. ASSERTCMP(y, ==, 0x44332211);
  783. printk(KERN_NOTICE "___ MOV (Rm+),Rn ___\n");
  784. r = p + 256;
  785. asm volatile("mov (%0+),%1" : "+r"(r), "=r"(y));
  786. ASSERTCMP(r, ==, p + 256 + 4);
  787. ASSERTCMP(y, ==, 0x44332211);
  788. printk(KERN_NOTICE "___ MOV (Rm+,8),Rn ___\n");
  789. r = p + 256;
  790. asm volatile("mov (%0+,8),%1" : "+r"(r), "=r"(y));
  791. ASSERTCMP(r, ==, p + 256 + 8);
  792. ASSERTCMP(y, ==, 0x44332211);
  793. printk(KERN_NOTICE "___ MOV (7,SP),Rn ___\n");
  794. asm volatile(
  795. "add -16,sp \n"
  796. "mov +0x11,%0 \n"
  797. "movbu %0,(7,sp) \n"
  798. "mov +0x22,%0 \n"
  799. "movbu %0,(8,sp) \n"
  800. "mov +0x33,%0 \n"
  801. "movbu %0,(9,sp) \n"
  802. "mov +0x44,%0 \n"
  803. "movbu %0,(10,sp) \n"
  804. "mov (7,sp),%1 \n"
  805. "add +16,sp \n"
  806. : "+a"(q), "=d"(x));
  807. ASSERTCMP(x, ==, 0x44332211);
  808. printk(KERN_NOTICE "___ MOV (259,SP),Rn ___\n");
  809. asm volatile(
  810. "add -264,sp \n"
  811. "mov +0x11,%0 \n"
  812. "movbu %0,(259,sp) \n"
  813. "mov +0x22,%0 \n"
  814. "movbu %0,(260,sp) \n"
  815. "mov +0x33,%0 \n"
  816. "movbu %0,(261,sp) \n"
  817. "mov +0x55,%0 \n"
  818. "movbu %0,(262,sp) \n"
  819. "mov (259,sp),%1 \n"
  820. "add +264,sp \n"
  821. : "+d"(tmp), "=d"(x));
  822. ASSERTCMP(x, ==, 0x55332211);
  823. printk(KERN_NOTICE "___ MOV (260,SP),Rn ___\n");
  824. asm volatile(
  825. "add -264,sp \n"
  826. "mov +0x11,%0 \n"
  827. "movbu %0,(260,sp) \n"
  828. "mov +0x22,%0 \n"
  829. "movbu %0,(261,sp) \n"
  830. "mov +0x33,%0 \n"
  831. "movbu %0,(262,sp) \n"
  832. "mov +0x55,%0 \n"
  833. "movbu %0,(263,sp) \n"
  834. "mov (260,sp),%1 \n"
  835. "add +264,sp \n"
  836. : "+d"(tmp), "=d"(x));
  837. ASSERTCMP(x, ==, 0x55332211);
  838. printk(KERN_NOTICE "___ MOV_LNE ___\n");
  839. tmp = 1;
  840. tmp2 = 2;
  841. q = p + 256;
  842. asm volatile(
  843. "setlb \n"
  844. "mov %2,%3 \n"
  845. "mov %1,%2 \n"
  846. "cmp +0,%1 \n"
  847. "mov_lne (%0+,4),%1"
  848. : "+r"(q), "+d"(tmp), "+d"(tmp2), "=d"(x)
  849. :
  850. : "cc");
  851. ASSERTCMP(q, ==, p + 256 + 12);
  852. ASSERTCMP(x, ==, 0x44332211);
  853. printk(KERN_NOTICE "___ MOV in SETLB ___\n");
  854. tmp = 1;
  855. tmp2 = 2;
  856. q = p + 256;
  857. asm volatile(
  858. "setlb \n"
  859. "mov %1,%3 \n"
  860. "mov (%0+),%1 \n"
  861. "cmp +0,%1 \n"
  862. "lne "
  863. : "+a"(q), "+d"(tmp), "+d"(tmp2), "=d"(x)
  864. :
  865. : "cc");
  866. ASSERTCMP(q, ==, p + 256 + 8);
  867. ASSERTCMP(x, ==, 0x44332211);
  868. printk(KERN_NOTICE "<==test_misalignment()\n");
  869. return 0;
  870. }
  871. arch_initcall(test_misalignment);
  872. #endif /* CONFIG_TEST_MISALIGNMENT_HANDLER */