Over the years there have been a number of attempts to port gcc
to the 6809. None of these have ever ended up as part of the standard
gcc distribution. What is offered here is the best version that I am
aware of.
This distribution is based on the work of James Dessart, whose
gcc for 6809 page
was the basis for this version. You should
visit James' page for some background on the history of this port.
You do not need any of the files from his site in order to build gcc
proper. You will, however, need the assembler and linker that are
there, in order to make final executables.
Again, the gcc here will only translate C source code into
6809 assembler files. You still need an assembler and linker,
and possibly libraries, to complete your application. At present
the only supported assembler is the asxxxx tools from Alan
Baldwin. At least version 1.5.2 should be used; I'm currently doing
most of my testing with version 4.1.0.
As of the latest development tree, gcc versions 3.4.4 through 3.4.6
work correctly. gcc 4.x compiles but frequently aborts. gcc 3.3.6
used to work OK but isn't supported anymore.
This is an active project; if you want to contribute, have any
questions, or want to report any bugs with this software, contact me at
brian@oddchange.com.
Source Code Packages
Packages are not being provided for future versions of gcc6809,
due to lack of interest. See information below on how to access
the online source repository; this is open to everyone.
Download the
gcc6809 Release 1.2
source code if you want to build
the compiler yourself. You'll need a native version of gcc on your
host system.
This tarball consists of the 6809 machine definition and some
replacements for some core gcc files. Once you've downloaded it,
expand it using tar and bunzip.
In order to build, you'll also need an official gcc tarball for
the version you want to build. You can get this from any GNU mirror.
For example, for gcc6809 3.4.5, download gcc-3.4.5.tar.bz2. Place
this file into the releases directory that was created when you
expanded the 6809 tarball.
Finally, to build the compiler, just type make everything, and
hopefully it will work for you. Read the Makefile for a list
of other ways you can kick off the build, and for more information on
what to do next.
If you use Cygwin, beware that building the compiler is slow.
Note, you do not need the patchfiles on James' web site, as they
have been incorporated into the 6809 tarball for one-stop downloading.
Online Source Code Access
The source code is managed in a Subversion repository at the following
location:
http://www.oddchange.com/svn/public/gcc6809
Anonymous read-only access to the repository is allowed to all.
You will need a Subversion client in order to checkout the files; or
you can use WebSVN to browse the repository
and/or download tarballs.
The latest stable release of the code is located in the
tags/2006-06-09 directory. The absolute latest changes can
always be found by going into the trunk directory.
Philosophical Differences
I've made a number of changes which relate specifically to the pilot project on
which I am using this compiler. I believe that these are worthy changes that
apply elsewhere, too, but users of previous versions of gcc6809 may not agree.
By default, int is an 8-bit quantity, not a 16-bit one. Even though
gcc can do some 16-bit math using the index registers, fundamentally I believe
the machine to be 8-bit and believe that the programmer should explicit ask for
16-bit quantities when needed. In many cases, this is sufficient, and leads to
better register usage.
I've made little attempts to keep compatibility with James' original
version, as I've gotten no interest from anyone using that version to
migrate to the new one. I'm willing to work with other parties to
help keep compatibility for existing projects.
Release Notes
Release 1.3 (Coming Soon -- these changes are only in SVN)
- GCC 3.4 is now working. I've tested with 3.4.4 through 3.4.6.
- #pragma naked and #pragma interrupt are now deprecated,
and may not always work correctly. Use __attribute__((naked))
and __attribute__((interrupt)) instead.
- The condition code register is now exposed. Declaring a variable as
asm ("cc") ties it to the CC register. The only operations
supported are AND or OR, corresponding to the andcc and orcc instructions.
- Enhanced versions of subreg patterns, which allows more
mixed 8-bit and 16-bit arithmetic to compile OK.
- Optimize calls to noreturn functions.
Release 1.2
- Branch instructions should be auto-selected based on instruction sizes.
If the target can be reached with a short branch, use that, otherwise use
a longer one. The old solution relies on the programmer to select
this using command-line options and #pragmas. The old pragmas will be
retained for compatibility. The command-line switches -mshort-branch
and -mlong-branch will also override. Normally, neither of these
should be used.
- For the WPC, use the hardware shifter when possible. The
-mwpc option will enable all WPC extensions. Warning, this is
not interrupt-safe at the moment.
Release 1.1
- Files have been cleaned up significantly in terms of alignment.
They are much more readable than before, which will help with maintenance.
Also, many of the constructs used in the backend have been around since
gcc 1.x. A lot of these has been rewritten to take advantage of newer
gcc features.
- Integer defaults to 8-bit. You can override this using -mint16.
- Many new instruction patterns have been added to the backend. This
fixes many compiler aborts for when a particular sequence could not be
generated. Note: there are still some problems, but quite a few have been
resolved. Most of the problems relate to complex 16-bit math, for which
library functions should really be used.
- -O2 works, at least for me.
- Function arguments can be passed in registers. The CVS version pushes
all arguments on the stack. If you don't like the new method, use
-mno-regargs.
- Function return value for 16-bit quantities is placed in the X register
rather than D. The rationale is that most 16-bit quantities will be
pointers.
- The X register is considered call-clobbered, and does not need to be
saved on entry to a function.
- Limited support for direct mode addressing has been added. You can
declare variables as belonging in the direct section, via
__attribute__((section("direct"))), and the compiler will use
direct addressing when doing memory accesses. This generates shorter
instructions and also executes them faster. You can disable this feature
by using -mnodirect.
- #pragma naked can be used before any function to disable
the function prologue/epilogue. This can be used to write C functions that
act like true assembly language routines.
- Short branch instructions are the default. In large functions,
this will break; you can use a #pragma long_branch before such
a function, and then #pragma short_branch after it to change
the method.
Future Enhancements
More changes are in the pipeline:
- Support inline const function arguments. These require that the caller
place the arguments in memory immediately following the function call.
The subroutine finds the arguments in memory using the return address,
and adjusts it accordingly. This saves memory in that callers do not
need to load registers/memory with constant arguments, nor do they need
to pass a pointer to a structure, since the location is implied. There is
extra overhead in the subroutine to decode the arguments this way, but
for frequently used functions with only constant arguments, there will
be space savings.
- Use the 'A' accumulator register more. It is mostly ignored or
only used internally for certain multi-instruction sequences. Using
'A' better reduces the need for more expensive memory operations.
- Work with the GCC 4.0 releases. This work is being done in
branches/gcc41 to avoid breaking the working GCC 3.x releases
on the mainline.
- Provide more optimal patterns for some instructions that are still
slightly inefficient.