Bug 2829 - bad disassembly for 0xC7 /1 "movl $___,"
Summary: bad disassembly for 0xC7 /1 "movl $___,"
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: binutils (show other bugs)
Version: 2.18
: P2 minor
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-06-23 15:06 UTC by Jan Kratochvil
Modified: 2006-07-15 16:33 UTC (History)
2 users (show)

See Also:
Host: i686-pc-linux-gnu
Target: i686-pc-linux-gnu
Build: i686-pc-linux-gnu
Last reconfirmed:


Attachments
libopcodes CVS version patch (770 bytes, patch)
2006-06-23 15:07 UTC, Jan Kratochvil
Details | Diff
A patch (605 bytes, patch)
2006-07-14 23:28 UTC, H.J. Lu
Details | Diff
Source for the testcase (99 bytes, text/plain)
2006-07-15 07:09 UTC, Jan Kratochvil
Details
Testcase output from original unpatched objdump (225 bytes, text/plain)
2006-07-15 07:09 UTC, Jan Kratochvil
Details
Testcase output from patched objdump by the H.J.Lu patch (404 bytes, text/plain)
2006-07-15 07:11 UTC, Jan Kratochvil
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Jan Kratochvil 2006-06-23 15:06:24 UTC
John Reiser:
On x86, the byte sequence {0xc7,0310,1,2,3,4} superficially looks like "move
immediate to r/m dword" because of the opcode 0xC7.  Actually, it is an illegal
instruction because 0!=(070 & mod_rm); namely, the 0310 should be 0300.  Gdb
disassembly should report illegal instruction, but instead says "movl
$0x4030201,%eax".

Please see the original post:
https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=172034

Steps to Reproduce:
1. Compile and run this program under gdb:
-----foo.S
_start: .globl _start
        nop; int3
        .byte 0xc7,0310,1,2,3,4
        nop; nop
-----
$ gcc -o foo -nostartfiles -nostdlib foo.S
$ gdb foo
(gdb) run
2.
3.
  

Actual Results:  Program received signal SIGTRAP, Trace/breakpoint trap.   ## as
expected for 'int3'
0x08048076 in _start ()
(gdb) x/i $pc
0x8048076 <_start+2>:   mov    $0x4030201,%eax   ## gdb says it's OK
(gdb) stepi

Program received signal SIGILL, Illegal instruction.   ## CPU rejects
0x08048076 in _start ()
0x8048076 <_start+2>:   mov    $0x4030201,%eax
(gdb)


Expected Results:  Program received signal SIGTRAP, Trace/breakpoint trap.
0x08048076 in _start ()
(gdb) x/i $pc
0x8048076 <_start+2>:   (bad)  ## modrm of 0310 is illegal for opcode 0xC7
Comment 1 Jan Kratochvil 2006-06-23 15:07:43 UTC
Created attachment 1117 [details]
libopcodes CVS version patch

https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=172034

See IA-32 Intel® Architecture Software Developer's Manual Volume 2B:
Instruction Set Reference, N-Z, page 434 (of 582),
http://download.intel.com/design/Pentium4/manuals/25366719.pdf
Opcodes 0xC6 and 0xC7 do not have ('reg' (Bits 5,4,3) != 0) defined.
Comment 2 H.J. Lu 2006-07-14 23:28:37 UTC
Created attachment 1164 [details]
A patch

Can you try this patch instead?
Comment 3 Jan Kratochvil 2006-07-15 07:09:14 UTC
Created attachment 1166 [details]
Source for the testcase
Comment 4 Jan Kratochvil 2006-07-15 07:09:55 UTC
Created attachment 1167 [details]
Testcase output from original unpatched objdump
Comment 5 Jan Kratochvil 2006-07-15 07:11:40 UTC
Created attachment 1168 [details]
Testcase output from patched objdump by the H.J.Lu patch

Your patch works fine while done the right way, thanks.
Comment 6 H.J. Lu 2006-07-15 16:33:45 UTC
Fixed.