All of lore.kernel.org
 help / color / mirror / Atom feed
From: Scott Wood <scottwood@freescale.com>
To: Chris Friesen <cfriesen@nortel.com>
Cc: linuxppc-dev@ozlabs.org
Subject: Re: help with inline assembly code?
Date: Fri, 24 Apr 2009 12:34:57 -0500	[thread overview]
Message-ID: <49F1F841.8080507@freescale.com> (raw)
In-Reply-To: <49F1F56C.8000708@nortel.com>

Chris Friesen wrote:
> 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, 

Verified by looking at the address in "addr", or by looking at the 
reported faulting 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?

Is the compiler assigning r0 to addr?  That will be treated as a literal 
zero instead.  Try changing "r" (addr) to "b" (addr), or use stwx.

-Scott

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

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-04-24 17:22 help with inline assembly code? Chris Friesen
2009-04-24 17:34 ` Scott Wood [this message]
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=49F1F841.8080507@freescale.com \
    --to=scottwood@freescale.com \
    --cc=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.