All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Chris Friesen" <cfriesen@nortel.com>
To: linuxppc-dev@ozlabs.org
Subject: help with inline assembly code?
Date: Fri, 24 Apr 2009 11:22:52 -0600	[thread overview]
Message-ID: <49F1F56C.8000708@nortel.com> (raw)

Hi,

I've got a function that is used to overwrite opcodes in order to create 
self-modifying code.  It worked just fine with previous compilers, but 
with gcc 4.3 it seems like it sometimes (but not always) causes problems 
when inlined.  If I force it to never be inlined, it works fine.

First, here's the code:

void alter_opcode(unsigned long *addr, unsigned long opcode)
{
	asm volatile(
                 "stw    %1,0(%0)	\n\t"
                 "dcbf   0,%0		\n\t"
                 "sync			\n\t"
                 "icbi   0,%0,		\n\t"
                 "isync			\n\t"
                     :: "r" (addr), "r" (opcode): "memory");
}

The symptom of the problem is a segfault on the "stw" instruction.  I've 
verified that the address it's trying to write to is the expected 
address, and that the opcode being written is the expected opcode.

I assume I've mixed up the registers or constraints or 
something...anyone want to take a crack at it?

Chris

             reply	other threads:[~2009-04-24 17:23 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-04-24 17:22 Chris Friesen [this message]
2009-04-24 17:34 ` help with inline assembly code? Scott Wood
2009-04-24 18:06   ` Chris Friesen
2009-04-24 18:14     ` Scott Wood
2009-04-24 18:23       ` Chris Friesen

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=49F1F56C.8000708@nortel.com \
    --to=cfriesen@nortel.com \
    --cc=linuxppc-dev@ozlabs.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.