Page 1 of 1

ARM is soo sweet!

Posted: Fri Jul 07, 2006 3:35 am
by Pype.Clicker
Hi.

I'm now more and more involved in ARM development. with my IXP2400 board, of course (starring a intel strongARM processor to schedule the 'microengines' behaviour), but also with my nintendo DS (which features two ARMs) ... And my Zaurus PDA also has an ARM stuff ... I think that means i now have more ARMs around me than x86 :P ... well maybe not yet, i still need to buy a couple of other devices ;)

'til yesterday, i mainly used gcc cross-compiler to program all those stuff -- and in Linux environment most of the times, so you barely notice the fact you're running on a different beast ... just the minicom's red bar reminds me i'm not in "just-another-ssh-session"

But today, i'm going into the details of ARM instruction set, and let me tell you it's way sweeter than all i've seen in x86 world. More registers, position-relative addressing (you know, that thing that is terribly missing for relocatable code on PCs :P ), conditional execution of load/store (e.g. you have load-unless-Zero-flag-is-clear, store-if-Zero-flag-is-set, and probably much more).

And the most surprising is probably the absence of a RET instruction (afaik, you just copy PC into another register) and the multi-usage-memory-swiss-knife instruction, aka "LoaD Multiple, Increase After" (ldmia for friends). That one is simply magic! let's say you want to load a whole structure into a couple of registers. Easy game. You just put your structure's address into any register (say R2) and the list of registers you want to see filled (e.g. {R3, R4, R5}) and voil?.
That also means that a function's epilog can be expressed with

Code: Select all

   add sp, sp, #4    ;  sp := sp + 4 as you may guess
   ldmia sp!, {r4, r5, pc} 
      ; fill r4 with [sp], r5 with [sp+4] and pc with [sp+8]
      ; "ia" stands for 'increment after'. there is also 'pre-increment',
      ; post-decrement and pre-decrement, as you may guess.
      ; the sp! means you want sp to be refreshed with sp+12 at
      ; the end of the instruction
okay ... x86_64 also has PC-relative access and we now have cmove to mimmic the ldreq/strne instructions. Yet i see no x86_64 around (none i can hook for osdeving, at least).

So, anyone of you targetting ARM products in your projects ? or having ARM-equipped devices handing around ?

Re:ARM is soo sweet!

Posted: Fri Jul 07, 2006 5:07 am
by AxelDominatoR
I agree with you. ARM is a simple and elegant processor. Look at features like Thumbs/Thumbs-2 and NEON. Plus it has the best instruction/watt ratio, IIRC. It is used everywhere in the embedded field. The 4 bit conditional jump on every instruction is great...I'd like to get one of those GP2X to start hacking at it. Maybe I'll target my OS at the ARM architecture, too.

Useful link to those who wish to know more about ARM:
http://en.wikipedia.org/wiki/ARM_architecture

Axel

Re:ARM is soo sweet!

Posted: Fri Jul 07, 2006 6:00 am
by Solar
Pype.Clicker wrote:So, anyone of you targetting ARM products in your projects ?
I'll pester you about putting PDCLib to the trial on your ARM devices once I get into alpha stage. ;D
or having ARM-equipped devices handing around ?
Not since they stole my HP Jornada 720 from my office some time ago. Bastards.

Re:ARM is soo sweet!

Posted: Fri Jul 07, 2006 9:29 am
by Pype.Clicker
oh... and for those who intend to port their project to ARM, let me tell you one thing: beware of padding/packing. As osdever's we tend to abuse of unaligned/unpacked things by simply checking that things work on our x86 setup ... a thing as simple as

Code: Select all

/** license warning: this is not PD at all **/
struct esphdr{
  unsigned char   version;
  unsigned char   reserved:1,
                  exec:2,
                  rb:1,
                  err:1,
                  loc:3;
  unsigned char   opcode;
  unsigned char   len;
  unsigned short  cid;
};
turns into a nightmare when ported to ARM. There are of course oddities due to moving from little-endian to big-endian architecture, but one thing i had underestimated is that sizeof(struct esphdr) will not be 6 as you might expect but rather 8! and the gcc-ARM does that everywhere. Virtually all structures are padded to fit an integer number of words (well, that's a RISC processor, so somehow it wants structures to fit nicely into arrays).

Another odd thing is that handling of those bitfields we love to use in order to express our page tables entries and the like do not behave as we expect _at all_. Coming from intel world it seemed natural to me that "reserved:1" will be the least-significant bit in a char pattern ... well, it's not. Don't ask me what occured exactly, but you definitely have to move to "unsigned char flags" and "#define ESP_ERR 16" all over the place.

Not so hard do you think ? o yeah. Now pick up a pencil and try to figure out how you're going to translate

Code: Select all

   esph.rb=0;
   esph.exec/=2;
not impossible, but not that easy either.

Re:ARM is soo sweet!

Posted: Fri Jul 07, 2006 10:37 am
by Candy
Pype.Clicker wrote: okay ... x86_64 also has PC-relative access and we now have cmove to mimmic the ldreq/strne instructions.
I was about to answer you...
Yet i see no x86_64 around (none i can hook for osdeving, at least).
I'll get my new computer set up, it's a dualcore 64-bit machine intended for OS development & testing. Throw out the hook ;)

Re:ARM is soo sweet!

Posted: Sat Jul 08, 2006 11:58 am
by ineo
Pype.Clicker wrote: oh... and for those who intend to port their project to ARM, let me tell you one thing: beware of padding/packing. As osdever's we tend to abuse of unaligned/unpacked things by simply checking that things work on our x86 setup ...
[...]
It's really hard to write a protable OS. I got the same problems on Sparc cpu with alignement requirements. I am happy that the only part impacted is cpu specific therefore it has to be rewritten and is quite small (microkernel).

Re:ARM is soo sweet!

Posted: Sat Jul 08, 2006 5:36 pm
by GLneo
So, anyone of you targetting ARM products in your projects ?
Well not my OS but I am writing an arm emulator as part of my Game boy Advance emulator, and this architecture is sweet, I wish x86 was this clean! ;D

Re:ARM is soo sweet!

Posted: Sun Jul 09, 2006 10:24 am
by oswizard
fyi, for poeple "now [looking] for something completely different"

The LEGO MINDSTORMS NXT is ARM7-based, and starting August 1, the complete hardware specification (memory mappings, etc) and firmware source code will be released by LEGO.

Re:ARM is soo sweet!

Posted: Mon Jul 10, 2006 12:57 pm
by Mark
I've been hacking on the ARM since 1988 when I got an ARM2 based Acorn Archimedes. An excelent processor to program by hand as the instruction set is nice and simple.

There are a couple of ARM emulators around. skyeye (http://www.skyeye.org/index.shtml) is a good GPL'd one.

Cheers
Mark

Re:ARM is soo sweet!

Posted: Tue Jul 11, 2006 10:42 am
by mystran
Sounds like ARM would be a lot nicer target for Lisp than x86 is. :o