This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB 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: [PATCH v3 2/2] Check thumb2 load/store and cache hit addressing mode


On Tue, 2018-10-02 at 13:39 -0400, Simon Marchi wrote:
> This is a bit out of my comfort zone.  I'm reading the code with the 
> reference manual on the side, and don't see the mapping.  I'd prefer if 
> somebody from ARM took a look.  In the mean time, could you point me to 
> the relevant sections in the manual for this patch?

Most useful reference I've found is a file named Thumb-
2SupplementReferenceManual.pdf, easily located via google.  Section
3.3.3 describes all possible "Load and store single data item, and
memory hints" thumb2 instructions.  The figure there made it easy to
come up with a decision tree to arrive at which valid encoding, if any,
was in use.

> > +
> > +  switch (bits (thumb2_insn_r->arm_insn, 8, 10))
> > +    {
> > +      case 0x4:
> > +	return 3; /* Rn - imm8 */
> > +      case 0x6:
> > +	return 4; /* Rn + imm8, User privilege */
> > +      case 0x1:
> > +      case 0x3:
> > +	return 5; /* Rn post-indexed by +/- imm8 */
> > +      case 0x5:
> > +      case 0x7:
> > +	return 6; /* Rn pre-indexed by +/- imm8 */
> > +      default:
> > +	return -1; /* reserved */
> 
> Do these modes have names?  Could we define an enum instead of using 
> magic numbers?

No official names that I know of.  The numbers appear in a table
listing all possible instruction formats in the document I described
above.  E.g. "LDR, LDRB, ..., (immediate offset)" must use format 2. 
"PLI, PLD" may use 1, 2, 3, or 7.  And so on.  The comments I added by
each return statement are how the format is described.

I could condense the logic in this function to one that returns a
boolean, based on if the current version would return 1,2,3,7 or not. 
Basically, make it check solely for a valid PLD/PLI instruction.  But
since the format being decoded here is common to the other
instructions, this lets me enhance the decoding of them too.  And the
code is easier to follow if it's more directly analogous to the
documentation, which is clearly part of the design of the existing
recording code.  It's not a coincidence that thumb2_record_ld_mem_hints
records every instruction appearing in exactly one section of the
reference manual.

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