This site is no longer active and is available for archival purposes only. Registration and login is disabled.

Arm Self Modifying code


Arm Self Modifying code

Postby GlenCook » May 9, 2004 @ 10:25pm

Hi,

Has anyone successfully got self modifying code to run on a PPC. I've been having a go at it, but keep getting access violations.

Here is a snippet of code that is causing the problems

3402F764 E3833A02 orr r3, r3, #2, 20
3402F768 E1CF31B4 strh r3, [pc, #0x14]
3402F76C E38CC040 orr r12, r12, #0x40
3402F770 E1A00086 mov r0, r6, lsl #1
3402F774 E1A02586 mov r2, r6, lsl #11
3402F778 E1800002 orr r0, r0, r2
3402F77C E1A02B86 mov r2, r6, lsl #23
3402F780 E1800002 orr r0, r0, r2
3402F784 E3A02000 mov r2, #0

The code at #3402f768 is storing a count value to modify the last mov r2,#number.

Due to paging, the PC is set to #0002f768

Anyone have any ideas?

Thanks

Glen.
GlenCook
pm Member
 
Posts: 6
Joined: Mar 6, 2004 @ 1:59pm
Location: UK


Postby refractor » May 9, 2004 @ 11:41pm

Essentially you need an "IMB" (Instruction Memory Barrier) between your code modification and hitting the code that you've modified... well, unless the block of memory you're executing is uncached, and unbuffered (i.e. slow as hell).

If the memory is buffered (but not cached), you'll "only" have to flush the write buffer to get the data out and back into the right place, before you run it.

If the memory is cached, due to the fun of having a separate instruction and data cache, you have to flush the data cache, flush the write buffer, and then flush the instruction cache.

Thus, self-modification is costly, don't bother unless you're going to use the modified-code lots.

Apart from that the code looks reasonable to me - you've adjusted for the pipeline, which is what gets most people.
User avatar
refractor
pm Insider
 
Posts: 2304
Joined: Feb 5, 2002 @ 1:12pm
Location: Luxembourg


Postby GlenCook » May 9, 2004 @ 11:52pm

GlenCook
pm Member
 
Posts: 6
Joined: Mar 6, 2004 @ 1:59pm
Location: UK


Postby Tala » May 10, 2004 @ 1:53am

Tala
pm Member
 
Posts: 125
Joined: Feb 6, 2004 @ 4:32pm


Postby hm » May 10, 2004 @ 2:47am

User avatar
hm
pm Member
 
Posts: 201
Joined: Dec 28, 2003 @ 8:47pm
Location: Seattle, WA


Postby drgoldie » May 10, 2004 @ 11:38am

drgoldie
pm Member
 
Posts: 330
Joined: Jan 10, 2003 @ 10:46am
Location: Vienna


Postby hm » May 10, 2004 @ 5:01pm

User avatar
hm
pm Member
 
Posts: 201
Joined: Dec 28, 2003 @ 8:47pm
Location: Seattle, WA


Return to Windows Mobile


Sort


Forum Description

A discussion forum for mobile device developers on the Windows Mobile platform. Any platform specific topics are welcome.

Moderators:

Dan East, sponge, Digby, David Horn, Kevin Gelso, RICoder

Forum permissions

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum