linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ppc32: emulate load/store string instructions
@ 2005-03-11 22:12 Kumar Gala
  2005-03-19 14:36 ` Segher Boessenkool
  0 siblings, 1 reply; 4+ messages in thread
From: Kumar Gala @ 2005-03-11 22:12 UTC (permalink / raw)
  To: Andrew Morton; +Cc: linux-kernel, linuxppc-embedded

Andrew,

Some Book-E implementations (e500) do not implement the userland 
load/store string instructions.  Apparently these instructions are rather 
painful to implement do to the fact that they modify the destination 
register differently then ever other instruction.  Matt did the inital 
work some time ago, and I finally got around to cleaning it up.

Signed-off-by: Matt McClintock
Signed-off-by: Kumar Gala <kumar.gala@freescale.com>

---

diff -Nru a/arch/ppc/kernel/traps.c b/arch/ppc/kernel/traps.c
--- a/arch/ppc/kernel/traps.c	2005-03-11 15:07:28 -06:00
+++ b/arch/ppc/kernel/traps.c	2005-03-11 15:07:28 -06:00
@@ -389,6 +389,87 @@
 #define INST_MCRXR		0x7c000400
 #define INST_MCRXR_MASK		0x7c0007fe
 
+#define INST_STRING		0x7c00042a
+#define INST_STRING_MASK	0x7c0007fe
+#define INST_STRING_GEN_MASK	0x7c00067e
+#define INST_LSWI		0x7c0004aa
+#define INST_LSWX		0x7c00042a
+#define INST_STSWI		0x7c0005aa
+#define INST_STSWX		0x7c00052a
+
+static int emulate_string_inst(struct pt_regs *regs, u32 instword)
+{
+	u8 rT = (instword >> 21) & 0x1f;
+	u8 rA = (instword >> 16) & 0x1f;
+	u8 NB_RB = (instword >> 11) & 0x1f;
+	u32 num_bytes;
+	u32 EA;
+	int pos = 0;
+
+	/* Early out if we are an invalid form of lswx */
+	if ((instword & INST_STRING_MASK) == INST_LSWX)
+		if ((rA >= rT) || (NB_RB >= rT) || (rT == rA) || (rT == NB_RB))
+			return -EINVAL;
+
+	/* Early out if we are an invalid form of lswi */
+	if ((instword & INST_STRING_MASK) == INST_LSWX)
+		if ((rA >= rT) || (rT == rA))
+			return -EINVAL;
+
+	EA = (rA == 0) ? 0 : regs->gpr[rA];
+
+	switch (instword & INST_STRING_MASK) {
+		case INST_LSWX:
+		case INST_STSWX:
+			EA += NB_RB;
+			num_bytes = regs->xer & 0x7f;
+			break;
+		case INST_LSWI:
+		case INST_STSWI:
+			num_bytes = (NB_RB == 0) ? 32 : NB_RB;
+			break;
+		default:
+			return -EINVAL;
+	}
+
+	while (num_bytes != 0)
+	{
+		u8 val;
+		u32 shift = 8 * (3 - (pos & 0x3));
+
+		switch ((instword & INST_STRING_MASK)) {
+			case INST_LSWX:
+			case INST_LSWI:
+				if (get_user(val, (u8 __user *)EA))
+					return -EFAULT;
+				/* first time updating this reg,
+				 * zero it out */
+				if (pos == 0)
+					regs->gpr[rT] = 0;
+				regs->gpr[rT] |= val << shift;
+				break;
+			case INST_STSWI:
+			case INST_STSWX:
+				val = regs->gpr[rT] >> shift;
+				if (put_user(val, (u8 __user *)EA))
+					return -EFAULT;
+				break;
+		}
+		/* move EA to next address */
+		EA += 1;
+		num_bytes--;
+
+		/* manage our position within the register */
+		if (++pos == 4) {
+			pos = 0;
+			if (++rT == 32)
+				rT = 0;
+		}
+	}
+
+	return 0;
+}
+
 static int emulate_instruction(struct pt_regs *regs)
 {
 	u32 instword;
@@ -422,6 +503,10 @@
 		regs->xer &= ~0xf0000000UL;
 		return 0;
 	}
+
+	/* Emulate load/store string insn. */
+	if ((instword & INST_STRING_GEN_MASK) == INST_STRING)
+		return emulate_string_inst(regs, instword);
 
 	return -EINVAL;
 }

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] ppc32: emulate load/store string instructions
  2005-03-11 22:12 [PATCH] ppc32: emulate load/store string instructions Kumar Gala
@ 2005-03-19 14:36 ` Segher Boessenkool
  2005-03-21 15:29   ` Kumar Gala
  0 siblings, 1 reply; 4+ messages in thread
From: Segher Boessenkool @ 2005-03-19 14:36 UTC (permalink / raw)
  To: Kumar Gala; +Cc: Andrew Morton, linux-kernel, linuxppc-embedded

> +	/* Early out if we are an invalid form of lswi */
> +	if ((instword & INST_STRING_MASK) == INST_LSWX)

Typo --------------------------------------------^


Segher

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] ppc32: emulate load/store string instructions
  2005-03-19 14:36 ` Segher Boessenkool
@ 2005-03-21 15:29   ` Kumar Gala
  2005-03-21 15:39     ` [PATCH] ppc32: typo fix in load/store string emulation Kumar Gala
  0 siblings, 1 reply; 4+ messages in thread
From: Kumar Gala @ 2005-03-21 15:29 UTC (permalink / raw)
  To: Segher Boessenkool
  Cc: Andrew Morton, linux-kernel, Kumar Gala, linuxppc-embedded

Thanks, will send a patch to fix that.

- kumar

On Mar 19, 2005, at 8:36 AM, Segher Boessenkool wrote:

>> +	/* Early out if we are an invalid form of lswi */
>> +	if ((instword & INST_STRING_MASK) == INST_LSWX)
>
> Typo --------------------------------------------^
>
>
> Segher

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH] ppc32: typo fix in load/store string emulation
  2005-03-21 15:29   ` Kumar Gala
@ 2005-03-21 15:39     ` Kumar Gala
  0 siblings, 0 replies; 4+ messages in thread
From: Kumar Gala @ 2005-03-21 15:39 UTC (permalink / raw)
  To: Andrew Morton; +Cc: linux-kernel, Segher Boessenkool, linuxppc-embedded

Andrew,

Patch fixes a typo in the emulation of load/store string emulations 
pointed out by Segher Boessenkool.


Signed-off-by: Kumar Gala <kumar.gala@freescale.com>

---
diff -Nru a/arch/ppc/kernel/traps.c b/arch/ppc/kernel/traps.c
--- a/arch/ppc/kernel/traps.c	2005-03-21 09:36:28 -06:00
+++ b/arch/ppc/kernel/traps.c	2005-03-21 09:36:28 -06:00
@@ -412,7 +412,7 @@
 			return -EINVAL;
 
 	/* Early out if we are an invalid form of lswi */
-	if ((instword & INST_STRING_MASK) == INST_LSWX)
+	if ((instword & INST_STRING_MASK) == INST_LSWI)
 		if ((rA >= rT) || (rT == rA))
 			return -EINVAL;
 

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2005-03-21 15:39 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-03-11 22:12 [PATCH] ppc32: emulate load/store string instructions Kumar Gala
2005-03-19 14:36 ` Segher Boessenkool
2005-03-21 15:29   ` Kumar Gala
2005-03-21 15:39     ` [PATCH] ppc32: typo fix in load/store string emulation Kumar Gala

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).