linux-mips
[Top] [All Lists]

[PATCH 1/7] Make get_frame_info() more readable.

To: anemo@mba.ocn.ne.jp
Subject: [PATCH 1/7] Make get_frame_info() more readable.
From: Franck Bui-Huu <vagabon.xyz@gmail.com>
Date: Thu, 3 Aug 2006 09:29:15 +0200
Cc: ralf@linux-mips.org, linux-mips@linux-mips.org, Franck Bui-Huu <vagabon.xyz@gmail.com>
Domainkey-signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; b=SJzNVPGFlD8h3+ehkGR0MOifxUKxzLC/w6ic+ZOhJzwpU8kelh+IX9ljw5+oDa7KIhMiR8vVO7WW2BFL7nvRCLYD9lk9hlo/RzFPnf3bHDA9dbsSLZ0jOSzqh2qlwF4mp7v6Ld8EFgHFPdWm0vOQTTRXCGF6yAUKfRD6mbTpdks=
In-reply-to: <11545901611096-git-send-email-vagabon.xyz@gmail.com>
Original-recipient: rfc822;linux-mips@linux-mips.org
References: <11545901611096-git-send-email-vagabon.xyz@gmail.com>
Sender: linux-mips-bounce@linux-mips.org
Signed-off-by: Atsushi Nemoto <anemo@mba.ocn.ne.jp>
Signed-off-by: Franck Bui-Huu <vagabon.xyz@gmail.com>
---
 arch/mips/kernel/process.c |   67 ++++++++++++++++++++++++--------------------
 1 files changed, 36 insertions(+), 31 deletions(-)

diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
index 8709a46..93d5432 100644
--- a/arch/mips/kernel/process.c
+++ b/arch/mips/kernel/process.c
@@ -281,48 +281,53 @@ static struct mips_frame_info {
 } *schedule_frame, mfinfo[64];
 static int mfinfo_num;
 
+static inline int is_ra_save_ins(union mips_instruction *ip)
+{
+       /* sw / sd $ra, offset($sp) */
+       return (ip->i_format.opcode == sw_op || ip->i_format.opcode == sd_op) &&
+               ip->i_format.rs == 29 &&
+               ip->i_format.rt == 31;
+}
+
+static inline int is_jal_jalr_jr_ins(union mips_instruction *ip)
+{
+       if (ip->j_format.opcode == jal_op)
+               return 1;
+       if (ip->r_format.opcode != spec_op)
+               return 0;
+       return ip->r_format.func == jalr_op || ip->r_format.func == jr_op;
+}
+
+static inline int is_sp_move_ins(union mips_instruction *ip)
+{
+       /* addiu/daddiu sp,sp,-imm */
+       if (ip->i_format.rs != 29 || ip->i_format.rt != 29)
+               return 0;
+       if (ip->i_format.opcode == addiu_op || ip->i_format.opcode == daddiu_op)
+               return 1;
+       return 0;
+}
+
 static int get_frame_info(struct mips_frame_info *info)
 {
-       int i;
-       void *func = info->func;
-       union mips_instruction *ip = (union mips_instruction *)func;
+       union mips_instruction *ip = info->func;
+       int i, max_insns =
+               min(128UL, info->func_size / sizeof(union mips_instruction));
+
        info->pc_offset = -1;
        info->frame_size = 0;
-       for (i = 0; i < 128; i++, ip++) {
-               /* if jal, jalr, jr, stop. */
-               if (ip->j_format.opcode == jal_op ||
-                   (ip->r_format.opcode == spec_op &&
-                    (ip->r_format.func == jalr_op ||
-                     ip->r_format.func == jr_op)))
-                       break;
 
-               if (info->func_size && i >= info->func_size / 4)
+       for (i = 0; i < max_insns; i++, ip++) {
+
+               if (is_jal_jalr_jr_ins(ip))
                        break;
-               if (
-#ifdef CONFIG_32BIT
-                   ip->i_format.opcode == addiu_op &&
-#endif
-#ifdef CONFIG_64BIT
-                   ip->i_format.opcode == daddiu_op &&
-#endif
-                   ip->i_format.rs == 29 &&
-                   ip->i_format.rt == 29) {
-                       /* addiu/daddiu sp,sp,-imm */
+               if (is_sp_move_ins(ip)) {
                        if (info->frame_size)
                                continue;
                        info->frame_size = - ip->i_format.simmediate;
                }
 
-               if (
-#ifdef CONFIG_32BIT
-                   ip->i_format.opcode == sw_op &&
-#endif
-#ifdef CONFIG_64BIT
-                   ip->i_format.opcode == sd_op &&
-#endif
-                   ip->i_format.rs == 29 &&
-                   ip->i_format.rt == 31) {
-                       /* sw / sd $ra, offset($sp) */
+               if (is_ra_save_ins(ip)) {
                        if (info->pc_offset != -1)
                                continue;
                        info->pc_offset =
-- 
1.4.2.rc2


<Prev in Thread] Current Thread [Next in Thread>