Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 85522
b: refs/heads/master
c: 86c0179
h: refs/heads/master
v: v3
  • Loading branch information
Magnus Damm authored and Paul Mundt committed Feb 14, 2008
1 parent e9667d4 commit ca39675
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 46 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 1cfb629cfa4a8d9b65c0f60c65ec731bde82d60c
refs/heads/master: 86c0179c9307bd600a96a44d623814c33bdbe0f0
68 changes: 23 additions & 45 deletions trunk/arch/sh/kernel/traps_32.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,21 @@ static int die_if_no_fixup(const char * str, struct pt_regs * regs, long err)
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
Expand Down Expand Up @@ -178,25 +193,13 @@ static int handle_unaligned_ins(u16 instruction, struct pt_regs *regs)
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;
Expand Down Expand Up @@ -253,25 +256,12 @@ static int handle_unaligned_ins(u16 instruction, struct pt_regs *regs)
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;

Expand Down Expand Up @@ -299,21 +289,9 @@ static int handle_unaligned_ins(u16 instruction, struct pt_regs *regs)
#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;
}
Expand Down

0 comments on commit ca39675

Please sign in to comment.