cc65 C Cross Compiler

discussion of beeb/electron applications, languages, utils and educational s/w
atcurtis
Posts: 34
Joined: Fri Apr 08, 2016 9:47 am

cc65 C Cross Compiler

Postby atcurtis » Thu Nov 03, 2016 12:30 pm

I couldn't find where much existing work on supporting the BBC Micro with the CC65 cross compiler so I just had a go at hacking it.

I've posted my work on github, https://github.com/atcurtis/cc65 and I hope that it can be used seriously someday :D .
As it currently stands, it will generate runnable binaries and the appropriate INF file. What is needed is support for file I/O.

Next, I shall probably toy around with extending it to create ROM images.

User avatar
tricky
Posts: 1823
Joined: Tue Jun 21, 2011 8:25 am
Contact:

Re: cc65 C Cross Compiler

Postby tricky » Thu Nov 03, 2016 12:39 pm

I can't remember what the IO system is like, but if you tackle it, it might be worth looking at the restrictions emposed by the various mmc systems. I think they only do sector (or 2) reads and don't handle byte streams, but I could be wrong.

atcurtis
Posts: 34
Joined: Fri Apr 08, 2016 9:47 am

Re: cc65 C Cross Compiler

Postby atcurtis » Thu Nov 03, 2016 12:43 pm

Looking at the MOS calls available, it pretty much looks like only byte streams but block I/O there is OSGBPB.

dominicbeesley
Posts: 401
Joined: Tue Apr 30, 2013 11:16 am

Re: cc65 C Cross Compiler

Postby dominicbeesley » Wed Jul 19, 2017 2:52 pm

Did you get anywhere with this?

I started on a bbc target a long time ago and I was about to resurrect it and try and get it into 2.16.

D

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

Re: cc65 C Cross Compiler

Postby Elminster » Wed Jul 19, 2017 2:57 pm

Have you seen this thread?

puppeh's GCC6 for 6502

It is based on (bits of) cc65 as well
Last edited by Elminster on Wed Jul 19, 2017 6:14 pm, edited 1 time in total.

dominicbeesley
Posts: 401
Joined: Tue Apr 30, 2013 11:16 am

Re: cc65 C Cross Compiler

Postby dominicbeesley » Wed Jul 19, 2017 3:19 pm

Thanks, No I hadn't, I'll have a look!

(Though I quite liked hacking cc65 whereas gcc is just too big to be fun and quick to change, I've been trying to get gcc6809 working too...

dominicbeesley
Posts: 401
Joined: Tue Apr 30, 2013 11:16 am

Re: cc65 C Cross Compiler

Postby dominicbeesley » Thu Jul 20, 2017 10:27 am

I managed to get work I'd done copied over to a newer 2.16 version of cc65. This compiles and I've run a simple hello world program built by it but not much more. I suspect there are bugs and I seem to remember pressing Esacape caused programs to die horribly!

https://github.com/dominicbeesley/cc65

I need to tidy this up as it contains a load of stuff where I'd started putting some of the shared libraries into a Clib ROM (or sideways RAM) but it never got finished.

I'll try and get the gcc working too and compare the quality, size, speed of the emitted code at some point.

cc65 is worth a look for its nice assembler. The gcc assembler always makes me feel unwell!

D

User avatar
flibble
Posts: 567
Joined: Tue Sep 22, 2009 10:29 am
Contact:

Re: cc65 C Cross Compiler

Postby flibble » Sat Jul 29, 2017 8:09 pm

dominicbeesley wrote:I managed to get work I'd done copied over to a newer 2.16 version of cc65. This compiles and I've run a simple hello world program built by it but not much more. I suspect there are bugs and I seem to remember pressing Esacape caused programs to die horribly!

https://github.com/dominicbeesley/cc65


I've had a try with this repository and got things to compile but not link,

Using a very simple hello.c;

Code: Select all

#include <stdio.h>
#include <stdlib.h>

int main(void)
{

  printf("Hello, World!\n");
  exit(0);
}


Commands were
cl65 -c -t bbc -O -o hello.o hello.c
cl65 -t bbc -m hello.map -o hello hello.o

Error returned from link line was

Code: Select all

Unresolved external `BRKV' referenced in:
  bbc/brkvec.s(26)
  bbc/brkvec.s(28)
  bbc/brkvec.s(37)
  bbc/brkvec.s(39)
  bbc/brkvec.s(43)
  bbc/brkvec.s(45)
  bbc/brkvec.s(57)
  bbc/brkvec.s(59)
Unresolved external `EVNTV' referenced in:
  bbc/crt0.s(46)
  bbc/crt0.s(48)
  bbc/crt0.s(52)
  bbc/crt0.s(54)
  bbc/crt0.s(99)
  bbc/crt0.s(101)
Unresolved external `OSARGS' referenced in:
  bbc/lseek_extra.s(30)
  bbc/lseek_extra.s(54)
Unresolved external `OSASCI' referenced in:
  bbc/print0.s(9)
Unresolved external `OSBPUT' referenced in:
  bbc/write.s(116)
Unresolved external `OSBYTE' referenced in:
  bbc/init_stack.s(15)
  bbc/disable_cursor_edit.s(18)
  bbc/disable_cursor_edit.s(28)
  bbc/crt0.s(64)
  bbc/crt0.s(80)
  bbc/crt0.s(89)
Unresolved external `OSFIND' referenced in:
  bbc/fdtable.s(228)
Unresolved external `OSNEWL' referenced in:
  bbc/write.s(125)
Unresolved external `OSWRCH' referenced in:
  bbc/write.s(122)
  bbc/printhex.s(18)
  bbc/printhex.s(25)
  bbc/brkvec.s(163)
ld65: Error: 9 unresolved external(s) found - cannot create output file
Makefile:40: recipe for target 'hello' failed
make: *** [hello] Error 1



Any advice?

DigitalDunc
Posts: 43
Joined: Fri Sep 02, 2016 6:27 pm
Location: Oadby, Leicster, UK.

Re: cc65 C Cross Compiler

Postby DigitalDunc » Sun Jul 30, 2017 8:15 am

Just taking a stab in the dark but try including os.s in your crt0.s file. I've seen that os.s is exporting these missing symbols.

I guess we need some better documentation for cc65 and it's associated bits to give it that little more usability. It's still brilliant though.

User avatar
flibble
Posts: 567
Joined: Tue Sep 22, 2009 10:29 am
Contact:

Re: cc65 C Cross Compiler

Postby flibble » Sun Jul 30, 2017 5:14 pm

DigitalDunc wrote:Just taking a stab in the dark but try including os.s in your crt0.s file. I've seen that os.s is exporting these missing symbols.


I tried tweaking libsrc/bbc/crt0.s to include oslib/os.s where it then complained on making that it was including duplicate defines for things, so I'm pretty sure bbc.lib has os.s in already.

I ran strings on the bbc.lib and confirmed that it seems to contain 'BRKV', 'EVNTV' in.

My only thought is that my link line isn't actually using bbc.lib, but then even explicitly adding the lib to the link line returns the exact same error messages about missing 'BRKV' etc.

cl65 -t bbc -m hello.map -o hello hello.o /usr/share/cc65/lib/bbc.lib


I guess we need some better documentation for cc65 and it's associated bits to give it that little more usability. It's still brilliant though.


A few pointers, even just how to get a first program working would be appreciated :)

paulb
Posts: 764
Joined: Mon Jan 20, 2014 9:02 pm

Re: cc65 C Cross Compiler

Postby paulb » Sun Jul 30, 2017 7:53 pm

flibble wrote:I ran strings on the bbc.lib and confirmed that it seems to contain 'BRKV', 'EVNTV' in.

My only thought is that my link line isn't actually using bbc.lib, but then even explicitly adding the lib to the link line returns the exact same error messages about missing 'BRKV' etc.

cl65 -t bbc -m hello.map -o hello hello.o /usr/share/cc65/lib/bbc.lib


I haven't used cc65 for probably ten years or something like that. But might it be possible that you have to use the conventional linking syntax like this...?

Code: Select all

cl65 -t bbc -m hello.map -lbbc -o hello hello.o

User avatar
sweh
Posts: 1833
Joined: Sat Mar 10, 2012 12:05 pm
Location: New York, New York
Contact:

Re: cc65 C Cross Compiler

Postby sweh » Sun Jul 30, 2017 9:32 pm

I've never used cl65 before, so take all this with a grain of salt.

paulb wrote:

Code: Select all

cl65 -t bbc -m hello.map -lbbc -o hello hello.o

The BBC library is being pulled in, 'cos the errors are from bbc/brkvec.s bbc/crt0.s and so on.

("-l" on cl65 appears to create assembling listing files, anyway)

So for a laugh I did

Code: Select all

strace -ff -o /tmp/foo bin/cl65 -t bbc -o hello hello.c


and we can see the commands it tries to run:

Code: Select all

execve("bin/cl65", ["bin/cl65", "-tbbc", "-o", "hello", "hello.c"], [/* 44 vars */]) = 0
execve("bin/cc65", ["bin/cc65", "-t", "bbc", "hello.c"], [/* 44 vars */]) = 0
execve("bin/ca65", ["bin/ca65", "-t", "bbc", "hello.s"], [/* 44 vars */]) = 0
execve("bin/ld65", ["bin/ld65", "-o", "hello", "-t", "bbc", "hello.o", "bbc.lib"], [/* 44 vars */]) = 0


So definitely we can see the bbc library has been brought in.

This appears to work... but it's clearly a kludge

Code: Select all

bin/cl65 -tbbc -o hello hello.c libsrc/bbc/oslib/os.s

It seems as if os.s needs to be compiled into bbc.lib
Rgds
Stephen

dominicbeesley
Posts: 401
Joined: Tue Apr 30, 2013 11:16 am

Re: cc65 C Cross Compiler

Postby dominicbeesley » Mon Jul 31, 2017 9:08 am

I'm glad you're taking a look at it. The whole thing is very thrown together from bits of what I was working on about 15 years ago so my memory is dim, to say the least.

I got it all working well enough to compile and run the Contiki operating and run it as a web-server on my Master hooked up to the internet via a serial ppp link.

This is very dim memory but I think how it used to work was that it built all the stuff in libsrc/bbc/os/* into a second library "oslib.lib" which could be linked in with the program. I then started work on making a ROM (or it might have been a pair of ROMS) to take most of the common code into ROM. It look like when I've moved over to the new build system it is no longer building oslib. The idea was if you wanted to run with the roms there would be cut down oslib and bbclib stub libraries to link to...I didn't get very far with it and other things took over!

Probably the easiest fix would be to include all the stuff in libsrc/bbc/os/ in bbc.lib

I'll try and get a look at it this week. I got as far as compiling the test program I needed then left it...I've got a lot on at the moment.

I seem to remember the tricky bit in the libraries was trapping errors when they occurred.

D

User avatar
flibble
Posts: 567
Joined: Tue Sep 22, 2009 10:29 am
Contact:

Re: cc65 C Cross Compiler

Postby flibble » Mon Jul 31, 2017 10:00 am

dominicbeesley wrote:I'm glad you're taking a look at it. The whole thing is very thrown together from bits of what I was working on about 15 years ago so my memory is dim, to say the least.

I got it all working well enough to compile and run the Contiki operating and run it as a web-server on my Master hooked up to the internet via a serial ppp link.


From a personal point of view a C cross compiler may be the holy grail of BBC dev tools :)

Probably the easiest fix would be to include all the stuff in libsrc/bbc/os/ in bbc.lib


I've temporarily use the 'kludge' suggested by sweh

sweh wrote:

Code: Select all

bin/cl65 -tbbc -o hello hello.c libsrc/bbc/oslib/os.s


This created a binary, then a little play with using puts() instead of printf() generated a 2k smaller binary :)

Unfortunately I've run into my next issue, it doesn't actually do anything with *RUN on the box. Reading up the thread this may be due to load/exec addresses on the file (no .INF). This is my first time creating a machine code program on the beeb (albeit indirectly), what's the way to calculate these?

dominicbeesley
Posts: 401
Joined: Tue Apr 30, 2013 11:16 am

Re: cc65 C Cross Compiler

Postby dominicbeesley » Mon Jul 31, 2017 10:34 am

Yes, printf is huge, one of the reasons why the idea of having the c library in ROM came about!

If you find the bbc.cfg file (should be in /usr/local/share/cc65/cfg/bbc.cfg) it should have the load address coded in there. (Default is E00 for working on a Master).

You can either copy or edit that file and use the command line option to move to &1900 or whatever.

It should then be a case of
*LOAD <whatever> E00
CALL &E00

Or set the correct load/exec addresses - I'm pretty sure I made sure it ran from the load address!

D

User avatar
flibble
Posts: 567
Joined: Tue Sep 22, 2009 10:29 am
Contact:

Re: cc65 C Cross Compiler

Postby flibble » Mon Jul 31, 2017 11:00 am

dominicbeesley wrote:It should then be a case of
*LOAD <whatever> E00
CALL &E00

Or set the correct load/exec addresses - I'm pretty sure I made sure it ran from the load address!


Thank you!

win.png

User avatar
sweh
Posts: 1833
Joined: Sat Mar 10, 2012 12:05 pm
Location: New York, New York
Contact:

Re: cc65 C Cross Compiler

Postby sweh » Mon Jul 31, 2017 1:04 pm

flibble wrote:Unfortunately I've run into my next issue, it doesn't actually do anything with *RUN on the box. Reading up the thread this may be due to load/exec addresses on the file (no .INF). This is my first time creating a machine code program on the beeb (albeit indirectly), what's the way to calculate these?

I dunno how you're creating the SSD image for BeebEm, but if it uses inf files (pretty common) then something like

Code: Select all

$.HELLO      E00    E00  CRC=0

might work
Rgds
Stephen

User avatar
flibble
Posts: 567
Joined: Tue Sep 22, 2009 10:29 am
Contact:

Re: cc65 C Cross Compiler

Postby flibble » Mon Jul 31, 2017 2:16 pm

sweh wrote:I dunno how you're creating the SSD image for BeebEm, but if it uses inf files (pretty common) then something like

Code: Select all

$.HELLO      E00    E00  CRC=0

might work


I was using FSManager to put the file on a disc image, tweaked load and exec to E00 in that and I can *RUN it :)


Return to “software: other”

Who is online

Users browsing this forum: No registered users and 3 guests