From: Adrian M. <ad...@mc...> - 2002-04-22 21:42:29
|
if I have a function in C - say: foobar(int32 x, void* y, int16 z) When that turns up in SH4 assembler - how are the parameters passed? Adrian |
From: Stuart M. <stu...@st...> - 2002-04-23 10:41:04
|
Adrian This is something I wrote a while ago when somebody asked the same question (I assume were talking gcc here). Simply: - r0-r7 are caller save (ie the called function can use them without having to save them first) - r8-r15 and pr are callee save (ie if the called function wants to update them then it must save them first) - First four integer parameters are passed in register r4-r7, remainder on the stack - r15 is the stack pointer, so will generally by saved/restored automatically, and r14 is the frame pointer, which you may or may not choose to use. - r0 is used for the return value, if it fits in a word, otherwise the function is called with r2 as a pointer to where the result should be stored. Floating point I'm not so sure about, and can be complex, but basically: - fr0-fr11 are caller save fr12-fr15 are callee save - Parameters are passed in dr4-dr10 (which corrisponds to fr4-fr11), but when a mix of floats and doubles are passed they are 'packed' into the lower registers, possibly 'rounding up' to get the next available double length register. The remainder are on the stack. In general the easiest way to do anything with this is experiment. Try writing a small C program which does what you want, and look at the generated assembler. So for your example: foobar(int32 x, void* y, int16 z) x, y and z will be in r4, r5 and r6 respectivly. Hope this is some help Stuart On Mon, 22 Apr 2002 22:42:38 +0100 ad...@mc... wrote: > if I have a function in C - say: > > foobar(int32 x, void* y, int16 z) > > When that turns up in SH4 assembler - how are the parameters passed? > > Adrian > > _______________________________________________ > Linuxdc-dev mailing list > Lin...@li... > https://lists.sourceforge.net/lists/listinfo/linuxdc-dev -- Stuart Menefy stu...@st... STMicroelectronics Ltd ST Intranet: mo.bri.st.com Bristol, UK Rest of the World: www.linuxsh.st.com |
From: Adrian M. <ad...@mc...> - 2002-04-23 22:30:07
|
On Tuesday 23 Apr 2002 11:40 am, Stuart Menefy wrote: > Adrian > > This is something I wrote a while ago when somebody asked the same question > (I assume were talking gcc here). > Stuart, Thanks very much for this - very helpful and already the dissasembly is beginning to make sense - but what is the frame register (r14) - ie what is it's function. This is not a term I've coem across before and I cannot find it referenced in the Hitachi programming manual. Thanks, Adrian |
From: Stuart M. <stu...@st...> - 2002-04-24 12:29:13
|
Adrian The frame pointer is used when stack contains objects of unknown size, for example variable size arrays, or when alloca() is used. It is also used sometimes when setting up the parameters for functions which take a large number of parameters. In this case the stack will look something like: higher address |caller's stack +------------------ |parameters | |local variables +------------------ <- frame pointer | |dynamic data | +------------------ <- stack pointer lower address Normally the compiler uses the offset from the stack pointer to reference local variables. However when there is dynamic data, the compiler cannot use the stack pointer because it doesn't know at compile time the size of the dynamic data. So what the compiler will do, when it detects this situation, is after moving the stack pointer down to make room for the local variables, it copies the stack pointer into the frame pointer, and from then on reference local variables and parameters through the frame pointer. The stack pointer is now used only for allocating dynamic data and making further function calls. In theory the compiler only need to do this when dynamic data is being used, but in practice it makes backtracing through code easier if the frame pointer is always used. So you'll frequently see code which stores the frame pointer on the stack, and copies stack pointer to frame pointer on entry to a function, and then never uses it, simply because it makes backtracing easier for debugger. Stuart On Tue, 23 Apr 2002 23:27:07 +0100 ad...@mc... wrote: > On Tuesday 23 Apr 2002 11:40 am, Stuart Menefy wrote: > > Adrian > > > > This is something I wrote a while ago when somebody asked the same question > > (I assume were talking gcc here). > > > > Stuart, > > Thanks very much for this - very helpful and already the dissasembly is > beginning to make sense - but what is the frame register (r14) - ie what is > it's function. > > This is not a term I've coem across before and I cannot find it referenced in > the Hitachi programming manual. > > Thanks, > > Adrian -- Stuart Menefy stu...@st... STMicroelectronics Ltd ST Intranet: mo.bri.st.com Bristol, UK Rest of the World: www.linuxsh.st.com |