flat assembler
Message board for the users of flat assembler.

Index > Non-x86 architectures > FASMARM v1.43 - Cross assembler for ARM CPUs

Goto page Previous  1, 2, 3, 4, 5 ... 29, 30, 31  Next
Author
Thread Post new topic Reply to topic
Giant



Joined: 10 Feb 2006
Posts: 14
Giant
Revolution, thank you so very, very much! I just ran my first fasm executable on the gumstix:
Code:
format ELF executable
entry start
section readable writeable executable
code32
start:
        mov     r0,7            ;proof!
        swi     0x900001      ;syscall exit
        
section readable writeable
        test_data dd 0
    

Then, using a hex editor I modified byte 12h of the file to 28h (40 DECIMAL!) to set the arm architecture flag on.

I then tested it with a:
#./fhello ; echo $?
#7


I am extremely excited. Thank you for your help.

I am sure something will backfire with the data section or something else... But at least I have a starting point. Please let me know if I can be of any help with incorporating these things into the next version.
Post 13 Feb 2006, 22:00
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 16882
Location: In your JS exploiting you and your system
revolution
Quote:
28h (40 DECIMAL!)
Oops, sorry to give you wrong information in my previous post, yep, 40 decimal (not hex) is definitely the correct value.

I will attempt to make a quick patch for the existing version (1.04) but still intended to work with FASM v1.64. That should save you having to use a hex editor all the time. What value do you need for the flags to for it work correctly?

Quote:
Please let me know if I can be of any help with incorporating these things into the next version.
If you could make a "hello world" example then I can incorporate it into the examples.

BTW: Just to remind you that the ARM "word" is 32 bits, so your example above has this ...
Code:
test_data dd 0    
... which may not give you what you expected. The DD operator is for 64 bit data.

You may find these macros helpful also. They are intended for PC relative addressing in ARM mode.:
Code:
macro adr reg,location {
        add reg,pc,location-$-8
}

macro adrl reg,location {
        sub reg,pc,(-location+$+8) and (0ffh shl 2)
        sub reg,reg,(-location+$+4) and (0ffffff00h shl 2)
}    


Last edited by revolution on 22 Feb 2010, 12:59; edited 1 time in total
Post 14 Feb 2006, 02:15
View user's profile Send private message Visit poster's website Reply with quote
Giant



Joined: 10 Feb 2006
Posts: 14
Giant
Revolution, here is the source for arm-linux-as. I hacked it from the c-compiled code (god, my eyes still reel from the sheer ugliness! No wonder all current appls are megabytes of code - gcc is atrocious!). I know there is a better way to load a pc-relative address of the string... I am still stumbling around with the ARM architecture
Code:
        .file   "hello.c"
        .text
        .align  2
        .global _start
_start:
        mov     r0,#0                   @ out
        ldr     r1, .L7
        mov     r2,#12
        swi     0x900004

        mov     r0,#6
        swi     0x900001
        .align  2
.L7:
        .word   .LC0
        .size   _start,.-_start

        .section        .rodata
        .align  2
.LC0:
        .ascii  "Hello World\n\000"
        .ident  "Giant"
    

After assembly and linkage with no startup code it becomes:
Code:
0000000: 7f45 4c46 0101 0161 0000 0000 0000 0000  .ELF...a........
0000010: 0200 2800 0100 0000 7480 0000 3400 0000  ..(.....t...4...
0000020: d400 0000 0202 0000 3400 2000 0200 2800  ........4. ...(.
0000030: 0700 0600 0100 0000 0000 0000 0080 0000  ................
0000040: 0080 0000 a000 0000 a000 0000 0500 0000  ................
0000050: 0080 0000 0100 0000 a000 0000 a000 0100  ................
0000060: a000 0100 0000 0000 0000 0000 0600 0000  ................
0000070: 0080 0000 0000 a0e3 0c10 9fe5 0c20 a0e3  ............. ..
0000080: 0400 90ef 0600 a0e3 0100 90ef 9080 0000  ................
0000090: 4865 6c6c 6f20 576f 726c 640a 0000 0000  Hello World.....
00000a0: 0047 6961 6e74 0000 2e73 6873 7472 7461  .Giant...shstrta
00000b0: 6200 2e74 6578 7400 2e72 6f64 6174 6100  b..text..rodata.
00000c0: 2e64 6174 6100 2e62 7373 002e 636f 6d6d  .data..bss..comm
00000d0: 656e 7400 0000 0000 0000 0000 0000 0000  ent.............
00000e0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000f0: 0000 0000 0000 0000 0000 0000 0b00 0000  ................
0000100: 0100 0000 0600 0000 7480 0000 7400 0000  ........t...t...
0000110: 1c00 0000 0000 0000 0000 0000 0400 0000  ................
0000120: 0000 0000 1100 0000 0100 0000 0200 0000  ................
0000130: 9080 0000 9000 0000 1000 0000 0000 0000  ................
0000140: 0000 0000 0400 0000 0000 0000 1900 0000  ................
0000150: 0100 0000 0300 0000 a000 0100 a000 0000  ................
0000160: 0000 0000 0000 0000 0000 0000 0100 0000  ................
0000170: 0000 0000 1f00 0000 0800 0000 0300 0000  ................
0000180: a000 0100 a000 0000 0000 0000 0000 0000  ................
0000190: 0000 0000 0100 0000 0000 0000 2400 0000  ............$...
00001a0: 0100 0000 0000 0000 0000 0000 a000 0000  ................
00001b0: 0700 0000 0000 0000 0000 0000 0100 0000  ................
00001c0: 0000 0000 0100 0000 0300 0000 0000 0000  ................
00001d0: 0000 0000 a700 0000 2d00 0000 0000 0000  ........-.......
00001e0: 0000 0000 0100 0000 0000 0000            ............    


I will post a fasm version of hello world tomorrow.
Post 14 Feb 2006, 02:36
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 16882
Location: In your JS exploiting you and your system
revolution
Given the dump above it seems gnu does not follow the ELF specifications. Although that is not suprising really because ARM also don't even follow there own specifications.

Based on the above I have updated the code in the first page of this thread to version 1.05 to give basic support for elf executable format and included a hello world example in elf format. But it is untested, feel free to test it if you get a chance.
Post 14 Feb 2006, 05:30
View user's profile Send private message Visit poster's website Reply with quote
Giant



Joined: 10 Feb 2006
Posts: 14
Giant
I haven't had a chance to assemble the example provided in 1.05, but I remember not being able to assemble the SWI instructions without code32...
Post 14 Feb 2006, 14:25
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 16882
Location: In your JS exploiting you and your system
revolution
Quote:
armelf.asm needs code32
But I have updated the elf executable code to set the the code type to code32 by default. I assembled the example as given and included the executable in the download. However also including a code32 directive will do no harm so you can place it if you want.
Post 14 Feb 2006, 15:31
View user's profile Send private message Visit poster's website Reply with quote
Artlav



Joined: 23 Dec 2004
Posts: 188
Location: Moscow, Russia
Artlav
Well done, revolution!
armelf assembles and runs fine without any hexeditor mods.
Tested at Cacko linux 1.23 on Xscale-PXA270 (armv4l).

Btw, anyone tryed running fasmarm on the arm host with qemu?
It runs fine, but takes about half-a-minute to assemble armelf.
And, somewhy, it says 2419000.0 seconds of run-time instead of 24.19. No other bugs noticed.
Post 14 Feb 2006, 16:41
View user's profile Send private message Visit poster's website Reply with quote
Giant



Joined: 10 Feb 2006
Posts: 14
Giant
400MHz Intel XScale PXA255 (arm5te) on gumstix linux kernel 2.6.15gum works. Thank you
Post 14 Feb 2006, 21:01
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7106
Location: Slovakia
vid
revolution move FASM-ARM version to projects section please...
Post 15 Feb 2006, 14:40
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 16882
Location: In your JS exploiting you and your system
revolution
Quote:
revolution move FASM-ARM version to projects section please...
You mean we can move threads around? How to do that?
Post 15 Feb 2006, 17:01
View user's profile Send private message Visit poster's website Reply with quote
decard



Joined: 11 Sep 2003
Posts: 1095
Location: Poland
decard
No, you need to be a moderator to do that.
I've just moved it Smile
Post 15 Feb 2006, 17:28
View user's profile Send private message Visit poster's website Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7106
Location: Slovakia
vid
i meant new thread... with relevant first post and moderated rest... but this is also okay. It would be best if everyone could moderate his own project thread to keep it clear, but i am not sure if it is possible with phpBB
Post 15 Feb 2006, 17:42
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7106
Location: Slovakia
vid
doesn't arm have any instructions working with 8bit arguments?
Post 23 Feb 2006, 19:05
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 16882
Location: In your JS exploiting you and your system
revolution
Quote:
doesn't arm have any instructions working with 8bit arguments?
The architechure is LOAD/OP/STORE, that means all OP's work with 32 bits. The LDR and STR instructions can work with 8, 16, 32 and 64 bit data sizes, both with zero extension or signed extension. Check the manual for LDRH, LDRSH, LDRB, LDRSB, LDRD and the equivalent STR versions.
Post 24 Feb 2006, 01:01
View user's profile Send private message Visit poster's website Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7106
Location: Slovakia
vid
so if you changed meaning of "word" to 32 bits, then what is size operator for 8 and 16?
Post 24 Feb 2006, 04:39
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 16882
Location: In your JS exploiting you and your system
revolution
8 bit is BYTE, 16 bit is HALF WORD, 32 bit is WORD, 64 bit is DOUBLE WORD. Respectively, DB, DH, DW, DD and RB, RH, RW, RD. This from the readme.txt in the download:
Code:
X86  ARM  comment
---+----+---------
DB | DB | same: 8 bits
DW | DH | half word: 16 bits
DU | DU | same: 16 bits
DD | DW | word: 32 bits
DQ | DD | double word: 64 bits
RB | RB | same: 8 bits
RW | RH | half word: 16 bits
RD | RW | word: 32 bits
RQ | RD | double word: 64 bits
DF | -- |  not valid
DP | -- |  not valid
DT | -- |  not valid
RF | -- |  not valid
RP | -- |  not valid
RT | -- |  not valid    
Post 24 Feb 2006, 05:19
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 16882
Location: In your JS exploiting you and your system
revolution
Quote:
then what is size operator for 8 and 16?
I think I misread your question the first time. The operators are BYTE, HWORD, WORD, DWORD. Try this:
Code:
code32

virtual at 0
  var_d  dd 8
  var_w  dw 4
  var_h  dh 2,2
  var_b  db 1,1,1,1
end virtual

ldrb r1,byte[r2,var_d]
ldrb r1,byte[r2,var_w]
ldrb r1,byte[r2,var_h]
ldrb r1,    [r2,var_b]

ldrbt r1,byte[r2],var_d
ldrbt r1,byte[r2],var_w
ldrbt r1,byte[r2],var_h
ldrbt r1,    [r2],var_b

        ;armv4

ldrsb r1,byte[r2,var_d]
ldrsb r1,byte[r2,var_w]
ldrsb r1,byte[r2,var_h]
ldrsb r1,    [r2,var_b]

ldrh r1,hword[r2,var_d]
ldrh r1,hword[r2,var_w]
ldrh r1,     [r2,var_h]
ldrh r1,hword[r2,var_b]

ldrsh r1,hword[r2,var_d]
ldrsh r1,hword[r2,var_w]
ldrsh r1,     [r2,var_h]
ldrsh r1,hword[r2,var_b]

        ;armv1

ldr r1,word[r2,var_d]
ldr r1,    [r2,var_w]
ldr r1,word[r2,var_h]
ldr r1,word[r2,var_b]

ldrt r1,word[r2],var_d
ldrt r1,    [r2],var_w
ldrt r1,word[r2],var_h
ldrt r1,word[r2],var_b

        ;armv5te

ldrd r2,     [r4,var_d]
ldrd r2,dword[r4,var_w]
ldrd r2,dword[r4,var_h]
ldrd r2,dword[r4,var_b]

        ;armv1

strb r1,byte[r2,var_d]
strb r1,byte[r2,var_w]
strb r1,byte[r2,var_h]
strb r1,    [r2,var_b]

strbt r1,byte[r2],var_d
strbt r1,byte[r2],var_w
strbt r1,byte[r2],var_h
strbt r1,    [r2],var_b

        ;armv4

strh r1,hword[r2,var_d]
strh r1,hword[r2,var_w]
strh r1,     [r2,var_h]
strh r1,hword[r2,var_b]

        ;armv1

str r1,word[r2,var_d]
str r1,    [r2,var_w]
str r1,word[r2,var_h]
str r1,word[r2,var_b]

strt r1,word[r2],var_d
strt r1,    [r2],var_w
strt r1,word[r2],var_h
strt r1,word[r2],var_b

        ;armv5te

strd r2,     [r4,var_d]
strd r2,dword[r4,var_w]
strd r2,dword[r4,var_h]
strd r2,dword[r4,var_b]

code16

ldr r1,word[r2,var_d]
ldr r1,    [r2,var_w]
ldr r1,word[r2,var_h]
ldr r1,word[r2,var_b]

ldrb r1,byte[r2,var_d]
ldrb r1,byte[r2,var_w]
ldrb r1,byte[r2,var_h]
ldrb r1,    [r2,var_b]

ldrh r1,hword[r2,var_d]
ldrh r1,hword[r2,var_w]
ldrh r1,     [r2,var_h]
ldrh r1,hword[r2,var_b]

str r1,word[r2,var_d]
str r1,    [r2,var_w]
str r1,word[r2,var_h]
str r1,word[r2,var_b]

strb r1,byte[r2,var_d]
strb r1,byte[r2,var_w]
strb r1,byte[r2,var_h]
strb r1,    [r2,var_b]

strh r1,hword[r2,var_d]
strh r1,hword[r2,var_w]
strh r1,     [r2,var_h]
strh r1,hword[r2,var_b]    
Post 24 Feb 2006, 05:39
View user's profile Send private message Visit poster's website Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7106
Location: Slovakia
vid
revolution: well, i don't have any device to run it Sad
Post 24 Feb 2006, 05:46
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Giant



Joined: 10 Feb 2006
Posts: 14
Giant
Here is a problem:

Code:
myreg equ r1
ldmia myreg!,{r0,lr}
    


ldmia does not work; somehow the ! is not parsed correctly unless the register preceding it is a real (not equated) ARM register...
Post 27 Feb 2006, 18:47
View user's profile Send private message Reply with quote
UCM



Joined: 25 Feb 2005
Posts: 285
Location: Canada
UCM
maybe you would want to use fix instead of equ for a temporary replacement.
Post 27 Feb 2006, 23:11
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page Previous  1, 2, 3, 4, 5 ... 29, 30, 31  Next

< Last Thread | Next Thread >
Forum Rules:
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 vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2019, Tomasz Grysztar.

Powered by rwasa.