public inbox for linux-sh@vger.kernel.org
 help / color / mirror / Atom feed
From: Magnus Damm <magnus.damm@gmail.com>
To: linux-sh@vger.kernel.org
Subject: [PATCH] sh: break out unaligned sign extension code
Date: Wed, 06 Feb 2008 15:02:50 +0000	[thread overview]
Message-ID: <20080206150250.27073.50160.sendpatchset@clockwork.opensource.se> (raw)

Break out the sign extension code since it's used in multiple places.

Signed-off-by: Magnus Damm <damm@igel.co.jp>
---

 arch/sh/kernel/traps_32.c |   68 +++++++++++++++------------------------------
 1 file changed, 23 insertions(+), 45 deletions(-)

--- 0001/arch/sh/kernel/traps_32.c
+++ work/arch/sh/kernel/traps_32.c	2008-02-05 14:18:19.000000000 +0900
@@ -147,6 +147,21 @@ static int die_if_no_fixup(const char * 
 	return -EFAULT;
 }
 
+static inline void sign_extend(unsigned int count, unsigned char *dst)
+{
+#ifdef __LITTLE_ENDIAN__
+	if ((count = 2) && dst[1] & 0x80) {
+		dst[2] = 0xff;
+		dst[3] = 0xff;
+	}
+#else
+	if ((count = 2) && dst[2] & 0x80) {
+		dst[0] = 0xff;
+		dst[1] = 0xff;
+	}
+#endif
+}
+
 /*
  * handle an instruction that does an unaligned memory access by emulating the
  * desired behaviour
@@ -178,25 +193,13 @@ static int handle_unaligned_ins(u16 inst
 			dst = (unsigned char*) rn;
 			*(unsigned long*)dst = 0;
 
-#ifdef __LITTLE_ENDIAN__
-			if (copy_from_user(dst, src, count))
-				goto fetch_fault;
-
-			if ((count = 2) && dst[1] & 0x80) {
-				dst[2] = 0xff;
-				dst[3] = 0xff;
-			}
-#else
+#if !defined(__LITTLE_ENDIAN__)
 			dst += 4-count;
-
-			if (__copy_user(dst, src, count))
+#endif
+			if (copy_from_user(dst, src, count))
 				goto fetch_fault;
 
-			if ((count = 2) && dst[2] & 0x80) {
-				dst[0] = 0xff;
-				dst[1] = 0xff;
-			}
-#endif
+			sign_extend(count, dst);
 		} else {
 			/* to memory */
 			src = (unsigned char*) rm;
@@ -253,25 +256,12 @@ static int handle_unaligned_ins(u16 inst
 		dst = (unsigned char*) rn;
 		*(unsigned long*)dst = 0;
 
-#ifdef __LITTLE_ENDIAN__
-		if (copy_from_user(dst, src, count))
-			goto fetch_fault;
-
-		if ((count = 2) && dst[1] & 0x80) {
-			dst[2] = 0xff;
-			dst[3] = 0xff;
-		}
-#else
+#if !defined(__LITTLE_ENDIAN__)
 		dst += 4-count;
-
+#endif
 		if (copy_from_user(dst, src, count))
 			goto fetch_fault;
-
-		if ((count = 2) && dst[2] & 0x80) {
-			dst[0] = 0xff;
-			dst[1] = 0xff;
-		}
-#endif
+		sign_extend(count, dst);
 		ret = 0;
 		break;
 
@@ -299,21 +289,9 @@ static int handle_unaligned_ins(u16 inst
 #if !defined(__LITTLE_ENDIAN__)
 			dst += 2;
 #endif
-
 			if (copy_from_user(dst, src, 2))
 				goto fetch_fault;
-
-#ifdef __LITTLE_ENDIAN__
-			if (dst[1] & 0x80) {
-				dst[2] = 0xff;
-				dst[3] = 0xff;
-			}
-#else
-			if (dst[2] & 0x80) {
-				dst[0] = 0xff;
-				dst[1] = 0xff;
-			}
-#endif
+			sign_extend(2, dst);
 			ret = 0;
 			break;
 		}

                 reply	other threads:[~2008-02-06 15:02 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20080206150250.27073.50160.sendpatchset@clockwork.opensource.se \
    --to=magnus.damm@gmail.com \
    --cc=linux-sh@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox