sh: add byte support to the sign extension code
authorMagnus Damm <magnus.damm@gmail.com>
Thu, 7 Feb 2008 10:58:46 +0000 (19:58 +0900)
committerPaul Mundt <lethal@linux-sh.org>
Thu, 14 Feb 2008 05:22:09 +0000 (14:22 +0900)
This patch adds byte support to the sign extension code. Unaligned access
traps should never be generated on 8-bit io operations, but we will use this
code for trapped io and we do need byte support there.

Signed-off-by: Magnus Damm <damm@igel.co.jp>
Signed-off-by: Paul Mundt <lethal@linux-sh.org>
arch/sh/kernel/traps_32.c

index 7154a7b..2e7dd2e 100644 (file)
@@ -150,14 +150,24 @@ static int die_if_no_fixup(const char * str, struct pt_regs * regs, long err)
 static inline void sign_extend(unsigned int count, unsigned char *dst)
 {
 #ifdef __LITTLE_ENDIAN__
+       if ((count == 1) && dst[0] & 0x80) {
+               dst[1] = 0xff;
+               dst[2] = 0xff;
+               dst[3] = 0xff;
+       }
        if ((count == 2) && dst[1] & 0x80) {
                dst[2] = 0xff;
                dst[3] = 0xff;
        }
 #else
-       if ((count == 2) && dst[2] & 0x80) {
+       if ((count == 1) && dst[3] & 0x80) {
+               dst[2] = 0xff;
+               dst[1] = 0xff;
                dst[0] = 0xff;
+       }
+       if ((count == 2) && dst[2] & 0x80) {
                dst[1] = 0xff;
+               dst[0] = 0xff;
        }
 #endif
 }