flat assembler
Message board for the users of flat assembler.

Index > Projects and Ideas > 64-bit Forth using fasm/ELF64

Author
Thread Post new topic Reply to topic
rrq



Joined: 17 May 2021
Posts: 10
rrq 31 Jul 2021, 23:38
This is more of an announcement than dropping an idea, but anyhow:

I very recently "discovered" the charm of FASM, when, out of general curiosity, I looked into jonasforth hoping to learn something about the dark art of UEFI programming. However I was more taken by FASM (than UEFI), and as a result I started this toy project "rrqforth" to learn more.

"rrqforth" is a reasonably complete 64-bit Forth interpreter as an ELF64 static binary developed on and for Linux. In this context it's kind of an illustration of what a FASM-beginner might do without getting bogged down into ontological concerns around data representation (since Forth doesn't really do data abstraction).

Some people might be interested in the "utility tool", fas2txt.lsp, which processes the .fas file that is generated by the fasm compiler into a text file representing the core image of the executable. That text file was very useful when debugging (using gdb) as it associates the core image addresses with the source line(s) for the code layout, whether it's from a macro or an included file etc. I used newlisp for fas2txt.lsp because I find this to be a quite handy high-level scripting language for low-level data manipulation.

enjoy
Post 31 Jul 2021, 23:38
View user's profile Send private message Reply with quote
pabloreda



Joined: 24 Jan 2007
Posts: 121
Location: Argentina
pabloreda 02 Aug 2021, 13:59
Nice to see another forth!

thank's fpr sharing
Post 02 Aug 2021, 13:59
View user's profile Send private message Visit poster's website Reply with quote
emanuele6



Joined: 11 Dec 2025
Posts: 3
emanuele6 13 Dec 2025, 20:27
Very cool!

By the way, on the off chance that someone is still interested in this after more than 4 years, I have found a bug in the REALLOC implementation located in stdio.asm: it was meant to call the mremap Linux syscall by jumping to sys_mremap_asm, but it is actually jumping to sys_mmap_asm calling the mmap syscall.

Cheers!
Post 13 Dec 2025, 20:27
View user's profile Send private message Reply with quote
rrq



Joined: 17 May 2021
Posts: 10
rrq 14 Dec 2025, 02:17
Many thanks, Currection pushed.
Post 14 Dec 2025, 02:17
View user's profile Send private message Reply with quote
emanuele6



Joined: 11 Dec 2025
Posts: 3
emanuele6 14 Dec 2025, 04:44
Hey. Thank you for responding to my comment! Very Happy

I've tried the new version; unfortunately, REALLOC still does not seem to work as intended; simply jumping to the correct label was not enough.

The problem seems to be that mremap has got an optional fifth argument which sys_mremap_asm always expects, so it is taking an extra value from the stack and passing arguments to the syscall shifted one position.

Now, it is actually invoking mremap, though, so, at least, it is possible to make this work passing an extra 1 externally for MREMAP_MAYMOVE, and letting the one pushed internally by the word act as the dummy optional parameter.
Code:
$ strace -emmap,mremap ./rrqforth
mmap(NULL, 10000, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f96a0a4b000
10 MALLOC . 10 EMIT
mmap(NULL, 1073741824, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f9660a00000
mmap(NULL, 10, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f96a0a4a000
140284916965376
140284916965376 10 20 REALLOC
mremap(0x508f4b, 140284916965376, 10, MREMAP_DONTUNMAP|0x10) = -1 EINVAL (Invalid argument)
140284916965376 10 20 1 REALLOC
mremap(0x7f96a0a4a000, 10, 20, MREMAP_MAYMOVE) = 0x7f96a0a4a000    

To better fix this, I think you could push a dummy value before the jmp.

Have a nice day!
Post 14 Dec 2025, 04:44
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< 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-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.