Skip to content

Commit 56dfb70

Browse files
mpredfearnralfbaechle
authored andcommitted
MIPS: Refactor handling of stack pointer in get_frame_info
Commit 34c2f66 ("MIPS: microMIPS: Add unaligned access support.") added handling of microMIPS instructions to manipulate the stack pointer. The code that was added violates code style rules with long lines caused by lots of nested conditionals. The added code interprets (inline) any known stack pointer manipulation instruction to find the stack frame size. Handling the microMIPS cases added quite a bit of complication to this function. Refactor is_sp_move_ins to perform the interpretation of the immediate as the instruction manipulating the stack pointer is found. This reduces the amount of indentation required in get_frame_info, and more closely matches the operation of is_ra_save_ins. Suggested-by: Maciej W. Rozycki <[email protected]> Signed-off-by: Matt Redfearn <[email protected]> Cc: Marcin Nowakowski <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Paul Burton <[email protected]> Cc: [email protected] Cc: [email protected] Patchwork: https://patchwork.linux-mips.org/patch/16958/ Signed-off-by: Ralf Baechle <[email protected]>
1 parent 41885b0 commit 56dfb70

File tree

1 file changed

+30
-31
lines changed

1 file changed

+30
-31
lines changed

arch/mips/kernel/process.c

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -313,9 +313,11 @@ static inline int is_jump_ins(union mips_instruction *ip)
313313
#endif
314314
}
315315

316-
static inline int is_sp_move_ins(union mips_instruction *ip)
316+
static inline int is_sp_move_ins(union mips_instruction *ip, int *frame_size)
317317
{
318318
#ifdef CONFIG_CPU_MICROMIPS
319+
unsigned short tmp;
320+
319321
/*
320322
* addiusp -imm
321323
* addius5 sp,-imm
@@ -325,20 +327,39 @@ static inline int is_sp_move_ins(union mips_instruction *ip)
325327
* microMIPS is not more fun...
326328
*/
327329
if (mm_insn_16bit(ip->word >> 16)) {
328-
return (ip->mm16_r3_format.opcode == mm_pool16d_op &&
329-
ip->mm16_r3_format.simmediate & mm_addiusp_func) ||
330-
(ip->mm16_r5_format.opcode == mm_pool16d_op &&
331-
ip->mm16_r5_format.rt == 29);
330+
if (ip->mm16_r3_format.opcode == mm_pool16d_op &&
331+
ip->mm16_r3_format.simmediate & mm_addiusp_func) {
332+
tmp = ip->mm_b0_format.simmediate >> 1;
333+
tmp = ((tmp & 0x1ff) ^ 0x100) - 0x100;
334+
if ((tmp + 2) < 4) /* 0x0,0x1,0x1fe,0x1ff are special */
335+
tmp ^= 0x100;
336+
*frame_size = -(signed short)(tmp << 2);
337+
return 1;
338+
}
339+
if (ip->mm16_r5_format.opcode == mm_pool16d_op &&
340+
ip->mm16_r5_format.rt == 29) {
341+
tmp = ip->mm16_r5_format.imm >> 1;
342+
*frame_size = -(signed short)(tmp & 0xf);
343+
return 1;
344+
}
345+
return 0;
332346
}
333347

334-
return ip->mm_i_format.opcode == mm_addiu32_op &&
335-
ip->mm_i_format.rt == 29 && ip->mm_i_format.rs == 29;
348+
if (ip->mm_i_format.opcode == mm_addiu32_op &&
349+
ip->mm_i_format.rt == 29 && ip->mm_i_format.rs == 29) {
350+
*frame_size = -ip->i_format.simmediate;
351+
return 1;
352+
}
336353
#else
337354
/* addiu/daddiu sp,sp,-imm */
338355
if (ip->i_format.rs != 29 || ip->i_format.rt != 29)
339356
return 0;
340-
if (ip->i_format.opcode == addiu_op || ip->i_format.opcode == daddiu_op)
357+
358+
if (ip->i_format.opcode == addiu_op ||
359+
ip->i_format.opcode == daddiu_op) {
360+
*frame_size = -ip->i_format.simmediate;
341361
return 1;
362+
}
342363
#endif
343364
return 0;
344365
}
@@ -375,29 +396,7 @@ static int get_frame_info(struct mips_frame_info *info)
375396
}
376397

377398
if (!info->frame_size) {
378-
if (is_sp_move_ins(&insn))
379-
{
380-
#ifdef CONFIG_CPU_MICROMIPS
381-
if (mm_insn_16bit(insn.word >> 16))
382-
{
383-
unsigned short tmp;
384-
385-
if (ip->mm16_r3_format.simmediate & mm_addiusp_func)
386-
{
387-
tmp = ip->mm_b0_format.simmediate >> 1;
388-
tmp = ((tmp & 0x1ff) ^ 0x100) - 0x100;
389-
/* 0x0,0x1,0x1fe,0x1ff are special */
390-
if ((tmp + 2) < 4)
391-
tmp ^= 0x100;
392-
info->frame_size = -(signed short)(tmp << 2);
393-
} else {
394-
tmp = (ip->mm16_r5_format.imm >> 1);
395-
info->frame_size = -(signed short)(tmp & 0xf);
396-
}
397-
} else
398-
#endif
399-
info->frame_size = - ip->i_format.simmediate;
400-
}
399+
is_sp_move_ins(&insn, &info->frame_size);
401400
continue;
402401
} else if (!saw_jump && is_jump_ins(ip)) {
403402
/*

0 commit comments

Comments
 (0)