At&t syntax emitter

For other topics related to the FreeBASIC project or its community.
parkovski
Posts: 16
Joined: Apr 05, 2010 23:26

At&t syntax emitter

Postby parkovski » Oct 24, 2010 18:24

Hello everyone.
I posted a while back about porting fb to the mac, but have not had much time in the past few months. Recently however, I've had a little time and have managed to get fb to emit at&t syntax assembly (mac doesn't support intel syntax).
It's not entirely complete yet, especially when dealing with floating point instructions, but many of the example programs compile fine, and it won't cause any problems unless you explicitly turn it on - I've created a new command line option "-as att|intel", though this could be merged into the "-gen" option if the devs think that would be better.
I'm not exactly sure how to go about submitting a patch though - should I just bundle up the files I changed and send them to someone or is there some type of diff program I need to run, etc?
Thank you all for your help. I'm hoping to have fb running on the mac within a couple months if all goes well.
vdecampo
Posts: 2982
Joined: Aug 07, 2007 23:20
Location: Maryland, USA
Contact:

Postby vdecampo » Oct 24, 2010 18:46

Were you able to convert the FB runtime to the MAC?

-Vince
parkovski
Posts: 16
Joined: Apr 05, 2010 23:26

Postby parkovski » Oct 24, 2010 19:11

Rtlib compiled fine last time I checked. A cocoa port of gfxlib2 will take some work, but you may be able to use mac's x11 in the meantime. The biggest issue right now is getting the compiler to conform to mac's abi I think.
TJF
Posts: 3604
Joined: Dec 06, 2009 22:27
Location: N47°, E15°
Contact:

Congratulations for first success!

Postby TJF » Oct 24, 2010 20:30

Sorry, I'm neither able to help nor am I able to test for you (I have no MAC).

But I like the idea to get my FreeBasic software running on a MAC anytime in the future!

Good luck for your project!
dkl
Site Admin
Posts: 3217
Joined: Jul 28, 2005 14:45
Location: Germany

Postby dkl » Oct 25, 2010 14:43

Pretty cool. I'd not have tried it that way -- I thought we could compile darwin binutils, including an up to date GNU assembler that understands Intel syntax and then distribute a standalone FB mac release. But this is really good too, it allows to use Apple's assembler, and besides that it would fix the namespace conflicts between global variables and registers on Linux.

About applying the changes, I think it's worth being put into SVN, and it'd be easiest if you make a patch against the current SVN content (svn diff > att-emitter.patch). But if you want to sent over the files (or upload them, e.g. on our Sourceforge patch tracker), that would work too.
marcov
Posts: 3052
Joined: Jun 16, 2005 9:45
Location: Eindhoven, NL
Contact:

Postby marcov » Oct 25, 2010 15:50

dkl wrote:Pretty cool. I'd not have tried it that way -- I thought we could compile darwin binutils, including an up to date GNU assembler that understands Intel syntax and then distribute a standalone FB mac release.


Interesting, so you saw that binutils was functioning on Mac ( at last)? Do you know if they also support PPC targets?
dkl
Site Admin
Posts: 3217
Joined: Jul 28, 2005 14:45
Location: Germany

Postby dkl » Oct 25, 2010 16:26

No, I haven't seen (or tried) it, but I figured it could work, seeing that the MacPorts page lists binutils 2.20.1:
http://trac.macports.org/browser/trunk/dports/devel/binutils/Portfile
parkovski
Posts: 16
Joined: Apr 05, 2010 23:26

Postby parkovski » Oct 25, 2010 16:49

I submitted the patch - sorry I didn't have time to run diff on the files, but they're on the sf.net tracker.
I'll be out of town for the next week, but if anyone runs into any problems with this (besides those I already found), please let me know as I haven't been able to fully test it yet.
Most everything that I tried compiles (including the compiler itself), but things aren't linking yet - it seems like symbols are not being made public, and I'm not sure why this is yet.
haegartheroot
Posts: 112
Joined: Jul 27, 2007 15:45
Location: Bremen, Germany
Contact:

Postby haegartheroot » Oct 26, 2010 9:46

A mac port of FreeBasic would be great!
The last time I created a cross platform application I had to use Mono VB.Net, because OSX was not supported by FB.
In the future I can fully switch back to FB.
Thank you for your support!
TeeEmCee
Posts: 318
Joined: Jul 22, 2006 0:54
Location: Auckland

Postby TeeEmCee » Nov 13, 2010 9:04

Hi,

I ported FB to Mac OS X a month ago using a bunch of dirty hacks, but did not post to the forums because... the hacks are too dirty! I intended to at least clean up my patches a bit before posting them. But I've had exams, assignments, etc., not to mention I'm lazy.

It's really awesome to see that you've done this, because it's complementary to the work that I've done. My approach was to emit intel syntax, then cross compile it to a linux ELF object file with a cross-compiling build of binutils as (does the Macports version of binutils as actually support Mach-O properly? My impression was that it's completely unfinished and not working), and then translate that to a Mach-O object file using objconv (I had to add missing functionality to objconv to get it working). I think I've already solved the linking problems you were having, implemented the OSX ABI, fixed various rtlib problems, and so on.

This double-cross-compiling hack works amazingly well, but it would be great to replace it with your at&t syntax assembly emitter, which would be the proper way of doing things.

So, my build of fbc seems to work flawlessly (I've been distributing Mac builds of the OHRRPGCE for a month with only a single reported crash)... except that for some reason the version of ld on OS 10.6 and later appears to produce corrupt binaries. I haven't had time to figure out how to fix this, but I think it's about time to get some other people to test out my build.

I'll organise everything and then post a separate topic about it.
Landeel
Posts: 763
Joined: Jan 25, 2007 10:32
Location: Brazil
Contact:

Postby Landeel » Nov 13, 2010 16:16

I don't have a MAC, but it would be very nice to see my games running on MAC.
This sounds very promising. Congratulations!
Keep up the good work! :)
parkovski
Posts: 16
Joined: Apr 05, 2010 23:26

Postby parkovski » Nov 17, 2010 22:15

Hi TeeEmCee,
That's great to hear that you've had so much success porting FB! Unfortunately my emitter is giving me some crashes on obscure things that are proving fairly difficult to track down (especially since it usually works fine on smaller programs, so I have to sift through large asm files to find the bugs). But I have made a decent amount of progress, so maybe it could be of some help.

To be honest I've had almost no experience with at&t syntax asm before this, so most of my work here is based on gcc's output and google searches. I also have not really done any native mac programming, and am pretty unfamiliar with binutils, so I'm not sure if I'm really the right one for this job, but it was looking like if I wanted fb on my mac, I was gonna have to do it myself. I haven't really had much time to work on this lately, but I am still very interested in getting it working.

I've made a bit more progress than what I uploaded a while back, though there are still random hard to find crashes. Let me know if you'd like a copy of what I've got. And any mac abi tips are definitely appreciated, though that's a ways off coming from this angle.
srvaldez
Posts: 2578
Joined: Sep 25, 2005 21:54

Postby srvaldez » Nov 18, 2010 0:24

I know your post is addressed to TeeEmCee, but I would be interested in your latest Mac FB build.
thank you :)
Ryan
Posts: 695
Joined: Jun 10, 2005 2:13
Location: Louisville, KY
Contact:

Postby Ryan » Nov 18, 2010 1:07

Mac user here, just chiming in to say I would absolutely love to use FB on the Mac. Does the compiler itself work on Mac or would I have to do development on the PC and just compile to target the Mac? Point me in the right direction and I'll be happy to test. : )
parkovski
Posts: 16
Joined: Apr 05, 2010 23:26

Postby parkovski » Nov 27, 2010 20:56

Ok, for anyone who's interested, here is my emit_x86_att.bas. It does fine with the majority of the language's features, but certain things cause random crashes while running (the test suite might be a good place to start debugging). It's something to look into for someone who has more experience in asm than I do, otherwise I'll continue to keep working on it when I have the time.

In order to make this work you'll have to add a command line option to the compiler, I used "-as att|intel", and add another emitter mode that calls emitGasX86Att_ctor instead of emitGasX86_ctor. The changes in the other files can be downloaded from the patches tracker.

Edit: the whole file doesn't fit here. Download it from https://sites.google.com/site/parkersnell/files

Return to “Community Discussion”

Who is online

Users browsing this forum: No registered users and 6 guests