puppeh's GCC6 for 6502

discussion of beeb/electron applications, languages, utils and educational s/w
cmorley
Posts: 264
Joined: Sat Jul 30, 2016 7:11 pm
Location: Oxford

puppeh's GCC6 for 6502

Postby cmorley » Sat May 27, 2017 5:33 pm

I was talking with Kieran at ABUG Cambridge about GCC and he suggested it's worth starting a thread.

I've successfully been using puppeh's GCC 6 6502 for writing code for the B. I got it working because I needed to write my test code for my memory modules and C is simply quicker. It took me a week to figure it out and get a build environment to work from Visual Studio.

I made a few changes to the linker file to make it play nice with BASIC (so you can RTS back to BASIC with a return value) and fixed an issue with the crt0 which had a rogue C64 statement in there which trashed a useful ZP pointer. I've got it to compile binarys and also to compile a mainless ROM image.

The code it produces is good and bad in places. You get nice stuff like (GNU)C11 and modern optimisations which is good. Pointer code is a bit rough and at some points it triggers a spill emits a huge amount or code with many redunant instructions to save stuff on a stack then reload :( However these things could be improved!

The C library isn't great and I ended up writing a printf. I also marshalled quite a few things to BASIC2 or the OS via inlie ASM functions in my code - which helps with executable size. C library as a ROM image could be a possibility to free up memory.

https://github.com/puppeh

Worth starting a discussion anyway. It is definitely in a state where you canrapidly throw code together and have it work.

User avatar
BigEd
Posts: 1500
Joined: Sun Jan 24, 2010 10:24 am
Location: West
Contact:

Re: puppeh's GCC6 for 6502

Postby BigEd » Sat May 27, 2017 6:36 pm

This sounds good!

It turns out we'd seen this compiler over on 6502.org, but I'd forgotten about it. Getting it tweaked to work well for the Beeb is certainly a step forward.

User avatar
Elminster
Posts: 1632
Joined: Wed Jun 20, 2012 8:09 am
Location: Essex, UK

Re: puppeh's GCC6 for 6502

Postby Elminster » Sat May 27, 2017 7:45 pm

I had a play with it before. You can probably see my bug I hit in gihub compiling and had to use the latest gcc6 version. Did you hit that issue as well?

But that was as far as I got as distraced with hardware lists and a basic program I am wrestling with writing. But I will be back to C.

I have this version to play cross with and then on the box itself I have Acorn C and Beebug C. But the later 2 have limited features and compiling a pain, so I had hoped to do all the work on gcc6, plus it is faster.

User avatar
Elminster
Posts: 1632
Joined: Wed Jun 20, 2012 8:09 am
Location: Essex, UK

Re: puppeh's GCC6 for 6502

Postby Elminster » Sat May 27, 2017 7:48 pm

Oh and can you write up and dump your notes. Rather than me reinvent the wheel.

When I say I am writing a BASIC program I actually ended up writting both C and Pythn test program on Mac to test it with.

But AngryC is next on my list.

Edit: forgot to say I got as far as writing hello world, cross compile on ubuntu and ran on a Master.

cmorley
Posts: 264
Joined: Sat Jul 30, 2016 7:11 pm
Location: Oxford

Re: puppeh's GCC6 for 6502

Postby cmorley » Sun May 28, 2017 8:14 pm

I didn't have any problems compiling it at all. I compiled for cygwin (and build cc65 from source for cygwin) following the instructions in the repo. It all just worked for me.

Most of the time I spent was getting my build environment working rather than GCC-6502. I wrote a 38k4 serial routine + CRC in 6502 asm (less than one page) and a C# program to init the link, send the fast RX, send the code to test then execute it. So now I have Visual Studio build & squirt to the Beeb. All I have to do is a *fx2,1 on the Beeb & I'm away - remote everything else from the PC. That's what took most of the time. And the printf rewrite of course...

Once that was up and running fixing the few problems with crt0 and map files went smoothly. I got my test tools running well & tested a ROM image which just responds to *HELP at the moment.

So no problems with the gcc-6502 build at all.

I can write up the changes I made to the 6502 target stuff.

User avatar
Elminster
Posts: 1632
Joined: Wed Jun 20, 2012 8:09 am
Location: Essex, UK

Re: puppeh's GCC6 for 6502

Postby Elminster » Sun May 28, 2017 8:25 pm

Cygwin and visual studio suggest windows, which I don't use. Was build on ubuntu 17 I think, either just to create a linux VM on Mac fusion than mess about. The build failure was todo with building with gcc6. A common issue with gcc6, Puppeh had some new code for gcc6 and that fixed the issue. Possible he may have put that in the main now so that maybe why you had no issue, or just that you are on a completely different platform.

puppeh
Posts: 11
Joined: Tue Sep 27, 2016 9:48 pm

Re: puppeh's GCC6 for 6502

Postby puppeh » Thu Jun 01, 2017 9:32 am

Hi!

Thank you for trying out my 6502 GCC port! I'm not working on it very actively at the moment, but I'll be willing to consider any patches you come up with for inclusion (I know "libtinyc" is not great and is very incomplete. It's just barely sufficient to run the compiler testsuite really). The pointer/spill code is difficult -- it's a fun game trying to shoehorn the hypothetical ideal code generation strategy into what can be achieved with an existing compiler (I started writing up what the port does, but I haven't got very far yet). GCC has supported a wild & wonderful selection of CPUs over the years, so it's grown some useful tricks, but the 6502 is still an outlier in a few respects.

Jules/pup

User avatar
Elminster
Posts: 1632
Joined: Wed Jun 20, 2012 8:09 am
Location: Essex, UK

Re: puppeh's GCC6 for 6502

Postby Elminster » Thu Jun 01, 2017 12:25 pm

Would be good to have a decent c Compiler (cross or native) on 6802. Something between simple but slowish BASIC and complex but fast ASM (complex for me anyway). C has the benefit of all that code already out there in the wild, making easy to port stuff.

I have high expectations of everyone fixing it for me! Not sure the skills to do it are in my main memory. Writing C code is about my limit. But I am happy to encourage people :)

cmorley
Posts: 264
Joined: Sat Jul 30, 2016 7:11 pm
Location: Oxford

Re: puppeh's GCC6 for 6502

Postby cmorley » Tue Jun 06, 2017 9:28 am

puppeh wrote:Thank you for trying out my 6502 GCC port!


More than trying out, I've used it to write the test programs for my hardware modules. It works fine for me like that at the moment. ZP on the 6502 is essentially a register set so I did wonder if it would be better to use lots more ZP registers (64 or 128 say) and eliminate the liklihood of spill & requirements to copy memory around. Indeed if that could then eliminate the need for the runtime stack that would be interesting - so only need the page 1 call stack. I've not looked into that in much depth but might well do when I have less on.

Thanks for the work on this!

User avatar
Elminster
Posts: 1632
Joined: Wed Jun 20, 2012 8:09 am
Location: Essex, UK

Re: puppeh's GCC6 for 6502

Postby Elminster » Tue Jun 06, 2017 10:13 am

@cmorley, Dont forget you were going to write up how you got to your setup, while it maybe not what I will do it could encourage other people to start using it. Plus I am interested to see how you are using it. And of course the more people that use it the more stuff might get added, fixed etc.

cmorley
Posts: 264
Joined: Sat Jul 30, 2016 7:11 pm
Location: Oxford

Re: puppeh's GCC6 for 6502

Postby cmorley » Wed Jun 07, 2017 8:41 am

Elminster wrote:@cmorley, Dont forget you were going to write up how you got to your setup


Code: Select all

++joblistlen;

User avatar
Elminster
Posts: 1632
Joined: Wed Jun 20, 2012 8:09 am
Location: Essex, UK

Re: puppeh's GCC6 for 6502

Postby Elminster » Wed Jun 07, 2017 8:49 am

:D

I'll write you a todo list in ...... BASIC

cmorley
Posts: 264
Joined: Sat Jul 30, 2016 7:11 pm
Location: Oxford

Re: puppeh's GCC6 for 6502

Postby cmorley » Wed Jun 07, 2017 8:50 am

"No room" ;)

User avatar
myelin
Posts: 204
Joined: Tue Apr 26, 2016 9:17 pm
Location: San Francisco, CA, USA
Contact:

Re: puppeh's GCC6 for 6502

Postby myelin » Thu Jul 06, 2017 5:25 pm

cmorley wrote:"No room" ;)


Any chance you could throw up a github fork with your patches, even if you don't have time to clean them up or document them? I would *love* to be able to use C rather than assembly for BBC programming, and this sounds like the best option...
SW/EE from New Zealand, now in San Francisco, making BBC/Electron hardware projects for fun.
So far: fast serial port, 32k flash cart, USB cart interface, 3-cart expansion, Elk PiTubeDirect.

cmorley
Posts: 264
Joined: Sat Jul 30, 2016 7:11 pm
Location: Oxford

Re: puppeh's GCC6 for 6502

Postby cmorley » Fri Jul 07, 2017 10:19 am

I'll do a diff this weekend and post my changes. There really wasn't much - mainly just removed a C64 remnant and moved the registers in ZP to preserve the BASIC workspace. Everything else was as per the github clone zip.

janrinze
Posts: 52
Joined: Sat Mar 19, 2016 6:38 am

Re: puppeh's GCC6 for 6502

Postby janrinze » Thu Oct 19, 2017 10:41 pm

Is there documentation on how to get a new platform (Acorn ATOM) supported with this compiler?
Having access to C++11 for the ATOM would be a big step forward for me.

cmorley
Posts: 264
Joined: Sat Jul 30, 2016 7:11 pm
Location: Oxford

Re: puppeh's GCC6 for 6502

Postby cmorley » Wed Oct 25, 2017 6:59 am

janrinze wrote:Having access to C++11 for the ATOM would be a big step forward for me.


It is C only AFAIK.


Return to “software: other”

Who is online

Users browsing this forum: No registered users and 7 guests