PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

StrongARM instruction set and opcode list

Anybody got any idea where I can find a complete list of StrongARM assembly instructions and information on opcode encoding?

Thanks

Jon
Intel's site for the StrongARM documentation.

A copy of the ARM Architectural Reference Manual (the "ARM ARM") would also be worth grabbing. You can either buy one... or download it from here:

http://www.altera.com/literature/lit-exc.html

(all 13MB of it)

If that doesn't answer the questions you have, yell at me and I'll go through my ARM documentation and tell you what shows you the op-code definitions (the ARM ARM should though).

If you're working on a disassembler, can I have a copy? :D

Cheers,

Ref.
Cheers Ref, you're one seriously useful guy to have around :D

Not working on a disassembler just yet, rather, I'm toying with ARM code generation at runtime for performance speedups because it looks relatively simple.

Do you ever get the feeling you're digging yourself a <i>massive</i> hole to fall into? :D
i also want the disassembler :) But i want a profiler even more! Do you guys know of a profiler that works from eVC and profiles actual ARM executables on the device?

cryo
angedelamort · 04 Sep 2002, 19:26 UTC
I think you should write your own profiler. It will be a lot more efficient and you should know where your bottle neck are.

But, here what I found to create a real memory profiler under EVC.

If you use the option -Gh when you compile, the compiler will add penter() and pexit() at each of your function. You only have to reimplement those function to calculate the time or the number of time the function is called. It's not really difficult, but don't forget that those call are called in each function. So, that will slow down considerably your application.

So, if anyone is going to release a good profiler, I will be interested for sure :P
Pardon my lack of knowledge here...but what is a profiler...?
BurningSheep · 04 Sep 2002, 21:35 UTC
A profiler keeps track of the execution time of parts of your code (functions for example). You use it to optimize your code and isolate performance bottlenecks. In Visual C++ there is a build in profiler (build->profile).
angedelamort · 04 Sep 2002, 21:44 UTC
How to explain it easyly... it's to help you to profile your progam :P

Here an example of what a profiler can do:

Code:

//code here
BEGIN_PROFILER(DRAWING);
draw()
END_PROFILER();


So the output could be like this:

Total running time: 60 sec
total drawing time: 30 sec


So, you know that your drawing routine is taking 50% of the program time.

This is the main idea. It's to calculate information about your running program. It's really usefull to optimize your works.

Hope it help ya to understand.
-Gh is no longer supported in the current CE ARM compiler. It's present in the version shipped with EVC 3.0 (although not officially supported), but don't expect anything your write to rely on _penter/_pexit to work in future versions of the compiler.

Malmer I can't believe you don't know what a profiler is. Shame on you! :)
refractor wrote:
Intel's site for the StrongARM documentation.

A copy of the ARM Architectural Reference Manual (the "ARM ARM") would also be worth grabbing. You can either buy one... or download it from here:

http://www.altera.com/literature/lit-exc.html

(all 13MB of it)

If that doesn't answer the questions you have, yell at me and I'll go through my ARM documentation and tell you what shows you the op-code definitions (the ARM ARM should though).

If you're working on a disassembler, can I have a copy? :D

Cheers,

Ref.


err i though there were dissamlblers already... dunno but i know thats what the crackers use.
I know this isn't exactly the right place to ask, but this is my thread and I'll do what I want with it :D 8O

Although I used to do loads of x86 asm in my more youthful days, I'm having difficulty getting my head around the actual operation of the LEA instruction.

As far as I can see, "LEA AX,[1234]" does exactly the same as "MOV AX,1234" - but I'm not entirely convinced. Especially given that I was looking through some old code in DOS debug last night (what a great program :wink: ) and LEA instructions seem to use segment overrides.

If anybody could shed any light on this, it's driving me crazy! All the documentation I've read really skims over the issue...
Jadam:

Yes, you're right, there are disassemblers... but so far as I know, there's nothing that does in-place disassembly on the PDAs. For Windows, the IDAPro disassembler is rather nice. I currently use my old ARM-based RiscPC to disassemble stuff. :)

Not working on a disassembler just yet, rather, I'm toying with ARM code generation at runtime for performance speedups because it looks relatively simple.

Do you ever get the feeling you're digging yourself a massive hole to fall into?


Run-time code generation is "dicey" on later ARM processors (and lots of other processors). The main problem area is the Harvard-cache. The problem is between the "data" area (where your generated code will be written) and the "instruction" area.

IIRC, if you write into the data area, it doesn't invalidate the instruction area, so it potentially uses "old" code and goes "bang".

So, if you're using self-generating code, or self-modifying code on the StrongARM (presumably the XScale too), you have to flush the cache lines that you've written the code to before you branch into it.. and flushing the cache is *expensive*.

Digby:
but don't expect anything your write to rely on _penter/_pexit to work in future versions of the compiler.


Argh, shit! :(

Cheers,

Ref.
jont wrote:
Do you ever get the feeling you're digging yourself a <i>massive</i> hole to fall into? :D


Ref, looks like I've just got the spade out of the shed and am ready to start digging :)

According to the ARM ARM (not quoted cos it won't let me copy/paste :( so you're stuck with my interpretation) --

Each ARM architecture provides something called an <i>Instruction Memory Barrier</i> sequence which must be executed after the new instructions have been loaded to memory, but before they are executed. This enables the use of self-modifying code.

However, the ARM software interrupts that faciliate this are mostly permitted only to priveleged mode programs and not to user programs. Therefore it is normally necessary to rely on operating system calls that allow access to this feature.

It's also possible to specify a range of addresses to which self modifying code can be reliably stored and executed. This is done in the same way (using interrupts), and the start and end addresses are
placed in registers.

And a brief quote:

"On some ARM implementations, the execution time cost of an IMB can be very large (many thousands of clock cycles), even when a small address size is specified. For small-scale uses of self-modifying code, this is likely to lead to a major loss of performance".

Ref, I'm guessing that the overall effect of what's described here is going to be similar to flushing the instruction cache prior to execution of self-modifying code.

What do you reckon?
(The Adobe Acrobat Reader has a text selection tool for copy and paste).

The ARM IMB should indeed be an instruction cache flush.

From the Intel StrongARM FAQ <a href="http://www.intel.com/design/pca/applicationsprocessors/faq/sa1110faq.htm#3.0">(cache section)</a> :

Question: How long does it take to flush the Icache and Dcache?

Resolution: Although the term flush is used, it is not an accurate way to describe what is actually being done to the Icache. The Icache is invalidated immediately with a single coprocessor write, but not flushed. (See Section 6.1.2.1 of the Developer's Manual).

The Dcache is flushed by first forcing a writeback that requires doing 2048 word (8192 byte) load from a cache flush area. This forces write backs of any dirty lines to prevent the loss of data. The time required is the run time of the code to do the loads plus the time required to write back the dirty lines. Since the number of dirty lines is unknown, the write back time can be variable. If the Icache is enabled, and the loads are from the flush area, the instructions execute at core speed. Only the upper half (4 words) of a dirty dcache line is written back if the lower half of the cache line is not dirty, and likewise only the lower half of a dirty cache line is written back if the upper half of the line is not dirty. There is a description of this in section 6.2.3 of the manual.


Unless you're "making" a lot of code, and it's going to run significantly faster than a generic function, personally I wouldn't touch self-modifying code with a barge-pole...

I'm not sure if it's possible, but mapping the same area into logical space twice, once cached, and once uncached might work. You could store the code to uncached, unbuffered, memory (avoiding the data cache... it'll be slow storing it though), and then branch into the cached area so it gets cached and buffered in the instruction cache(and runs quickly). However, you might still run into the same problem if some of the cached-mapped space gets loaded into the instruction cache before you hit it.

I guess it really depends how "often" you want to use the generated code. If you want to generate code once and use it a lot, the above method would be worth considering... if you want to make different code very frequently, I'd forget it...

Cheers,

Ref.
So I guess the best solution lies in generating optimized code, reusing it as often as possible and invalidating the instruction cache as seldom as possible. I'm getting some real good ideas here...

I'm guessing the answer will be no here, but any idea if the IMB interrupt calls or instruction cache invalidate instructions are available to user-level programs in Pocket PC 2002? I have a feeling I'm heading into hard-reset territory on my ipaq :)

Cheers
That last post was from me by the way :)
I believe it'll a coprocessor instruction on the StrongARM (co-pro 15 is the only one implemented too I think).

You might have to try and force the processor into supervisor mode to access the "coprocessor", and I'm not entirely sure PocketPC2002 will let you do that. It's definitely worth a try though, because I've been doing some low-level stuff and it hasn't complained at all so far to me (though I've not tried changing modes).

You want to look at the MRS and MSR instructions - move the current processor status register (CPSR) into a general purpose register, clear the bottom 5 bits, set it to 11001 (supervisor mode) and shove it back into the CPSR (using the copro, IIRC) and see what happens. I can post more detailed code to do that tomorrow if you need it (though I'd just cut and paste from an interrupt service routine, so you might have better luck elsewhere or trying it out yourself)....

Hope that helps,

Ref.
(Sorry, I should've said, I would think that any cache-flushing routines are buried somewhere in the vendor-specific part of the kernel and would be hard to find and pretty inaccessible/inhospitable to user routines).
Look for CacheSync in the Platform Builder docs.
So my general understanding here is that we've hit a dead end if trying to do things "officially" and the only way is dirty hacks that undermine the operating system?

Presumably, even if I did somehow manage to link and run the CacheSync() function, it would make an assumption that the current flow of execution was within the kernel rather than a user program, with less than desirable results.

Apologies if it sounds like I don't know what I'm talking about - that's because I'm not sure that I do :D
lea is load effective address. It's used mostly to add two or more operands to create an effective address. Stack vars, for instance, usually are relative ebp, so lea ebx,[ebp+4] adds 4 to ebp and returns the result in ebx. You can also use a scale (+4 would be index of ebp) such as lea ebx,[ebp+esi*4]. This instruction is also used as a fast multiplier, for a limited set of multipliers (can also add in an index to get x5, etc.). mov ebx, offset * works the same as a simple lea ebx, offset, but mov won't do for stack vars, and it doesn't index, and it doesn't scale, and none of this is in an ARM.
jadam":3dsrv52q]


nah, we ahem THEY just use IDA.
Anon: Thanks for the reply.
I'm aware that lea is nothing to do with ARM (I did tons of x86 asm in the old days but years of self-abuse have erased the important bits), but thought an ARM assembly thread might attract some x86 types :)
So if I restrict myself to 286 instructions in real mode then I can pretty much assume that "lea reg16,[adr]" is the same as "mov reg16,number" ?
Cheers
You can call CacheSync from an app. I use it to flush the data cache each time I run a series of my memory bandwidth benchmarks.
Digby

Sorry to sound like an idiot, but will I need Platform Builder SDK to access the CacheSync function? I don't appear to have pkfuncs in any of my include directories, or anywhere else on my HDD for that matter.

Cheers
You'll need the pkfuncs.h file from somewhere, yes... :wink:
Time to go rooting through the yellow CDs in MSDN library then I guess :) working for a software dev company has some benefits ...