flat assembler
Message board for the users of flat assembler.
 Home   FAQ   Search   Register 
 Profile   Log in to check your private messages   Log in 
flat assembler > Unix > fasm on MacOS X [Snow Leopard / Lion]

Goto page Previous  1, 2
Author
Thread Post new topic Reply to topic
zab



Joined: 28 May 2012
Posts: 6
Hi guys,

I hope that this thread is still alive!

Following "Shirk" excellent advices and tips, I successfully built FASM 1.70.02 on my OSX machines (32-bits and 64-bits).

I want to share the binary with everyone interested on programming with FASM under OSX (see USAGE file).

QUESTION for "Tomasz Grysztar": "Shrink" provided a patch (fasm-fix-out-of-memory-lion.diff.txt) which allow to compile FASM on OSX. Any chance to get it commited to FASM source code?

Thanks
Zab


Description: FASM (v1.70.02) and OBJCONV (v2.14) binaries.
Allow you compile 32-bits and 64-bits FASM programs on OSX.

Download
Filename: fasm-osx.zip
Filesize: 258.3 KB
Downloaded: 168 Time(s)

Post 29 May 2012, 21:20
View user's profile Send private message Reply with quote
STLVNUB



Joined: 08 Aug 2008
Posts: 13
good one
Post 30 May 2012, 04:31
View user's profile Send private message Reply with quote
Shirk



Joined: 12 Sep 2011
Posts: 10
Uh, this got sticky - nice Smile

Apparently I'm back to my pet os project, back to fasm and we still need the patched version.. (checked no path in 1.70.3 or 1.71 previews).

Not sure if Tomasz reads this forum / has interest in the patch but big thanks to zab for providing the binaries!

Maybe someone could mail him?
Post 24 Sep 2012, 17:03
View user's profile Send private message Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 6635
Location: Kraków, Poland
I cannot approve such kind of fix. If that one relocation is processed incorrectly then the other relocations also cannot be trusted and it is inherently unsafe to try fixing it this way. One should rather search for the real source of the problem, that is the underlying bug related to relocations - and report it.
Post 24 Sep 2012, 17:21
View user's profile Send private message Visit poster's website Reply with quote
Shirk



Joined: 12 Sep 2011
Posts: 10
Hi Tomasz,
please don't get me wrong - my post was in no way meant to insult anyone.
It was just written in a challenging tone to lure an answer out of you. Wink

I agree that the real fix would be to determine why this one relocation is messed up. If you ask me - it's a flaw in objconv.. I looked through most of the code by now and everything else seems fine. (could be related to different reloc handling in mach-o).

But to be honest - osx or mach-o is nowhere near your target / planned features list and I neither have the time nor the fasm-guts to dig through the whole code to add a mach-o backend. So it looks like mac users are still dependent on this (possibly flawed, however working-fine-so-far) patched binary.
I'm fine with that and most of us can resort back to a VM if hard comes to hard..

so keep the thread sticky and most of us should be happy Smile

Cheers,
Shirk

P.S. - my vote for a fasm mach-o backend
Post 25 Sep 2012, 05:52
View user's profile Send private message Reply with quote
STLVNUB



Joined: 08 Aug 2008
Posts: 13
Working on 10.8.2 with 1.71.06
Post 15 Dec 2012, 20:25
View user's profile Send private message Reply with quote
STLVNUB



Joined: 08 Aug 2008
Posts: 13
Weird, can compile and run fasm.asm with fasm, but try to compile for efi and back to "out of memory"
Post 15 Dec 2012, 20:55
View user's profile Send private message Reply with quote
STLVNUB



Joined: 08 Aug 2008
Posts: 13
ok changed buffer rb 1000h in fasm.asm to buffer rb 4000h
Now compiles efi Wink
Post 15 Dec 2012, 21:45
View user's profile Send private message Reply with quote
STLVNUB



Joined: 08 Aug 2008
Posts: 13
Just compiled fasm.efi and works Smile
I should note that fast.asm for efi already had buffer set to 4000h
so that appears to be the "out of memory" bug
Post 15 Dec 2012, 22:12
View user's profile Send private message Reply with quote
STLVNUB



Joined: 08 Aug 2008
Posts: 13
OS X appears to need more buffer space as 1000h leads to "Out Of Memory" errors and also leads to some examples that have buffer set to 1000h, getting errors too.

Is there a reason why OS X needs bigger buffer space??
Of course, it won't work otherwise.

So set the buffer to 4000h and you can do wonders.Wink
Post 16 Dec 2012, 06:21
View user's profile Send private message Reply with quote
STLVNUB



Joined: 08 Aug 2008
Posts: 13
tools/libc/listing.asm is one example that now works.
As well as compiling fasm and fasm.efi from newest sources.

All this on Mountain Lion.

Anybody interested???


Last edited by STLVNUB on 17 Dec 2012, 20:07; edited 1 time in total
Post 16 Dec 2012, 06:25
View user's profile Send private message Reply with quote
KevinN



Joined: 09 Oct 2012
Posts: 161
Yep, as soon as my monitor works again.. And if i can get mountain lion up on a custom
Post 16 Dec 2012, 06:44
View user's profile Send private message Reply with quote
KevinN



Joined: 09 Oct 2012
Posts: 161
I've got ML running now.. it might be interesting to get fasm running

I found a few OSX Nasm examples too.. there was a quartz and an OPENGL one.. and a boilerplated hello world

http://michaux.ca/articles/assembly-hello-world-for-os-x

http://forum.nasm.us/index.php?topic=1075.0 (OpenGL)
Post 22 Dec 2012, 16:36
View user's profile Send private message Reply with quote
KevinN



Joined: 09 Oct 2012
Posts: 161
http://osxbook.com/blog/2009/03/15/crafting-a-tiny-mach-o-executable/

https://gist.github.com/1084476

http://www.feiri.de/macho/

http://seriot.ch/hello_macho.php

looks like others have, and continue to play with macho-o. I think the above examples are good for understanding the bare minimum requirements for a macho32 and macho64. I just nasm assembled the second example off git and it works:

Code:

$nasm -O0 -f bin -o tiny_hello gistfile2.asm

$chmod +x tiny_hello

$wc -c tiny_hello
     251 tiny_hello

$./tiny_hello 
HelloWorld!




251 bytes on ML! hehe Smile small enough to get to know macho bit by bit and byte by byte


im trying to see if i can get some function out of tinycc on osx with objconv [edit: tinycc can be used same way fasm works with objconvert and ld.. ld adds a lot of weight, probably a lot unnecessary.]


Last edited by KevinN on 02 Jan 2013, 14:53; edited 6 times in total
Post 01 Jan 2013, 23:55
View user's profile Send private message Reply with quote
KevinN



Joined: 09 Oct 2012
Posts: 161
here are some gui programs used as tools to examine macho:

http://sourceforge.net/projects/machoview/

http://www.affinic.com/?page_id=109
Post 02 Jan 2013, 00:13
View user's profile Send private message Reply with quote
KevinN



Joined: 09 Oct 2012
Posts: 161
http://opensource.apple.com/release/developer-tools-45/

the source for cctools including ld, otool, as etc
Post 02 Jan 2013, 07:00
View user's profile Send private message Reply with quote
Shirk



Joined: 12 Sep 2011
Posts: 10
Nice analysis on mach-o so far -- I had a look into a fasm mach-o backend but tbh. couldn't find my way around mach-o 64..

@STLVNUB - the buffer size problems could be a result of things like the additional alignment requirements and other features like these that Xnu enforces.
Post 19 Aug 2013, 10:01
View user's profile Send private message Reply with quote
alexfru



Joined: 23 Mar 2014
Posts: 32
I'm getting close to declaring official support of Mac OS X in my C compiler and just for the fun of it I made FASM executables out of fasm.o for Linux, Mac OS X and DOS/DPMI.

I used my compiler's C library and two pages of simple asm & C code to translate names (leading underscores are used by default in my compiler), preserve regs (my compiler preserves only the obvious: EBP, ESP) and intercept fopen() (it should really be called with "rb" and "wb" and not "r" and "w") and gettimeofday() (not implemented in my library, not part of the C standard).

The result seems to be working so far. I compiled a few C apps with my compiler instructed to use FASM in place of NASM.

Btw, the DOS/DPMI version is somewhat "cleaner" in that it does not try to use unreal mode.

If anyone is interested I could share the code & instructions and the binary(-ies).
Post 16 Oct 2017, 10:22
View user's profile Send private message Reply with quote
alexfru



Joined: 23 Mar 2014
Posts: 32
So, it looks like my Smaller C compiler is working on Mac OS X 10.6 (Snow Leopard) through Mac OS X 10.12 (Sierra).

Here's how I turn fasm.o into various executables.


Code:

; file: compata.asm
bits 32

section .text

%macro wrapper 2
extern %2
global %1
%1:
    push    ebx
    push    ecx
    push    edx
    push    esi
    push    edi
    pushfd
    push    dword [esp+(6+4)*4]
    push    dword [esp+(6+4)*4]
    push    dword [esp+(6+4)*4]
    push    dword [esp+(6+4)*4]
    call    %2
    add     esp4*4
    popfd
    pop     edi
    pop     esi
    pop     edx
    pop     ecx
    pop     ebx
    ret
%endmacro

wrapper malloc_malloc
wrapper free,   _free
wrapper getenv_getenv
wrapper fopen,  _fopen_wrapper
wrapper fclose_fclose
wrapper fread,  _fread
wrapper fwrite_fwrite
wrapper fseek,  _fseek
wrapper ftell,  _ftell
wrapper time,   _time
wrapper exit,   _exit
wrapper write,  _write
wrapper gettimeofday_gettimeofday_wrapper

extern main
global _main
_main:
    cld
    jmp     main





Code:

// filecompatc.c
#include <string.h>
#include <stdio.h>
#include <time.h>

FILEfopen_wrapper(const charnameconst charmode)
{
  if (!strcmp(mode"r"))
    mode = "rb";
  else if (!strcmp(mode"w"))
    mode = "wb";
  else
    return NULL;
  return fopen(namemode);
}

struct my_timeval
{
  unsigned tv_sectv_usec;
};

int gettimeofday_wrapper(struct my_timevaltpvoidtzp)
{
  (void)tzp;
  tp->tv_sec = time(NULL);
  tp->tv_usec = 0;
  return 0;
}




Compiling for MacOS:

Code:

smlrcc compata.asm compatc.c fasm.o -o fasmm -macos




Compiling for DOS/DPMI:

Code:

smlrcc compata.asm compatc.c fasm.o -o fasmdp.exe -dosp -minheap 17000000




Compiling for Windows:

Code:

smlrcc compata.asm compatc.c fasm.o -o fasmw.exe -win




My compiler depends on NASM and the above asm code is for NASM, so you should have NASM 2.03 or newer if you want to recompile FASM using Smaller C and the above pieces of code.

Smaller C should work out of the box on Windows and DOS, just include the path to v0100\binw or v0100\bind in %PATH%.

On Linux and Mac OS X you can simply recompile the compiler, using the usual (you will need NASM already installed):

Code:

./configure
make
sudo make install



On Mac you may see an error from readlink, but it should still work.

I'm attaching the binaries.

What else?.. Feel free to poke around the compiler's library source for Mac OS X system calls. Ditto for the linker if you want to make 32-bit Mach-O executables by hand. Or you could just use the linker as-is.


Description: Precompiled FASM 1.71.64 for Windows
Download
Filename: fasmw.exe.zip
Filesize: 66.51 KB
Downloaded: 17 Time(s)

Description: Precompiled FASM 1.71.64 for DOS/DPMI (will need CWSDPMI)
Download
Filename: fasmdp.exe.zip
Filesize: 68.29 KB
Downloaded: 18 Time(s)

Description: Precompiled FASM 1.71.64 for Mac OS X
Download
Filename: fasmm.zip
Filesize: 58.6 KB
Downloaded: 20 Time(s)

Post 18 Oct 2017, 03:44
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

< 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


Powered by phpBB © 2001-2005 phpBB Group.

Main index   Download   Documentation   Examples   Message board
Copyright © 2004-2016, Tomasz Grysztar.