Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.sys.apple2.programmer > #2891

Re: GCC for 6502

From D Finnigan <dog_cow@macgui.com>
Newsgroups comp.sys.apple2.programmer
Subject Re: GCC for 6502
Date 2016-08-08 19:11 +0000
Organization Mac GUI
Message-ID <dog_cow-1470683495@macgui.com> (permalink)
References <dog_cow-1470091530@macgui.com>

Show all headers | View raw


Here is another one for consideration:
http://oric.free.fr/COMPILERS/gcc6502.src.tgz

These are the files necessary to configure GCC to generate code for a 6502
microprocessor.

===============================================================================

		Targeting GCC for a 6502 Microprocessor

			2/3/97

		By Dave_Mcwherter@franklin.com

===============================================================================
Introduction

This document describes a port of GCC to the 6502 microprocessor. (This port
is
referred to as GCC02 in the rest of this document). The port was done at
Franklin
Electronic Publishers, Inc. to support development of their electronic books
on their BOOKMAN (registered trademark of Franklin Electronic Publishers,
Inc.)
platforms. It generates assembly code for the in-house Franklin 6502
assembler
Asm6, which is not part of this contribution. Changing the assembly output
to
accomodate other assemblers should not be difficult, however.

The port was originally done using GCC version 2.6.3 and has since been
tested
with GCC version 2.7.2. The port was done on a Macintosh Power PC using the
Metrowerks Codewarrior C compiler versions CW8 through CW10. Getting GCC
to build and run on a non-Unix box is a worthwhile topic in its own right.

*** There are changes necessary to the GCC source files to support this
port!!!!
*** Not everything could be accomplished using the 'standard' GCC porting
*** mechanisms. These changes are described at the end of this document.

===============================================================================
Deviations from ANSI C

* All local storage is static - local variables which overflow the sixteen
	zero-page registers will be allocated from static RAM.

* Functions which have more than twelve arguments will cause the compiler to
	abort. (Because a frame pointer is not supported.)

* GCC02 does not promote chars to ints in these three situations:
	- case selections in switch statements
	- function arguments
	- function return values
	(These are done via changes to the GCC source code, so you don't
	have to make the changes if you don't want to.)

* The standard GCC option '-fshort-enums' is hard-wired ON to make
enumerated
things only as big as they need to be (most often, they will be of size
char).

* 'size_t' is defined as 16 bits.

* Nested functions are not supported yet.

* Floating point or long longs are not supported yet.

All of these changes were done so that we could generate code for a typical
Franklin application as efficiently as possible without any overhead which
our applications would never use anyway.

===============================================================================
Compiling

You must use the -b6502 switch to select 6502 code generation.

GCC02 can only generate 6502 code at optimization level 2, so that's
hard-wired into the compiler (because a frame pointer is not supported). You
can select any other optimization level you want and it will have no effect.

Other options: (described in detail somewhere below)

	-mconfig-filename	specify filename as the configuration file

	-m16bitx		don't convert 16-bit indices to 8-bit

	-mdoasr			don't convert asr's to lsr's

	-mfarcall		support Franklin's farcall system (not
				supported in this submission)

===============================================================================
Output format

GCC02 produces assembly code in Asm6 (Franklin's in-house assembler) format.
Asm6 is not part of this submission and is not available from Franklin.

===============================================================================
Target model

GCC02 is implemented using a pseudo-register model because the 6502 doesn't
have anywhere near enough registers to properly support a machine of the
class
which GCC expects. There are 16 24-bit pseudo-registers r0-r15 located in
zero
page. There is also a 24-bit temporary register "t" in zero page. All other
RAM
is available for the compiled application.

GCC02 also uses the 6502 A, X, and Y registers as a 24-bit temporary
register.



===============================================================================
Coding tips

These are things you can do in your C source code to make your generated
6502 code better...

Avoid signed variables. Sign extension is expensive on the 6502. If a
variable
requires signedness only occasionally and can be unsigned most of the time,
consider casting it when you need the signedness. If it always must be
signed,
then consider casting it to unsigned especially if you use it as an index
into
an array, unless you absolutely need to go backwards from the base of the
array.

Make sure your BOOL's and BOOLEAN's are typedef'ed as 8 bits.

Remember that long's are 24 bits - not 32. Some code uses the upper 8 bits
of a 
presumed 32-bit long. You will need to change such code or hand-code it.

Avoid recursion. Sometimes it will work and sometimes (most of the time) it
won't. If a function requires no local storage (everything is kept in
r8-r15),
then it will work until you exceed the capabilities of the 256-byte 6502
stack
(probably real quick). Otherwise, it won't.

Back to comp.sys.apple2.programmer | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

GCC for 6502 D Finnigan <dog_cow@macgui.com> - 2016-08-01 22:45 +0000
  Re: GCC for 6502 mmphosis <mmphosis@macgui.com> - 2016-08-02 16:11 +0000
    Re: GCC for 6502 D Finnigan <dog_cow@macgui.com> - 2016-08-02 19:09 +0000
  Re: GCC for 6502 Michael Pohoreski <michael.pohoreski@gmail.com> - 2016-08-03 10:35 -0700
  Re: GCC for 6502 David Schmenk <dschmenk@gmail.com> - 2016-08-03 13:30 -0700
    Re: GCC for 6502 D Finnigan <dog_cow@macgui.com> - 2016-08-03 21:24 +0000
      Re: GCC for 6502 Bill Buckels <bbuckels@escape.ca> - 2016-08-03 17:57 -0700
        Re: GCC for 6502 D Finnigan <dog_cow@macgui.com> - 2016-08-04 17:40 +0000
          Re: GCC for 6502 handyandy802@gmail.com - 2017-07-06 12:05 -0700
  Re: GCC for 6502 D Finnigan <dog_cow@macgui.com> - 2016-08-08 19:11 +0000

csiph-web