Hi all, Below code is part of powerpc 555 boot up code, could any one explain, why 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.
Could any one clarify the below codes.
Started by ●June 25, 2008
Reply by ●June 25, 20082008-06-25
On Jun 25, 7:22 am, "Mohan kumar" <mohankumar_be...@yahoo.co.in> wrote:> Below code is part of powerpc 555 boot up code, could any one explain, why > stack is terminated by "stwu r0,-64(r1)">addi r0,r0,0 # Clear r0. >stwu r0,-64(r1) # Terminate stack.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 by ●June 26, 20082008-06-26
Hi thanks for your reply, the puzzling question that rocks my mind is why should they terminate the 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 by ●June 26, 20082008-06-26
Op Thu, 26 Jun 2008 01:10:21 -0500 schreef Mohan kumar:> Hi thanks for your reply, > > the puzzling question that rocks my mind is why should they terminate the > 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)Wrong. EA is nowhere stored> => value at the effective address is cleared to zero. > > Why should the stack pointer will now hold the address given by EA.? > > Any guess?No guess, EA is only used to determine the address where the value of r0 is to be stored. -- Coos
Reply by ●June 26, 20082008-06-26
On Jun 26, 2:10 am, "Mohan kumar" <mohankumar_be...@yahoo.co.in> wrote:> the puzzling question that rocks my mind is why should they terminate the > stack by subtracting 64 with the stack pointer(r1)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 by ●June 26, 20082008-06-26
"Mohan kumar" <mohankumar_beece@yahoo.co.in> writes:> Hi thanks for your reply, > > the puzzling question that rocks my mind is why should they terminate the > 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.Are you certain of that? It appears to do nothing. ANDI r0,r0,0 would clear 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 by ●June 26, 20082008-06-26
On Jun 26, 11:13 am, moja...@mojaveg.lsan.mdsg-pacwest.com (Everett M. Greene) wrote:> "Mohan kumar" <mohankumar_be...@yahoo.co.in> writes: > > Hi thanks for your reply, > > > the puzzling question that rocks my mind is why should they terminate the > > 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. > > Are you certain of that? It appears to do nothing. > ANDI r0,r0,0 would clear R0.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 by ●June 27, 20082008-06-27
On 26/06/2008 Coos Haak wrote:> Op Thu, 26 Jun 2008 01:10:21 -0500 schreef Mohan kumar: > > > Hi thanks for your reply, > > > > the puzzling question that rocks my mind is why should they > > terminate the 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) > Wrong. EA is nowhere storedYes, it is; the calculated value of EA is loaded into r1. See here: http://pds.twi.tudelft.nl/vakken/in1200/labcourse/instruction-set/stwu.h tml> > => value at the effective address is cleared to zero. > > > > Why should the stack pointer will now hold the address given by EA.? > > > > Any guess?> No guess, EA is only used to determine the address where the value of > r0 is to be stored.Wrong. See link above. -- John B
Reply by ●June 27, 20082008-06-27
Op 27 Jun 2008 11:57:42 GMT schreef John B:> On 26/06/2008 Coos Haak wrote: > >> Op Thu, 26 Jun 2008 01:10:21 -0500 schreef Mohan kumar: >> >>> Hi thanks for your reply, >>> >>> the puzzling question that rocks my mind is why should they >>> terminate the 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) >> Wrong. EA is nowhere stored > > Yes, it is; the calculated value of EA is loaded into r1. See here: > > http://pds.twi.tudelft.nl/vakken/in1200/labcourse/instruction-set/stwu.h > tml > >>> => value at the effective address is cleared to zero. >>> >>> Why should the stack pointer will now hold the address given by EA.? >>> >>> Any guess? > >> No guess, EA is only used to determine the address where the value of >> r0 is to be stored. > > Wrong. See link above.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