[cgen-ibld-dis] fill_cache vs variable sized opcodes

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

[cgen-ibld-dis] fill_cache vs variable sized opcodes

DJ Delorie-2

M32C opcodes range from one to ten bytes long, so occasionally
fill_cache would attempt to read a "word" that extended beyond the end
of the memory segment, and would fail (this shows up with "objdump
-d").

There was already a partial test for this, but it didn't account for
opcodes longer than a word.  This patch changes the logic to account
for both short opcodes and long-but-not-whole-words opcodes, although
it uses "min_insn_bitsize < base_insn_bitsize" as a generic test for
"variable length opcodes".

Ok?

        * cgen-ibld.in (extract_normal): Avoid memory range errors.

Index: cgen-ibld.in
===================================================================
RCS file: /cvs/src/src/opcodes/cgen-ibld.in,v
retrieving revision 1.18
diff -p -U3 -r1.18 cgen-ibld.in
--- cgen-ibld.in 1 Jul 2005 11:16:31 -0000 1.18
+++ cgen-ibld.in 7 Dec 2005 22:12:46 -0000
@@ -440,9 +440,8 @@ extract_normal (CGEN_CPU_DESC cd,
      word_length may be too big.  */
   if (cd->min_insn_bitsize < cd->base_insn_bitsize)
     {
-      if (word_offset == 0
-  && word_length > total_length)
- word_length = total_length;
+      if (word_offset + word_length > total_length)
+ word_length = total_length - word_offset;
     }
 
   /* Does the value reside in INSN_VALUE, and at the right alignment?  */


Reply | Threaded
Open this post in threaded view
|

Re: [cgen-ibld-dis] fill_cache vs variable sized opcodes

Nick Clifton
Hi DJ,

> * cgen-ibld.in (extract_normal): Avoid memory range errors.

Approved - please apply.

Cheers
   Nick

Reply | Threaded
Open this post in threaded view
|

Re: [cgen-ibld-dis] fill_cache vs variable sized opcodes

DJ Delorie-2

> > * cgen-ibld.in (extract_normal): Avoid memory range errors.
>
> Approved - please apply.

Done.  Note that there's a second place where this logic is used
(insert_normal), but I couldn't guarantee that the change was valid
for that case, so I left it alone.

That, and it hasn't bitten me yet ;-)