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

See the CrossGCC FAQ for lots more information.


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

Re: Variable passing C -> assembly, for m68k?



>I'm writing (and porting) some assembly language routines and need to
>know how gcc handles variable passing. I've read through "Using and
>Porting GCC", but can't find anything specific. It appears that in
>some architectures it uses the stack in others registers. I know I can
>use inline assembly and operand constraints, but would prefer to use
>standalone assembly programs that can be called from my C program.
>
>Where could I find the specific details for how gcc handles this for
>the m68k? Did I overlook it?

The best way I found to determine the calling convention is to write
some simple functions and run them through the compiler.  Ugly, but
insightful.

Here's the basics; you'll have to figure out the esoteric parts(such
as how are structures passed/returned, how varargs are used, etc).

Simple return types (char, short, int, long(if 32 bits), pointer) are
returned through %d0.  If you have an FPU then float, double are
returned through %fp0.  If you don't, float is return in %d0, double
is return in %d0/%d1.

Simple parameter types are pushed onto the stack, right to left so
upon entry to the function, the return address is at (%sp), the first
parameter is at 4(%sp), the 2nd parameter is at 8(%sp), etc.  If the
called function uses a frame pointer(via the 'link' instruction),
you'll find that the old frame pointer is 4(%sp) (%sp at the entry to
the function), and now the parameters start at 8 bytes off the frame
pointer after the link instruction is executed. 

One thing you'll have to determine for yourself(again by running code
through the compiler) is whether or not your system is expecting 1 or
two byte parameters(char, short) to only use 2 bytes of space on the
stack.  This is possible since for the older 68k variants the stack only
needed to be aligned on an even boundary.  For the newer 68k variants
it is much faster for the parameters to be aligned on a 4 byte
boundaries, so char/short pare pushed as a 4 byte word.

All registers except %d0/%d1/%a0/%a1 have to have the same
values across the execution of a function(and *all* subfunctions).  If
there's an FPU involved, I think %fp2-%fp7 have to be saved and
restored as well.

Hope this synposis is enough to get you started :-)

-- 
Peter Barada                                   Peter.Barada@motorola.com
Wizard                                         781-852-2768 (direct)
WaveMark Solutions(wholly owned by Motorola)   781-270-0193 (fax)

------
Want more information?  See the CrossGCC FAQ, http://www.objsw.com/CrossGCC/
Want to unsubscribe? Send a note to crossgcc-unsubscribe@sourceware.cygnus.com


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