aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatt Redfearn <matt.redfearn@imgtec.com>2017-08-08 08:22:34 -0400
committerRalf Baechle <ralf@linux-mips.org>2017-09-06 07:21:00 -0400
commit41885b02127c7ae169dc94542de4a8eed175495a (patch)
treea073396c687dc15cba0850905b3315659d253bb2
parentcea8cd498f4f1c30ea27e3664b3c671e495c4fce (diff)
MIPS: Stacktrace: Fix microMIPS stack unwinding on big endian systems
The stack unwinding code uses the mips_instuction union to decode the instructions it finds. That union uses the __BITFIELD_FIELD macro to reorder depending on endianness. The stack unwinding code always places 16bit instructions in halfword 1 of the union. This makes the union accesses correct for little endian systems. Similarly, 32bit instructions are reordered such that they are correct for little endian systems. This handling leaves unwinding the stack on big endian systems broken, as the mips_instruction union will then look for the fields in the wrong halfword. To fix this, use a logical shift to place the 16bit instruction into the correct position in the word field of the union. Use the same shifting to order the 2 halfwords of 32bit instuctions. Then replace accesses to the halfword with accesses to the shifted word. In the case of the ADDIUS5 instruction, switch to using the mm16_r5_format union member to avoid the need for a 16bit shift. Fixes: 34c2f668d0f6 ("MIPS: microMIPS: Add unaligned access support.") Signed-off-by: Matt Redfearn <matt.redfearn@imgtec.com> Reviewed-by: James Hogan <james.hogan@imgtec.com> Cc: Marcin Nowakowski <marcin.nowakowski@imgtec.com> Cc: Ingo Molnar <mingo@kernel.org> Cc: Paul Burton <paul.burton@imgtec.com> Cc: linux-mips@linux-mips.org Cc: linux-kernel@vger.kernel.org Patchwork: https://patchwork.linux-mips.org/patch/16956/ Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
-rw-r--r--arch/mips/kernel/process.c16
1 files changed, 7 insertions, 9 deletions
diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
index debc0410a2d5..86139ac3bbad 100644
--- a/arch/mips/kernel/process.c
+++ b/arch/mips/kernel/process.c
@@ -208,7 +208,7 @@ static inline int is_ra_save_ins(union mips_instruction *ip, int *poff)
208 * 208 *
209 * microMIPS is way more fun... 209 * microMIPS is way more fun...
210 */ 210 */
211 if (mm_insn_16bit(ip->halfword[1])) { 211 if (mm_insn_16bit(ip->word >> 16)) {
212 switch (ip->mm16_r5_format.opcode) { 212 switch (ip->mm16_r5_format.opcode) {
213 case mm_swsp16_op: 213 case mm_swsp16_op:
214 if (ip->mm16_r5_format.rt != 31) 214 if (ip->mm16_r5_format.rt != 31)
@@ -287,7 +287,7 @@ static inline int is_jump_ins(union mips_instruction *ip)
287 * 287 *
288 * microMIPS is kind of more fun... 288 * microMIPS is kind of more fun...
289 */ 289 */
290 if (mm_insn_16bit(ip->halfword[1])) { 290 if (mm_insn_16bit(ip->word >> 16)) {
291 if ((ip->mm16_r5_format.opcode == mm_pool16c_op && 291 if ((ip->mm16_r5_format.opcode == mm_pool16c_op &&
292 (ip->mm16_r5_format.rt & mm_jr16_op) == mm_jr16_op)) 292 (ip->mm16_r5_format.rt & mm_jr16_op) == mm_jr16_op))
293 return 1; 293 return 1;
@@ -324,7 +324,7 @@ static inline int is_sp_move_ins(union mips_instruction *ip)
324 * 324 *
325 * microMIPS is not more fun... 325 * microMIPS is not more fun...
326 */ 326 */
327 if (mm_insn_16bit(ip->halfword[1])) { 327 if (mm_insn_16bit(ip->word >> 16)) {
328 return (ip->mm16_r3_format.opcode == mm_pool16d_op && 328 return (ip->mm16_r3_format.opcode == mm_pool16d_op &&
329 ip->mm16_r3_format.simmediate & mm_addiusp_func) || 329 ip->mm16_r3_format.simmediate & mm_addiusp_func) ||
330 (ip->mm16_r5_format.opcode == mm_pool16d_op && 330 (ip->mm16_r5_format.opcode == mm_pool16d_op &&
@@ -364,12 +364,10 @@ static int get_frame_info(struct mips_frame_info *info)
364 for (i = 0; i < max_insns && ip < ip_end; i++) { 364 for (i = 0; i < max_insns && ip < ip_end; i++) {
365 ip = (void *)ip + last_insn_size; 365 ip = (void *)ip + last_insn_size;
366 if (is_mmips && mm_insn_16bit(ip->halfword[0])) { 366 if (is_mmips && mm_insn_16bit(ip->halfword[0])) {
367 insn.halfword[0] = 0; 367 insn.word = ip->halfword[0] << 16;
368 insn.halfword[1] = ip->halfword[0];
369 last_insn_size = 2; 368 last_insn_size = 2;
370 } else if (is_mmips) { 369 } else if (is_mmips) {
371 insn.halfword[0] = ip->halfword[1]; 370 insn.word = ip->halfword[0] << 16 | ip->halfword[1];
372 insn.halfword[1] = ip->halfword[0];
373 last_insn_size = 4; 371 last_insn_size = 4;
374 } else { 372 } else {
375 insn.word = ip->word; 373 insn.word = ip->word;
@@ -380,7 +378,7 @@ static int get_frame_info(struct mips_frame_info *info)
380 if (is_sp_move_ins(&insn)) 378 if (is_sp_move_ins(&insn))
381 { 379 {
382#ifdef CONFIG_CPU_MICROMIPS 380#ifdef CONFIG_CPU_MICROMIPS
383 if (mm_insn_16bit(ip->halfword[0])) 381 if (mm_insn_16bit(insn.word >> 16))
384 { 382 {
385 unsigned short tmp; 383 unsigned short tmp;
386 384
@@ -393,7 +391,7 @@ static int get_frame_info(struct mips_frame_info *info)
393 tmp ^= 0x100; 391 tmp ^= 0x100;
394 info->frame_size = -(signed short)(tmp << 2); 392 info->frame_size = -(signed short)(tmp << 2);
395 } else { 393 } else {
396 tmp = (ip->halfword[0] >> 1); 394 tmp = (ip->mm16_r5_format.imm >> 1);
397 info->frame_size = -(signed short)(tmp & 0xf); 395 info->frame_size = -(signed short)(tmp & 0xf);
398 } 396 }
399 } else 397 } else