flat assembler
Message board for the users of flat assembler.

Index > Main > fasm for MacOS (intel CPU)

Author
Thread Post new topic Reply to topic
m



Joined: 28 Dec 2006
Posts: 304
Location: in
m 31 Jan 2008, 09:01
do we have fasm for MacOS?
i have mac with intel processor.

_________________
Attitude!
Post 31 Jan 2008, 09:01
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8351
Location: Kraków, Poland
Tomasz Grysztar 31 Jan 2008, 09:41
After I finish the planned Mach-O support, it should be then quite easy to make Mac port of the libc version.
I still cannot give you exact time when Mach-O support is ready, though (there was a chance I could get a Mac machine for testing, but afterall I haven't got it and this caused postponing of this feature implementation).
Post 31 Jan 2008, 09:41
View user's profile Send private message Visit poster's website Reply with quote
m



Joined: 28 Dec 2006
Posts: 304
Location: in
m 31 Jan 2008, 09:54
thanks Smile i will wait.
Post 31 Jan 2008, 09:54
View user's profile Send private message Reply with quote
OzzY



Joined: 19 Sep 2003
Posts: 1029
Location: Everywhere
OzzY 31 Jan 2008, 23:19
Is it possible to install Mac OS for Intel together with Windows XP and Linux?
I'd like to try it. Very Happy
Post 31 Jan 2008, 23:19
View user's profile Send private message Reply with quote
HyperVista



Joined: 18 Apr 2005
Posts: 691
Location: Virginia, USA
HyperVista 01 Feb 2008, 01:22
Hi Ozzy - Parallels hypervisor product (it's a true hypervisor, by the way) allows a Mac user to run Windows and Linux on the Mac. I'm not sure if Xen will allow you to run Mac on a x86 box but it sure will allow you to run Linux and Windows simultaneously on the same box.
Post 01 Feb 2008, 01:22
View user's profile Send private message Visit poster's website Reply with quote
f0dder



Joined: 19 Feb 2004
Posts: 3175
Location: Denmark
f0dder 01 Feb 2008, 10:56
OS X runs on stock x86 hardware, Apple moved away from non-x86 quite a while ago.

However, there's two issues. The first is that there's limited driver support, since Apple only support the hardware they ship themselves. The second is that Apple are monopolist bigots and only want OS X to run on "their hardware".

But you can find patches that'll allow you to run OS X on (most) standard PCs (assuming you have compatible hardware), either on real machines or in vmware/whatever.
Post 01 Feb 2008, 10:56
View user's profile Send private message Visit poster's website Reply with quote
AlexP



Joined: 14 Nov 2007
Posts: 561
Location: Out the window. Yes, that one.
AlexP 02 Feb 2008, 15:35
I believe that mac's should be shot and killed on sight Smile.
Post 02 Feb 2008, 15:35
View user's profile Send private message Visit poster's website Reply with quote
rugxulo



Joined: 09 Aug 2005
Posts: 2341
Location: Usono (aka, USA)
rugxulo 02 Feb 2008, 17:46
I started a poll here to see how many people would use this.
Post 02 Feb 2008, 17:46
View user's profile Send private message Visit poster's website Reply with quote
f0dder



Joined: 19 Feb 2004
Posts: 3175
Location: Denmark
f0dder 03 Feb 2008, 23:26
AlexP wrote:
I believe that mac's should be shot and killed on sight Smile.


You mean "macs" and not "mac's", right? You're an Amerikan and don't know when to insert the apostrophe? >_<

Do you mean macs, or mac users? And why?

_________________
Image - carpe noctem
Post 03 Feb 2008, 23:26
View user's profile Send private message Visit poster's website Reply with quote
hawk



Joined: 16 Mar 2004
Posts: 3
hawk 04 Apr 2008, 22:27
Well, I have a working "libc fasm" on my Mac (as of now Wink ) thanks to objconv ( http://www.agner.org/optimize/#objconv ) and to BogdanOntanu who started me up on this.
You have it attached.
Basically it's not very complicated once you have objconv converting the ELF object file intro Mach-O object file, however there are some (minor?) glitches:
1. For some reason objconv doesn't like the elf format that fasm produces in that it can't convert the external references to have an underline in front - you have to manually change fseek to _fseek and so on
2. The bigger problem is that MacOS requires (stupidly, perhaps) that at the moment of each and every call to a system function the stack be aligned at 16bytes boundary. The only quick solution (for me at least) was to change ccall macro to do that. I know it's not a "nice" thing to do, even more it's a very dirty change - e.g. it uses 2 global variables to save stack and eax Razz
3. Because of laziness (or whatever) I changed ccall to accept standard calls (w/o arguments) and also align the stack.

So for better or worse, here is what I've done (using the latest fasm download, built on Linux machine, link edited with gcc on Mac)

In fasm/fasm/source/libc/fasm.asm

1.Changed macro ccall to (warning, ugly code):
Code:
macro ccall proc,[arg]                  ; call CDECL procedure
 { common
    local size
    size = 0
   if ~ arg eq
    forward
     size = size+4
    common
   end if
mov [stack_ccall],esp
mov [save_eax],eax

mov eax,esp
; sub eax,4
sub eax,size
and eax,15
sub esp,eax
mov eax,[save_eax]

   if ~ arg eq
   reverse
    pushd arg
   common
   end if
    call proc
mov esp,[stack_ccall]
}
    


2. added global variables needed for the above macro, at the end of fasm (where its other globals are):
Code:
stack_ccall dd ?
save_eax dd ?
    


3. changed extrn to have an underline in front:
extrn _gettimeofday
and, of course
ccall _gettimeofday,buffer,0


In fasm/fasm/source/libc/system.inc
1. Again, all extrn to start with underline
[code]
extrn _malloc
extrn _free
extrn _getenv
extrn _fopen
extrn _fclose
extrn _fread
extrn _fwrite
extrn _fseek
extrn _ftell
extrn _time
extrn _exit

extrn '_write' as libc_write
[code]
Don't forget _write!
When changing function names through the code be careful to also replace call with ccall when appropriate
(IIRC only _exit needs that, and it could be neglected, MacOS allows simple ret instruction to cleanly terminate the program and pass whatever is in eax as return value)
e.g.

Assemble as usual - fasm fasm.asm
Now for the funny part:
1. take the fasm.o object file to you mac (you could run objconv on linux, I think but... mac is needed anyway for the next step Razz
2. apply objconv as follows:
[code]
Hawk-MB:libc hawk$ objconv -fmacho fasm.o fasm.mach.o

Input file: fasm.o, output file: f.o
Converting from ELF32 to Mach-O Little Endian32

0 Debug sections removed
0 Exception sections removed
Hawk-MB:libc hawk$
[/code]
3. gcc to link (you could use ld but it's more complicated)
gcc fasm.mach.o -o fasm

And you have a working libc fasm on mac os
(Hope I haven't forgot anything)


Description: Working fasm binary (object and executable), along with its modified sources.
Download
Filename: fasm_mac.tgz
Filesize: 280.23 KB
Downloaded: 654 Time(s)


_________________
Always begining something
Post 04 Apr 2008, 22:27
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4024
Location: vpcmpistri
bitRAKE 04 Apr 2008, 23:40
Might want to atleast use something like this:
Code:
macro ccall proc,[arg]                  ; call CDECL procedure
 { common 
    local size 
    size = 0 
   if ~ arg eq 
    forward 
     size = size+4 
    common 
   end if 

push ebp
mov ebp,esp
sub esp,size
and esp,-16
add esp,size

   if ~ arg eq 
   reverse 
    pushd arg 
   common 
   end if 
    call proc 

leave

}    
...otherwise the ccalls are not stackable because of the global data use! The above uses EBP and the local stack to perform the alignment.

_________________
¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup
Post 04 Apr 2008, 23:40
View user's profile Send private message Visit poster's website Reply with quote
hawk



Joined: 16 Mar 2004
Posts: 3
hawk 05 Apr 2008, 06:58
bitRAKE,
Thanks for the improvement.
You are right, in fact at some point I thought I should use a separate macro "extcall" or something like that, for system calls. However, after seeing that in fasm ccall is used only for system calls.. I took the easier path.
Post 05 Apr 2008, 06:58
View user's profile Send private message Reply with quote
rugxulo



Joined: 09 Aug 2005
Posts: 2341
Location: Usono (aka, USA)
rugxulo 14 Apr 2008, 20:05
Has Tomasz read this thread lately? It should be made "sticky", IMO.
Post 14 Apr 2008, 20:05
View user's profile Send private message Visit poster's website Reply with quote
turdus



Joined: 19 Apr 2006
Posts: 8
turdus 26 Apr 2008, 14:50
Hawk: thank you very much for mac version of fasm! That's what I was looking for! And, I noticed that there's a predefine option, I don't know if it's your version's improvement, but about a year (or two) ago I was asking for this feature here in this forum, and I ended up by overwriting the fasm source. So, mac+predefine well done, thank you very much!!!
Post 26 Apr 2008, 14:50
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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.