[gnu.gcc.bug] Porting GCC to Gmicro CPU

yuhara@minako.stars.flab.fujitsu.junet (Masanobu Yuhara) (10/19/89)

Dear Sirs,

I'm Masanobu Yuhara at Fujitsu Labs.
I ported gcc (1.36) to the Gmicro CPU.

The Gmicro is a 32 bit microprocessor family developed/being developed by
Fujitsu (Gmicro/300), Hitachi (Gmicro/200) and Mitsubishi (Gmicro/100).
Performance of the Gmicro/300 is in the range of next generation
CISC microprocessors (such as i486 and 68040).

Since the Gmicro is based on the TRON specifications, my port may be
applicable to other TRONCHIPs developed/being developed by Toshiba,
Matsushita, Oki,....

We are enjoying the benefit of GNU software,
so I would like to contribute to GCC by distributing my porting.

"README.Gmicro" is included at the end of this mail.

I think my port (tm-gmicro.h, gmicro.md, out-gmicro.c, etc.) should be
copyrighted by both FSF and Fujitsu Labs. under GNU general public license.
If the copyright by both is a problem, please let me know.

I will mail my port to you in a week or so.
I am also planning to post the port to the network.

Files I added are:
    config/tm-gmicro.h
    config/gmicro.md
    config/out-gmicro.c

Files I modified are:
    Makefile	(gcc -> gmc, etc.)
    c-decl.c	(for __builtin_smov() (string copy))
    config.gcc	(new entries for the Gmicro)
    expmed.c	(enhanced version of expand_mult() by K.Kumon)
    expr.c	(for __builtin_smov() (string copy))
    rtl.def	(for __builtin_smov() (string copy))
    tree.h	(for __builtin_smov() (string copy))
    varasm.c	(Gmicro asm does not have ".comm".
		 I had to use ".res" (reserve bytes) and ".export" instead
		 which must be the bss section.
		 As a quick hack, I forced to call "data_section ()"
		 before the ".res" sequence.)
    version.c	(to reflect minor changes of the port.)

------------------------------
Masanobu Yuhara
AI Labs.
Fujitsu Laboratories LTD.
    yuhara@flab.fujitsu.co.jp
    yuhara%flab.fujitsu.co.jp@uunet.uu.net

============== README.Gmicro ==============
1. Abstract

I ported the gcc to the Gmicro -- a 32 bit microprocessor series based on
the TRON specification.
GCC for the Gmicro, which I call "gmc", is not yet complete,
but it seems to produce better code than existing Gmicro C-compilers.
Since the machines using the Gmicro CPU is not yet popular,
GMC works as a cross-compiler.
GMC has been tested on the SUN3 and Sony NEWS, and it should not be difficult
to port it to other machines.

Since I have not ported GNU AS or GNU LD,
GMC must be used with the standard Gmicro assembler/linker
(on SUN3, VAX, etc.) which is sold by Fujitsu and other Gmicro companies.
(This means you always have to give the -S option to GMC.)

"DOC.Gmicro.EUC" contains almost the same information as this file though
it is written in Japanese (EUC code) in a ditroff format.

2. Copyright

The original GCC is of course copyrighted by the Free Software Foundation.
Fujitsu Laboratories LTD.  hold copyright on my modification,
but my modification is free.
You may redistribute it and/or modify it under the terms of the
GNU general Public License as published by the Free Software Foundation;
either version 1 or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.

Though I can not promise I will fix bugs in the future,
bug reports and comments are welcomed.
You can contact me at:

	Masanobu Yuhara
	Artificial Laboratories
	Fujitsu Laboratories LTD. Kawasaki
	1015 Kamikodanaka, Nakahara-ku,
	Kawasaki, 211, JAPAN

or if the message does not contain any commercial value,
you can use any of the following electric-mail addresses.

	yuhara@flab.fujitsu.co.jp
	yuhara%flab.fujitsu.co.jp@uunet.uu.net
	...!uunet!kddlab!titcca!fgw!flab!yuhara

3. Porting Strategy

The Gmicro CPU has an orthogonal instruction set.
There is no distinction between data registers and address registers.
In a sense, it resembles the VAX architecture.
But the Gmicro CPU does not contain a Floating Point UNIT in it
(at least not yet), so an external FPU must be attached.
Floating point instructions take the form of co-processor instructions,
which is why I ported gcc based on the m68k version (but partially on
the VAX version).
Simple compilation was possible in only a week. I could compile dhrystone
(with some bugs) at the beginning of the third week.
This fact shows the GREAT portability of GCC.

4. Current Status

GMC has hardly been tested.
It may contain a lot of bugs,
especially concerning floating point data and bit-field structures which
haven't been checked at all.
GMC is now based on gcc 1.36.

"gnulib" is not yet ready.
If you need gnulib, compile it using another C-compiler for the Gmicro.


5. Extension to the GCC

(1) Constant multiplication.

Constant integer multiplications are expanded to add/mova/shift instructions.
This part was done by Kumon Kouichi at our Labs.

(2) built-in strcpy

Built-in strcpy is supported.
The name of the function is __builtin_smov(), not strcpy(),
but its arguments and the function are the same as strcpy's.
If the source string is a constant string,
the expansion uses the knowledge of the length of the string.

6. How to install.

(1) Restore source files from the tape.

(2) DO "make clean" and  "touch cexp.c c-parse-tab.c".

(3) If you are installing GMC on SUN3, do "config.gcc gmicro-sun3".
    If you are installing GMC on Sony NEWS, do "config.gcc gmicro-news".
    If you are installing GMC on other machines, check config.gcc
    and change the configuration_file to xm-YOUR-MACHINE.h.

(4) If you are installing on a Sony NEWS, change the definition of GCC in
    the Makefile (around line 70) from "cc" to "gcc".
    This must be done because some files cannot be compiled by Sony-cc.
    (First you have to install gcc for the NEWS.)
    If you are installing on another machine including the SUN3, make sure
    that the GCC in the Makefile (around line 70) is defined as "cc" not "gcc".

(5) Run "make".

(6) Do "make install". Installed files are as follows.
    The name "gmc" is used so as not to confuse with the native gcc.
	/usr/local/bin/gmc
	/usr/local/lib/gmc-cpp
	/usr/local/lib/gmc-cc1
	/usr/local/lib/gmc-include/*
	/usr/local/man/man1/gmc.1    (general gcc man)

7. Usage

You have to read at least the five chapters of gcc.info.
In this section, I only describe Gmicro specific items.

(1) Machine dependent options

Default options are "-mg300 -mfpu -mno-bitfield -mno-force-smov".

-mg300	[default]
	Compile for the Gmicro/300. 
	"mtst" instruction is used with -mg300.

-mg200	Compile for the Gmicro/200.
	"mtst" instruction is not used.

-mg100	Compile for the Gmicro/100.
	FPU and "mtst" instructions are not used.

-mfpu	[default]
	Use FPU instructions.

-msoft-float	Do not use FPU instructions.

-mrtd	Use a different function-calling convention, in which functions
	that take a fixed number of arguments return with the "exitd"
	instruction (corresponds to m68k's "rtd" instruction),
	which pops their arguments while returning.
	(See m68k options in gcc-info for restrictions with this option).
	(Normally, even if the "exitd" instruction is used, its second operand
	 is zero.)

-mregparm
	Pass function arguments in registers.
	This is experimental.

-mbitfield
	Use bitfield instructions.

-mno-bitfield	[default]
	Do not use bitfield instructions.
	(Bitfield is not debugged.)

-mnewreturn
	Produce code without register conflicts when returning from a function.
	This option cannot be used for programs that run in RING zero.
	With this option memory locations below the stack pointer temporarily
	contain active data. Therefore, when running in RING zero,
	this data could be destroyed in the EIT-handler routine.
	(EIT = Exception, Interrupt and Trap)

-mforce-smov
	__builtin_smov (strcmp) usually expands to multiple mov instructions
	if the second argument is a short string constant.
	With this option, __builtin_smov always uses the "smov" instruction.
	(Except when the string constant is smaller than 4 bytes.)

(2) Predefined Macros

Macro "gmicro" is predefined.

(3) Register Names

Register names are used if you use "asm" function or -ffixed-REG, 
-fcall-used-REG, -fcall-saved-REG options.
They are r0, r1, ...., r13, fp, sp, fr0, fr1, ...,fr15.

Default fixed-registers is sp.
Default call-used-registers are r0-r3, sp, fr0-fr3.
Default call-saved-registers are r4-r13, fr4-fr15.

(4) Recommended options

You have to specify the "-O -fomit-frame-pointer" option to get good code.

"-fforce-mem" and "-fforce-addr" may (or may not) give better code.

Try "-mnewreturn" if it is allowed.