This is the mail archive of the binutils@sources.redhat.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: how to calculate opcode mask


Shinpei Kato <shinny@j02.itscom.net> writes:

> > The mask picks out the fixed bits in the instruction.  Any instruction
> > for which
> >     (insn & 0xfc0007ff) == 0x20
> > is the add instruction.
> > 
> > The assembler does not use the mask field in any significant way.  It
> > is the disassembler which uses the mask field.  It uses it to decide
> > which instruction it is looking at.
> > 
> > 0xfc0007ff is closely related to "d,v,t", because the assembler will
> > use those codes to fill in the bits which are zero in 0xfc0007ff.  The
> > letter codes are defined in include/opcode/mips.h.  But I don't think
> > there is a one-to-one mapping between letter codes and the mask.
> 
> I see. I couldn't get it by myself. But I need the mask after all, don't
> I? Sorry for my weak brain, I can't still understand how I can set up
> the mask.
> I don't think I can't find answer 0xfc0007ff with macros in
> include/opcode/mips.h, though... How can I?

You need the mask if you want the disassembler to recognize the
instructions which you are adding.

The mask follows from the definition of the instruction.  Any
instruction has some fixed bits which define the instruction.  Most
but not all instructions have some variable bits which are register
numbers, immediate values, etc.  The mask is simply the fixed bits
which define the instruction.

I can translate d,v,t into a mask by looking at the definitions in
include/opcode/mips.h, and doing
    ~ ((OP_MASK_RD << OP_SH_RD)
       | (OP_MASK_RS << OP_SH_RS)
       | (OP_MASK_RT << OP_SH_RT))
As I said, though, that approach doesn't always work for all
instructions.

> And could I ask one more question?
> There are several shift counters for registers such as OP_SH_FT,
> OP_SH_FS, etc. Maybe these are used to set up a next register number, I
> suppose. 

Those are shift counts for fields within an instruction.

> Then, how these shift counters are decided? If I want to change the
> number of the registers, for example changing the floating-point regs
> number to 8 from 32, do I have to change the shift counters? If so, how
> do I do it?

Hmmm.  To change the number of registers you need to define new fields
within the instruction, and you need to write new code to set those
fields.  Note that you are asking about MIPS, and the MIPS chip
already has 32 floating point registers.

Ian


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]