[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [openrisc] Function prologue and stack frame



Hallo everybody. I'm sorry for my late answer, but anyway here it is.

> > It seems to me that there are some inconsistences between the prologue
> > that GCC introduces and what GDB expects to find at the beginning of
> > functions. I've looked at source code, and or32_output_file (in GCC
> > sources, or32.c) and or1k_skip_prologue (GDB sources, or1k-tdep.c) simply
> > don't match. Moreover, the prologue format expected by the mentioned
> > or1k_skip_prologue and by or1k_frame_chain (also from GDB sources) is not
> > the same.
>
> Yes, function prologues/epilogues were changed many times, since the
> original (in the manual) had problems. Note that specifications for this
> are very strict, and can cause lot of problems with OS development. As it
> did in our case ;)
> And I was doing gdb somewhere in the middle ;)
>
> Can you please post the differences, so we can choose the prologue we are
> happy with. I know Simon did a most of work on this when he was doing
> uClinux port.

The prologue introduced by GCC is as follows:

	l.movhi	r11, hi(stack_size)		|
	l.ori		r11, r11, lo(stack_size)	| this if stack_size >= 0x8000
	l.sub		r1, r1, r11				|
			or
	l.addi	r1, r1, -stack_size		| this if 0 < stack_size < 0x8000

	l.sw		I(r1), r2				| here I reserves space for		|
								| outgoing args and link register	|
								| save						| if needed
															| to save
	l.add		r2, r1, r11				| stack_size  >= 0x8000			| frame pointer
			or												|
	l.addi	r2, r1, stack_size		| 0 <= stack_size <= 0x8000		|

	l.sw		I(r1), r9				| I reserves space for			| if saving
								| outgoing args only				| link register

	l.sw		I(r1), rx				| As needed to save
								| registers used in function

While the prologue expected in or1k_skip_proloque is completely different (see 
or1k-tdep.c in GDB sources). Strangely, or1k_frame_chain DOES expect the 
format intoduced by GCC (???).

> > On the other hand, the stack frame format depicted on the OpenRISC
> > Architecture Manual is different to the one created by the code actually
> > inserted by GCC. The latter puts local variables just below FP, and
> > previous FP and return address below those.

The prologue shown above creates a stack frame like this:

FP ------>	------------------------
		Function variables
		------------------------
SP+4 --->	Previous FP
SP------->	Return address

that doesn't match with the one shown on the ABI chapter of the Architecture 
Manual. So when I say that or1k_frame_chain expects the prologue actually 
introduced by GDB y meant that expects the frame format created by that 
prologue.

I hope my explanations are clear enough. It's not easy to draw such memory 
diagrams using ASCII :-(

Best regards,

	Carlos
--
To unsubscribe from openrisc mailing list please visit http://www.opencores.org/mailinglists.shtml