All of lore.kernel.org
 help / color / mirror / Atom feed
* Immediate branch offset
@ 2013-06-07 10:34 Alexis BRENON
  2013-06-07 16:25 ` David Daney
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Alexis BRENON @ 2013-06-07 10:34 UTC (permalink / raw)
  To: linux-mips

Hi everyone,

I'm new on the list, so I'll make a short introduction of me.
First of all, I'm french, so, please, be indulgent for my english 
mistakes...
I'm working on the Pypy project, to create a MIPS backend (a MIPS JIT).

To create the JIT, I have to load some MIPS instruction directly in 
memory without passing through a .asm file or else. So, I cannot set 
some labels. So to make some branches, I try to load the equivalent 
instruction of :
     bne $t0, $t1, -8
to go back, just before the bne instruction, if $t0 and $t1 are equals. 
But when it run, I've got an illegal instruction error.
To debug, I write a small program in the MARS MIPS simulator with this 
instruction. But when compiling, assembler says me that -8 is an operand 
of incorrect type.
I would like to know if it's possible to make a branch, with an 
immediate offset, or have I to always provide a label ?

I hope my question is clear.
Thanks for your attention, and for your answer :-p

Alexis BRENON

P.S. I try to go to the IRC channel, but I receive '#mipslinux :Cannot 
send to channel' every time  I send message. Is there any particular 
process to join the channel ?

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

* Re: Immediate branch offset
  2013-06-07 10:34 Immediate branch offset Alexis BRENON
@ 2013-06-07 16:25 ` David Daney
  2013-06-09 14:43 ` Maciej W. Rozycki
  2013-06-19  9:11 ` Ralf Baechle
  2 siblings, 0 replies; 7+ messages in thread
From: David Daney @ 2013-06-07 16:25 UTC (permalink / raw)
  To: Alexis BRENON; +Cc: linux-mips

On 06/07/2013 03:34 AM, Alexis BRENON wrote:
> Hi everyone,
>
> I'm new on the list, so I'll make a short introduction of me.
> First of all, I'm french, so, please, be indulgent for my english
> mistakes...
> I'm working on the Pypy project, to create a MIPS backend (a MIPS JIT).
>
> To create the JIT, I have to load some MIPS instruction directly in
> memory without passing through a .asm file or else. So, I cannot set
> some labels. So to make some branches, I try to load the equivalent
> instruction of :
>      bne $t0, $t1, -8
> to go back, just before the bne instruction, if $t0 and $t1 are equals.
> But when it run, I've got an illegal instruction error.
> To debug, I write a small program in the MARS MIPS simulator with this
> instruction. But when compiling, assembler says me that -8 is an operand
> of incorrect type.


Dump out your program so you can disassemble it with objdump -d (or 
dissassemble it with gdb)  And verify that the code looks good.

David Daney


> I would like to know if it's possible to make a branch, with an
> immediate offset, or have I to always provide a label ?
>
> I hope my question is clear.
> Thanks for your attention, and for your answer :-p
>
> Alexis BRENON
>
> P.S. I try to go to the IRC channel, but I receive '#mipslinux :Cannot
> send to channel' every time  I send message. Is there any particular
> process to join the channel ?
>
>
>

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

* Re: Immediate branch offset
  2013-06-07 10:34 Immediate branch offset Alexis BRENON
  2013-06-07 16:25 ` David Daney
@ 2013-06-09 14:43 ` Maciej W. Rozycki
  2013-06-10  7:18   ` Alexis BRENON
  2013-06-19  9:11 ` Ralf Baechle
  2 siblings, 1 reply; 7+ messages in thread
From: Maciej W. Rozycki @ 2013-06-09 14:43 UTC (permalink / raw)
  To: Alexis BRENON; +Cc: linux-mips

On Fri, 7 Jun 2013, Alexis BRENON wrote:

> To create the JIT, I have to load some MIPS instruction directly in memory
> without passing through a .asm file or else. So, I cannot set some labels. So
> to make some branches, I try to load the equivalent instruction of :
>     bne $t0, $t1, -8
> to go back, just before the bne instruction, if $t0 and $t1 are equals. But
> when it run, I've got an illegal instruction error.

 Please note that BNE means Branch-if-Not-Equal, your quoted instruction
will jump backwards if $t0 and $t1 are *not* equal.

> To debug, I write a small program in the MARS MIPS simulator with this
> instruction. But when compiling, assembler says me that -8 is an operand of
> incorrect type.

 The instruction you quoted assembles for me successfully, what version of 
binutils do you use and what exact error message do you get?

 Please note however that this instruction is not what I understand you 
need -- it is treated as a branch to the absolute address -8 (0xfffffff8 
in the o32 ABI), rather than 8 bytes back (there's an off-by-four bug in 
GAS here too making it jump to -4 instead, and some other issues; I'll see 
if I can get them fixed sometime -- see the discussion around 
http://sourceware.org/ml/binutils/2012-09/msg00288.html if interested in 
the gory details).

 If you want to jump to the instruction immediately preceding the branch 
and avoid a label (assuming the standard MIPS ISA), use:

	bne	$t0, $t1, . - 4

-- "." is a special "the address of this instruction" designator (see the 
GAS manual for further information), so this produces the machine 
instruction you require (the jump is calculated as relative to the next 
instruction -- that is (. + 4) -- so the ultimate effective (i.e. shifted 
rather than as encoded in the instruction's 16-bit immediate operand 
field) offset is -8).

$ cat foo.s
	bne	$t0, $t1, . - 4
$ mips-linux-as -o foo.o foo.s
$ mips-linux-objdump -dr foo.o

foo.o:     file format elf32-tradbigmips


Disassembly of section .text:

00000000 <.text>:
   0:	1509fffe 	bne	t0,t1,0xfffffffc
   4:	00000000 	nop
	...
$ mips-linux-as --version
GNU assembler (GNU Binutils) 2.23.2
[...]

Likewise with the current binutils trunk.

 I hope this helps.

  Maciej

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

* Re: Immediate branch offset
  2013-06-09 14:43 ` Maciej W. Rozycki
@ 2013-06-10  7:18   ` Alexis BRENON
  2013-06-10 18:26     ` Maciej W. Rozycki
  0 siblings, 1 reply; 7+ messages in thread
From: Alexis BRENON @ 2013-06-10  7:18 UTC (permalink / raw)
  To: Maciej W. Rozycki; +Cc: linux-mips

Le 09/06/2013 16:43, Maciej W. Rozycki a écrit :
> On Fri, 7 Jun 2013, Alexis BRENON wrote:
>
>> To create the JIT, I have to load some MIPS instruction directly in memory
>> without passing through a .asm file or else. So, I cannot set some labels. So
>> to make some branches, I try to load the equivalent instruction of :
>>      bne $t0, $t1, -8
>> to go back, just before the bne instruction, if $t0 and $t1 are equals. But
>> when it run, I've got an illegal instruction error.
>   Please note that BNE means Branch-if-Not-Equal, your quoted instruction
> will jump backwards if $t0 and $t1 are *not* equal.
>

Yes, sorry, it's just a typing mistake, since I tried with all branch 
instructions.

>> To debug, I write a small program in the MARS MIPS simulator with this
>> instruction. But when compiling, assembler says me that -8 is an operand of
>> incorrect type.
>   The instruction you quoted assembles for me successfully, what version of
> binutils do you use and what exact error message do you get?

I didn't try to assemble it, but only to run it in the MARS simulator. 
If I assemble it with GNU AS, it assembles successfully.

>   Please note however that this instruction is not what I understand you
> need -- it is treated as a branch to the absolute address -8 (0xfffffff8
> in the o32 ABI), rather than 8 bytes back (there's an off-by-four bug in
> GAS here too making it jump to -4 instead, and some other issues; I'll see
> if I can get them fixed sometime -- see the discussion around
> http://sourceware.org/ml/binutils/2012-09/msg00288.html if interested in
> the gory details).
>
>   If you want to jump to the instruction immediately preceding the branch
> and avoid a label (assuming the standard MIPS ISA), use:
>
> 	bne	$t0, $t1, . - 4
>
> -- "." is a special "the address of this instruction" designator (see the
> GAS manual for further information), so this produces the machine
> instruction you require (the jump is calculated as relative to the next
> instruction -- that is (. + 4) -- so the ultimate effective (i.e. shifted
> rather than as encoded in the instruction's 16-bit immediate operand
> field) offset is -8).
>
> $ cat foo.s
> 	bne	$t0, $t1, . - 4
> $ mips-linux-as -o foo.o foo.s
> $ mips-linux-objdump -dr foo.o
>
> foo.o:     file format elf32-tradbigmips
>
>
> Disassembly of section .text:
>
> 00000000 <.text>:
>     0:	1509fffe 	bne	t0,t1,0xfffffffc
>     4:	00000000 	nop
> 	...
> $ mips-linux-as --version
> GNU assembler (GNU Binutils) 2.23.2
> [...]
>
> Likewise with the current binutils trunk.
>
>   I hope this helps.
>
>    Maciej

I downloaded MIPS32 Architecture For Programmers Volume II: The MIPS32 
Instruction Set. If you read the BNE-BEQ-B... description it says :

     Purpose:
To compare GPRs then do a PC-relative conditional branch

	Description: if rs = rt then branch
An 18-bit signed offset (the 16-bit offset field shifted left 2 bits) is added to the address of the instruction
following the branch (not the branch itself), in the branch delay slot, to form a PC-relative effective target
address.

It says that it's a PC-relative jump, the offset is added to the PC 
value, and not a absolute jump as the J instruction. Nevertheless, I try 
to type this :

loop:
         addiu $v0, $v0, 1
         bne $v0, $t1, .-4


or this :

loop:
         addiu $v0, $v0, 1
         bne $v0, $t1, -8

In both cases, the objdump command says me :

    8:   24420001        addiu   v0,v0,1
    c:   1449fffe        bne     v0,t1,8 <loop>
   10:   00000000        nop

It seems to be equivalent.

Thanks for your answer.
Friendly,
Alexis BRENON

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

* Re: Immediate branch offset
  2013-06-10  7:18   ` Alexis BRENON
@ 2013-06-10 18:26     ` Maciej W. Rozycki
  0 siblings, 0 replies; 7+ messages in thread
From: Maciej W. Rozycki @ 2013-06-10 18:26 UTC (permalink / raw)
  To: Alexis BRENON; +Cc: linux-mips

On Mon, 10 Jun 2013, Alexis BRENON wrote:

> > > To debug, I write a small program in the MARS MIPS simulator with this
> > > instruction. But when compiling, assembler says me that -8 is an operand
> > > of
> > > incorrect type.
> >   The instruction you quoted assembles for me successfully, what version of
> > binutils do you use and what exact error message do you get?
> 
> I didn't try to assemble it, but only to run it in the MARS simulator. If I
> assemble it with GNU AS, it assembles successfully.

 So what assembler have you been referring to above?

  Maciej

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

* Re: Immediate branch offset
  2013-06-07 10:34 Immediate branch offset Alexis BRENON
  2013-06-07 16:25 ` David Daney
  2013-06-09 14:43 ` Maciej W. Rozycki
@ 2013-06-19  9:11 ` Ralf Baechle
  2013-06-19 10:56   ` Ralf Baechle
  2 siblings, 1 reply; 7+ messages in thread
From: Ralf Baechle @ 2013-06-19  9:11 UTC (permalink / raw)
  To: Alexis BRENON; +Cc: linux-mips

On Fri, Jun 07, 2013 at 12:34:33PM +0200, Alexis BRENON wrote:

> P.S. I try to go to the IRC channel, but I receive '#mipslinux
> :Cannot send to channel' every time  I send message. Is there any
> particular process to join the channel ?

A particular Freenode nuisance.  You need to register and identify with
nickserv to be able to send to a channel or other users.

This is a common problem and I'd be happy to disable this "feature" for
#mipslinux if there was a way to do so.

  Ralf

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

* Re: Immediate branch offset
  2013-06-19  9:11 ` Ralf Baechle
@ 2013-06-19 10:56   ` Ralf Baechle
  0 siblings, 0 replies; 7+ messages in thread
From: Ralf Baechle @ 2013-06-19 10:56 UTC (permalink / raw)
  To: Alexis BRENON; +Cc: linux-mips

On Wed, Jun 19, 2013 at 11:11:44AM +0200, Ralf Baechle wrote:

> On Fri, Jun 07, 2013 at 12:34:33PM +0200, Alexis BRENON wrote:
> 
> > P.S. I try to go to the IRC channel, but I receive '#mipslinux
> > :Cannot send to channel' every time  I send message. Is there any
> > particular process to join the channel ?
> 
> A particular Freenode nuisance.  You need to register and identify with
> nickserv to be able to send to a channel or other users.
> 
> This is a common problem and I'd be happy to disable this "feature" for
> #mipslinux if there was a way to do so.

Shouting to a mailing list sometimes helps :)  The problem should be
fixed now.  Let's hope irc abusers don't force us into reenabling this
inconvenient feature.

  Ralf

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

end of thread, other threads:[~2013-06-19 10:56 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-06-07 10:34 Immediate branch offset Alexis BRENON
2013-06-07 16:25 ` David Daney
2013-06-09 14:43 ` Maciej W. Rozycki
2013-06-10  7:18   ` Alexis BRENON
2013-06-10 18:26     ` Maciej W. Rozycki
2013-06-19  9:11 ` Ralf Baechle
2013-06-19 10:56   ` Ralf Baechle

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.