Re: calling conventions for MIPS 2000/3000

chenw@crhc.uiuc.edu (William Chen)
Fri, 23 Aug 91 04:00:14 GMT

          From comp.compilers

Related articles
calling conventions for MIPS 2000/3000 pjh@cs.unh.edu (1991-08-21)
Re: calling conventions for MIPS 2000/3000 chenw@crhc.uiuc.edu (1991-08-23)
| List of all articles for this month |
Newsgroups: comp.compilers
From: chenw@crhc.uiuc.edu (William Chen)
Keywords: architecture, design
Organization: University of Illinois
References: 91-08-113
Date: Fri, 23 Aug 91 04:00:14 GMT

> In particular I am confused about the size of the "procedure call
> argument area". I realize that I must allocate space here even though
> arguments are being passed in registers. What I'm baffled about is
> exactly how much space must be allocated here.
>
> For example, for this simple C function,
>
> void main()
> {
> float x;
>
> x = 1.0;
> printf("%e\n",x);
> }
>
> "cc -O" generates a frame of length 24 bytes. This apparently
> includes 4 unused bytes at the "top" of the frame, 4 bytes for saving
> r31, and 16 bytes for the arguments area. Why 16 bytes here? It looks
> like only 12 bytes are needed, 4 for the char * first parameter and 8
> for x converted to a double. But if only 12 bytes are allocated then
> printf prints garbage.


One reason immediately comes to mind is variable parameter passing. The
callee will assume the maximum number of parameters passed in registers. In
this example, "printf" is a variable parameter function, and MIPS will save
all passing registers ($4, $5, $6, and $7) on the stack first. If the caller
does not allocate 16 bytes, other values on the stack will be overwritten.


Since separate compilation is possible, there is no way for the caller to
predict how much stack space the callee is required, and the full 16 bytes
must be allocated.


In your example, 16 bytes of parameter passing space is needed regardless,
since the 'double' variable is aligned on the 3rd passing parameter ($6,$7,
and register $5 is skipped). Then you have $4, blank, $6, $7 (char * is 4
bytes, 4 bytes of blank space, and 8 bytes for the double).


Also, very *** IMPORTANT *** is that MIPS architecture requires the frame size
to be a multiple of * 8 *. This can explain your example where 24 bytes of
stack space is required (16 bytes for parameter, 4 bytes for the return
address, and 4 bytes for alignment). In your example, I am not exactly sure
what you did, but the garbage value printed out is very possibly caused by the
non-multiple of 8 stack frame.


-Bill


--
William Y. Chen | chenw@crhc.uiuc.edu
University of Illinois |
Center for Reliable and | (217)333-4171
High-Performance Computing |
kkk
--


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.