Could any one clarify the below codes.

Hi all, Below code is part of powerpc 555 boot up code, could any one explain, wh stack is terminated by "stwu r0,-64(r1)"

addi r1,r11,_ld_stack_end@l # value in linker command file. addis r13,r0,_SDA_BASE_@ha # Initialize r13 to sdata base addi r13,r13,_SDA_BASE_@l # (provided by linker). addis r2,r0,_SDA2_BASE_@ha # Initialize r2 to sdata2 base addi r2,r2,_SDA2_BASE_@l # (provided by linker). addi r0,r0,0 # Clear r0. stwu r0,-64(r1) # Terminate stack.

Expecting replies from you all.

Reply to
Mohan kumar
Loading thread data ...

A little googling shows that it's powerpc convention to store a pointer to the previous stack frame in a new one, basically making them a linked list. This seems to be setting up the first-ever stack frame, and so it's storing zero to indicate there was no previous one. I'm not completely sure, but this may not actually be necessary for execution, but instead just to be to help a debugger figure out that it's the first frame and there are no previous ones that can be examined.

Reply to
cs_posting

Hi thanks for your reply,

the puzzling question that rocks my mind is why should they terminate th stack by subtracting 64 with the stack pointer(r1)

addi r1,r11,__stackstart_pt@ha addi r1,r11,__stackstart_pt@l addi r0,r0,0 stwu r0,-64(r1)

  1. first two lines of code have defined the stack pointer(r1)
  2. third lines has cleared register r0.
  3. r1 is the stack pointer(sp) and sp is already initialised by first two lines. and in the fourth line, they carry out this operation on stack pointer "stwu r0,-64(r1)" Instruction does the following. => Effective address(EA) r1-64 => EA is stored in stack pointer(r1) => value at the effective address is cleared to zero.

Why should the stack pointer will now hold the address given by EA.?

Any guess?

Reply to
Mohan kumar

Op Thu, 26 Jun 2008 01:10:21 -0500 schreef Mohan kumar:

Wrong. EA is nowhere stored

No guess, EA is only used to determine the address where the value of r0 is to be stored.

--
Coos
Reply to
Coos Haak

They clear r0 to zero and store that value at a location of -64 relative to the stack pointer. It looks to me like that location is the place in the stack frame where a pointer to the (non-existent) parent stack frame should go, so that's where they are putting the zero/null value to indicate that there is no parent.

Reply to
cs_posting

Are you certain of that? It appears to do nothing. ANDI r0,r0,0 would clear R0.

Reply to
Everett M. Greene

I'm not quite sure what the first line does that persists, but the second line loads r1 with the sum of r11 (probably some base register) and a constant displacement named "stackstart".

The third line clears r0 as you said

And the fourth line stores this value of 0 at -64 relative to the value having something to do with "stackstart" that was loaded into r1.

So yeah, I think it's initializing some part of the stack frame to zero, probably the pointer to a non-existent previous stack frame.

Storing things at small constant offsets from the stack pointer is a favorite habit of compilers... you see instructions to this effect all the time, on all sorts of processors. Keeping track of those offsets especially in relation to a stack pointer that may change during your procedure is a royal pain to do when coding assembly by hand, but very easy for a compiler.

Reply to
cs_posting

Yes, it is; the calculated value of EA is loaded into r1. See here:

formatting link
tml

Wrong. See link above.

--
John B
Reply to
John B

Op 27 Jun 2008 11:57:42 GMT schreef John B:

I didn't know the instruction set of the Power PC, obviously. Some time ago I searched for it, but to no avail. Now I know that u stands for update. Thank you!

--
Coos
Reply to
Coos Haak

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.