From: "Chris Friesen" <cfriesen@nortel.com>
To: Scott Wood <scottwood@freescale.com>
Cc: linuxppc-dev@ozlabs.org
Subject: Re: help with inline assembly code?
Date: Fri, 24 Apr 2009 12:06:16 -0600 [thread overview]
Message-ID: <49F1FF98.1000100@nortel.com> (raw)
In-Reply-To: <49F1F841.8080507@freescale.com>
Scott Wood wrote:
> 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?
Verified by running it in userspace under gdb, then looking at the
registers listed in the disassembly and comparing it to the process maps.
>> 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.
Bingo! Is there a constraint to tell the compiler to not use r0 for addr?
Chris
next prev parent reply other threads:[~2009-04-24 18:10 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
2009-04-24 18:06 ` Chris Friesen [this message]
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=49F1FF98.1000100@nortel.com \
--to=cfriesen@nortel.com \
--cc=linuxppc-dev@ozlabs.org \
--cc=scottwood@freescale.com \
/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 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).