This is the mail archive of the crossgcc@cygnus.com mailing list for the crossgcc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: PowerPC 403 cross


root@cicdphx.com (root) writes:

> 
> 		Hello All....
> 
> 
> 	I have been working recently on compiling C programs using gcc 
> (target: powerpc-elf32), and was interested if anyone had some 
> information specific to the PPC403 when using gcc.  I am unsure as to 
> which registers are used for what, and any compiler flags I need to use.  
> Currently I use flags: -mcpu=403, -D_BIG_ENDIAN.  I have figured out that 
> r1 appears to used as a stack pointer of sorts, but as far as which 
> registers are used for scratch, how parameters are passed, etc. I am in 
> the dark.  

Get the following files via anonymous ftp from cambridge.cygnus.com:

	~ftp/pub/ppc-docs/ppc-sysv-1995-09.ps.gz
	~ftp/pub/ppc-docs/ppc-eabi-1995-01.ps.gz

The first is the System V ABI that originally came from Sun (for the short
lived Solaris port to PowerPC), and the second is the eABI (embedded
application binary interface) that is a modification of the System V ABI
(changes the stack alignment, removes some relocations and adds others, makes
r2 be a secondary small data register).

In short, the ABI looks like:

	SP---->	+---------------------------------------+
		| back chain to caller			| 0
		+---------------------------------------+
		| saved LR				| 4
		+---------------------------------------+
		| Parameter save area (P)		| 8
		+---------------------------------------+
		| Alloca space (A)			| 8+P
		+---------------------------------------+
		| Local variable space (L)		| 8+P+A
		+---------------------------------------+
		| saved CR (C)				| 8+P+A+L
		+---------------------------------------+
		| Save area for GP registers (G)	| 8+P+A+L+C
		+---------------------------------------+
		| Save area for FP registers (F)	| 8+P+A+L+C+G
		+---------------------------------------+
	old SP->| back chain to caller's caller		|
		+---------------------------------------+

   The registers are used as follows (volatile means that a function does not
have to preserve its value when it returns, saved means that a function must
restore its value before returnning):

    r0		volatile, may be used by function linkage
    r1		stack pointer
    r2		secondary small data area pointer
    r3	.. r4	volatile, pass 1st - 2nd int args, return 1st - 2nd ints
    r5  .. r10	volatile, pass 3rd - 8th int args
    r11	.. r12	volatile, may be used by function linkage
    r13		small data area pointer
    r14 .. r30	saved
    r31		saved, static chain if needed.
    f0		volatile
    f1		volatile, pass 1st float arg, return 1st float
    f2  .. f8	volatile, pass 2nd - 8th float args
    f9  .. f13	volatile
    f14 .. f31	saved
    lr		volatile, return address
    ctr		volatile
    xer		volatile
    fpscr	volatile*
    cr0		volatile
    cr1		volatile**
    cr2 .. cr4	saved
    cr5 .. cr7	volatile

* The VE, OE, UE, ZE, XE, NI, and RN (rounding mode) bits of the FPSCR may be
changed only by a called function such as fpsetround that has the documented
effect of changing them, the rest of the FPSCR is volatile.

** Bit 6 of the CR (CR1 floating point invalid exception bit) is set to 1 if a
variable argument function is passed floating point arguments in registers.

   When alloca is executed, the back chain to the caller's stack frame and the
link register save area must be updated.

   The parameter save area does not contain space to store the 8 integer
arguments.  If it is desired that they be stored, the callee must allocate
space to save it in the local variable area of the stack.  Structures and
unions are copied into temporary slots and an address of the temporary slot is
passed as the argument.

   Variable argument functions must store the registers used for passing
arguments that aren't used for fixed arguments into a 96 word area on the stack
in the local variable section.  If bit 6 of the CR is not 1, it doesn't have to
save the floating point registers.  The va_list type is defined as follows:

	typedef struct {
	    char gpr;			/* index to next saved gp register */
	    char fpr;			/* index to next saved fp register */
	    char *overflow_arg_area;	/* ptr to next overflow argument */
	    char *reg_save_area;	/* ptr to reg save area */
	} va_list[1];

-- 
Michael Meissner, Cygnus Solutions (East Coast)
4th floor, 955 Massachusetts Avenue, Cambridge, MA 02139, USA
meissner@cygnus.com,	617-354-5416 (office),	617-354-7161 (fax)