linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* Question about powerpc branch instructions
@ 2009-08-07  8:47 HongWoo Lee
  2009-08-07  8:52 ` Benjamin Herrenschmidt
  2009-08-07 19:37 ` Scott Wood
  0 siblings, 2 replies; 3+ messages in thread
From: HongWoo Lee @ 2009-08-07  8:47 UTC (permalink / raw)
  To: linuxppc-dev

Hi~

I want to know about bl instruction and the difference between branch 
instructions.
I found this code segment.

{{{
....
bl  go_to_real
insrdi  r18, r19, 32, 0
....
}}}

And I found the explanation about branch instructions in PowerISA 2.06 
document.

{{{
b target_addr (AA=0 LK=0)
ba target_addr (AA=1 LK=0)
bl target_addr (AA=0 LK=1)
bla target_addr (AA=1 LK=1)

If AA=0 then the branch target address is the sum of LI || 0b00 
sign-extended and the address of this instruction,
with the high-order 32 bits of the branch target address set to 0 in 
32-bit mode.

If AA=1 then the branch target address is the value LI || 0b00 
sign-extended,
with the high-order 32 bits of the branch target address set to 0 in 
32-bit mode.

If LK=1 then the effective address of the instruction following the 
Branch instruction is placed into the Link Register.
}}}

Questions
#1: Is there any special reason to concatenate 0b00 ?  Why 0b00 ??
#2: Is b similar to the jmp in x86 ? and bl is similar to the call in x86 ?

Thanks in advance.

HongWoo.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Question about powerpc branch instructions
  2009-08-07  8:47 Question about powerpc branch instructions HongWoo Lee
@ 2009-08-07  8:52 ` Benjamin Herrenschmidt
  2009-08-07 19:37 ` Scott Wood
  1 sibling, 0 replies; 3+ messages in thread
From: Benjamin Herrenschmidt @ 2009-08-07  8:52 UTC (permalink / raw)
  To: HongWoo Lee; +Cc: linuxppc-dev

On Fri, 2009-08-07 at 17:47 +0900, HongWoo Lee wrote:

> #1: Is there any special reason to concatenate 0b00 ?  Why 0b00 ??

Because instructions have to be aligned on 4 bytes boundaries ?

> #2: Is b similar to the jmp in x86 ? and bl is similar to the call in x86 ?

I'm not totally familiar with x86 but I "sounds" like it, though of
course they can be (ab)used in some more subtle ways.

Cheers,
Ben.

> Thanks in advance.
> 
> HongWoo.
> _______________________________________________
> Linuxppc-dev mailing list
> Linuxppc-dev@lists.ozlabs.org
> https://lists.ozlabs.org/listinfo/linuxppc-dev

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Question about powerpc branch instructions
  2009-08-07  8:47 Question about powerpc branch instructions HongWoo Lee
  2009-08-07  8:52 ` Benjamin Herrenschmidt
@ 2009-08-07 19:37 ` Scott Wood
  1 sibling, 0 replies; 3+ messages in thread
From: Scott Wood @ 2009-08-07 19:37 UTC (permalink / raw)
  To: HongWoo Lee; +Cc: linuxppc-dev

On Fri, Aug 07, 2009 at 05:47:00PM +0900, HongWoo Lee wrote:
> #2: Is b similar to the jmp in x86 ? 

Yes, specifically a relative near jmp.

> and bl is similar to the call in x86 ?

Sort of (and again, specifically a relative near call).  Call on x86
pushes the return address on the stack, while bl on powerpc puts the
return address in a special register (lr) that the called function has to
save on the stack itself if it wants to call another function.

-Scott

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2009-08-07 19:38 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-08-07  8:47 Question about powerpc branch instructions HongWoo Lee
2009-08-07  8:52 ` Benjamin Herrenschmidt
2009-08-07 19:37 ` Scott Wood

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).