flat assembler
Message board for the users of flat assembler.

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

Goto page Previous  1, 2, 3 ... , 31, 32, 33  Next
Author
Thread Post new topic Reply to topic
igneele



Joined: 26 Dec 2015
Posts: 1
igneele 16 Mar 2020, 18:07
Hi, i have some strange in this code:
Code:
thumb

struc GPIO_RegMap
{
  .OTYPER dw ?
}

virtual at r1
  gpiob GPIO_RegMap
end virtual
ldr r0, [gpiob.CRL]
str r0, [gpiob.CRL]
    

If field CRL is missing in gpiob, compiler says "Error: (R15) not valid as second parameter" on str instruction, but if delete "thumb" - compiler says "Error: undefined symbol gpiob.CRL" on ldr instruction as it should... why str, r15, thumb?
Post 16 Mar 2020, 18:07
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20300
Location: In your JS exploiting you and your system
revolution 17 Mar 2020, 01:33
It's a bug. Thanks for reporting.

There are some other bugs and updates that fasmarm is due for. They ill be fixed soon hopefully.
Post 17 Mar 2020, 01:33
View user's profile Send private message Visit poster's website Reply with quote
MazeGen



Joined: 06 Oct 2003
Posts: 977
Location: Czechoslovakia
MazeGen 13 May 2020, 07:28
Are there any instructions how to build FASMARM? I can tell how to combine FASMARM sources with FASM thanks to ProMiNick's fasmpack, however, what about the compatibility? Is v1.43 compatible with the latest FASM version? I read the ReadMe but didn't find this information.

EDIT: just found this post from 2017:
revolution wrote:
revolution wrote:
Note that this version assembles against fasm v1.73.01
I have update the download package with the bug fix from fasm v1.73.02
WHATSNEW.TXT wrote:
Fixed a bug in the storage of "virtual as" blocks.
It would be nice to see this info in ReadMe.
Post 13 May 2020, 07:28
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: 20300
Location: In your JS exploiting you and your system
revolution 13 May 2020, 07:34
Because of the way the patching works, you need the matching version of fasm.

The most recent build uses 1.72.02
https://board.flatassembler.net/topic.php?p=201689#201689

From there just copy the files from fasmarm into the same folders as fasm. All the files are separate so it doesn't overwrite any files. Then change into the fasmarm folder and use fasm to compile fasmarm/fasmwarm.
Post 13 May 2020, 07:34
View user's profile Send private message Visit poster's website Reply with quote
TmEE



Joined: 19 Jun 2019
Posts: 5
Location: Estonia
TmEE 04 Feb 2021, 12:11
I'm finally starting to get back into ARM development again and I see there's been no fixes since last time I was here.

I took a look at the source code and I couldn't really see where I should dig into to fix the problem I originally described. Where should I look to make an attempt to fix it myself ?
Post 04 Feb 2021, 12:11
View user's profile Send private message Visit poster's website Reply with quote
zhak



Joined: 12 Apr 2005
Posts: 501
Location: Belarus
zhak 16 Feb 2021, 22:02
flat assembler for ARM version 1.43 (built on fasm 1.73.02)

There seems to be something wrong with ADRP instruction.
Code:
        processor cpu64_v8
        code64

        mrs x9, mpidr_el1
        tst x9, 11b
        b.eq __init
        wfe
        b.al $ - 4

__init:

        adr x9, $$
        mov sp, x9

        adrp x9, bss
        add x9, x9, bss and 0xfff
        mov x8, bss_size / 16
        stp xzr, xzr, [x9], 16
        subs x8, x8, 1
        b.gt $ - 8
        b.al $

        align 16

bss:
        align 16
bss_size = $ - bss
    

fails with error:
Code:
        adrp x9, bss
processed: adrp x9,bss
error: Address is not aligned.
    

However, changing "ADRP x9, bss" to "dw 0x90000009"
compiles and correctly disassembles into ADRP x9, 0x0
Post 16 Feb 2021, 22:02
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20300
Location: In your JS exploiting you and your system
revolution 17 Feb 2021, 02:26
Thank you for the report. I will add it to the list of things to fix when I am back to my desk.

The problem appears to be with adrp trying to use labels defined later in the source.

Also: Note that your bss_size is zero.
Post 17 Feb 2021, 02:26
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: 20300
Location: In your JS exploiting you and your system
revolution 17 Feb 2021, 08:03
You can apply a temporary fix around line 24774 in armv8.asm:
Code:
;...
ARM64_adr:
        ;used by ADR, ADRP
        call    decode_template
    TEMPLATE \
        <TMPL_dword_z_reg,TMPL_address64>       ;0=xd,imm
        test    [cpu_capability_flags2],1 shl CPU64_CAPABILITY_V8 shr 32
        jz      ERROR_requires_cpu64_capability_v8
        mov     ebp,[arm64_instruction]
        mov     eax,[immediate_value]
        mov     edx,[immediate_value_high]
        mov     ecx,[addressing_space]
        add     eax,[ecx+0]
        adc     edx,[ecx+4]
        sub     eax,edi
        sbb     edx,0
        test    ebp,ebp                         ;ADRP?
        jns     .offset_okay
        test    eax,0xfff
        mov     ecx,ERROR_branch_misaligned
;       jnz     ARM_store_instruction_with_error ; <--- comment out this line
        shrd    eax,edx,12
        sar     edx,12
    .offset_okay:
;...    
Post 17 Feb 2021, 08:03
View user's profile Send private message Visit poster's website Reply with quote
zhak



Joined: 12 Apr 2005
Posts: 501
Location: Belarus
zhak 17 Feb 2021, 11:09
Thanks for the workaround, revolution. Source doesn't compile with the latest fasm, but I found 1.73.04 build somewhere on the internet and it worked fine.
Post 17 Feb 2021, 11:09
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20300
Location: In your JS exploiting you and your system
revolution 18 Feb 2021, 03:53
I see that the download page has only version 1.73.05 and up now.

http://flatassembler.net/fasmw17305.zip
http://flatassembler.net/fasm-1.73.05.tgz
http://flatassembler.net/fasm17305.zip
http://flatassembler.net/fasm-1.73.05.tar.gz

I don't know if that version will work though.
Post 18 Feb 2021, 03:53
View user's profile Send private message Visit poster's website Reply with quote
ProMiNick



Joined: 24 Mar 2012
Posts: 798
Location: Russian Federation, Sochi
ProMiNick 18 Feb 2021, 05:54
revolution, somewhere on the internet - I guess it is some of mines (fasmpack, at home I get fasmwarm 1.43 build on 1.73.27, (in net on 1.73.25 - core has no significant changes for ARM from 1.73.27)) adaptations (last patch thou introduced wasn`t there).
Thou still can`t return to home?
Post 18 Feb 2021, 05:54
View user's profile Send private message Send e-mail Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8351
Location: Kraków, Poland
Tomasz Grysztar 18 Feb 2021, 10:02
revolution wrote:
I see that the download page has only version 1.73.05 and up now.
It is possible to get the sources of older versions from the GitHub repository.
Post 18 Feb 2021, 10:02
View user's profile Send private message Visit poster's website Reply with quote
guignol



Joined: 06 Dec 2008
Posts: 763
guignol 24 May 2021, 05:38
revolution wrote:
Thank you for the report. I will add it to the list of things to fix when I am back to my desk...
so,,, v9?..
Post 24 May 2021, 05:38
View user's profile Send private message Reply with quote
petelomax



Joined: 19 Jan 2013
Posts: 11
Location: London
petelomax 12 Aug 2022, 02:04
As I understand it there is no way for FASMARM to invoke libc/printf, maybe this will help:
Code:
@ compile on an RPi with as -o hw2.o hw2.s
@                   then ld -o hw2 hw2.o -e main -s -lc -dynamic-linker /lib/ld-linux-armhf.so.3 
@                   then strip -s hw2 --> 1364 bytes

.global main
main:
        push {fp,lr}
        ldr r0, =format
        mov r1, #123
        bl printf
        mov r7, #1
        swi #0
        pop {fp,pc}

.data
        format: .ascii "The result is: %d\n"

.global printf      
    

That gives me a working 1364 byte program, with 14 or so segments/sections.
In contrast, fasmarm armelf.asm (using swi 4 instead of printf) gives me a working 124 byte program with 3 segments.
I'm about to try giving the bigger one bit of a battering, as in write a simple (non-asm) program that directly reads/overwrites the binary bytes, and see how many things [if any] I can delete and have it still working.
Post 12 Aug 2022, 02:04
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: 20300
Location: In your JS exploiting you and your system
revolution 12 Aug 2022, 03:04
petelomax wrote:
As I understand it there is no way for FASMARM to invoke libc/printf, ...
FASMARM can be modified to link to libc natively if you need to, but you need x86 code and an x86 machine to run it on.

I'm not clear about how you can link ARM code to the x86 application. Is there some sort of emulator/translator you use on the RPi to do some conversion magic?
Post 12 Aug 2022, 03:04
View user's profile Send private message Visit poster's website Reply with quote
petelomax3



Joined: 12 Aug 2022
Posts: 2
Location: London
petelomax3 12 Aug 2022, 11:29
Just to be clear, that 1364 byte program is ARM/ELF running ARM libc/printf on an ARM machine, w/o any conversion magic.
My hope is that FASMARM can be modified to allow "extern printf" and/or whatever, my current needs are forcing me down the as/ld path.
One of your posts a couple of years ago said something about struggling with C flags and linker settings, I thought this might help.

UPDATE -pie on the ld command is probably the smarter thing to do.


Last edited by petelomax3 on 14 Aug 2022, 09:04; edited 1 time in total
Post 12 Aug 2022, 11:29
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: 20300
Location: In your JS exploiting you and your system
revolution 12 Aug 2022, 11:36
Okay, thanks.

I think what is required is a segment dynamic and segment interpreter syntax similar to the ones used in fasm. Then you cold link to the .so files in Linux.
Post 12 Aug 2022, 11:36
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: 20300
Location: In your JS exploiting you and your system
revolution 01 Jul 2023, 11:59
Version 1.44 now available:
Quote:
v1.44 2023-Jul-01
  • Update for compatibility with fasm v1.73.30
  • MOVN/MOVZ with zero immediate now encodes any given shift
  • Add Linux 64-bit version: fasmarm.x64
  • Add PE64 support for PIE code without relocations
  • Fix PE header bug in SizeOf(Un)InitializedData values
  • Fix errant check for thumb STRD duplicated source registers
  • Add allowance for DSB, DMB and ISB to accept numeric values
  • Honour two reg encoding for small immediates in thumb code
  • Add missing {VPUSH|VPOP}{.32|.64} aliases
  • Fix bug with 'IT LE' condition mis-tracking
  • Add alias of APSR_NZCV to R15 for VMRS/FMRX
  • Encode ROR by 0 to use LSL 0
  • Fix bug using LDMIA/STMDB for LDRB/STRB and LDRH/STRH
  • Reduce aggressiveness of register swapping in thumb mode
  • Fix detection of invalid values, this improves the minimisation in thumb mode
  • Fix STMDB/LDMIA conversion to PUsH/POP in thumb mode
  • Encode single reg LDM as LDM, not as LDR, in thumb mode
  • Fix bug with LDRD literal load permitting writeback
  • Delay triggering of using wide instructions until 6 passes before the last
  • Add ITAUTO and ITNOAUTO directives
  • Add support for '-' as input/output file in Linux, enabling FASMARM to be used in pipeline
  • Add Windows armpe64.asm example
  • Add swapping of ADD(S) X?,X?,SP & W?,W?,WSP in 64-bit code
  • Fix bug with ADRP erroneously giving unaligned error
  • Fix ELF format flags for Version5 EABI
  • Fix bug with undefined symbol used as an implicit address giving unexpected invalid R15 usage error
  • Fix crash bug in square and curly expression parsers
  • Set machine type for ELF64 to AARCH64
  • Fix bug with explicit register expressions creating bad immediate offsets
Note that this version assembles against fasm v1.73.30
Post 01 Jul 2023, 11:59
View user's profile Send private message Visit poster's website Reply with quote
TmEE



Joined: 19 Jun 2019
Posts: 5
Location: Estonia
TmEE 05 Sep 2023, 14:27
Thänk you very much for this update ~
Post 05 Sep 2023, 14:27
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8351
Location: Kraków, Poland
Tomasz Grysztar 05 Sep 2023, 14:44
The armpe64.exe from the package did not work for me on Windows 11 on ARM. I got it working by adding fixups:
Code:
section '.reloc' fixups data readable discardable

  if $=$$
    dw 0,8              ; if there are no fixups, generate dummy entry
  end if    
Now, with this addition, it even works with F9 from FASMWARM.
Post 05 Sep 2023, 14:44
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page Previous  1, 2, 3 ... , 31, 32, 33  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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.